Skip to content

Block 260 of 297

Sparkline Table

A compact metrics table with each row's current value, percent change and an inline trend line.

Puck key
SparklineTableBlock
Export
sparklineTableBlock
React component
<SparklineTable />
Path
components/puck/sparkline-table-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 compact table of metrics, each row with a small trend line, the current value and a percent-change badge. In a narrow card the change badge moves under the value and the Change column disappears, so the table fits without scrolling. Values and trends accept {{ source.field }} bindings.

  • A weekly digital services summary for a communications team
  • Several fundraising indicators side by side
  • Operational metrics where some improve as they fall, such as response time
Writing the content
  • Enter Trend values comma-separated, oldest first; each row needs at least two numbers to draw.
  • Current value is shown exactly as written, like $12,480 or 4.2 hrs.
  • Set An increase is to Bad on rows like response time, so a drop shows green.
  • Fill Change compared with, like "vs. prior 4 weeks"; it prints under the table and is read with every change. Metrics take up to twelve rows.
Accessibility
  • It is a real table with column headers, metric names as row headers and a hidden caption from the title (WCAG 1.3.1).
  • Each sparkline has role="img" and an aria-label listing its values from oldest to newest.
  • Change badges include hidden Up or Down, better or worse, and the comparison period, so direction is not carried by color alone (WCAG 1.4.1).
Customizing the code
  • Sparkline size is set by W and HT in the viewBox and by the h-6 w-16 @md:h-9 @md:w-24 classes.
  • The line color is text-indigo-600 with an indigo-600/10 fill.

Editor fields

What content editors see in the P1 sidebar when they select this block.

  • Titletext
  • Heading levelselect
  • Subtitle or periodtext
  • Metricsarray
  • Trend column labeltext
  • Change compared withtext
  • Footnotetext