Cohort grid
Retention by cohort: one row per group of users who started together, one column per period since, and the share still active written in every cell over a colour that deepens with it. Read down a column to compare cohorts at the same age. For any other matrix, use the heatmap.
Install
npx shadcn@latest add @thrum-pro/cohort-gridThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Data shape
type CohortGridCohort = {
name: string;
size: number; // users at the start
retained: (number | null)[]; // still active per period
};[
{ name: "6 Oct", size: 1240, retained: [1240, 520, 410, 352] },
{ name: "13 Oct", size: 1385, retained: [1385, 601, 470] },
]Props
| Prop | Type | Default | Description |
|---|---|---|---|
periods | readonly string[] | Required | Names of the periods, the column headers, from period 0. |
cohorts | readonly CohortGridCohort[] | Required | One row per cohort, oldest first. Each cell is retained divided by size. A retained list shorter than the periods leaves the rest of the row empty: those periods are not reached yet. A null is a period with no data, written as a dash. |
label | string | Required | What the table shows. Used as its caption and as the name of its scrolling region. |
color | string | Default var(--chart-1) | Any CSS colour. Each cell is this colour mixed into the card colour, from 6% at 0% retained to 60% at 100%. Mixing into the card turns the scale round in a dark theme, so a higher share is always the more intense cell. |
average | boolean | Default true | Add an Average row at the foot: for each period, the users retained over all cohorts that reached it, divided by those cohorts' sizes added up. Its size cell is the total of all cohorts. |
cohortLabel | string | Default "Cohort" | Header of the first column. |
sizeLabel | string | Default "Users" | Header of the size column. |
format | Intl.NumberFormatOptions | Default { maximumFractionDigits: 0 } | How cohort sizes are written. Shares are always whole percentages. |
locale | string | Default "en-US" | Locale for numbers. Fixed by default so the server and the browser print the same text. |
emptyLabel | string | Default "No data" | Text shown when there are no cohorts. |
className | string | – | Sets the width; the default is full width. A table wider than its box scrolls sideways inside it, with the cohort column kept in view. |
Motion and sound
Motion
- Nothing moves. New data replaces the cells at once.
Sound
Silent. This component makes no sound.
Accessibility
- It is a real table with a caption, column headers for the periods and row headers for the cohorts, so a screen reader can move cell by cell and hear both headers. It is its own text alternative; there is no hidden copy.
- Every cell carries its share as text. The colour reinforces it: the strong end of the scale stops at 60% of the colour, where the number keeps 4.5:1 against its fill in a light and a dark theme.
- A period with no data reads “No data”; a period not reached yet is an empty cell.
- The scrolling region is named by the label and is a tab stop, so it can be scrolled with the keyboard. The cohort column stays in view while it scrolls.
- The table frame is a panel surface: under a glass material it turns translucent like a card. The cohort column keeps the solid card colour, so the cells that slide under it stay hidden.
| Keys | Action |
|---|---|
| Tab | Focus the table's scrolling region. |
| ← → | Scroll the table sideways when it is wider than its box. |
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/cohort-grid.tsx- Packages
motion- Brings along
- Chart foundationsMotion tokensSound engine
Changelog
- 1.0.0 · 2026-12-03First release.