Stat card
A headline number that counts up, a trend pill and a chart in one card.
Installation
pnpm add @heyramzi/uiUsage
import { StatCard } from "@heyramzi/ui/charts";<StatCard
label="Revenue"
value={48200}
delta={12.4}
caption="vs last month"
variant="area"
data={[{ m: "Jan", v: 3200 }]}
xKey="m"
yKey="v"
/>Keyboard and accessibility
- The label and value are plain text. The trend chart is an image named by the label plus "trend".
- The change arrow is hidden from screen readers.
API reference
dataTData[]- Default
[] - Series for the line/area/bar variants. Unused by the gauge variant.
xKeykeyof TData & stringyKeykeyof TData & stringvariant"line" | "area" | "bar" | "gauge"- Default
"area" - Chart kind. "gauge" puts a radial gauge to the right of the figure.
gaugeValuenumber- Arc fill 0-100 for variant="gauge". Falls back to `value` when numeric.
gaugeLabelstring- Label under the gauge percentage.
labelstring- Metric name shown top-left. Omit (or set `figureOnly`) for a bare chart.
valuenumber- Headline number; counts up on mount.
deltanumber- Percentage change. Its sign drives the trend color/arrow unless `trend` is set.
trend"up" | "down" | "neutral"- Force the trend direction independent of `delta`'s sign.
captionstring- Caption under the value, e.g. "Avg" or "vs last month".
figureOnlyboolean- Default
false - Render only the edge-to-edge chart, no header/value/caption.
colorstring- Default
"var(--chart-series-1)" heightnumber- Default
150 - Chart height in px.
smoothboolean- Default
true edgeFadeboolean | number- Default
true - Softens the left and right ends of the line and the area fill instead of cutting them off at the card edge.
formatValue(v: number) => string- Default
(v) => v.toLocaleString() - Format for the headline value.
formatX(v: unknown) => string- Default
(v) => String(v) - Format for the x value shown as the tooltip header (e.g. a date/period).
iconSnippet- Leading icon next to the label.
classstring
| Prop | Type | Default |
|---|---|---|
data Series for the line/area/bar variants. Unused by the gauge variant. | TData[] | [] |
xKey | keyof TData & string | |
yKey | keyof TData & string | |
variant Chart kind. "gauge" puts a radial gauge to the right of the figure. | "line" | "area" | "bar" | "gauge" | "area" |
gaugeValue Arc fill 0-100 for variant="gauge". Falls back to `value` when numeric. | number | |
gaugeLabel Label under the gauge percentage. | string | |
label Metric name shown top-left. Omit (or set `figureOnly`) for a bare chart. | string | |
value Headline number; counts up on mount. | number | |
delta Percentage change. Its sign drives the trend color/arrow unless `trend` is set. | number | |
trend Force the trend direction independent of `delta`'s sign. | "up" | "down" | "neutral" | |
caption Caption under the value, e.g. "Avg" or "vs last month". | string | |
figureOnly Render only the edge-to-edge chart, no header/value/caption. | boolean | false |
color | string | "var(--chart-series-1)" |
height Chart height in px. | number | 150 |
smooth | boolean | true |
edgeFade Softens the left and right ends of the line and the area fill instead of cutting them off at the card edge. | boolean | number | true |
formatValue Format for the headline value. | (v: number) => string | (v) => v.toLocaleString() |
formatX Format for the x value shown as the tooltip header (e.g. a date/period). | (v: unknown) => string | (v) => String(v) |
icon Leading icon next to the label. | Snippet | |
class | string |