Toggle
A two-state button that can be either on or off.
<Toggle aria-label="Toggle bold"><b>B</b></Toggle>
Toggle — bouton on/off à deux états (bold, italic, mute…). Différent de Switch qui représente un préférence "activer/désactiver ce feature" — Toggle est un mode d'affichage/formattage local.
Installation
$ bext ui add toggle
Copy and paste the following into src/components/ui/toggle.tsx.
<Toggle aria-label="Toggle bold"><b>B</b></Toggle>
This component is interactive — make sure the shared island is loaded (see Islands). It reacts to data-ui="toggle" hooks.
Usage
Anatomy
<Toggle pressed={boolean}>Content</Toggle>API Reference
Toggle
| Prop | Type | Default | Description |
|---|---|---|---|
| pressed | boolean | — | État initial pressé. |
| variant | "default" | "outline" | "default" | undefined |
| size | "sm" | "default" | "lg" | "default" | undefined |
| disabled | boolean | — | undefined |
| children | ReactNode | — | undefined |
Data Attributes
Attributs qu'on peut cibler en CSS custom pour override le style par état.
| Attribute | On | Values | Description |
|---|---|---|---|
| data-ui="toggle" | root | undefined | undefined |
| data-state | root | "on" | "off" | undefined |
Keyboard
| Key | Action |
|---|---|
| Space / Enter | Basculer on ↔ off. |
Accessibility
role="button" aria-pressed. Wrapper avec un aria-label explicite ("Toggle bold").
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