Button.tsx 1002 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React from 'react';
  2. import './button.css';
  3. interface ButtonProps {
  4. /**
  5. * Is this the principal call to action on the page?
  6. */
  7. primary?: boolean;
  8. /**
  9. * What background color to use
  10. */
  11. backgroundColor?: string;
  12. /**
  13. * How large should the button be?
  14. */
  15. size?: 'small' | 'medium' | 'large';
  16. /**
  17. * Button contents
  18. */
  19. label: string;
  20. /**
  21. * Optional click handler
  22. */
  23. onClick?: () => void;
  24. }
  25. /**
  26. * Primary UI component for user interaction
  27. */
  28. export const Button = ({
  29. primary = false,
  30. size = 'medium',
  31. backgroundColor,
  32. label,
  33. ...props
  34. }: ButtonProps) => {
  35. const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
  36. return (
  37. <button
  38. type="button"
  39. className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
  40. {...props}
  41. >
  42. {label}
  43. <style jsx>{`
  44. button {
  45. background-color: ${backgroundColor};
  46. }
  47. `}</style>
  48. </button>
  49. );
  50. };