- Docs
- Components
- Actions
Toggle
A tool that's pressed or not. With only an icon, its name shows as its tooltip.
- Import
- @qeetrix/react
- Status
- StableSince 0.0.2
- Renders
<button aria-pressed>Server-rendered- Tested
- WCAG 2.2 AAaxe on every pull request
01
Playground
Every prop, live, and the code it takes.
Icon
Size
import { StarIcon } from "@qeetrix/icons";
import { Toggle } from "@qeetrix/react";
<Toggle icon={StarIcon} filledWhenPressed defaultPressed>Favourite</Toggle>02
Off, on and disabled
Pressed shows as a fill. An icon alone needs a name, which shows as its tooltip.
<Inline gap="sm">
<Toggle icon={BoldIcon} aria-label="Bold" />
<Toggle icon={ItalicIcon} aria-label="Italic" defaultPressed />
<Toggle icon={UnderlineIcon} aria-label="Underline" disabled />
<Toggle icon={ItalicIcon} aria-label="Italic, locked" disabled defaultPressed />
</Inline>03
With a label
The icon leads its label. filledWhenPressed swaps to the icon's filled drawing.
<Inline gap="sm">
<Toggle icon={StarIcon} filledWhenPressed defaultPressed>Favourite</Toggle>
<Toggle icon={BellIcon} filledWhenPressed>Notify me</Toggle>
<Toggle>Show archived</Toggle>
</Inline>04
Sizes
A control's height in the region's density; inside a group, the group's size wins.
<Inline gap="sm" align="center">
<Toggle size="sm" icon={BoldIcon} aria-label="Bold, small" defaultPressed />
<Toggle size="md" icon={BoldIcon} aria-label="Bold, medium" defaultPressed />
<Toggle size="lg" icon={BoldIcon} aria-label="Bold, large" defaultPressed />
</Inline>05
Tooltips
An icon-only toggle shows its name; tooltip adds a shortcut, tooltipSide moves it.
<Inline gap="sm">
<Toggle icon={BoldIcon} aria-label="Bold" tooltip="Bold (Ctrl+B)" tooltipSide="bottom" />
<Toggle icon={ItalicIcon} aria-label="Italic" tooltip="Italic (Ctrl+I)" tooltipSide="bottom" />
<Toggle icon={UnderlineIcon} aria-label="Underline" tooltip="Underline (Ctrl+U)" tooltipSide="bottom" />
</Inline>06
Controlled
pressed and onPressedChange: the page follows the toggle.
Acme Pvt Ltd stays at the top of the list.
const [pinned, setPinned] = useState(true);
<Inline gap="md" align="center">
<Toggle icon={PinIcon} filledWhenPressed pressed={pinned} onPressedChange={setPinned}>
Pin to top
</Toggle>
<Text tone="subtle">{pinned ? "Acme Pvt Ltd stays at the top of the list." : "Acme Pvt Ltd sorts with the rest."}</Text>
</Inline>