# Meter

A level against a limit, in five forms: one bar, a bar in parts, a limit as a row, a grid of windows, and a room that fills up.

Live variants: https://design.arcadia.is/components/meter

```tsx
import {
  Meter, MeterList, MeterListGroup, fmtLeft, leftTone, fmtReset, formatBytes,
} from "@arcadia/ui";
```

- Room left: neutral
- 15% or under: warning
- Spent: danger
- `off`: a sign-in to renew
- `unknown`: nothing reported
- `pending`: not read yet
- `busy`: working on it
- `stale`: an old number
- `emphasis`: strong, normal, quiet
- `muted`: room, low, spent

## In parts

Point at a segment to read what remains in that account.

```tsx
import { useState } from "react";
import { Meter } from "@arcadia/ui";

function Accounts() {
  const [active, setActive] = useState<string | null>(null);
  const shown = ACCOUNTS.find((a) => a.id === (active ?? "work"))!;
  const value = shown.state === "off" ? "Signed out" : shown.tone === "danger" ? "Limit reached" : `${shown.value}% left`;
  return (
    <div {...sx("cmp-meter-parts-row", sParts.row)}>
      <span {...sx("cmp-meter-parts-name", sParts.name)}>Five accounts</span>
      <span {...sx("cmp-meter-parts-meter", sParts.meter)}><Meter label="Five accounts" segments={ACCOUNTS} active={active} onActiveChange={setActive} /></span>
      <span {...sx("cmp-meter-parts-value", sParts.value)}>{value}</span>
    </div>
  );
}
```

## As a row

Plan windows as limit rows: what is left, low from 15%, spent as Limit reached.

```tsx
import { MeterList } from "@arcadia/ui";

<div {...sx("cmp-plans", sBar.stack)}>
  <MeterList>
    <PlanWindow label="5-hour" left={72} resetsIn={2 * HOUR + 10 * 60_000} />
    <PlanWindow label="Weekly" left={9} resetsIn={3 * 24 * HOUR} />
    <PlanWindow label="Daily" left={0} exhausted resetsIn={7 * HOUR} />
  </MeterList>
</div>
```

## A grid

Four accounts at 15:25: one open and lit, two closed by their 5-hour though their weeks remain, and one closed by its week.

```tsx
import { useState } from "react";
import { Meter, Card, CardBody } from "@arcadia/ui";

function PoolGrid({ accounts, windows, ends, count, point = null }: {
  accounts: Account[]; windows: Kind[]; ends: Partial<Record<Kind, string>>; count: string; point?: string | null;
}) {
  const [active, setActive] = useState(point);
  const at = accounts.find((a) => a.id === active);
  const rows: MeterGridRow[] = windows.map((w) => ({
    id: w, label: LABELS[w], end: at ? said(at.off ? undefined : at.r[w]) : ends[w],
    segments: accounts.flatMap((a) => segment(a, w) ?? []),
  }));
  return (
    <Card rootStyle={sGrid.card}>
      <CardBody render={<div {...stylex.props(sGrid.body)} />}>
      <div {...sx("cmp-meter-grid-head", sGrid.head)}>
        <span {...sx("cmp-meter-grid-title", sGrid.title)}>Claude</span>
        {at ? (
          <span {...sx("cmp-meter-grid-who", sGrid.who, sGrid.note)}>
            {at.lit && <span {...sx("cmp-meter-grid-dot", sGrid.dot)} />}
            <span {...sx("cmp-meter-grid-id", sGrid.whoId)}>{at.id}</span>{" "}<span {...sx("cmp-meter-grid-plan", sGrid.plan)}>{at.off ? "Sign-in expired" : at.plan}</span>
          </span>
        ) : <span {...sx("cmp-meter-grid-count", sGrid.note)}>{count}</span>}
      </div>
      <Meter rows={rows} active={active} onActiveChange={setActive} label="Claude usage"
        columnLabel={(id) => `${id}, ${accounts.find((a) => a.id === id)!.say}`} />
      </CardBody>
    </Card>
  );
}
```

## A capacity

A team's storage: what it holds by kind, against its limit, and what is free.

```tsx
import { Meter } from "@arcadia/ui";

<Meter used={26.8 * MB} limit={250 * MB} kinds={[
  { name: "Images", value: 18.2 * MB }, { name: "Files", value: 6.1 * MB }, { name: "Exports", value: 2.5 * MB },
]} />
```

## Accessibility

### On a level

With a `label` the bar is a `meter` with its value and range, and a `valueText` that says the whole fact: "52% left, resets October 11 at 16:37". Without a label it is decorative, beside text that already says it. Tone is colour only, so the words beside the bar carry low and spent too: a window under one percent reads as less than 1% left, a spent one as `Limit reached`. `held` is never spoken on its own, so a `valueText` names it; a `none` slot is hidden from assistive technology. Under forced colours, which drop every fill, the track keeps an edge in the system's ink and the fill takes the system's highlight.

