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

## Description
Shows one figure that matters on a page, with its name, how it changed since the last period and what it counts.

`import { Stat } from "@/components/cobalt/ui/stat"`, source `registry/cobalt/ui/stat.tsx`, status `ready`.
Foundation: `hand-rolled`. Traps checked: `trap/numbers-shift`, `trap/color-only-status`, `trap/empty-value`, `trap/text-measure`, `trap/weight-shift`, `trap/loading-layout-shift`.

`trap/numbers-shift` is answered by tabular figures on the value and the change (Tokens). `trap/color-only-status` by the sign beside the colour, with the direction word for a screen reader (Anti-slop). `trap/empty-value` by `missing(reason)`, which reads the reason through MissingValue, and by `none` for a value of nothing (States). `trap/text-measure` by the value's break inside a long figure (Limits). `trap/weight-shift` n/a: nothing changes weight between states. `trap/loading-layout-shift` by `pending`, whose skeleton lines take each line's own height (States).

### Foundation
Not applicable: hand-rolled.

| Given by the foundation | Added by the team |
|---|---|
| Not applicable: hand-rolled, a `dl` with one `dt` and up to three `dd` | The value at the page title's size and weight (`text-2xl font-semibold tracking-tight`) in tabular figures; `change` as a percentage formatted by `change()` from `@/lib/cobalt/format`, with its sign, "+2.4%", and a direction word a screen reader hears after it (`sr-only`), "+2.4% up", since on screen the sign already says it and "+2.4% up" said the direction twice; `positive` to say which direction is good, so a falling cost reads in the good colour; zero reads "No change" and a change that is not a number shows nothing; a figure the source did not give, `missing(reason)` from `registry/cobalt/lib/missing.ts`, reads its reason through MissingValue at the figure's size in the label's ink (`registry/cobalt/ui/stat.tsx:140-142`), and a value of nothing reads `none`; `words` for another language; `pending` for the first load: the label, a skeleton line at the value's size, and one at the change's and the note's size when `change` or `note` is written but not here yet, with `aria-busy` |

## Examples
A figure, its change since the last filing, and what it counts.

Real uses, 0 call sites (`rg -n "<Stat\b" app registry --glob '!registry/cobalt/ui/*'`): the part is new. Atlas renders 18 stats by hand on its profile pages (`docs/research/2026-10-17-coverage.md`, section 3).

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/stat/default.tsx` | default | A figure, its change since the last filing, and what it counts |
| `docs/system/examples/stat/positive-up.tsx` | positive=up | Where more is better, a rise reads in the good colour and a fall in the bad |
| `docs/system/examples/stat/positive-down.tsx` | positive=down | For a cost or a wait, where less is better, a fall reads in the good colour |
| `docs/system/examples/stat/state-no-change.tsx` | state:no-change | A change of zero says No change instead of a sign |
| `docs/system/examples/stat/state-missing.tsx` | state:missing | A figure the filing did not give reads its reason, Not reported, at the figure's size in the label's ink |
| Not applicable: a headline figure of nothing reads as a 0 the host formats; `none` is there for a value the host leaves empty | state:none | A value of nothing reads None |
| `docs/system/examples/stat/pending.tsx` | state:pending | Figures on their first load: each label shows at once and each figure holds its line with a skeleton line at its size |
| `docs/system/examples/stat/in-card.tsx` | composition:Card | Three figures across a card, the head of a fund's page |

Example: A figure, its change since the last filing, and what it counts (`docs/system/examples/stat/default.tsx`)

```tsx
import { Stat } from "@/components/cobalt/ui/stat";

export default function Example() {
  return <Stat label="Gross assets" value="$4.8B" change={2.4} note="Since the June filing" />;
}
```

Example: Three figures across a card, the head of a fund's page (`docs/system/examples/stat/in-card.tsx`)

```tsx
import { Card, CardContent } from "@/components/cobalt/ui/card";
import { Stat } from "@/components/cobalt/ui/stat";

export default function Example() {
  return (
    <Card className="w-full max-w-2xl">
      <CardContent className="grid gap-6 sm:grid-cols-3">
        <Stat label="Gross assets" value="$4.8B" change={2.4} note="Since the June filing" />
        <Stat label="Holdings" value="186" change={-1.1} note="Since the June filing" />
        <Stat label="Expense ratio" value="0.42%" change={0} positive="down" note="Since last year" />
      </CardContent>
    </Card>
  );
}
```

## Variants

### positive
- `up`: a rise is good news, such as assets or bookings. The default. Used at 0 call sites.
- `down`: a fall is good news, such as a cost or a wait. Used at 0 call sites.

Example: Where more is better, a rise reads in the good colour and a fall in the bad (`docs/system/examples/stat/positive-up.tsx`)

```tsx
import { Stat } from "@/components/cobalt/ui/stat";

