You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ToggleButton.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // @flow
  2. import React from 'react';
  3. import { Icon, IconCheck } from '../../../icons';
  4. const mainClass = 'toggle-button';
  5. type Props = {
  6. /**
  7. * Text of the button.
  8. */
  9. children: React$Node,
  10. /**
  11. * If the button is toggled or not.
  12. */
  13. isToggled?: boolean,
  14. /**
  15. * OnClick button handler.
  16. */
  17. onClick: Function
  18. }
  19. /**
  20. * Button used as a toggle.
  21. *
  22. * @returns {ReactElement}
  23. */
  24. function ToggleButton({ children, isToggled, onClick }: Props) {
  25. const className = isToggled ? `${mainClass} ${mainClass}--toggled` : mainClass;
  26. return (
  27. <div
  28. className = { className }
  29. onClick = { onClick }>
  30. <div className = 'toggle-button-container'>
  31. <div className = 'toggle-button-icon-container'>
  32. <Icon
  33. className = 'toggle-button-icon'
  34. size = { 10 }
  35. src = { IconCheck } />
  36. </div>
  37. <span>{children}</span>
  38. </div>
  39. </div>
  40. );
  41. }
  42. export default ToggleButton;