index.tsx
20 lines
| 1 | import styles from './style.module.scss'; |
| 2 | |
| 3 | interface ToggleSwitchProps { |
| 4 | onChange: React.Dispatch<React.SetStateAction<boolean>>; |
| 5 | checked: boolean; |
| 6 | ariaLabel?: string; |
| 7 | } |
| 8 | |
| 9 | const ToggleSwitch = ({ariaLabel, checked, onChange}: ToggleSwitchProps) => { |
| 10 | return ( |
| 11 | <label className={styles.container}> |
| 12 | <input type="checkbox" aria-label={ariaLabel} checked={checked} onChange={() => onChange(!checked)} /> |
| 13 | <span className={styles.switch} /> |
| 14 | <span>{ariaLabel && ariaLabel}</span> |
| 15 | </label> |
| 16 | ); |
| 17 | }; |
| 18 | |
| 19 | export default ToggleSwitch; |
| 20 |