Components · Form Controls
Switch
StableAdded v0.0.1
Toggle control for binary on/off settings. Built on Radix UI Switch.
import { Switch } from '@nexub/react';Playground
Props
size
<Switch defaultChecked />Examples
Default
Sizes
States
defaultdisabledinvalidreadOnlyloadingcheckedsize="sm"size="md"size="lg"
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | — | Controlled checked state. |
| defaultChecked | boolean | false | Uncontrolled initial state. |
| onCheckedChange | (checked: boolean) => void | — | Callback when checked state changes. |
| disabled | boolean | false | Disables interaction. |
| size | 'sm' | 'md' | 'lg' | 'md' | Switch size. |
| checkedIcon | React.ReactNode | — | Small icon inside the thumb while on. |
| invalid | boolean | — | Error border on the track and aria-invalid. |
| loading | boolean | — | Spinner in the thumb and aria-busy; clicks don't toggle while loading. Stays focusable. |
| readOnly | boolean | — | Focusable but cannot toggle; sets aria-readonly. |
| uncheckedIcon | React.ReactNode | — | Small icon inside the thumb while off. |
Design tokens
Switch reads these component tokens. Each one is unset by default and falls back to the semantic role it aliases, so nothing changes until you set it. Set one on any element to restyle every Switch below it, and leave the roles other components share alone. See the three token tiers.
| Token | Aliases | Notes |
|---|---|---|
| --switch-track-on | --color-primary | — |
/* One area of your app */
.checkout {
--switch-track-on: var(--color-secondary);
}On iOS & Android: Switch
@nexub/react-nativeAlpha
import { Switch } from '@nexub/react-native';
<Switch label="Face ID" checked={on} onCheckedChange={setOn} />Web vs mobile
Same tokens and prop names. Where the platforms differ:
| Web | iOS & Android | |
|---|---|---|
| Look | Nexub switch. | The platform switch (UISwitch / Material) in Nexub colours. |
| Label | Compose Label + control + HelperText (or FormField). | One component: label, helperText and error are props. |
Interactive preview of @nexub/react-native rendered for the web. Native chrome (switches, pickers, Liquid Glass) looks like the platform on a device.
On device

iPhone (iOS simulator)

Pixel (Android emulator)
Screenshots from the latest CI run of the showcase app; the live frame renders the same code for the web.
Switch props
| Prop | Type | Default | Description |
|---|---|---|---|
| labelrequired | string | — | Accessible name (visible label lives in the ListItem / row next to it). |
| checked | boolean | — | — |
| defaultChecked | boolean | false | — |
| onCheckedChange | (checked: boolean) => void | — | — |
| disabled | boolean | — | — |
| loading | boolean | — | Spinner beside the switch and busy for screen readers; it can't toggle while loading. |
| invalid | boolean | — | Error colour on the track and announced as invalid. |
| readOnly | boolean | — | Can be focused and read but not toggled. |
| size | Extract<ControlSize, 'sm' | 'md' | 'lg'> | 'md' | md is the platform switch's own size; sm and lg scale it. |
| checkedIcon | React.ReactNode | — | Small icon inside the thumb while on. With an icon the Nexub-drawn switch is used, since the platform switch has no room for one. |
| uncheckedIcon | React.ReactNode | — | Small icon inside the thumb while off. Uses the Nexub-drawn switch, like checkedIcon. |
| accessibilityHint | string | — | What screen readers say after the label, e.g. the setting's description. |