export default function Example() {
  return (
    <div className="grid max-w-md grid-cols-2 gap-6">
      <Stat label="Nights booked" value="1,284" change={6.1} positive="up" note="This month" />
      <Stat label="Occupancy" value="71%" change={-3.2} positive="up" note="This month" />
    </div>
  );
}
```

Example: For a cost or a wait, where less is better, a fall reads in the good colour (`docs/system/examples/stat/positive-down.tsx`)

```tsx
import { Stat } from "@/components/cobalt/ui/stat";

export default function Example() {
  return (
    <div className="grid max-w-md grid-cols-2 gap-6">
      <Stat label="Expense ratio" value="0.42%" change={-4.5} positive="down" note="Since last year" />
      <Stat label="Average check-in wait" value="6 min" change={12} positive="down" note="This week" />
    </div>
  );
}
```

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| plain | no `change` | read the figure | the label and the value | test |
| rise | `change` above 0 | read it | the plus sign, and the word "up" for a screen reader | test |
| fall | `change` below 0 | read it | the minus sign, and the word "down" for a screen reader | test |
| no-change | `change` is 0 | read it | the words "No change" | test |
| missing | `value` is `missing(reason)` | read why the figure is not there | the reason's words through MissingValue at the value's size, in the label's colour, such as "Not reported", and `data-missing` with the reason | test |
| none | `value` is null, undefined, false or an empty string | read that there is nothing | the word "None" at the value's size, in the label's colour | test |
| pending | `pending`, the first load | wait | the label; a skeleton line in the value's place, and in the change's and note's when they are written but not here; `aria-busy` | test |

Example: A change of zero says No change instead of a sign (`docs/system/examples/stat/state-no-change.tsx`)

```tsx
import { Stat } from "@/components/cobalt/ui/stat";

export default function Example() {
  return <Stat label="Holdings" value="186" change={0} note="Since the June filing" />;
}
```

Example: A figure the filing did not give reads its reason, Not reported, at the figure's size in the label's ink (`docs/system/examples/stat/state-missing.tsx`)

```tsx
import { Stat } from "@/components/cobalt/ui/stat";
import { missing } from "@/lib/cobalt/missing";

export default function Example() {
  return <Stat label="Beneficial owners" value={missing("not-reported")} note="Not in this filing" />;
}
```

Example: Figures on their first load: each label shows at once and each figure holds its line with a skeleton line at its size (`docs/system/examples/stat/pending.tsx`)

```tsx
import { useEffect, useState } from "react";

import { Card, CardContent } from "@/components/cobalt/ui/card";
import { Stat } from "@/components/cobalt/ui/stat";

type Figures = { assets: string; assetsChange: number; holdings: string; holdingsChange: number; ratio: string; ratioChange: number };

// Stands in for your API call. It answers after 1.5 seconds.
const readFigures = () =>
  new Promise<Figures>((resolve) =>
    setTimeout(
      () => resolve({ assets: "$4.8B", assetsChange: 2.4, holdings: "312", holdingsChange: -1.3, ratio: "0.42%", ratioChange: 0 }),
      1500,
    ),
  );

