Components
Switch
A tactile Material 3 toggle switch with dynamic thumb scaling, optional state icons, and three size presets.
import { Switch } from "@/components/ui/switch";
export default function Particle() {
return <Switch aria-label="Toggle setting" defaultChecked />;
}
Installation
pnpm dlx shadcn@latest add @taut-ui/switch
Usage
import { Switch } from "@/components/ui/switch"<Switch defaultChecked />Examples
Checked Icon
import { Switch } from "@/components/ui/switch";
export default function Particle() {
return <Switch aria-label="Checked icon" defaultChecked icons="checked" />;
}
Both Icons
import { Switch } from "@/components/ui/switch";
export default function Particle() {
return <Switch aria-label="Both icons" defaultChecked icons="both" />;
}
Small
import { Switch } from "@/components/ui/switch";
export default function Particle() {
return <Switch aria-label="Small switch" defaultChecked size="sm" />;
}
Large
import { Switch } from "@/components/ui/switch";
export default function Particle() {
return <Switch aria-label="Large switch" defaultChecked size="lg" />;
}
Disabled
import { Switch } from "@/components/ui/switch";
export default function Particle() {
return <Switch aria-label="Disabled switch" disabled />;
}
In Card
Auto-save
Automatically persist changes as you edit.
"use client";
import { useState } from "react";
import { Card } from "@/components/ui/card";
import { Switch } from "@/components/ui/switch";
export default function Particle() {
const [enabled, setEnabled] = useState(true);
return (
<Card className="w-80 flex-row items-center justify-between gap-4 p-4">
<div className="space-y-0.5">
<p className="font-medium text-foreground text-sm">Auto-save</p>
<p className="text-muted-foreground text-xs">
Automatically persist changes as you edit.
</p>
</div>
<Switch
aria-label="Auto-save"
checked={enabled}
icons="checked"
onCheckedChange={setEnabled}
/>
</Card>
);
}
API Reference
Switch
Wraps Base UI Switch.Root and Switch.Thumb with Material 3 thumb scaling and optional icons.
| Prop | Type | Default | Description |
|---|---|---|---|
icons | "checked" | "both" | - | "checked" shows a check when on; "both" also shows an × when off |
size | "sm" | "default" | "lg" | "default" | Overall track and thumb size preset |
checked | boolean | - | Controlled checked state |
defaultChecked | boolean | false | Initial uncontrolled checked state |
onCheckedChange | (checked: boolean) => void | - | Called when the checked state changes |
disabled | boolean | false | Disables interaction and dims the switch |
className | string | - | Additional CSS classes |
...props | Base UI Switch Root props | - | All standard switch attributes (name, value, required, etc.) |