bx

Switch

A control that allows the user to toggle between checked and not checked.

tsx
<Switch id="airplane" />
<Label htmlFor="airplane">Airplane mode</Label>

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

Terminal
$ bext ui add switch

Usage

tsx
import { Switch, Label } from "@bext-stack/ui/primitives"

<div className="flex items-center gap-2">
  <Switch id="airplane" />
  <Label htmlFor="airplane">Airplane mode</Label>
</div>

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é.

Try it live
Open in play

Edit this component live in the bext playground. The PRISM + signals version is the bext-native idiom — fine-grained reactivity, no virtual DOM.

src/app/page.tsx 2 files · signals · runs in your browser
Pure PRISM + real bext signals — fine-grained, no re-render.