Toggle
A button that stays pressed, like Bold in a format bar.
import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react"
import { Toggle } from "@/components/ui/toggle"
export default function ToggleDemo() {
return (
<div className="flex items-center gap-1">
<Toggle aria-label="Bold" defaultPressed>
<BoldIcon strokeWidth={2.5} />
</Toggle>
<Toggle aria-label="Italic">
<ItalicIcon />
</Toggle>
<Toggle aria-label="Underline" variant="outline">
<UnderlineIcon />
</Toggle>
</div>
)
}Installation
pnpm dlx shadcn@latest add @cupertinoui/toggleThe first install also adds the macOS theme. See Installation to set up the registry.
Usage
import { Toggle } from "@/components/ui/toggle"
<Toggle aria-label="Bold">
<BoldIcon />
</Toggle>API Reference
Every part forwards the props of the underlying Base UI Toggle part. The props below are the ones CupertinoUI adds or changes.
Toggle
| Prop | Type | Description |
|---|---|---|
variant | "default" | "outline"Default: "default" | Borderless, or a bordered button. |
size | "sm" | "default" | "lg"Default: "default" | 20, 24 or 28pt tall. |
pressed / defaultPressed | boolean | Whether it is on. |
onPressedChange | (pressed: boolean) => void | Called when it turns on or off. |
className | string | Extra classes, merged with the component's own. |