NOCTA UI

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:

Terminal
npx nocta-ui add switch

Then import the component:

Import
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

PropTypeDefaultDescription
checkedbooleanfalseWhether 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
disabledbooleanfalseWhether the switch is disabled
classNamestring''Additional CSS classes to apply
idstring-The id attribute for the switch input

The Switch component also accepts all standard HTML input element props through the ...props spread operator.