Usage
import { DashboardKpis } from './DashboardKpis.jsx'
// Without data the row shows its sample bakery. Wire it to your numbers:
<DashboardKpis
locale="en"
currency="USD"
ranges={[{ id: 'week', label: 'This week', compare: 'vs last week', points: weekdays }]}
data={{ week: [{ id: 'sales', label: 'Sales', format: 'currency', value: 27720, previous: 25980, trend: daily }] }}
// or one period, no tabs: data={[{ id: 'brews', label: 'Brews', value: 42 }, { id: 'time', label: 'Avg brew', format: 'duration', value: 245 }]}
onRangeChange={async (range) => (await fetchKpis(range)).list}
onSelect={(id) => setChartMetric(id)}
loading={kpis.loading}
error={kpis.error}
onRetry={kpis.reload}
/>Props
| Prop | Type | Default | What it does |
|---|---|---|---|
locale | 'en' | 'zh-CN' | 'es' | 'ja' | 'en' | Language of the built-in text, the sample numbers and the number formats. |
ranges | Array<{ id, label, compare, points? }> | today, week, month | The periods of the switch: their tab label, what the change compares with, and the name of each trend point. |
data | { [rangeId]: Array<{ id, label, value, previous?, trend?, format?, better? }> } | Array<…> | sample bakery | The cards of each period; a plain array is one period, shown without tabs. format is 'number', 'currency' (or 'money'), 'percent', 'duration' (seconds) or a function (value) => string; better: 'down' makes a fall green. |
range / defaultRange | string | 'week' | The period shown, controlled or at first. |
selected | string | first card | The chosen card, ringed in the accent. |
currency | string | by locale | ISO currency code of the 'money' cards. |
onRangeChange | (range) => void | Promise<cards> | — | The period changed. Resolve with the cards of a period missing from data; the row dims meanwhile. |
onSelect | (id) => void | — | A card was chosen, for example to show it in a bigger chart. |
loading | boolean | false | Shows the skeleton of the cards. |
error / onRetry | boolean | string / () => void | false | Shows the error banner with a retry button; a string replaces its sentence. |
labels | object | — | Replaces any built-in text (keys as in copy.js). |
Add it to your project
Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the block together with the components it is built from.
DashboardKpis.jsxdashboard-kpis.csscopy.jskit.jsxkit.cssui/base-button/ui/rolling-number/ui/alert-banner/ui/skeleton-shimmer/ui/sliding-tabs/tokens.cssREADME.md
The block, its stylesheet and text, the shared kit, the components it uses and tokens.css install together into one folder.