Button.js 516 B

123456789101112131415161718192021
  1. import './button.css';
  2. export const createButton = ({
  3. primary = false,
  4. size = 'medium',
  5. backgroundColor,
  6. label,
  7. onClick,
  8. }) => {
  9. const btn = document.createElement('button');
  10. btn.type = 'button';
  11. btn.innerText = label;
  12. btn.addEventListener('click', onClick);
  13. const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
  14. btn.className = ['storybook-button', `storybook-button--${size}`, mode].join(' ');
  15. btn.style.backgroundColor = backgroundColor;
  16. return btn;
  17. };