Switch
A control that allows the user to toggle between checked and not checked.
Switch — toggle iOS-style. Sémantiquement équivalent à un Checkbox mais visuellement plus adapté pour on/off d'une préférence (activer notifications, dark mode, feature flag).
Installation
$ bext ui add switch
Copy and paste the following into src/components/ui/switch.tsx.
This component is interactive — make sure the shared island is loaded (see Islands). It reacts to data-ui="switch" hooks.
Usage
Anatomy
<Switch id="sw-id" checked={boolean} />API Reference
Switch
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | — | undefined |
| checked | boolean | — | undefined |
| name | string | — | undefined |
| disabled | boolean | — | undefined |
Data Attributes
Attributs qu'on peut cibler en CSS custom pour override le style par état.
| Attribute | On | Values | Description |
|---|---|---|---|
| data-ui="switch" | root | — | Island toggle. |
| data-state | root | "checked" | "unchecked" | État actuel — anime le knob. |
Keyboard
| Key | Action |
|---|---|
| Space | Toggle. |
Accessibility
Devrait porter role="switch" aria-checked. Label associé recommandé.
Edit this component live in the bext playground. The PRISM + signals version is the bext-native idiom — fine-grained reactivity, no virtual DOM.
Pure PRISM + real bext signals — fine-grained, no re-render.
The React idiom — same UI, for comparison.
On This Page