Web · Components
Stat
Metric (KPI) card for dashboards: name, large value, change from the previous period, description and trend chart.
7 exports
Live example
Preview
Monthly revenue
$0
12.4% increasevs last monthCode
Events
- Events appear here when you interact with the preview.
Dashboard grid
Revenue
$48,230
12.4% increaseNew members
1,284
2% decreasethis weekError rate
1.2%
18% decreaseTarget: below 1%
Response time
182ms
No changeImport
Metric (KPI) card for dashboards: name, large value, change from the previous period, description and trend chart.
- Numbers are formatted by the
UIProviderlocale (format: currency, percent, compact…). - If
previousValueis given, the change ratio is computed; the arrow direction and color are chosen byhigherIsBetter(a cost decrease is green). - With
sparklinea small trend chart is drawn below the value. - With
animatethe number counts up when it enters the screen. - While
loading, placeholders are shown without layout shift. - Screen readers read the change as "12.5% increase"; the arrow icon is hidden.
Use a grid to line cards up side by side: <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">…</div>.
Examples
statChange
functionComputes the change ratio and direction.
StatTrend
typeDirection of a change.
StatFormat
typeFormat of the value. Same as ChartFormat: "number", "compact" (1.2M), "percent" (0.25 → 25%), "currency" ($1,250), Intl.NumberFormatOptions or a function.
StatVariant
typeLook.
card: bordered card; lined up side by side on dashboards.plain: frameless; inside a card or a header.
StatClassNames
interfaceClasses that can be passed to the inner parts of Stat.
| Name | Type | Description |
|---|---|---|
label? | string | Label. |
icon? | string | Icon box. |
value? | string | Main value. |
change? | string | Change badge. |
description? | string | Description row. |
sparkline? | string | Small chart. |
StatProps
interfaceProps of the Stat component.
Extends: Omit<ComponentProps<"div">, "children" | "prefix">
| Name | Type | Default | Description |
|---|---|---|---|
label | ReactNode | Name of the metric (e.g. "Monthly revenue"). | |
value | number | ReactNode | Value. A number is written for the locale according to format; text or an element is shown as is. | |
format? | StatFormat | "number" | Format of a numeric value. See StatFormat. |
prefix? | ReactNode | Prefix before the value (e.g. "≈"). | |
suffix? | ReactNode | Unit after the value (e.g. "pcs", "ms"). | |
previousValue? | number | Value of the previous period. If given, the change ratio (change) is computed automatically. | |
change? | number | Change ratio: 0.125 = 12.5% increase, -0.04 = 4% decrease. If omitted, computed from previousValue. | |
changeFormat? | StatFormat | "percent" | Format of the change. |
changeLabel? | ReactNode | Period written next to the change (e.g. "vs last month"). | |
higherIsBetter? | boolean | true | Is an increase good? For metrics like error count, cost or response time pass false: decreases look green, increases red. |
description? | ReactNode | Description below the value (e.g. "Target: $50,000"). | |
icon? | IconProp | Icon next to the label: name or element. | |
sparkline? | readonly (number | null | undefined)[] | Data of the small chart showing the trend (e.g. values of the last 12 days). See Sparkline. | |
sparklineType? | "line" | "area" | "bar" | "area" | Chart type. |
sparklineColor? | ChartColor | Chart color. If omitted, by trend (good: green, bad: red). | |
animate? | boolean | false | Whether the number counts up from zero/the previous value when it enters the screen and whenever it changes. Off with the "reduced motion" preference. |
loading? | boolean | Shows placeholders instead of the value and chart while data loads. | |
action? | ReactNode | Action in the top right corner (e.g. a menu). | |
variant? | StatVariant | CustomVariant<"stat"> | "card" | Look: built-in (StatVariant) or a custom look added with defineAppearance. If omitted, UIProvider appearance.defaults.stat.variant. |
effect? | EffectProp | Effect or effects (e.g. ["lift", "glow"]). The accent color is the theme's primary color. See BuiltinEffect. | |
size? | "sm" | "md" | "lg" | "md" | Size. |
locale? | string | {@link UIProvider}'s `locale | Locale (number format). |
currency? | string | {@link UIProvider}'s `currency | Currency. |
classNames? | StatClassNames | Classes added to the inner parts. |