Block 244 of 297
KPI Card
One headline metric with change vs. a prior period and a sparkline. Every value binds to a P1 data source.
- Puck key
- KpiCardBlock
- Export
- kpiCardBlock
- React component
- <KpiCard />
- Path
- components/puck/kpi-card-block.tsx
- Dependencies
- None
- License
- MIT
About this block
When to use it, how to write for it, and what to change in the code.
What it's for
A single headline number in a card, with an optional prefix or suffix, a change badge against a prior period and a small sparkline. Each figure is a text field, so you can type it or bind it to a P1 data source with a {{ source.field }} token. Use it inside a Dashboard Grid; placed alone on a page it centers at a readable width.
- Meals served, visitors, members or dollars raised on an impact dashboard
- Quarterly board reports comparing this period with the last
- Service metrics such as average wait time, where lower is better
Writing the content
- Value is shown exactly as written, so format it the way you want it read, like 48,210.
- Enter Change (%) as a bare number like 12.4 or -3; the block adds the sign and the percent. Blank hides the badge.
- Set An increase is to Bad for costs and wait times, so a drop shows green.
- Trend values are comma-separated, oldest first, and need at least two numbers to draw the sparkline.
Accessibility
- The change badge pairs color with an arrow and hidden text such as "Up" and "(better)", so direction and meaning are not carried by color alone (WCAG 1.4.1).
- The sparkline is an SVG with role="img" and an aria-label listing its values.
- The metric name can be an H2 to H4 or plain text; H3 is recommended inside a dashboard.
Customizing the code
- The sparkline color is text-indigo-600 with fill-indigo-600/10; swap both to rebrand.
- Good and bad tones are the emerald and red classes in the tone constant.
Editor fields
What content editors see in the P1 sidebar when they select this block.
- Metric nametext
- Heading levelselect
- Valuetext
- Prefixtext
- Suffixtext
- Change (%)text
- Compared withtext
- An increase isradio
- Trend valuestext
- Footnotetext