Switch
An on/off control, monochrome: an ink track when on; with a visible label the whole row toggles.
import { Switch } from "@arcadia/ui"Monochrome: on is an ink track with a page-coloured knob (white and night at night, night ink and white by day), never green. The knob comes to rest on the release spring (--ease-release, 280ms, a slight settle past its stop) and the track colour changes in 150ms. With a visible label the whole row is the click target, and className and style land on that row.
Examples
rootStyle takes where the switch sits (margins, self-alignment, flex and grid placement, size bounds) and the knobs below, each a token of its kind. A colour, a raw length or any other property is a type error: a look that comes up twice becomes a variant.
| Knob | Takes | Default | Sets |
|---|---|---|---|
Paint | var(--fill-2) | Track fill when off. | |
Paint | var(--fill-1) | Track fill when off, under the pointer (on the track or its label row). | |
Paint | var(--bg-inverse) | Track fill when on. | |
Paint | var(--bg-app) | Knob fill when on. |
rootStyle lands on the outermost element: the label row, or the track with hideLabel. The knobs live there too, so hovering the row lights the track.
A switch role with aria-checked; the label and the description are wired to it by id, so it reads "Tips, switch, on, Show a rotating tip on the empty screen". label is required, even with hideLabel. When a switch is disabled, say why in its description, as Completion sound does above.
- Space
- Toggles the switch
- Tab
- Moves to the next control
Switch
checked- boolean
- Controlled state.
defaultChecked- booleanDefaultfalse
- Initial state when uncontrolled.
onCheckedChange- (checked: boolean, details: { event: Event }) => void
- Called with the new state when the switch toggles.
readOnly- boolean
- Shown but not changeable (
aria-readonly). labelrequired- ReactNode
- Required. Rendered as the row label, or as
aria-labelwithhideLabel(then pass a string). description- ReactNode
- Secondary line under the label (text-3).
hideLabel- boolean
- Render only the track; the label becomes its accessible name.
size- "sm" | "md"Default"md"
md: 32×20 with a 16px knob, for settings.sm: 26×16 with a 12px knob, for menu rows.rootStyle- SwitchStyle
- Typed StyleX override on the outermost element (the label row, or the track with
hideLabel): layout and the--switch-*knobs. className- string
- A product's hook class on the outermost element, for its own layout rules. Being retired: new code places a switch with
rootStyle; the call sites left are counted by ui.lint (kit-classname) and only go down. disabled- boolean
- Dims the row and blocks toggling.
Rest props go to <button> props.