Switch
FormToggle switch for on/off boolean states.
Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.
"use client";
import { Switch } from "@dashboardpack/core/components/ui/switch";
import { Label } from "@dashboardpack/core/components/ui/label";
import { useState } from "react";
export default function SwitchExample() {
const [enabled, setEnabled] = useState(true);
return (
<div className="space-y-5">
<div className="flex items-center gap-3">
<Switch
id="switch-alerts"
checked={enabled}
onCheckedChange={setEnabled}
/>
<Label htmlFor="switch-alerts">
Email notifications {enabled ? "on" : "off"}
</Label>
</div>
<div className="flex items-center gap-3">
<Switch id="switch-disabled" disabled />
<Label htmlFor="switch-disabled">Organization policy</Label>
</div>
</div>
);
}Usage
Use switches for settings that take effect immediately. Use checked and onCheckedChange together for a controlled switch.
import { Switch } from "@dashboardpack/core/components/ui/switch";Available in the included @dashboardpack/core package. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.
API reference
Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.
| Prop | Type / Default | Description |
|---|---|---|
| checked | booleanDefault: — | Controlled on/off state. |
| onCheckedChange | (checked: boolean) => voidDefault: — | Handle state changes. |
| defaultChecked | booleanDefault: — | Initial uncontrolled state. |
| disabled | booleanDefault: false | Prevent interaction. |