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:

npx nocta-ui add switch

Import the component:

import { Switch } from '@/components/ui/switch';

Examples

Default Switch

Sizes

Three size options are available: sm, md, and lg. The default size is md.

Small
Medium
Large

API Reference

Switch Api Reference

PropTypeDefaultDescription
checkedbooleanfalseWhether the switch is checked (controlled)
defaultCheckedbooleanfalseInitial checked state (uncontrolled)
onCheckedChange(checked: boolean) => void-Callback fired when the switch state changes
size'sm' | 'md' | 'lg''md'The size of the switch
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 input props supported by @ariakit/react Checkbox through the ...props spread operator.