Components · Data
Metric
A key number with a label, an optional unit, and an optional change. change uses changeFormat (default: the value's format), so a revenue metric usually sets changeFormat "percent". goodDirection says whether up or down is good. sparkline (2-200 numbers, oldest first) draws a small trend line under the value. variant: "plain" shows the number, label, and change without the card, for a band of stats.
ExamplesLink to this section
Revenue
$1,284,000
+12.4% vs last month
Weekly active
18.4K
+6.1%
Errors
42
+8
Status
Healthy
Show JSONHide JSON
{
"version": 1,
"root": "grid",
"elements": {
"grid": {
"type": "Grid",
"props": { "columns": 2 },
"children": ["revenue", "active", "errors", "status"]
},
"revenue": {
"type": "Metric",
"props": {
"label": "Revenue",
"value": 1284000,
"format": "currency",
"currency": "USD",
"change": 12.4,
"changeFormat": "percent",
"changeLabel": "vs last month",
"goodDirection": "up"
}
},
"active": {
"type": "Metric",
"props": {
"label": "Weekly active",
"value": 18420,
"format": "compact",
"change": 6.1,
"changeFormat": "percent",
"goodDirection": "up",
"sparkline": [
12100,
12900,
13400,
13100,
14800,
15900,
15200,
16700,
17300,
18420
]
}
},
"errors": {
"type": "Metric",
"props": {
"label": "Errors",
"value": 42,
"change": 8,
"goodDirection": "down"
}
},
"status": {
"type": "Metric",
"props": { "label": "Status", "value": "Healthy" }
}
}
}PropsLink to this section
Generated from the zod schema the server validates with. Unknown props are ignored with a warning. Any prop can also be a dynamic value such as { "$state": "/path" }; it is checked again once it resolves.
| Prop | Type | Limits and defaults |
|---|---|---|
| labelrequired | string | max 80 chars |
| valuerequired | number | string | max 40 chars |
| unit | string | max 20 chars |
| format | "number" | "compact" | "percent" | "currency" | — |
| currency | string | 3-letter code |
| change | number | — |
| changeFormat | "number" | "compact" | "percent" | "currency" | — |
| changeLabel | string | max 60 chars |
| goodDirection | "up" | "down" | — |
| sparkline | (number | null)[] | max 200 items |
| variant | "card" | "plain" | — |
RulesLink to this section
changeuseschangeFormat, which defaults to the value'sformat. A revenue metric usually sets changeFormat "percent".goodDirectiondecides the color: a change in the good direction shows as success, the other way as danger.sparklinetakes 2 to 200 numbers, oldest first. null leaves a gap.variant: "plain"drops the card: the label, number, and change sit on whatever is behind them, for a row of stats in a band.
Children and eventsLink to this section
Metric is a leaf: it does not show children. Validation warns when a leaf has some; wrap them in a Stack or Card instead.
It emits no events.