# Cohort Retention (Lumen Halo): prompt.md (v1.0.0)

- id: `lumen-cohort-retention` · version 1.0.0 · component · pro (All-Access)
- category: Charts
- build: Base UI (one set of files; its dependencies follow the build)
- install (this build): `npx shadcn@latest add @beautiful-ui-pro/lumen-cohort-retention`
- npm dependencies: none
- registry dependencies: utils, @beautiful-ui/lumen-chart, https://beautiful-ui.dev/r/lumen-foundation.json
- docs: https://beautiful-ui.dev/components/lumen-cohort-retention
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

Cohorts as a triangle of lit cells: a row per cohort, a column per period since they started, each cell lit by the share still active. Periods not reached yet stay empty, never zero; the average row is weighted by cohort size; pointing at a cohort draws its curve against the average. The headline compares the newest cohort with the ones before it.

## Build it
- Stack: React 19 (`ref` is a plain prop), TypeScript, Tailwind CSS v4 utilities, a shadcn-initialised project with the `@/*` alias.
- Packages: none beyond React.
- Files: `components/ui/lumen/cohort-retention.tsx`; shared code: `lib/beautiful-ui/lumen/cohort-model.ts`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `lumen-chart`, `lumen-foundation`.
- Builds: one set of files for both, but its dependencies come in Base UI and Radix builds. Install the one that matches the project (see Install): a free item's bare URL installs the Base UI build of it and its dependencies.
- Exports to keep: `CohortRetention`, `CohortGrid`, `CohortHeadline`, and every exported type.
- CSS: the install merges this item's rules (the registry `css` field) into your global stylesheet, in `@layer components`, and adds the lumen foundation (tokens, keyframes, motion levels) once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Tokens: retheme with the `--lumen-*` custom properties (`--lumen-accent`, `--lumen-accent-text`, `--lumen-bad`, `--lumen-bad-text`, `--lumen-focus`, `--lumen-good`, `--lumen-good-text`, `--lumen-hairline`, `--lumen-ink`, `--lumen-muted-ink`, `--lumen-series-1`, `--lumen-series-2`, `--lumen-series-3`, `--lumen-series-4`, `--lumen-series-5`, `--lumen-series-6`, `--lumen-warn`, `--lumen-warn-text`); this item's CSS also reads `--lumen-font-mono`, `--lumen-font-sans`, `--lumen-radius-k`. Never add Tailwind colour classes inside the component.

```tsx
import { CohortRetention, CohortGrid, CohortHeadline, CohortTable } from "@/components/ui/lumen/cohort-retention";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `CohortRetention` | — | Data and the highlighted cohort. |
| `CohortGrid` | `cohort-grid` | The triangle of cells and the average row. |
| `CohortHeadline` | — | Newest cohort against the ones before. |

Style a part with `[data-slot="<slot>"]` selectors or its `className`; keep the attributes when editing.

## Sound
- Keep every `data-slot` and `data-sound` attribute: the sound layer reads them.
- Installing this item adds no audio. Nothing plays until the app mounts `GlassSoundProvider` once (install: `npx shadcn@latest add https://beautiful-ui.dev/r/glass-sound.json`, import from `@/components/beautiful-ui/glass-sound`); `GlassSoundToggle` is its mute control. Without a provider the audio engine never loads.

## Match the original
- Read `components/ui/lumen/cohort-retention.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- cohort retention, retention cohorts, cohort analysis, retention triangle, churn by signup month, user retention curve, Lumen
- How well each signup cohort stays, period by period
- Whether newer cohorts retain better than older ones after a change

### Not when
- A single retention number over time: use Trend
- Revenue retention bridges: use MRR Waterfall

## Mistakes
- Pass null for periods a cohort hasn't reached, not 0
- Keep cohorts oldest first, so the triangle reads left to right

## Usage

```tsx
import { CohortRetention, CohortGrid, CohortHeadline, CohortTable } from "@/components/ui/lumen/cohort-retention";

<CohortRetention cohorts={[{ label: "Jul 2026", size: 574, retained: [574, 448, 402] }, { label: "Aug 2026", size: 611, retained: [611, 477] }]} unit="month">
  <CohortHeadline />
  <CohortGrid />
  <CohortTable />
</CohortRetention>
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `cohorts` | `{ id?, label, size, retained: (number \| null)[] }[]` | `Lumen's monthly signup cohorts` | Oldest first. retained[p] is who is still active p periods after starting (counts, or rates with mode="rate"); null = not reached yet. |
| `mode` | `"count" \| "rate"` | `"count"` | Whether retained holds counts or 0–1 rates. Counts above the cohort's size are capped. |
| `unit` | `string` | `"month"` | The period in words ("week", "month"). |
| `cohort / defaultCohort / onCohortChange` | `number \| null` |  | The highlighted cohort (its curve shows). |
| `title / eyebrow / locale / motion / config` | `…` |  | Names, number locale, motion; config colours the cohort and average lines (keys cohort, average). |
| `Parts` | `CohortGrid · Curve · Headline · Table · Card` |  | Arrange them inside <CohortRetention>, or use CohortRetentionCard; useCohortRetention() reads the state. |

Full docs: https://beautiful-ui.dev/components/lumen-cohort-retention

## Customising
- Colours: set the `--lumen-*` tokens on `:root`, or on a container with the `lumen-scope` class to retheme one area. Add the `lumen-inherit` class to follow your shadcn palette instead (`--chart-N`, `--destructive`).
- Dark mode follows the `.dark` class on an ancestor (the shadcn and next-themes convention).
- Update later by re-running the install with `--overwrite` (review the diff if you edited it). Changelog: https://beautiful-ui.dev/r/changelog.json

## Keyboard

| Keys | Action |
|---|---|
| ← → ↑ ↓ | Walk the cells |
| Home / End | First or last cell |
| Escape | Clear |

## Motion inventory

| Interaction | What moves |
|---|---|
| Enter | Cells drop into place along the diagonals, block by block |
| Point | The step or cell lights; the rest dim |

## Accessibility contract (preserve when editing)
- The grid is one tab stop: arrows walk the cells and each is said with the cohort, the period, the share, its size and the average
- Not-yet periods are said as not reached, never as zero
- Every value is in the data table

## Install

```bash
npx shadcn@latest add @beautiful-ui-pro/lumen-cohort-retention
```

Pro item: needs the `@beautiful-ui-pro` registry in `components.json` and `BEAUTIFUL_UI_TOKEN` in `.env.local` (https://beautiful-ui.dev/account). Setup: https://beautiful-ui.dev/docs/pro. Your components.json `style` picks the build: radix-*, new-york and default get Radix, base-* gets Base UI.

## Credits
- Built on shadcn/ui chart conventions (https://ui.shadcn.com/charts)

The lumen foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://beautiful-ui.dev/r/lumen-foundation.json.
