Stat
One large figure with a label, unit and badge.
Demo
Usage
import { Badge, List, RollingNumber, Stat } from '@tuttn/slant'
<Stat label="Sessions" value="1,284" badge={<Badge mono tone="success">+12.4%</Badge>} />
// A unit after the figure, a line under it, the smaller size.
<Stat label="Focus" value="26.5" unit="h" description="In sessions over 25 min" size="md" />
// A RollingNumber rolls each digit to the new value; aria-live reads it out.
<Stat label="Sessions" value={<RollingNumber value={sessions} />} aria-live="polite" />
// Several in a List, each as an li.
<List>{figures.map(figure => <Stat key={figure.id} as="li" {...figure} />)}</List>Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | — | What the figure measures, written above it in the hint style. |
value | ReactNode | — | The figure, set large in monospace. A RollingNumber here rolls from one value to the next. |
unit | ReactNode | — | Written smaller just after the figure: "h", "ms", "%". |
badge | ReactNode | — | Sits after the figure, on its baseline: usually a Badge, such as a delta. |
description | ReactNode | — | A short line under the figure that says what it covers. |
size | 'md' | 'lg' | 'lg' | `lg` is the headline size; `md` matches a StatCard's figure. |
as | 'div' | 'li' | 'div' | The root element; use `li` inside a List. |
…rest | HTMLAttributes<HTMLElement> | — | className, style, aria-live, other attributes and the ref go on the root (div or li). |
A stat is one figure written large: the label above it in the hint style, the figure in monospace with tabular numbers, a smaller unit beside it and a badge on its baseline, and an optional line of description under it. It draws only the number. For a figure with a delta, a sparkline or progress toward a target, use a StatCard; for a reading on a scale, a RangeMeter.
It holds no state and handles no events, so it renders the same on the server. The label, figure, unit, badge and description are read in that order. When the figure changes while someone works nearby (a period switch, a chart they are exploring), put aria-live="polite" on the Stat or on the list that holds it, so the new figure is read out without interrupting. A RollingNumber as the value rolls each digit to the new one, and shows it at once under prefers-reduced-motion.