Components
A two-state button that can be either on or off.
Playground
aria-pressed and data-state for assistive technology and styling.import { Toggle } from "@workspace/ui/components/toggle"
<Toggle>Toggle</Toggle>group/toggle class, so children can restyle themselves per state. Phosphor icons switch to a solid look via weight="fill" rather than CSS, so render both weights and swap them with group-data-[state=on]/toggle:hidden.<Toggle aria-label="Toggle bookmark" size="sm" variant="outline">
<BookmarkSimpleIcon
data-icon="inline-start"
className="group-data-[state=on]/toggle:hidden"
/>
<BookmarkSimpleIcon
data-icon="inline-start"
weight="fill"
className="hidden group-data-[state=on]/toggle:block"
/>
Bookmark
</Toggle><Toggle variant="outline" aria-label="Toggle italic"> <TextItalicIcon data-icon="inline-start" /> Italic </Toggle> <Toggle variant="outline" aria-label="Toggle bold"> <TextBIcon data-icon="inline-start" /> Bold </Toggle>
data-icon="inline-start" or data-icon="inline-end" to the icon for the correct spacing, as with Button.<Toggle aria-label="Toggle italic"> <TextItalicIcon data-icon="inline-start" /> Italic </Toggle>
<Toggle variant="outline" size="sm" aria-label="Toggle small"> Small </Toggle> <Toggle variant="outline" size="default" aria-label="Toggle default"> Default </Toggle> <Toggle variant="outline" size="lg" aria-label="Toggle large"> Large </Toggle>
<Toggle aria-label="Toggle disabled" disabled> Disabled </Toggle> <Toggle variant="outline" aria-label="Toggle disabled outline" disabled> Disabled </Toggle>
<ToggleGroup type="multiple" variant="outline">
<ToggleGroupItem value="bold" aria-label="Bold">
<TextBIcon />
</ToggleGroupItem>
<ToggleGroupItem value="italic" aria-label="Italic">
<TextItalicIcon />
</ToggleGroupItem>
<ToggleGroupItem value="underline" aria-label="Underline">
<TextUnderlineIcon />
</ToggleGroupItem>
</ToggleGroup><div dir="rtl">
<Toggle variant="outline" aria-label="مفضلة">
<StarIcon data-icon="inline-start" />
مفضلة
</Toggle>
<Toggle variant="outline" aria-label="مائل">
<TextItalicIcon />
</Toggle>
<Toggle variant="outline" aria-label="تحته خط">
<TextUnderlineIcon />
</Toggle>
</div>defaultPressed or controlled via pressed + onPressedChange — plus the variant props below.| Prop | Type | Default |
|---|---|---|
| variant | "default" | "outline" | "default" |
| size | "default" | "sm" | "lg" | "default" |
| pressed | boolean | — |
| defaultPressed | boolean | false |
| onPressedChange | (pressed: boolean) => void | — |
Tokens used
8 design tokens consumed by the Toggle component.
--muted
Muted
--foreground
Foreground
--input
Input
--ring
Ring
--destructive
Destructive
--text-sm
Text Small (14px)
--radius-md
Radius 0.8× (8px)
--spacing
Spacing unit (4px)