Components
- Accordion
- Action BarUpdated
- Alert Dialog
- Alert
- Announcement
- Aspect Ratio
- Autocomplete
- Avatar
- BadgeUpdated
- Bottom Navigation
- Breadcrumb
- Button Group
- Button
- CalendarUpdated
- CardUpdated
- Carousel
- Chart
- Checkbox
- Circular Progress
- Circular Slider
- Clipboard
- Collapsible
- Color Picker
- Combobox
- Command
- Context MenuUpdated
- Data List
- Date Picker
- DialogUpdated
- DrawerUpdated
- Editable
- FieldUpdated
- File Upload
- Float
- Floating Panel
- Frame
- Hint
- Hover Card
- Image Cropper
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Link Overlay
- Listbox
- MarqueeUpdated
- Menu
- Native Select
- Number InputUpdated
- Pagination
- Popover
- Progress
- Prose
- QR Code
- Radio Group
- Rating
- Resizable
- Scroll Area
- Segment Group
- Select
- Separator
- Sheet
- Sidebar
- Signature Pad
- Skeleton
- Skip Nav
- Slider
- Spinner
- Status
- Steps
- Switch
- TableUpdated
- Tabs
- Textarea
- TimerUpdated
- ToastUpdated
- Toggle Group
- Toggle Tooltip
- Toggle
- Tooltip
- Tour
- Tree View
Hooks
Installation#
pnpm dlx shadcn@latest add @shark/switch
Usage#
import { Switch } from "@/components/ui/switch";
<Switch />
Controlled#
Use the checked and onCheckedChange props to control the switch state programmatically.
❌
States#
Invalid#
Use the invalid prop on the Field or in the Switch component to mark the switch as invalid.
Examples#
Disabled#
Use the disabled prop to disable the switch.
With Description#
Use FieldDescription to add a description to the switch.
Focus is shared across devices, and turns off when you leave the app.
Card Style#
Use a card-style layout with the switch for a more prominent display.
Form Integration#
Integrate the switch into a form with proper validation and error handling.
Customizing Size#
The switch size is controlled by the [--size-*] CSS variable.
API Reference#
Switch#
Toggle switch for on/off state. Use with a form control.
| Prop | Type | Default |
|---|---|---|
checked | boolean | - |
defaultChecked | boolean | false |
disabled | boolean | false |
invalid | boolean | false |
name | string | - |
value | string | number | "on" |
onCheckedChange | (details: CheckedChangeDetails) => void | - |
className | string | - |
| Attribute | Default |
|---|---|
--size | --spacing(4) |
For a complete list of props, see the Ark UI documentation.