Examples

Standalone

Preview
Example.tsx
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.

Preview
Example.tsx
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.

Preview
Example.tsx
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

ToggleButton props
PropTypeDefault
pressed
Controlled state.
boolean—
defaultPressed
Uncontrolled initial state.
booleanfalse
onPressedChange
(pressed: boolean) => void—
value
Identifies the button inside a group.
string—

ToggleButtonGroup props

ToggleButtonGroup props
PropTypeDefault
typerequired
Selection model.
'single' | 'multiple'—
value / defaultValue
Controlled / uncontrolled selection.
string | null · string[]—
onValueChange
(value) => void—
required
Single mode: prevent un-pressing the active button.
booleanfalse
size · variant · disabled · attached
Applied 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

VariableDefault
--pl-button-radiusvar(--pl-radius-md

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[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.
Keyboard interactions
KeyAction
Enter / SpaceToggle
TabNext 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.