Updated
Cohort Retention
NewCustomize
Color
Share
Width620px
Installation
npx shadcn@latest add https://uibrik.com/r/cohort-retention.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/cohort-retention/cohort-retention.tsx"use client"; // Weekly retention as the classic triangle: a row per signup cohort, a column // per week since signup, each cell shaded by the share still active. Cells // fill in a diagonal wave as the weeks unlock. Above, the selected cohort's // curve against the average; hovering a cell crosses its row and week and // reads it in full, hovering or tapping a cohort draws its curve, and the // cells can show shares or user counts. import { motion, useReducedMotion } from "motion/react"; import { useId, useMemo, useState, type CSSProperties } from "react"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; export type RetentionCohort = { /** Label for the row, e.g. "Sep 8". */ label: string; /** Users who signed up in the cohort. */ users: number; /** Share still active in week 1, 2, 3…, in percent. Shorter for younger cohorts. */ retention: number[]; };
Adds the files to
components/uibrik/cohort-retention and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/cohort-retention.Usage
import { CohortRetention } from "@/components/uibrik/cohort-retention/cohort-retention";<CohortRetention title="Retention" color="#12a594" display="percent" period="Week" width={620} // cohorts={[{ label: "…", users: 0, retention: [0] }]} // defaultCohort={0} // onCohortChange={(index) => {}}/>Where to use Cohort Retention
Product analytics dashboards
One grid shows whether newer cohorts stick better than older ones, without a chart per cohort.
Pairs with Subscriber Funnel and KPI Tile
Growth and lifecycle reviews
The gap to average on every cell says which launch or onboarding change moved retention.
Pairs with Revenue Dashboard
SaaS investor and board updates
A triangle that fills in reads as momentum before anyone looks at the numbers.
Props
CohortRetention- title
- Type string
- "Retention"
- Heading above the grid.
- color
- Type string
- "#12a594"
- Hue the cells are shaded from.
- display
- Type "percent" | "users"
- "percent"
- Show shares or user counts in the cells.
- period
- Type string
- "Week"
- Name of one period, for the column heads.
- width
- Type number
- 620
- Width of the card; never wider than its container.
- cohorts
- Type { label: string; users: number; retention: number[] }[]
- –
- Oldest first. retention holds the share active in period 1, 2, 3…, shorter for younger cohorts.
- defaultCohort / onCohortChange
- Type number / (index) => void
- –
- Cohort drawn in the chart on mount, and a callback when another is picked.
- className
- Type string
- –
- Classes for the wrapper.