Start here
  • InstallationAdd Nelumbo to a shadcn project
  • ThemingBrand accent, neutrals, dynamic color
  • Biology componentsSequences, maps, plates and trees
  • katalyx.bio

    Toggle and Toggle Group

    A Toggle is one on/off setting, such as bold or pin. A Toggle Group holds several toggles that work together: pick one (alignment) or several (text styles). Both keep their state in aria-pressed and data-state, and the selected state fills in, tightens from a pill to a rounded square and, for icons, fills the glyph. In a connected group the selected item turns inverse and rounds into a full pill; only its corners move, so no item changes width.

    Install

    npx shadcn@latest add @nelumbo/toggle @nelumbo/toggle-group

    Text formatting

    A toolbar of independent toggles. Each one is its own button with aria-pressed, so it works without a group.

    Toggle Group, multiple

    type="multiple" lets several items be on at once. The same toolbar as a connected group.

    Alignment, single

    type="single" holds one item on at a time. Clicking the selected item again turns it off, so this example ignores empty values to keep one on, like radio buttons.

    Text and icon

    A label beside the icon. The icon fills in when the item is on.

    Variants

    default is a plain toggle. outline adds an outline border that stays visible while the toggle is off; the selected state drops the border for an inverse fill.

    Sizes

    sm, default and lg match the heights of Nelumbo's buttons (32, 40 and 48px). On a Toggle Group, set size once on the group.

    Spacing

    spacing 0 (the default) connects the items, with the same corners as a connected button group. A number separates them by that many 4px steps, and each item keeps its own shape.

    Disabled

    Disabled items fade to 40% and stop responding. Arrow keys skip them.

    Toggle or Icon Button or Segmented Button?

    Toggle is an on/off setting inside a toolbar or form, with a text label or an icon. Use a Toggle Group when several related toggles belong together.

    Icon Button is an icon-only action, or a toggle with an icon that changes shape when on (favorite, bookmark). Reach for it when the icon alone says what it does.

    Segmented Button is a choice between two to five short options shown side by side, with a check mark on the selected one. Use it for view modes and filters where the choices need labels.

    Usage

    import { Toggle } from "@/components/ui/toggle"import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"import { Icon } from "@/components/ui/icon"​// shadcn's API<Toggle aria-label="Bold" pressed={bold} onPressedChange={setBold}>  <Icon name="format_bold" /></Toggle>​<ToggleGroup type="single" value={align} onValueChange={setAlign} aria-label="Alignment">  <ToggleGroupItem value="left" aria-label="Align left"><Icon name="format_align_left" /></ToggleGroupItem>  <ToggleGroupItem value="center" aria-label="Align center"><Icon name="format_align_center" /></ToggleGroupItem></ToggleGroup>​// Nelumbo: variants and sizes on the group, spacing for separated items<ToggleGroup type="multiple" variant="outline" size="sm" spacing={1} aria-label="Styles">  ...</ToggleGroup>

    Props

    PropTypeDefaultNotes
    pressedbooleanControlled state. Pair with onPressedChange
    defaultPressedbooleanfalseInitial state when uncontrolled
    onPressedChange(pressed: boolean) => voidCalled on every change
    variant"default" | "outline""default"outline adds an outline border
    size"sm" | "default" | "lg""default"Heights 32, 40 and 48px, matching Button
    type"single" | "multiple"ToggleGroup only. single keeps one item on
    value / defaultValuestring | string[]ToggleGroup selection. Arrays for multiple
    onValueChange(value) => voidToggleGroup selection change
    spacingnumber0ToggleGroup. 0 connects the items; n > 0 separates by n * 4px
    disabledbooleanfalseFades to 40% and skips arrow-key focus
    aria-labelstringRequired on icon-only toggles and on each group