Switch

On or off, and it happens now.

Default

One on, one off. Space flips the focused switch.

Use a switch when the change takes effect the moment it is flipped, and a checkbox when it only counts once the form is submitted. That is the whole difference, and readers feel it.

Installation

npx philcn@latest add switch

The file is written into your project. It is yours from then on — change it as you like.

Props

PropTypeWhat it does
Switch.checkedbooleanControlled: on or off.
Switch.defaultCheckedbooleanUncontrolled: how it starts.
Switch.onCheckedChange((checked: boolean) => void)Called with the new state on every flip.
Switch.disabledbooleanOut of reach, and out of the tab order.

Types are read from the library itself, so this table cannot describe an option the code no longer has.