Cohort Retention

Cohorts by period as a triangle table, shaded by % retained, with a size-weighted average row.

PROGet Cohort Retention and 168 other Pro components with pro lifetime — Get Pro

Category
Data & feedback
Access
Pro
Source
220 lines · one file
States
6 drawn

The decision inside it

It is a table, not a picture

Every cell is text with the cohort and period as headers, so a screen reader reads the grid in order and the shade is only a help.

When to use it

Use Cohort Retention for signup cohorts by week or month as a triangle table shaded by % retained, with a size-weighted average row. Pass counts, not percentages.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's Cohort Retention for this.
Install it: npx shadcn@latest add @liro/cohort-retention
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/cohort-retention.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Pro components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/retention.tsx
"use client";

import * as React from "react";
import { CohortRetention, type Cohort } from "@/components/ui/cohort-retention";

export function Retention({ weekly, monthly }: { weekly: Cohort[]; monthly: Cohort[] }) {
  const [period, setPeriod] = React.useState<"week" | "month">("week");
  return (
    <CohortRetention
      cohorts={period === "week" ? weekly : monthly}
      period={period}
      onPeriodChange={setPeriod}
      description="Retention of new workspaces by cohort"
    />
  );
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
cohortsCohort[] Yes–
period"week" | "month" NoNames the columns: "Week 1" or "Month 1". Default "week".
onPeriodChange(p: "week" | "month") => void NoShow the Weekly / Monthly switch; you swap the data.
show"percent" | "count" NoDefault "percent".
showToggleboolean NoShow the Percent / People switch. Default true.
descriptionstring YesAccessible caption.
loadingboolean No–
errorReact.ReactNode No–
onRetry() => void No–
classNamestring No–

Dependencies

npm packages

clsxtailwind-merge

Liro foundations, installed alongside it

liro-themechartsegmented-control

States

All of them are drawn by the component. None is left for you to design.

  • Weekly
  • Monthly
  • People
  • Loading
  • Empty
  • Error

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances