Dot Switch
A pill of dots and a key for the knob. Flip it and the knob slides across with a little bounce while the accent dissolves into the track behind it, dot by dot, and out again when it's turned off; the knob stretches while it's pressed. A real checkbox with the switch role lies under it, so Space and screen readers work, and its label is a real label.
Needs: None. Canvas 2D over a native checkbox.
Customize
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | – | On or off. Leave unset to let the switch keep its own. |
| defaultChecked | boolean | false | On or off at first, when checked isn't set. |
| onChange | (checked: boolean) => void | – | Called with the new state when it's flipped. |
| children | ReactNode | – | The label beside it. Clicking it flips the switch too. |
| tone | string | – | The track's colour when on. The page's accent by default. |
| pitch | number | 3 | Size of one dot in px. The switch is 17 by 11 dots. |
| disabled | boolean | false | Can't be flipped. |
| label | string | – | For screen readers, when there's no visible label. |
| className | string | – | Class on the switch's label. |
| style | CSSProperties | – | Style on the switch's label. |