Skip to Content
NarakUI

Switch

A toggle switch component for enabling or disabling features and settings.

Default

The default switch sits on a raised control surface. Pass labelClassName="pr-2" to balance the padding around the label.

Slim

slim drops the control surface. Use it inside menus, popovers and settings lists.

Small

size="sm" shrinks the track and thumb for dense toolbars.

Large

size="lg" enlarges the track and thumb for roomier layouts.

Slim and small

Combine slim and size="sm" for compact chart controls.

Green

Set color to green to fill the checked track with green.

Loading

isLoading disables the switch, shows a spinner in the thumb, and sets aria-busy.

Installation

pnpm dlx shadcn@latest add @narakui/switch

Add "@narakui": "https://ui.narakcode.dev/r/{name}.json" to components.json, or install directly from https://ui.narakcode.dev/r/switch.json.

Usage

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

<Switch title="Enable notifications" />
<Switch slim size="sm" defaultChecked title="Compact switch" />
<Switch checked={enabled} onCheckedChange={setEnabled} title="Controlled switch" />

Properties

PropTypeDefaultDescription
titlestring—The label text displayed next to the switch
checkedboolean—The controlled checked state of the switch
defaultCheckedboolean—The default checked state when used as an uncontrolled component
onCheckedChange(checked: boolean) => void—Event handler called when the checked state changes
disabledbooleanfalseWhether the switch is disabled
requiredboolean—When true, indicates that the user must toggle the switch before the owning form can be submitted
namestring—The name of the switch, used when submitting a form
valuestring'on'The value of the switch, used when submitting a form
slimbooleanfalseWhether to use the slim variant with reduced padding and no shadow
size'default' | 'sm' | 'lg''default'The size of the switch
color'default' | 'green''default'Fill color of the checked track
isLoadingbooleanfalseDisables the switch, shows a spinner in the thumb, and sets aria-busy
labelClassNamestring—Additional CSS classes to apply to the label
classNamestring—Additional CSS classes. Applied to both the outer label and the switch track.