### On a bar in parts

Without a `label` the group is decorative: say what it shows in the words beside it, or in the name of the control it sits in. With a `label` it is a `group` of its labelled segments, each a `meter` (or, when it is not a level, an `img` named by its state). Tone and emphasis are colour only, so the words carry spent, low and signed out too. A glide never runs under the pointer or the focus, so nothing moves while someone is reading it.

### On a row

A row is one thing to a screen reader: its bar is a `meter` named by the name and the scope ("Weekly Deep"), and its value text is the sentence a person reads, the figure and then the circumstance ("100% left, resets Nov 20, 6:27 AM"). The line itself is hidden from assistive technology, since the bar says it. A bar that is not a level is an image named the same way ("5-hour: Sign-in expired"), and a bar in parts a group.

The list is a list and each row an item; a group is a list of its own, named by its head. Nothing in a row takes focus. The one exception is an action, at a head's end or in a row's figure, and it is a real button or link. Colour is never alone: the figure's word says low and spent.

As a row's face the meter row is the toggle's content: the toggle is named by the sentence the row reads ("Anthropic: 1 of 4 open, 1 back in 1h 15m") and says whether it is expanded, and the bar inside it is drawn only. The row's actions stand beside the toggle, never in it, and come after it in the Tab order; the open action shows when it takes focus.

### On a grid

The grid is a `group` named by `label`. Its strips are one tab stop: Left and Right move along the columns, Home and End go to the ends, and Escape lets go. Each column is spoken by `columnLabel(id)`, so say the whole account there: its name, whether it is open, and when it comes back. The strips themselves are decorative, and the row labels and ends are plain text beside them.

### On a capacity

A room is one sentence to a screen reader, the line and then its kinds: "27 MB of 250 MB used, 223 MB free. Images 27 MB." The line, the bar and the legend are drawn for the eye and hidden from assistive technology, and nothing in the part takes focus.

Colour is never alone: each kind is named in the legend in the bar's order, and full and over are words. Under forced colours the kinds and their dots keep their colours, one fill takes the system's highlight, and the bar keeps an edge in the system's ink.

## API reference

### Meter

- `value` (`number`, required): What is left, 0..100 (clamped), never what is used.
- `held` (`number`): What comes back with it, 0..100: a faint second fill, drawn on a spent track too.
- `marker` (`number`): A reference mark on the remaining scale (for example where steady pace stands). Shown inside (0, 100) on a level bar and omitted on a stale one (H185).
- `tone` (`"neutral" | "warning" | "danger"`, default `"neutral"`): `warning` (yellow fill) at 15% left or under; `danger` (a red track) once spent.
- `size` (`"sm" | "md"`, default `"md"`): `md` (4px) or `sm` (2px, a dense row).
- `state` (`"level" | "off" | "unknown" | "pending" | "busy" | "none"`, default `"level"`): What the bar says when it is not a level.
- `emphasis` (`"strong" | "normal" | "quiet"`, default `"normal"`): The fill's rank among neighbouring meters.
- `stale` (`boolean`): The number is old (the last read failed): the bar steps back.
- `dim` (`boolean`): Another meter of its group has the pointer: this one goes quiet.
- `muted` (`boolean`): Every ink a step quieter, for a glance in the app's chrome such as a sidebar: the fill a little over the track, a spent track a dim red, a low fill a dim yellow.
- `label` (`string`): Accessible name ("Weekly"): with one the bar is a `meter`, without it is decorative.
- `valueText` (`string`): Spoken value: "52% left, resets October 11 at 16:37". Default: the rounded value with "left".
- `rootStyle` (`RootStyle<MeterKnobs>`): Typed StyleX override: layout and the `--meter-*` knobs.

### Meter segments

- `segments` (`readonly MeterSegment[]`, required): One to fifteen, in drawing order; dense past five.
- `size` (`"sm" | "md"`, default `"md"`): A level's `size`, for every segment.
- `active` (`string | null`): The segment with the pointer: it keeps its ink, the others go quiet.
- `onActiveChange` (`(id: string | null) => void`): The pointer came to a segment, or left the bar (`null`).
- `label` (`string`): Accessible name ("ChatGPT accounts"): with one it is a `group` of its labelled segments.
- `muted` (`boolean`): Every segment a step quieter: a level's `muted`.
- `rootStyle` (`RootStyle<MeterPartsKnobs>`): Typed StyleX override: layout and the `--meter-parts-*` knobs.

### Meter name

