# Stat

A number and what it is: a label, its period, the value with its change, and a sparkline whose reading writes the value.

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

```tsx
import { Stat, StatTone } from "@arcadia/ui/charts";
```

A dashboard's head: four tiles, each today against the same day four weeks before. Point at a sparkline and its tile reads the day.

```tsx
import { Sparkline, Stat } from "@arcadia/ui/charts";
import { fmtCount, Delta } from "@arcadia/ui";

<div {...sx("cmp-stat-row", StatS.row)}>
  <div {...sx("cmp-stat-tile", StatS.tile)}>
    <Stat label="Requests" period="Today" value={fmtCount(last(REQUESTS))} delta={<Delta value={change(REQUESTS)} baseline={SINCE} />}>
      <Sparkline label="Requests per day" x={FOUR_WEEKS} values={REQUESTS} kind="area" format={fmtCount} />
    </Stat>
  </div>
  <div {...sx("cmp-stat-tile", StatS.tile)}>
    <Stat label="Latency" period="Today" value={`${last(RESPONSE)}ms`} delta={<Delta value={change(RESPONSE)} baseline={SINCE} polarity="down" />}>
      <Sparkline label="Latency per day" x={FOUR_WEEKS} values={RESPONSE} unit="ms" />
    </Stat>
  </div>
  <div {...sx("cmp-stat-tile", StatS.tile)}>
    <Stat label="Errors" period="Today" value={fmtCount(last(FAILURES))} delta={<Delta value={change(FAILURES)} baseline={SINCE} polarity="down" />}>
      <Sparkline label="Errors per day" x={FOUR_WEEKS} values={FAILURES} kind="bars" />
    </Stat>
  </div>
  <div {...sx("cmp-stat-tile", StatS.tile)}>
    <Stat label="Sessions" period="Today" value={fmtCount(last(SESSIONS))} delta={<Delta value={change(SESSIONS)} baseline={SINCE} polarity="up" />}>
      <Sparkline label="Sessions per day" x={FOUR_WEEKS} values={SESSIONS} format={fmtCount} />
    </Stat>
  </div>
</div>
```

## Accessibility

A tile is a group (`role="group"`) named by its label. Inside it a screen reader meets the period, the value and its unit, the change in words, "up 12% from Sep 8", the note, then the sparkline, named from its data.

Its sparkline is a slider over its rows whose value text is the read row's: one key back from the newest, the first tile's reads "Mon, Oct 5: 9,070". That is what is heard as the keys step it; the tile's own value changes for the eye, so the tile needs no status region.

## API reference

### Stat

- `label` (`string`, required): What it counts: "Requests", "Spend in USD".
- `period` (`string`): What the value covers: "Today".
- `value` (`string`, required): In full: "12,480".
- `tone` (`"neutral" | "muted" | "accent" | "success" | "warning" | "danger"`, default `"neutral"`): The figure's ink: `neutral`, `muted` for a figure that matters less, `accent`, `success`, `warning` or `danger` for one already read against a limit.
- `unit` (`string`): A unit beside the value, in Caption: "%", "ms", "GB".
- `note` (`ReactNode`): One quiet line under the value and its change, in Caption: a limit, a count of boards.
- `delta` (`ReactNode`): A `Delta`.
- `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).
- `children` (`ReactNode`): A `Sparkline`, whose reading writes the value and the period.

Rest props go to `HTMLAttributes<HTMLDivElement>`.
