Actions
ToggleButton
A button that stays pressed (aria-pressed). Use it alone, or in a ToggleButtonGroup for single or multiple selection.
import { ToggleButton, ToggleButtonGroup } from '@reactloom/ui';Examples
Standalone
import { ToggleButton } from '@reactloom/ui';
import { Archive } from 'lucide-react';
export default function Example() {
return (
<ToggleButton startIcon={<Archive />} onPressedChange={(pressed) => console.log(pressed)}>
Show archived
</ToggleButton>
);
}Multiple selection
Independent options, like text formatting.
import { ToggleButton, ToggleButtonGroup } from '@reactloom/ui';
import { Bold, Italic, Underline } from 'lucide-react';
export default function Example() {
return (
<ToggleButtonGroup type="multiple" aria-label="Text formatting" attached defaultValue={['bold']}>
<ToggleButton value="bold" aria-label="Bold" data-icon-only="" startIcon={<Bold />} />
<ToggleButton value="italic" aria-label="Italic" data-icon-only="" startIcon={<Italic />} />
<ToggleButton value="underline" aria-label="Underline" data-icon-only="" startIcon={<Underline />} />
</ToggleButtonGroup>
);
}Single selection
required keeps one option pressed.
import { ToggleButton, ToggleButtonGroup } from '@reactloom/ui';
import { CalendarDays, Columns3, List } from 'lucide-react';
import { useState } from 'react';
export default function Example() {
const [view, setView] = useState<string | null>('board');
return (
<ToggleButtonGroup type="single" required aria-label="View" value={view} onValueChange={setView} size="sm">
<ToggleButton value="list" startIcon={<List />}>List</ToggleButton>
<ToggleButton value="board" startIcon={<Columns3 />}>Board</ToggleButton>
<ToggleButton value="calendar" startIcon={<CalendarDays />}>Calendar</ToggleButton>
</ToggleButtonGroup>
);
}API reference
ToggleButton props
| Prop | Type | Default |
|---|---|---|
pressedControlled state. | boolean | — |
defaultPressedUncontrolled initial state. | boolean | false |
onPressedChange | (pressed: boolean) => void | — |
valueIdentifies the button inside a group. | string | — |
ToggleButtonGroup props
| Prop | Type | Default |
|---|---|---|
typerequiredSelection model. | 'single' | 'multiple' | — |
value / defaultValueControlled / uncontrolled selection. | string | null · string[] | — |
onValueChange | (value) => void | — |
requiredSingle mode: prevent un-pressing the active button. | boolean | false |
size · variant · disabled · attachedApplied to every button. | | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
Renders Button, so its hooks apply too.
CSS variables
| Variable | Default |
|---|---|
--pl-button-radius | var(--pl-radius-md |
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-disabled] | present when on |
[data-full-width] | present when on |
[data-loading] | present when on |
[data-radius] | none · sm · md · lg · full |
[data-size] | sm · md · lg |
[data-variant] | primary · secondary · tertiary · outline · ghost · destructive · link |
Theme tokens it reads
--pl-color-accent-fg --pl-color-accent-solid --pl-color-accent-solid-active --pl-color-accent-solid-hover --pl-color-accent-subtle --pl-color-accent-subtle-hover --pl-color-bg-muted --pl-color-bg-subtle --pl-color-bg-surface --pl-color-border-default --pl-color-border-strong --pl-color-danger-on-solid --pl-color-danger-solid --pl-color-danger-solid-hover --pl-color-fg-default --pl-color-fg-disabled --pl-color-fg-link --pl-color-fg-on-accent --pl-control-height-lg --pl-control-height-md --pl-control-height-sm --pl-focus-ring-color --pl-focus-ring-offset --pl-focus-ring-width --pl-font-size-lg --pl-font-size-md --pl-font-size-sm --pl-radius-full --pl-radius-lg --pl-radius-md --pl-radius-none --pl-radius-sm --pl-shadow-xs
Accessibility
- Pressed state is exposed with aria-pressed and shown with the accent surface.
- Every button is a tab stop (APG toggle-button pattern). For arrow-key one-of selection, use SegmentedControl.
| Key | Action |
|---|---|
| Enter / Space | Toggle |
| Tab | Next button |
Usage guidelines
Do
- Keep labels constant — the pressed state carries the meaning.
Don’t
- Don’t change the label between states (“Show”/“Hide”) and toggle aria-pressed at the same time.