Skip to content
caliper ui docs

Components

Button group

A toolbar of related tools in one raised shell; toggled tools sink into it.

Free
pnpm dlx shadcn@latest add @caliper/button-group

Changelog entry

Shown to customers on the updates page

Ship notes for v2.14: faster cold starts in eu-central-1.

Installs components/ui/button-group.tsxDepends on none beyond ReactMotion none in component source

When to use

Use it for

  • Formatting and view tools that belong together, such as Bold, Italic and Underline.
  • Toolbars where the buttons share a size and emphasis, with aria-pressed for toggles.

Skip it when

  • The buttons are unrelated; give each its own spacing instead.
  • Only one choice can be active; use a segmented control.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/button-group

Adds its 3 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.

Usage

This is the code behind the preview above.

example.tsx
import { Bold, Italic, Link2, Underline } from "lucide-react"
import { useState, type ReactNode } from "react"
import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"

function Panel({ title, context, children }: { title: string; context: string; children: ReactNode }) {
  return (
    <section className="grid w-full max-w-md gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting">
      <div className="grid gap-1">
        <p className="font-medium">{title}</p>
        <p className="text-sm text-muted-foreground">{context}</p>
      </div>
      {children}
    </section>
  );
}

export function DraftActions() {
  const [marks, setMarks] = useState({ bold: true, italic: false, underline: false });
  const toggle = (key: keyof typeof marks) => setMarks((current) => ({ ...current, [key]: !current[key] }));
  return (
    <Panel title="Changelog entry" context="Shown to customers on the updates page">
      <ButtonGroup aria-label="Formatting" className="justify-self-start">
        <Button variant="secondary" size="icon" aria-label="Bold" aria-pressed={marks.bold} onClick={() => toggle("bold")}><Bold aria-hidden="true" /></Button>
        <Button variant="secondary" size="icon" aria-label="Italic" aria-pressed={marks.italic} onClick={() => toggle("italic")}><Italic aria-hidden="true" /></Button>
        <Button variant="secondary" size="icon" aria-label="Underline" aria-pressed={marks.underline} onClick={() => toggle("underline")}><Underline aria-hidden="true" /></Button>
        <Button variant="secondary" size="icon" aria-label="Insert link"><Link2 aria-hidden="true" /></Button>
      </ButtonGroup>
      <p
        className="rounded-control border border-border px-4 py-3 text-sm"
        style={{ fontWeight: marks.bold ? 600 : 400, fontStyle: marks.italic ? "italic" : "normal", textDecoration: marks.underline ? "underline" : "none" }}
      >
        Ship notes for v2.14: faster cold starts in eu-central-1.
      </p>
    </Panel>
  );
}

API reference

ButtonGroup

component

No props of its own; it accepts the native props of its root element.

Accessibility

It exposes group semantics.

No custom key handling; Tab and the native activation keys do the work.

Motion

It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.

All Actions examples