Switch
Toggle a setting on or off.
Import
tsx
import { Switch } from "@cronus-ui/ui";
bash
npx cronus-ui add switch
Examples
.cronus
The same component declared in Cronus. Emitted at build time from the audit fixtures — the kernel renders it as HTML with no React.
off.cronus
app "audit-fixtures" {
port 5176
}
style {
preset aurora
theme dark
}
component SwitchOff layout:inline style:switch {
aria-label:"Airplane mode"
label "Airplane mode"
}
page "/audit/switch/off" type:custom {
use SwitchOff
}
on.cronus
app "audit-fixtures" {
port 5176
}
style {
preset aurora
theme dark
}
component SwitchOn layout:inline style:switch {
checked:true
aria-label:"Airplane mode"
label "Airplane mode"
}
page "/audit/switch/on" type:custom {
use SwitchOn
}
API Reference
Generated from the component's exported types.
SwitchProps
Extends ComponentPropsWithoutRef<typeof SwitchPrimitive.Root>
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | — | Controlled checked state. Pair with `onCheckedChange`. |
defaultChecked | boolean | — | Uncontrolled initial checked state. |
onCheckedChange | (checked: boolean) => void | — | Called with the next checked value whenever the control toggles. |
disabled | boolean | — | Disables pointer and keyboard interaction. |
required | boolean | — | Marks the control as required. |
name | string | — | Submitted name when used in a form. |
value | string | — | Controlled value. |
asChild | boolean | — | Render as the child element via Slot. |