Cómo funciona
One card, five bodies: pick the one that tells the story. Every shape enters with transform, opacity or stroke-dashoffset only: the progress fill and blocks slide inside rounded clips, the split bar fills segment by segment, the sparkline draws through a normalised path length and its end dot pops at the end. Numbers count in JavaScript on the same 900ms curve, so the hero lands when its shape does. Nothing is measured except the sparkline width, which is read before the first paint.
Úsalo para
- A headline metric with one supporting view: a rate with a sentence, progress with the people doing it, a short trend.
- Two or three related numbers that read better together than as separate cards.
- Dashboards and overview pages where each card should be readable in a second.
Busca otra opción cuando
- Comparing many categories or periods: use a bar chart.
- Exact values over a long time: use a line or area chart with axes.
- More than three parts in one card: use a donut or segmented meter.
Uso
import { StatTrend } from './StatTrend.jsx'
export function SprintCard() {
return (
<StatTrend
title="Tasks completed"
qualifier="Sprint 14"
value={92}
unit="%"
delta={12}
deltaLabel="vs last sprint"
progress={0.92}
people={[{ name: 'Ada Moreno', initials: 'AM' }, { name: 'Ben Okafor', initials: 'BO' }]}
peopleMore={6}
footnote="46 of 50 tasks done"
/>
)
}
export function DeliveriesCard() {
return (
<StatTrend
title="Deliveries"
tone={5}
parts={[
{ label: 'Standard', value: 720, delta: 12, detail: 'vs last month' },
{ label: 'Express', value: 480, delta: -4, detail: 'vs last month' },
]}
/>
)
}
export function SavingsCard() {
return <StatTrend title="Savings" tone={6} prefix="$" value={8420} delta={18.2} data={[3120, 3480, 4010, 4380, 5060, 6620, 8420]} />
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
title / qualifier | string | — | Card title (15px semibold) and grey words after it. |
icon | ReactNode | — | An 18px icon in a 32px square tinted with the card colour. |
onAction / actionIcon / actionLabel / action | () => void / 'open' | 'more' / string / ReactNode | - / 'open' | A round chevron or three-dot button at the right of the title row, its accessible name, or your own element instead. |
caption | string | — | Grey line above the hero number. |
value / prefix / unit | number / string / string | — | The hero number (36px, counts up from zero on first view), text before it such as “$”, and a grey unit after it such as “%”. |
delta / deltaLabel / formatDelta / trendGoodWhen | number / string / (n) => string / 'up' | 'down' | - / - / `${n}%` / 'up' | A change beside the hero with a diagonal arrow: green when it moves the good way, red otherwise, with the direction also read out. |
formatValue | (n) => string | toLocaleString('en-US') | Formats the hero, the part values and the sparkline tooltip; it also receives in-between values while counting. |
note / onNote | ReactNode / () => void | — | A sentence in a filled panel (bold words in ink). With onNote the panel becomes a button with a chevron. |
progress / footnote | number (0-1) / ReactNode | — | A gradient pill that fills to this share, and a grey line under the body. |
people / peopleMore | { name, initials?, src?, color? }[] / number | — | Up to four overlapping 32px avatars at the right of the hero, and a “+N” bubble after them. |
parts / partsLayout | { label, value, unit?, delta?, deltaLabel?, detail?, color?, pattern?: 'hatch' | 'ticks' }[] / 'columns' | 'rows' | - / 'columns' | Several counted stats. Columns: side by side, each over a block sized by its share (never below 28%), the first hatched in the card colour and the next ticked in grey. Rows: a split bar on top and one row per part with its detail on the right, in shades of the card colour. |
data / labels / sparkHeight | number[] / string[] / number | - / - / 56 | A sparkline that draws from the left with a soft area and an end dot. Pointer, touch or the arrow keys show each point in an ink tooltip. |
tone | 1-8 | 1 | Card colour (--ds-chart-N) for the icon tint, progress, blocks, rows and line. |
plain | boolean | false | Drops the card surface, padding and shadow and uses a smaller hero, for use inside your own card. |
delay | number (ms) | 0 | Waits this long after the card comes into view before playing, to stagger a row of cards. |
text | object | — | Replaces built-in words (open, more, up, down, flat, good, bad, more_people, point, spark, progress); shallow-merged over the English defaults. |
label | string | — | Accessible name for the progress bar and sparkline; defaults to the title (and is shown as the title when no title is given). |
replayKey | any | — | Change it to play the entrance again from zero. |
...rest | HTMLAttributes<HTMLDivElement> | — | Other attributes go to the card. |
Accesibilidad
- Changes read their direction and whether it is good or bad in words, so colour is never the only cue.
- The progress bar is a progressbar with its share as text; the avatar stack names each person and reads the “+N” as words.
- The sparkline is a focusable group: Left and Right step through points, Home and End jump, Escape clears, and each step is announced.
- With reduced motion every shape is in place at once and the numbers show their final values.
Movimiento
When 30% of the card is on screen (after the optional delay) the hero counts up over 900ms on cubic-bezier(0.22, 1, 0.36, 1) while its shape grows on the same curve: the progress pill fills, the blocks slide in 120ms apart, the split bar fills 90ms apart, or the line draws and its end dot springs in at 760ms. Avatars pop in 60ms apart from 320ms. Later value changes count from the number on screen in 480ms. Hover and keyboard move the sparkline cursor and tooltip in 160ms; the note button presses to 0.98.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
StatTrend.jsxstat-trend.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

