switch.tsx 631 B

123456789101112131415161718192021222324252627
  1. import classNames from 'classnames'
  2. type SwitchProps = {
  3. onChange: () => void
  4. checked: boolean
  5. disabled?: boolean
  6. }
  7. function Switch({ onChange, checked, disabled = false }: SwitchProps) {
  8. return (
  9. // eslint-disable-next-line jsx-a11y/label-has-associated-control
  10. <label className={classNames('switch-input', { disabled })}>
  11. <input
  12. className="invisible-input"
  13. type="checkbox"
  14. role="switch"
  15. autoComplete="off"
  16. onChange={onChange}
  17. checked={checked}
  18. disabled={disabled}
  19. />
  20. <span className="switch" />
  21. </label>
  22. )
  23. }
  24. export default Switch