Skip to content
nexubDesign System
v12.7.0

Components · Form Controls

Switch

StableAdded v0.0.1

Toggle control for binary on/off settings. Built on Radix UI Switch.

import { Switch } from '@nexub/react';
View as Markdown

Playground

Props

size
TSX
<Switch defaultChecked />

Examples

Default

Sizes

States

  • default
  • disabled
  • invalid
  • readOnly
  • loading
  • checked
  • size="sm"
  • size="md"
  • size="lg"

Props

Props
PropTypeDefaultDescription
checkedboolean—Controlled checked state.
defaultCheckedbooleanfalseUncontrolled initial state.
onCheckedChange(checked: boolean) => void—Callback when checked state changes.
disabledbooleanfalseDisables interaction.
size'sm' | 'md' | 'lg''md'Switch size.
checkedIconReact.ReactNode—Small icon inside the thumb while on.
invalidboolean—Error border on the track and aria-invalid.
loadingboolean—Spinner in the thumb and aria-busy; clicks don't toggle while loading. Stays focusable.
readOnlyboolean—Focusable but cannot toggle; sets aria-readonly.
uncheckedIconReact.ReactNode—Small icon inside the thumb while off.

Design tokens

Switch reads these component tokens. Each one is unset by default and falls back to the semantic role it aliases, so nothing changes until you set it. Set one on any element to restyle every Switch below it, and leave the roles other components share alone. See the three token tiers.

Switch design tokens
TokenAliasesNotes
--switch-track-on--color-primary—
CSS
/* One area of your app */
.checkout {
  --switch-track-on: var(--color-secondary);
}