Built on Radix UI Switch
Switch
An on/off toggle. Mochi sleeps on the thumb when it is off and wakes up, smiling, when it is on.
Playground
import { ChibiSwitch } from '@chibi-ui/react/switch';
<ChibiSwitch label="Wake Mochi up" />Import
import {
ChibiSwitch,
} from '@chibi-ui/react/switch';Examples
<Controller
control={control}
name="newsletter"
render={({ field }) => (
<ChibiSwitch
label="Send me cute newsletters"
checked={field.value}
onCheckedChange={field.onChange}
onBlur={field.onBlur}
ref={field.ref}
name={field.name}
/>
)}
/>Accessibility
- role="switch" with aria-checked. Space toggles it, and clicking the label toggles it too.
- The state is shown by the thumb position and the mascot’s expression, not by colour alone. The track border stays at 3:1 or more in both states.
- A hidden checkbox mirrors the state for native form submission.
API reference
ChibiSwitch
| Prop | Type | Default | Description |
|---|---|---|---|
| label | ReactNode | — | Visible label, associated with the control. |
| description | ReactNode | — | Helper text, linked via aria-describedby. |
| error | ReactNode | — | Error message (e.g. errors.x?.message). Any truthy value sets aria-invalid; true marks invalid without a message. |
| containerClassName | string | — | Class for the wrapper holding label, control and messages. |
| checked / defaultChecked | boolean | — | Controlled / uncontrolled state. |
| onCheckedChange | (checked: boolean) => void | — | Change callback. |
| size | 'sm' | 'md' | 'md' | Track size. |
| labelPosition | 'start' | 'end' | 'end' | Label placement. |