Getting Started
Components52
- Accordion
- Alert
- Alert Dialog
- Attachment
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Checkbox
- Collapsible
- Command
- Context Menu
- Data Table
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
import { Label } from "@/components/ui/label"
import { Switch } from "@/components/ui/switch"
export function SwitchDemo() {
return (
<div className="flex flex-wrap items-center gap-2">
<div className="flex items-center gap-2">
<Switch id="sw-default" />
<Label htmlFor="sw-default">Default</Label>
</div>
<div className="flex items-center gap-2">
<Switch id="sw-on" defaultChecked />
<Label htmlFor="sw-on">On</Label>
</div>
<div className="flex items-center gap-2">
<Switch id="sw-sm" size="sm" defaultChecked />
<Label htmlFor="sw-sm">Small</Label>
</div>
<div className="flex items-center gap-2">
<Switch id="sw-disabled" disabled />
<Label htmlFor="sw-disabled">Disabled</Label>
</div>
</div>
)
}Installation#
pnpm dlx shadcn@latest add https://ui.ikramhasan.com/r/switch.json
Usage#
import { Switch } from "@/components/ui/switch"<Switch />Examples#
Settings#
Update products every hour.
Let Marketer read and update your storefront theme.
import {
Field,
FieldContent,
FieldDescription,
FieldGroup,
FieldLabel,
} from "@/components/ui/field"
import { Switch } from "@/components/ui/switch"
export function SwitchSettings() {
return (
<FieldGroup className="max-w-sm">
<Field orientation="horizontal">
<FieldContent>
<FieldLabel htmlFor="sw-sync">Data sync</FieldLabel>
<FieldDescription>Update products every hour.</FieldDescription>
</FieldContent>
<Switch id="sw-sync" defaultChecked />
</Field>
<Field orientation="horizontal">
<FieldContent>
<FieldLabel htmlFor="sw-theme">Edit theme</FieldLabel>
<FieldDescription>
Let Marketer read and update your storefront theme.
</FieldDescription>
</FieldContent>
<Switch id="sw-theme" />
</Field>
</FieldGroup>
)
}API Reference#
Switch is built on the Base UI Switch primitive. See the Base UI documentation for every prop.