Switch
A toggle switch component for binary choices with multiple variants, sizes and dark mode support
Installation
Install the Switch component using the nocta-ui CLI:
npx nocta-ui add switch
Then import the component:
import { Switch } from '@/components/ui/switch';
Basic Usage
Default Switch
Variants
The Switch component supports four variants: default
, success
, warning
, and destructive
.
Default
Success
Warning
Destructive
Sizes
Three size options are available: sm
, md
, and lg
. The default size is md
.
Small
Medium
Large
Switch States
Disabled State
Enabled (off)
Enabled (on)
Disabled (off)
Disabled (on)
Customization
Custom Styling
The Switch component accepts a className
prop for custom styling:
Scaled (1.25x)
75% Opacity
Square corners
API Reference
Switch Props
Prop | Type | Default | Description |
---|---|---|---|
checked | boolean | false | Whether the switch is checked |
onCheckedChange | (checked: boolean) => void | - | Callback fired when the switch state changes |
size | 'sm' | 'md' | 'lg' | 'md' | The size of the switch |
variant | 'default' | 'success' | 'warning' | 'destructive' | 'default' | The visual style variant |
disabled | boolean | false | Whether the switch is disabled |
className | string | '' | Additional CSS classes to apply |
id | string | - | The id attribute for the switch input |
The Switch component also accepts all standard HTML input element props through the ...props
spread operator.