Stat
Summary figures: Stat, StatLabel, StatValue (a number, a Quantity or a node), StatHint, StatDelta (a change with its direction in words) and StatMedia (an icon in a tone chip at the end), in a responsive StatGroup list.
Example
- Done12up 20% vs. last week
- Cost$4.20 (estimated)down 8% vs. last week
- DurationunknownNot reported
stat-demo.tsxCopy code
Installation
Copy code
Usage
ImportCopy code
For a KPI card, put a StatMedia with an icon and a tone among the parts; the Stat lays it out at the end, beside the label, value and hint.
API reference
StatMedia
| Prop | Type | Default |
|---|---|---|
toneThe chip's soft fill and the colour of the icon on it. Default `neutral`. | Tone | "neutral" |
labelNames what the media shows (`role="img"`); without it the chip is decorative and hidden from assistive technology. | string | – |
Also takes <div> attributes and render.
StatValue
| Prop | Type | Default |
|---|---|---|
value | number | Quantity | – |
Also takes <div> attributes and render, FormatQuantityOptions.
StatGroup
| Prop | Type | Default |
|---|---|---|
children | ReactNode | – |
Also takes <ul> attributes and render except children.
StatDelta
| Prop | Type | Default |
|---|---|---|
valuerequiredThe change, as a ratio by default: 0.12 reads "12%". Its sign gives the direction. | number | – |
directionOverrides the direction the sign gives, as for a value that rounds to zero. | "up" | "down" | "flat" | – |
invertFor a metric where down is good, like cost or errors: down reads success and up destructive. | boolean | false |
toneOverrides the tone the direction gives. | Tone | – |
comparisonWhat the change is measured against, like "vs. last week"; shown after the change, and read with it. | ReactNode | – |
format`Intl.NumberFormat` options for the change's size (a percent by default), or a function of it. | Intl.NumberFormatOptions | ((value: number) => string) | percent |
locale | string | – |
labels | Partial<StatDeltaLabels> | – |
Also takes <span> attributes and render except children.
Other exports
StatstatDeltaLabelsStatHintStatLabeltype StatDeltaDirectiontype StatDeltaLabelstype StatDeltaPropstype StatGroupPropstype StatMediaPropstype StatValuePropsAccessibility
- A labelled group of figures; unknown values show a dash and estimates a tilde, explained in their title.
- A StatMedia is decorative and hidden unless its label makes it an image with that name.
Agent actions
Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.