Button.jsx 1.1 KB

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