Switch
A control that toggles between checked and unchecked.
import { Switch } from "@dapplelight/signet-ui/components/switch"
import { Label } from "@dapplelight/signet-ui/components/label"
export function Demo() {
return (
<div className="flex items-center gap-2">
<Switch id="email-alerts" />
<Label htmlFor="email-alerts">Email alerts</Label>
</div>
)
}Installation
npm i @dapplelight/signet-uiUsage
import { Switch } from "@dapplelight/signet-ui/components/switch"
<Switch aria-label="Email alerts" />Examples
Size
import { Switch } from "@dapplelight/signet-ui/components/switch"
import { Label } from "@dapplelight/signet-ui/components/label"
export function Demo() {
return (
<div className="flex items-center gap-4">
<Switch size="sm" aria-label="Compact view" />
<Switch aria-label="Compact view" />
</div>
)
}Controlled
import { useState } from "react"
import { Switch } from "@dapplelight/signet-ui/components/switch"
import { Label } from "@dapplelight/signet-ui/components/label"
export function Demo() {
const [autoRenew, setAutoRenew] = useState(true)
return (
<div className="flex items-center gap-2">
<Switch id="auto-renew" checked={autoRenew} onCheckedChange={setAutoRenew} />
<Label htmlFor="auto-renew">Auto-renew subscription: {autoRenew ? "on" : "off"}</Label>
</div>
)
}Disabled
import { Switch } from "@dapplelight/signet-ui/components/switch"
import { Label } from "@dapplelight/signet-ui/components/label"
export function Demo() {
return (
<div className="flex items-center gap-2">
<Switch id="sso" disabled defaultChecked />
<Label htmlFor="sso">Single sign-on (managed by your admin)</Label>
</div>
)
}Invalid
import { Switch } from "@dapplelight/signet-ui/components/switch"
import { Label } from "@dapplelight/signet-ui/components/label"
export function Demo() {
return (
<div className="flex items-center gap-2">
<Switch id="terms" aria-invalid />
<Label htmlFor="terms">Accept the terms</Label>
</div>
)
}API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
size | "default" | "sm" | "default" | Track and thumb size. |
checked | boolean | - | Controlled state. |
defaultChecked | boolean | false | Initial state. |
onCheckedChange | (checked: boolean, details) => void | - | Called when toggled. |
disabled | boolean | false | Blocks interaction. |
readOnly | boolean | false | Shows the state but blocks changes. |
required | boolean | false | Require it to be on in a form. |
name | string | - | Form field name. |
value / uncheckedValue | string | "on" / none | Submitted when on / off. |
aria-invalid | boolean | - | Shows the destructive ring. |
The remaining props come from the Base UI switch root.