export default function Example() {
  const [figures, setFigures] = useState<Figures | null>(null);
  useEffect(() => {
    void readFigures().then(setFigures);
  }, []);
  const pending = figures === null;
  return (
    <Card className="w-full max-w-xl" aria-busy={pending}>
      <CardContent className="grid grid-cols-1 gap-6 sm:grid-cols-3">
        <Stat pending={pending} label="Gross assets" value={figures?.assets} change={figures?.assetsChange} note="Since the March filing" />
        <Stat pending={pending} label="Holdings" value={figures?.holdings} change={figures?.holdingsChange} note="Since the March filing" />
        <Stat pending={pending} label="Expense ratio" value={figures?.ratio} change={figures?.ratioChange} positive="down" note="Since the March filing" />
      </CardContent>
    </Card>
  );
}
```

### State precedence
- Rise, fall and no-change: Not applicable: a number is above, below or at zero.
- Missing or none and rise or fall: both show. The change still reads under the reason or "None", since a source can report a change without the figure.
- Pending and missing or none: pending wins. A value still on its way is not missing, so it draws a bar, never a reason or "None".
- Missing and none: Not applicable: a value is `missing(reason)` or empty, not both.
- Pending and a written note: both show. A note that is already words shows; only a note still on its way draws a bar.
- Plain and a change that is not a number: plain wins. `NaN` and `Infinity` format to nothing, so the line is left out.

### Motion
Not applicable: no motion. A figure that changes while the page is open swaps its text in place; a host that wants that seen wraps the value in `TextSwap`.

## Props

<!-- Props generated from registry/cobalt/ui/stat.tsx with TypeScript by scripts/props-table.mjs -->
| Prop | Type | Default | Purpose |
|---|---|---|---|
| `label` | `ReactNode` |  | What the figure is: "Gross assets", "Nights booked". |
| `value` | `ReactNode \| Missing` |  | The figure, already formatted: "$4.8B", "1,284"; or `missing(reason)` when the source did not give it. |
| `change?` | `number` |  | The change as a percentage, signed: 2.4 is a rise, -0.4 a fall. |
| `locale?` | `string` |  | The locale the change is formatted in. |
| `none?` | `string` |  | What a value of nothing reads: the answer that there is none. |
| `note?` | `ReactNode` |  | One line under the figure: the period, the source, what it counts. |
| `pending?` | `boolean` |  | The first load: the label, and a skeleton line for each line still on its way. |
| `positive?` | `"up" \| "down"` |  | Which direction is good news. |
| `words?` | `StatWords` |  | The direction words, for another language. |

Also accepts every native HTML attribute.

`label` names the figure. `value` is the figure, already formatted, or `missing(reason)` when the source did not give it. `change` is a signed percentage. `positive` says which direction is good. `note` is one line under the figure, such as the period. `none` is the text for a value of nothing. `words` replaces "up", "down" and "No change". `locale` formats the change. `pending` is the first load; write `change={data?.change}` and `note` as they will be loaded, and a line written but not here yet holds its place. Every native `dl` attribute passes through.

## Usage

### When to use
- A record or a dashboard leads with 2 to 4 figures a person checks first, such as assets, holdings and the expense ratio.
- A figure's change since the last period matters as much as the figure.

### When not to use
- The figures are facts about one thing with no change and no emphasis. Use DataList instead.
- The figures are a series over time. Use a chart instead, per coverage-gaps row "Charts".
- The figure is a count beside a heading. Use Badge instead.

### Rules
- `rule/stat-positive-for-costs`: When less is better for a figure, such as a fee, a wait or a churn rate, pass `positive="down"`, because the default reads a rise as good, and a rising cost in the good colour tells the person the opposite of the truth. Evidence: principle heuristic: match between system and the real world, the colour follows the meaning, not the sign; single use docs/system/examples/stat/positive-down.tsx:7. Check: review of every `Stat` whose label names a cost, a fee, a wait or a rate of loss.
  - Don't: `<Stat label="Expense ratio" value="0.42%" change={-4.5} />`
  - Do: `<Stat label="Expense ratio" value="0.42%" change={-4.5} positive="down" />`
- `rule/stat-change-is-percent`: When passing `change`, pass the signed percentage, such as 2.4 for a rise of 2.4 percent, and say the period in `note`, because the stat formats it through `change()` and a change without its period cannot be read. Evidence: app 2/2 source apps pair a change with its period, docs/research/2026-10-17-coverage.md section 3; principle heuristic: match between system and the real world. Check: review.
  - Don't: `<Stat label="Gross assets" value="$4.8B" change={0.024} />`
  - Do: `<Stat label="Gross assets" value="$4.8B" change={2.4} note="Since the June filing" />`
- `rule/stat-format-the-value`: When the value is a number, pass it through `compact()`, `compactMoney()` or `percent()` from `@/lib/cobalt/format` first, because the value is set at 24px and an unformatted 4800000000 is 10 digits that break the column. Evidence: measured "$1,400,000,000,000" breaks onto 2 lines in a 192px column at 320, docs/system/stress/stat.tsx. Check: review.
  - Don't: `<Stat label="Gross assets" value={4800000000} />`
  - Do: `<Stat label="Gross assets" value={compactMoney(4.8e9)} />`

### Content
- Follows `rule/writing-no-invented-numbers`.
- `rule/stat-label-names-the-figure`: When writing `label`, name what is counted in at most 4 words in sentence case, such as "Nights booked", and put the period in `note`, because the label is what a person reads to know which figure they are looking at. Evidence: principle heuristic: recognition rather than recall; app 2/2 source apps label stats with nouns, docs/research/2026-10-17-coverage.md section 3. Check: review of the stat slots in `docs/system/copy-inventory.tsv`.
  - Don't: `<Stat label="Total nights booked this month so far" value="1,284" />`
  - Do: `<Stat label="Nights booked" value="1,284" note="This month" />`

### Anti-slop
- `rule/stat-no-arrow-glyph`: When showing a change, rely on the sign `Stat` shows and the word it gives a screen reader instead of adding an arrow icon or a coloured badge, because the sign carries the direction on screen and the word carries it aloud, and a third mark only adds noise. Evidence: principle wcag: 1.4.1 Use of color, the sign and the word carry it; person D13. Check: review.
  - Don't: `<Stat label="Bookings" value="128" note={<><ArrowUpIcon /> 3%</>} />`
  - Do: `<Stat label="Bookings" value="128" change={3} />`
- `rule/stat-few-per-view`: When a view leads with stats, show at most 4 instead of a wall of tiles, because past 4 none of them is the figure the person checks first. Evidence: app 2/2 source apps lead a profile with 3 or 4 stats, docs/research/2026-10-17-coverage.md section 3; principle heuristic: aesthetic and minimalist design. Check: review of every view that renders `Stat`.
  - Don't: `{figures.map((f) => <Stat key={f.label} {...f} />)}` with 9 figures
  - Do: `<Stat label="Gross assets" value="$4.8B" />` and 2 more, with the rest in a `DataList`

- `rule/stat-pending-same-element`: When the figures load, render the same `Stat` with `pending` and its props read from the data, such as `change={data?.change}`, instead of a Skeleton block in its place, because the stat holds exactly the lines it will have and keeps its height. Evidence: person D37; measured Fund Census's stats at 122px loading and loaded, docs/research/2026-10-17-fund-census-states.md section 2. Check: test `stat.test.tsx` "shows the label and holds each line still on its way with a skeleton line".
  - Don't: `{data ? <Stat label="Gross assets" value={data.assets} /> : <Skeleton shape="block" className="h-16" />}`
  - Do: `<Stat pending={!data} label="Gross assets" value={data?.assets} change={data?.change} />`

### Limits
- `rule/stat-value-length`: When the value runs past 14 characters, shorten it with `compactMoney()` or `compact()` instead of the full figure, because at 24px a value of 18 characters breaks onto 2 lines in a 192px column. Evidence: measured "$1,400,000,000,000" on 2 lines at 192px (320) and on 1 line at 262px (390), docs/system/stress/stat.tsx. Check: probe docs/system/stress/stat.tsx on the break-ui harness at 320.
  - Don't: `<Stat label="Net assets" value="$1,400,000,000,000" />`
  - Do: `<Stat label="Net assets" value={compactMoney(1.4e12)} />`

## Accessibility
Rests on a `dl` with one `dt` and up to three `dd`.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the stat | passes over it; nothing in it is focusable | the next focusable element | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| root | list (from `dl`) | none | none | the label, the value, the change and the note, in that order | test |
| change | definition (from `dd`) | its text | `data-direction` for styling only | the sign as "plus" or "minus", the figure and the word, such as "plus 2.4 percent up" | test |

## Tokens
| Part | State | Token |
|---|---|---|
| label | all | `--muted-foreground` |
| value | all | `--foreground` |
| value | missing | `--muted-foreground`, through MissingValue |
| value | none | `--muted-foreground` |
| change | rise with `positive="up"`, fall with `positive="down"` | `--good` |
| change | fall with `positive="up"`, rise with `positive="down"` | `--bad` |
| change | no-change | `--muted-foreground` |
| note | all | `--muted-foreground` |

## Related
- DataList: facts with no change and no emphasis.
- MissingValue: the words a figure says when the source did not give it.
- Badge: a count beside a heading.
- Card: the surface a row of stats usually sits on.
- BarList: ranked names with their values, each row filled to its share of the largest.
- ChartCard: a card with a chart's title, headline figure, change and note.
- Chart: the frame every chart draws in: size, states, hover, tooltip, keyboard, legend and change chip.
- LineChart: a value over time, one line per series, with a dashed comparison.
- Sparkline: a trend at a glance, with no axes, for a table cell or beside a figure.
- WaterfallChart: how a total moved from one amount to another, step by step.
- ResultCount: how many results a query found: exact, about, at least, or capped with a way past the cap.
