# Stage bars

> A funnel you can read at a glance: every stage as a bar against the first, the drop-off between them, and widths that ease when the period changes.

Funnels are usually a trapezoid you can’t read numbers off. Here every stage is a bar measured against the first, with its count and share on its row and, between rows, how many carried on to the next stage. The headline is the one number people ask for: how many made it all the way. Switch from this week to last week or the last 30 days and every bar eases to its new width while every count, share and drop-off rolls to its new figure. The first time the card scrolls into view the bars grow from the left one after another. Point at a stage and the others dim. One hue that steps lighter down the funnel, as a magnitude should be drawn.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/stage-bars.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): `number-roll`
- Docs and live preview: https://hairlineui.com/ui/stage-bars
- Registry item (source): https://hairlineui.com/r/stage-bars.json

## Usage

```tsx
import { StageBars } from "@/components/stage-bars";

<StageBars
  title="App orders"
  stages={[{ id: "opened", label: "Opened the app" }, { id: "basket", label: "Added to basket" }, { id: "paid", label: "Paid" }]}
  periods={[{ id: "week", label: "This week", values: [2480, 1164, 611] }]}
/>
```

## From product analytics

Count distinct users per step on the server, one array per period in the same stage order.

```tsx
import { StageBars } from "@/components/stage-bars";
import { analytics } from "@/lib/analytics";

const STAGES = [
  { id: "opened", label: "Opened the app" },
  { id: "basket", label: "Added to basket" },
  { id: "checkout", label: "Started checkout" },
  { id: "paid", label: "Paid" },
];

export async function CheckoutFunnel() {
  const count = (since: string, until?: string) => analytics.funnel(STAGES.map((s) => s.id), { since, until }); // → number[]
  const [week, last, month] = await Promise.all([count("-7d"), count("-14d", "-7d"), count("-30d")]);
  return (
    <StageBars
      title="App orders"
      stages={STAGES}
      periods={[
        { id: "week", label: "This week", values: week },
        { id: "last", label: "Last week", values: last },
        { id: "month", label: "30 days", values: month },
      ]}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `stages` | `Stage[]` | – | In order, each { id, label }. |
| `periods` | `StagePeriod[]` | – | Each { id, label, values }, one count per stage; more than one shows a switch. |
| `value / defaultValue` | `string` | `the first period` | The period on show, by id; controlled or not. |
| `onValueChange` | `(id: string) => void` | – | Called when the period changes. |
| `title` | `string` | `"Funnel"` | Above the headline. |
| `format` | `Intl.NumberFormatOptions` | – | How counts read. |
| `locales` | `string \| string[]` | – | For number formatting. |

## States

- **arrive**: In view for the first time, each bar grows from the left (820ms, 90ms apart) and every count, share and drop-off rolls up from zero.
- **period**: The pill is thrown to the choice (460ms); every bar eases to its new width (820ms) and every figure, including the headline, rolls.
- **focus**: Pointing at a stage dims the others to 40%, leaving that stage and the drop-offs either side of it.

## What it handles

Funnels are usually a trapezoid you can’t read numbers off. Here each stage is a bar measured against the first, with the drop-off printed between the rows.

- **Every stage against the first**: Each bar is its share of the first stage, with its count and share written on its row.
- **The drop-off between stages**: Between rows it says how many carried on to the next stage.
- **The headline number**: How many made it all the way is the number at the top.
- **Switch the period**: Every bar eases to its new width and every figure rolls when you change from this week to last week.
- **Focus a stage**: Point at a stage and the others dim, leaving it and the drop-offs beside it.
- **Honest colour, readable by all**: One hue steps lighter down the funnel, because it is one measure shrinking. A hidden table gives each stage’s counts and shares.

## Replaces

a funnel chart library, conversion maths, a period switch, drop-off labels, a data table for screen readers

## Where it fits

- **Signup and activation funnels**: Visited, signed up, activated, paid.
- **Sales pipeline conversion**: Lead, demo, trial and customer, with the drop-off at each step.
- **Checkout funnels**: Where shoppers leave between cart and payment.
- **Onboarding drop-off**: How many people finish each step of a setup flow.

## Notes

- Grey in a new shadcn project? Its default theme sets --chart-1 to --chart-5 to greys. Set five colours, light and dark, as in Theming › Chart colours (/ui/theming#charts).
- An ordered list: every stage’s count and share is printed on its row, so nothing is hidden behind hover.
- The period switch is a radio group (arrow keys move).
- A visually hidden table gives each stage’s count, its share of the first stage and of the stage before.
- One hue (--chart-1) stepping lighter down the funnel: it’s one measure shrinking, not different categories.
- Installs Number roll. With reduced motion the bars are simply their width.

License: MIT (https://hairlineui.com/license#components)
