Primitive / Atomstable

Switch

On/off control built on Radix switch primitive.

@glinui/uiComponent: switch

Installation

Install from the package for shared ownership or from the registry for copy-paste control.

Package Manager

pnpm add @glinui/ui @glinui/tokens

Registry

pnpm dlx @glinui/cli@latest add switch

Usage

Basic

TSX
1import { Switch } from "@glinui/ui"
2
3export function Demo() {
4 return (
5 <label className="flex items-center gap-2 text-sm">
6 <Switch /> Notifications
7 </label>
8 )
9}

Disabled

TSX
1import { Switch } from "@glinui/ui"
2
3export function Demo() {
4 return (
5 <label className="flex items-center gap-2 text-sm opacity-50">
6 <Switch disabled /> Disabled
7 </label>
8 )
9}

Accessibility

  • Built on Radix Switch with `role="switch"`.
  • Pair with `<label>` for context.

Keyboard Interactions

KeyAction
SpaceToggle the switch on/off.

ARIA Attributes

  • `role="switch"`
  • `aria-checked`

Reduced Motion

Thumb slide transition respects `prefers-reduced-motion`.

Affected properties

transform

API Reference

PropTypeRequiredDefaultDescription
checkedbooleanNo-Controlled on/off state.
defaultCheckedbooleanNo-Initial state.
onCheckedChange(checked: boolean) => voidNo-Change handler.
disabledbooleanNofalseDisables interaction.
namestringNo-Form field name submitted with form data.
requiredbooleanNo-Marks the switch as required within a form.
valuestringNo-Value submitted with the form when checked.
variant"default" | "glass" | "frosted" | "liquid" | "matte"No"default"Variant option from switchVariants.

Source

Import directly from the package or browse the source on GitHub. Click any file to view it.

Import

import { Switch } from "@glinui/ui"

Source Files

Dependencies

@glinui/ui

Generated API Snapshot

Beta

Auto-extracted from TypeScript source in packages/ui/src/components/switch.tsx. This section is in beta and may lag behind hand-curated docs. Regenerate with pnpm --filter @glinui/docs api:generate.

Generated: 2026-02-19T17:59:28.468Z · Full index: /docs/api-metadata

Primary Props Type

SwitchProps

SwitchProps

PropTypeRequiredDefaultDescription
checkedbooleanNo-Controlled checked state.
defaultCheckedbooleanNo-Initial checked state for uncontrolled usage.
disabledbooleanNo-Prevents interaction and applies muted styling.
namestringNo-Form field name submitted with form data.
onCheckedChange(checked: boolean) => voidNo-Callback fired when the checked state changes.
requiredbooleanNo-Marks the switch as required within a form.
valuestringNo-Value submitted with the form when checked.
variant"default" | "glass" | "frosted" | "liquid" | "matte"No"default"Variant option from switchVariants.