Heatmap
A table of numbers read as colour: one cell per pair of row and column, on a scale of one hue. Use it to find the busy hours of a week or the strong pairs in a matrix. For daily values over a year, use the calendar heatmap; for retention by cohort, use the cohort grid.
Install
npx shadcn@latest add @thrum-pro/heatmapThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Data shape
rows: string[];
columns: string[];
values: (number | null)[][]; // values[row][column][
[12, 48, 61, 37],
[15, 52, null, 41],
]Props
| Prop | Type | Default | Description |
|---|---|---|---|
rows | readonly string[] | Required | Names of the rows, top to bottom. Names longer than a third of the width end in an ellipsis; the readout and the table carry them in full. |
columns | readonly string[] | Required | Names of the columns, left to right. Every nth name is shown so the widest has room. |
values | readonly (readonly (number | null)[])[] | Required | One list per row with one value per column. A null, or a value that is not there, is a missing cell: hatched, and read as “No data”. |
label | string | Required | What the values measure. Read by screen readers and used as the table caption. |
color | string | Default var(--chart-1) | Any CSS colour. Cells are this colour mixed into the background, from 6% at the low end up. Mixing into the background turns the scale round in a dark theme, so a higher value is always the more intense cell. |
min | number | Default lowest value | The value at the faint end of the scale. Values below it are drawn at the faint end. |
max | number | Default highest value | The value at the strong end of the scale. Values above it are drawn at the strong end. |
showValues | boolean | Default true | Write each value in its cell, when the widest one fits a cell and cells are at least 16 pixels tall. With values on, the strong end stops at 60% of the colour so the text keeps 4.5:1 in both themes; with values off it reaches full strength. |
legend | boolean | Default true | Show the colour scale under the grid with its ends and a round value between, and a hatched swatch when a cell is missing. |
format | Intl.NumberFormatOptions | Default compact | How values are written in cells, on the scale, in the readout and in the data table. |
locale | string | Default "en-US" | Locale for numbers. Fixed by default so the server and the browser print the same text. |
onActiveChange | (index: number | null) => void | – | Called with the index of the cell under the cursor, counted row by row (row × columns + column), or null when the cursor leaves. |
sound | boolean | Default true | Play a tick as the cursor moves between cells, if the visitor has sound on. |
emptyLabel | string | Default "No data" | Text shown when no cell has a value. |
className | string | – | Sets the size. The default is full width and 288 pixels tall, scale included. The cells share the room left after the names. |
Motion and sound
Motion
- First draw: the columns fade in left to right in 250 ms each, at most 300 ms apart from first to last.
- New data: cells take their new colour at once. A grid of another size is drawn again at once.
- The ring around the active cell follows the pointer on a stiff spring.
- Reduced motion: the grid appears complete, and the cursor moves instantly.
Sound
- A soft tick each time the cursor lands on a different cell, at most one every 40 ms.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- The grid is one tab stop. It is exposed as a slider whose value text is the cell under the cursor, for example “Tue, 10:00: 52”.
- A visually hidden table carries every value with row and column headers.
- Colour is a reinforcement: values are written in the cells where they fit, and the readout always gives the number. Missing cells are hatched, never just pale, so they cannot be read as low values.
- The whole grid is the pointer target; a pointer in a gap reads the cell beside it.
| Keys | Action |
|---|---|
| Tab | Focus the grid. The cursor goes to the last cell. |
| ← → | Move the cursor one column. It stops at the edge. |
| ↑ ↓ | Move the cursor one row. It stops at the edge. |
| Home / End | Jump to the first or the last cell. |
| Esc | Hide the cursor. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/heatmap.tsx- Packages
motion- Brings along
- Chart foundationsMotion tokensSound engine
Changelog
- 1.0.0 · 2026-12-03First release.