<!-- generated by scripts/gen-docs.mjs from docs/system/bar-list.md. Edit the source and rerun. -->
# BarList

## Description
Ranks names by value as rows of text, each filled as far as its share of the largest and each carrying its figure written out, so the fill is a picture of the text.

`import { BarList } from "@/components/cobalt/ui/bar-list"`, source `registry/cobalt/ui/bar-list.tsx`, status `ready-with-gaps`.
Foundation: `hand-rolled`. Traps checked: `trap/loading-layout-shift`, `trap/color-only-status`, `trap/numbers-shift`, `trap/motion-transition-all`, `trap/reduced-motion-ignored`, `trap/hover-unguarded` (n/a: the hover tint is Tailwind's `hover:` variant on a link row, which applies only where the device can hover), `trap/tooltip-essential` (n/a: there is no tooltip; every figure is written in the row), `trap/demo-on-timers` (n/a: every example holds fixed data), `trap/illustration-announced` (n/a: the fill is `aria-hidden` and the row's text carries the data), `trap/loop-offscreen` (n/a: nothing loops).

### Foundation
Not applicable: hand-rolled.

| Given by the foundation | Added by the team |
|---|---|
| `Empty` for the empty and failure states, `Skeleton` for the pending rows, `formatValue` from `chart-math.ts` for the figures and `defaultLink` from `registry/cobalt/lib/link.tsx` for links | The whole list: an `ol` of HTML rows, not the chart frame, whose rows share their columns through `grid-cols-subgrid`, so every `detail` and every figure lines up in its own column at the end in `tabular-nums`; each row `h-9` with its name truncating at the start; a fill behind the name, `bg-primary-soft`, as wide as the row's share of the largest value on the name's track, from the row's start to the gap before the figures, and never under 3 percent, so a fill never runs under a figure; a `rest` row last, muted, with no fill, so a long tail never shrinks the leaders to slivers; a row with `href` drawn through `renderLink`, so the host's router owns the navigation; its own pending state (nothing for 250ms through `useSlowWait`, then `placeholder` Skeleton rows), empty state and failure state (Empty with Retry). It does not use the chart frame, so it has no tooltip, no crosshair and no hidden table: the text is the data |

## Examples
Holdings by sector, ranked, each row a link to that sector's holdings.

Real uses, 0 call sites (`rg -n "<BarList\b" app registry docs/system/examples --glob '!docs/system/examples/bar-list/*'`): the showcase chrome renders no BarList of its own, and the examples folder does not count.

Uses inside the registry: none. `registry/cobalt/ui/bar-list.test.tsx` renders it for the tests.

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/bar-list/default.tsx` | default | Holdings by sector, ranked, each row a link to that sector's holdings |
| `docs/system/examples/bar-list/in-card.tsx` | composition:Card | The forms filed this month in a card, each with its change on last month, and the long tail summed in one row |

Example: Holdings by sector, ranked, each row a link to that sector's holdings (`docs/system/examples/bar-list/default.tsx`)

```tsx
import { BarList } from "@/components/cobalt/ui/bar-list";

const sectors = [
  { key: "tech", label: "Information technology", value: 1.84e9, href: "#technology" },
  { key: "health", label: "Health care", value: 9.6e8, href: "#health-care" },
  { key: "financials", label: "Financials", value: 7.1e8, href: "#financials" },
  { key: "industrials", label: "Industrials", value: 4.4e8, href: "#industrials" },
  { key: "energy", label: "Energy", value: 1.2e8, href: "#energy" },
];

export default function Example() {
  return <BarList className="w-full max-w-md" rows={sectors} format="money" />;
}
```

Example: The forms filed this month in a card, each with its change on last month, and the long tail summed in one row (`docs/system/examples/bar-list/in-card.tsx`)

```tsx
import { BarList } from "@/components/cobalt/ui/bar-list";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/cobalt/ui/card";

const forms = [
  { key: "adv", label: "Form ADV", value: 1284, detail: "+12%" },
  { key: "13f", label: "13F holdings", value: 942, detail: "+3%" },
  { key: "d", label: "Form D", value: 611, detail: "−4%" },
  { key: "pf", label: "Form PF", value: 208, detail: "+1%" },
];

