Menu

Switch

On/off toggle. 2 values × 4 states × 2 sizes.

Installation

$ npx uix-ui@latest add switch

This copies the file into components/ui/switch.tsx in your project. npx shadcn@latest add @uix/switch works too.

Usage

switch.tsx
import { Switch } from "@/components/ui/switch";

<div style={{ display: "grid", gap: 12 }}>
  <Switch size="sm" label="Small" defaultChecked />
  <Switch size="md" label="Medium" defaultChecked />
  <Switch label="Disabled" disabled />
</div>

Examples

Sizes and disabled

Props

PropTypeDefaultDescription
sizesm | md"md"
labelReact.ReactNode–

Everything else is passed to the root element, so className, aria-* and event handlers work as usual.

Dependencies

Installed for you by the CLI.

  • class-variance-authority
  • clsx
  • tailwind-merge
  • lib/utils.ts
esc

↑↓ to navigate · ↵ to select · esc to close