Loading component…
Loading component…
One number with its label, how it changed – green or red, lower can be better – and room for a chart below or beside it; numbers roll, the card can be a link
To reuse this local React demo, copy all files from the Code tab into the same folder, then import StatCard from ./stat-card.
import { StatCard } from "@/components/ui/stat-card";
import { TrendChart } from "@/components/ui/trend-chart";
export function Spend() {
return (
<StatCard
label="Spend"
value={2741}
format={(n) => `$${(n / 1000).toFixed(1)}k`}
change={16.5}
changeLabel="vs last week"
chart={
<TrendChart
variant="sparkline"
labels={["Mar 3", "Mar 4", "Mar 5", "Mar 6"]}
series={[{ label: "Spend", values: [412, 455, 398, 470] }]}
/>
}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| label | string | What the number is | |
| value | number \| string | A number rolls when it changes and is shown through format; a string is shown as it is | |
| format | (n: number) => string | 1,284 / 2.5B | Formats a number value |
| change | number | Change in percent against the period before – colored text with an arrow | |
| changeFormat | (n: number) => string | "12.4%" | Formats the change; gets the absolute value |
| changeLabel | string | Quiet text after the change, e.g. "vs last week" | |
| lowerIsBetter | boolean | false | A rise is bad news – red – and a fall good news – green |
| icon | ReactNode | A 16px icon before the label | |
| chart | ReactNode | Any chart – a Trend Chart sparkline fits it exactly | |
| layout | "stacked" \| "inline" | "stacked" | The chart below the number or to its right |
| footer | ReactNode | The card's last row | |
| loading | boolean | false | Placeholders instead of number, change and chart – the card keeps its size |
| href | string | Makes the whole card a link | |
| onClick | () => void | Makes the whole card a button | |
| hitProps | HTMLAttributes | Extra attributes for the link or button – e.g. role="tab", aria-selected and tabIndex when the cards pick what a chart shows | |
| action | ReactNode | A small control in the top right corner – a menu or filter; stays clickable on a link card | |
| selected | boolean | One card of a set is picked: false fades the card's content | |
| className | string | Extra class on the card | |
| style | CSSProperties | Inline styles on the card, e.g. CSS variables | |
| --ui-stat-skel-h | CSS variable | 44px | Height of the chart placeholder while loading – match it to a taller chart |
Fills its grid cell; the value wraps rather than being cut, the label and comparison end in an ellipsis
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"