Switch
Toggle switch component for boolean settings.
Basic Usage
import { Switch } from 'uiplex';
<Switch checked={checked} onChange={setChecked} />
<Switch defaultChecked />Labels: left, right, or both
<Switch label="Enable" />
<Switch leftLabel="Off" rightLabel="On" defaultChecked />
<Switch leftLabel="No" rightLabel="Yes" />
<Switch leftLabel="Left only" />
<Switch rightLabel="Right only" />Sizes
<Switch size="sm" defaultChecked />
<Switch size="md" defaultChecked />
<Switch size="lg" defaultChecked />Disabled
<Switch disabled />
<Switch disabled defaultChecked />API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | - | Controlled checked state |
| defaultChecked | boolean | false | Uncontrolled initial state |
| onChange | (checked: boolean) => void | - | Called when toggled |
| disabled | boolean | false | Disable the switch |
| size | "sm" | "md" | "lg" | "md" | Switch size |
| leftLabel | string | - | Label on the left of the switch |
| rightLabel | string | - | Label on the right of the switch |
| label | string | - | Single label (use with labelPosition) |
| labelPosition | "left" | "right" | "right" | Position when using label |