Skip to content
caliper ui docs

Components

Bars morph

One icon made of three bars that become one another. A menu turns into a cross, a plus into a minus, an arrow points the other way. The same bars stay on screen, so a toggle reads as one thing changing state.

Free
pnpm dlx shadcn@latest add @caliper/bars-morph

Toggles

Three bars, six shapes.

Installs components/ui/bars-morph.tsxDepends on none beyond ReactMotion none in component source

When to use

Use it for

  • Menu, close and expand toggles.
  • Back and forward controls that change with the page.

Skip it when

  • Icons with more than three strokes; swap them with `IconSwap`.
  • A state with no visible change in the glyph.

Decisions

Why it is built this way, so you know what to keep when you change your copy.

Behaviour

Springs between shapes
Each bar moves by translate, turn and length with a small overshoot, so shapes settle rather than stop.

Usage

The button carries the name
The glyph is hidden from assistive technology; name the button and set aria-expanded or aria-pressed on it.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/bars-morph

Adds its 2 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 { useState, type ReactNode } from "react"
import { BarsMorph, type BarsShape } from "@/components/ui/bars-morph"
import { Button } from "@/components/ui/button"

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

const shapeSets: { name: string; shapes: BarsShape[] }[] = [
  { name: "Menu", shapes: ["menu", "close"] },
  { name: "Expand", shapes: ["plus", "minus"] },
  { name: "Step", shapes: ["back", "forward"] },
];

export function BarsMorphDemo() {
  const [state, setState] = useState([0, 0, 0]);
  return (
    <Panel title="Toggles" context="Three bars, six shapes.">
      <div className="flex flex-wrap gap-3">
        {shapeSets.map((set, at) => (
          <Button
            key={set.name}
            variant="secondary"
            aria-label={`${set.name}: ${set.shapes[state[at]]}`}
            className="min-w-24"
            onClick={() => setState((current) => current.map((value, i) => (i === at ? 1 - value : value)))}
          >
            <BarsMorph shape={set.shapes[state[at]]} />
            {set.name}
          </Button>
        ))}
      </div>
    </Panel>
  );
}

API reference

BarsMorph

component

Also accepts the native props of its root element and a ref.

PropTypeDefaultDescription
shape *BarsShape—The glyph to show. Change it and the three bars move into the new shape.

Accessibility

It is built on native elements and keeps aria-hidden in step with state.

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 Surfaces examples