export default function Example() {
  return (
    <Card className="w-full max-w-md">
      <CardHeader>
        <CardTitle render={<h2 />}>Filings this month</CardTitle>
      </CardHeader>
      <CardContent>
        <BarList rows={forms} rest={{ key: "rest", label: "Every other form", value: 377 }} />
      </CardContent>
    </Card>
  );
}
```

## Variants
Not applicable: BarList has no variant axis. Every row is 36px tall and the list takes its container's width; the one choice a call makes is `format`, which shapes the figures and not the look.

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| idle | `rows` with at least one row | read the names and figures, follow a link row | the fill's length, the figure written at the row's end, `detail` before it when passed | test |
| unfilled | a row whose `value` is zero, negative or not a number | read the figure | no fill at all; the figure alone, with a true minus sign such as "−50" | test |
| rest | `rest` passed | read the sum of the tail | the row last, in muted text, with no fill and `data-rest` | test |
| hover | the pointer over a link row | follow the link | pointer only, a `--hover` tint behind the row; the fill and the text do not move | screenshot |
| focus | Tab reaches a link row | press Enter | the system focus outline on the row | by hand |
| pending | `status="pending"` | wait | `aria-busy`; nothing for 250ms, then `placeholder` Skeleton rows at the rows' own height and a hidden "Loading" | by hand |
| empty | no `rows`, no `rest` and not pending | read why | the sentence "Nothing to show yet." | test |
| failure | `status="failure"` | press Retry | the title "Could not load the list" announced once as an alert, and Retry when `onRetry` is passed | test |

### State precedence
- Failure and pending: failure wins. The list shows the failure and its Retry.
- Pending and empty: pending wins. The list stays blank, then shows the Skeleton rows after the slow wait; the empty sentence never flashes.
- Pending and idle: both show. The old rows stay until the slow wait passes, then the Skeleton rows take the list.
- Rest and unfilled: rest wins on the last row. A `rest` row never draws a fill, whatever its `value`.
- Hover and focus: both show. The tint and the outline stack on a link row.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| the pointer enters or leaves a link row | input | `duration-press`, `--t-press` 140ms on `--curve` | background colour | the same tint, which the base layer keeps |

## Props

<!-- Props generated from registry/cobalt/ui/bar-list.tsx with TypeScript by scripts/props-table.mjs -->
| Prop | Type | Default | Purpose |
|---|---|---|---|
| `rows` | `readonly BarListRow[]` |  |  |
| `format?` | `ValueFormat` | `"number"` |  |
| `labels?` | `Partial<BarListLabels>` |  |  |
| `locale?` | `string` |  |  |
| `onRetry?` | `(() => void)` |  |  |
| `placeholder?` | `number` | `5` | How many rows the loading state holds, the count you expect. |
| `renderLink?` | `RenderLink` | `defaultLink` |  |
| `rest?` | `Omit<BarListRow, "href">` |  | The tail as one row with no fill, last. |
| `status?` | `Status` | `"idle"` |  |

Also accepts every native `<ol>` attribute.

`rows` takes `key`, `label`, `value`, and optionally `href` and `detail`; the fill is each value's share of the largest, so pass the rows already ranked. `rest` takes the same without `href` and sits last with no fill. `format` shapes every figure, `status` and `onRetry` drive the pending and failure states, and `placeholder` is the count of Skeleton rows, 5 by default; the empty and failure states hold the same height, `placeholder` rows of 36px 4px apart, so the list never changes height between loading, failing and coming back empty. `className` reaches every state. `labels` replaces any of the words, `renderLink` hands a row's link to the host's router, and the other `ol` attributes pass through.

## Usage

### When to use
- Names ranked by one value that a person reads row by row, such as holdings by sector or filings by form.
- A long tail that would shrink the leaders to slivers: pass it as one `rest` row.

### When not to use
- A value over time, or two measures at once. Use LineChart or ScatterChart instead.
- One figure and its change, with no ranking. Use Stat instead.
- Records a person sorts, filters and opens. Use DataTable instead.
- One value against a fixed limit. Use Meter instead.

### Rules
- `rule/bar-list-link-through-render-link`: When a row names a thing with a page of its own, give the row an `href` and the list a `renderLink`, instead of an `onClick` on the list or a link written into the label, because the row then is a real link with normal Tab order, Enter and open-in-new-tab, and the host's router keeps its prefetch. Evidence: principle wcag: 2.1.1 Keyboard; principle heuristic: match between system and the real world, a link behaves as a link. Check: test `bar-list.test.tsx` expects `href="/tech"` on a row.
  - Don't: `<BarList rows={rows} onClick={() => navigate("/tech")} />`
  - Do: `<BarList rows={[{ key: "tech", label: "Technology", value: 200, href: "/tech" }]} renderLink={routerLink} />`
- `rule/bar-list-status-not-conditionals`: When the rows are loading or failed, pass `status` and `onRetry` instead of swapping the list for a spinner or a message, because the list waits 250ms before it shows the Skeleton rows, holds the rows' height, and announces a failure once. Evidence: person D39; person D37; principle heuristic: visibility of system status. Check: test `bar-list.test.tsx` expects `role="alert"` and the Retry button on failure.
  - Don't: `{loading ? <Spinner /> : <BarList rows={rows} />}`
  - Do: `<BarList rows={rows} status={query.status} onRetry={query.retry} placeholder={5} />`

### Content
- Follows `rule/writing-no-invented-numbers`.
- `rule/bar-list-detail-is-a-note`: When a row needs a note beside its figure, such as "12 funds", put it in `detail` as text instead of folding it into `label`, because the label truncates at its track while the detail has a column of its own that never shrinks, so the note stays when the name is cut. Evidence: single use registry/cobalt/ui/bar-list.tsx:146-148. Check: review of every `label` that holds a digit or a bracket.
  - Don't: `<BarList rows={[{ key: "adv", label: "Form ADV (12 funds)", value: 1284 }]} />`
  - Do: `<BarList rows={[{ key: "adv", label: "Form ADV", value: 1284, detail: "12 funds" }]} />`

### Anti-slop
- `rule/bar-list-fill-is-rank-not-status`: When a row needs a state such as over budget, say it in `detail` instead of recolouring that row's fill, because the fill is one soft tint of the accent that carries only the share, and colour has one job. Evidence: person D13; principle wcag: 1.4.1 Use of color. Check: review of every `BarList` `className` and `style`.
  - Don't: `<BarList rows={rows} className="[&_[data-slot=bar-list-fill]]:bg-bad" />`
  - Do: `<BarList rows={[{ key: "adv", label: "Form ADV", value: 1284, detail: "Over budget" }]} />`

### Limits
- `rule/bar-list-tail-in-rest`: When the tail holds values under 3 percent of the largest row, pass them summed as `rest` instead of as rows, because a row never fills under 3 percent, so every smaller value draws the same sliver and the fills stop ranking them. Evidence: measured width 3.00% for a value of 2 beside 200, registry/cobalt/ui/bar-list.test.tsx. Check: test `bar-list.test.tsx` expects `width:3.00%` and a `rest` row with no fill.
  - Don't: `<BarList rows={[...leaders, ...tail]} />`
  - Do: `<BarList rows={leaders} rest={{ key: "rest", label: "Everything else", value: tailTotal }} />`

## Accessibility
Rests on a native ordered list, `ol` with `li` rows, and a native link for a row with `href`. The fill is `aria-hidden`; the name and the figure are text, so no table or summary is added. Contrast of the figure on the soft fill: NEEDS REVIEW. Screen reader pass with VoiceOver: NEEDS REVIEW.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the list | focuses the first link row; rows with no `href` are skipped | the first link row | by hand |
| Tab | a link row | moves to the next link row, then out of the list | the next link row or control | by hand |
| Enter | a link row | follows the link | the page the link opens | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| list | list | nothing; name it with a heading above | `aria-busy` while the Skeleton rows show | "list, 5 items" when a reader reaches it | test |
| row | listitem | its text: the name, `detail` and the figure | `data-rest` on the rest row | the row's text, in that order | test |
| link row | link | its text: the name, `detail` and the figure | none | the text and "link" | test |
| fill | none, `aria-hidden="true"` | nothing | none | nothing | test |
| pending rows | none | a hidden "Loading" in the first item | `aria-busy` on the list; the Skeleton rows are `aria-hidden` | "Loading" once | by hand |
| failure | alert | its title | none | "Could not load the list" once | test |

## Tokens
| Part | State | Token |
|---|---|---|
| fill | all | `--primary-soft`, `--r-md` |
| row | hover | `--hover`, `--t-press`, `--curve` |
| figure | all | `--foreground` |
| detail | all | `--muted-foreground` |
| rest row | all | `--muted-foreground` |
| pending rows | pending | `--muted` through Skeleton |

## Related
- Meter: one value against a fixed limit.
- Stat: one figure and its change, with no ranking.
- DataTable: records a person sorts, filters and opens.
- Chart: values over time, or across groups where the shape is the point.
- BarChart: amounts per period or group, vertical or horizontal, grouped or stacked.
- Heatmap: values on a grid or a calendar, shaded by size.
- ScatterChart: two measures of many things, one dot each.
- CompositionBar: the parts of one whole in a single bar, with each part's amount and share.