- `name` (`string`, required): "Weekly": with `scope`, the bar's accessible name.
- `mark` (`IconName | ReactNode`): An icon's name or a `ProviderMark`, on the name's capitals.
- `scope` (`string`): Whose window it is, where one thing has its own ("Deep").
- `detail` (`string`): The circumstance ("Resets in 3h"): the first to give way.
- `figure` (`string`): What is left, in words ("64% left"): never cut.
- `action` (`ReactNode`): A button or link in the figure's place. As a row's `face` it has none: the row's own `action` stands there.
- `value` (`number`, default `0`): What is left, 0..100.
- `segments` (`readonly MeterSegment[]`): A bar in parts instead of one level.
- `active` (`string | null`): The segment with the pointer: it keeps its ink and the others go quiet.
- `onActiveChange` (`(id: string | null) => void`): The pointer came to a segment, or left the bar (`null`).
- `held` (`number`): A level's `held`.
- `marker` (`number`): A level's `marker`.
- `tone` (`"neutral" | "warning" | "danger"`, default `"neutral"`): A level's `tone`, which the figure takes too.
- `state` (`"level" | "off" | "unknown" | "pending" | "busy" | "none"`, default `"level"`): A level's `state`.
- `emphasis` (`"strong" | "normal" | "quiet"`, default `"normal"`): A level's `emphasis`; `quiet` quiets the figure too.
- `stale` (`boolean`): A level's `stale`.
- `valueText` (`string`): Default: the figure, then the detail.
- `onClick` (`() => void`): Makes the whole row a button (ignored inside a disclosure face or when `action` is set).
- `clickLabel` (`string`): Accessible name for an interactive row; defaults to the row's label and spoken value.
- `rootStyle` (`RootStyle`): A component's typed override prop: `Layout` and its documented knobs, each the references it takes or another kit knob of its kind; anything else is a type error at the call site (STYLEX.md).

### Meter rows

- `rows` (`readonly MeterGridRow[]`, required): The windows, a row each, top to bottom: its label, its end and its segments by column id.
- `active` (`string | null`): The column being read, in every row at once.
- `onActiveChange` (`(id: string | null) => void`): The pointer or the arrows came to a column, or left (`null`).
- `label` (`string`, required): The grid's accessible name ("Claude usage").
- `columnLabel` (`(id: string) => string`): A column's spoken name. Default: its id.
- `size` (`"sm" | "md"`, default `"md"`): A level's `size`, for every segment.
- `rootStyle` (`RootStyle<MeterGridKnobs>`): Typed StyleX override: layout and the `--meter-grid-*` knobs.

### Meter used

- `used` (`number | undefined`, required): What the room holds: bytes, or a count with `format`. Passed as `undefined`, the part holds its place, a line over a bar, for an amount not read yet. Always passed: it is what makes a meter a capacity.
- `pending` (`boolean`): The amount is still being read: the place holds a line and a bar, with the kit's `Skeleton`s in them. With no `used` the place stands whether or not the bones show, so a read does not move the page when it lands.
- `limit` (`number | null`): The most it holds, in `used`'s unit. Left out or `null`: no limit, so no bar and one line, "27 MB used". It may fall under what the room holds already: the bar stays full and nothing is hidden.
- `kinds` (`readonly MeterKind[]`): What it holds by kind, in the product's own order, kept as sizes change: the first takes `--chart-1`, the second `--chart-2`, so a kind keeps its colour. The bar and the legend draw them largest first. Past six the rest are one part, Other, and so is what `used` holds beyond the kinds.
- `format` (`((n: number, round?: ByteRounding) => string) | MeterUnit`, default `formatBytes`): How an amount is written. "27 MB". A counted thing passes its unit's words, a `MeterUnit`, and the unit is said once: "7 of 10 seats used", a legend of plain counts. Passed `"up"` for what is used or over, `"down"` for what is free and `"nearest"` for the limit, so a room never reads emptier or freer than it is.
- `usedText` (`(used: string, limit: string | null) => string`, default `"27 MB of 250 MB used"`): The words of what is used, from the amounts as written. And "27 MB used" with no limit.
- `freeText` (`(free: string) => string`, default `"223 MB free"`): The words of what is free.
- `fullText` (`string`, default `"Full"`): The word for no room left.
- `overText` (`(over: string) => string`, default `"Over by 62 MB"`): The words of how far past the limit.
- `otherText` (`string`, default `"Other"`): The name of the kinds past the sixth, with what `used` holds beyond the kinds.
- `rootStyle` (`RootStyle`): Typed StyleX override: layout.

Rest props go to `HTMLAttributes<HTMLDivElement>`.

### MeterList

- `label` (`string`): Its accessible name.
- `rootStyle` (`RootStyle`): A component's typed override prop: `Layout` and its documented knobs, each the references it takes or another kit knob of its kind; anything else is a type error at the call site (STYLEX.md).

### MeterListGroup

- `name` (`string`, required): "OpenAI": with `detail`, the group's accessible name.
- `mark` (`IconName | ReactNode`): An icon's name or a `ProviderMark`, on the name's capitals.
- `detail` (`string`): After the name ("ChatGPT Plus").
- `action` (`ReactNode`): At most one control, at the end.
- `rootStyle` (`RootStyle`): A component's typed override prop: `Layout` and its documented knobs, each the references it takes or another kit knob of its kind; anything else is a type error at the call site (STYLEX.md).
