Retention Cohorts

1 个变体

A cohort retention grid for analytics apps, with a crosshair tooltip, keyboard navigation, and users and revenue views.

Cohort grid

A weekly cohort retention grid with a diagonal blur-rise entrance, a row-and-column crosshair tooltip, and arrow-key navigation. Users and Revenue tabs crossfade every cell's shade, and a footer line sums up week-1 retention, the best cohort, and the latest trend.

Retention

Weekly signup cohorts, last 8 weeks

CohortW0W1W2W3W4W5W6W7
Sep 291,240
Oct 61,385
Oct 131,162
Oct 201,508
Oct 271,620
Nov 31,447
Nov 101,712
Nov 171,834
All cohorts

Avg W145.2%BestNov 1050.0%Latest vs prev+5.0pts

"use client";

import { RetentionCohorts } from "@/components/premium/retention-cohorts";

export function RetentionCohortsGridPreview() {
  return (
    <div className="w-full px-4 py-10">
      <RetentionCohorts />
    </div>
  );
}

安装

$ bunx --bun shadcn add @beui-pro/retention-cohorts-grid

API 参考

除标注为必填的属性外,其余均为可选。数据、文案和颜色默认使用示例内容。

RetentionCohorts12 个属性
  • cohorts

    Cohorts from oldest (top) to newest (bottom), each with a series per metric.

    RetentionCohort[]
  • metrics

    Metrics the tabs switch between, with their hue and formatting.

    RetentionMetric[]
  • metric

    Controlled metric id.

    string
  • defaultMetric

    Initial metric id when uncontrolled. Defaults to the first metric.

    string
  • onMetricChange

    Called with the metric id a tab selects.

    ((metric: string) => void)
  • periods

    Number of period columns. Defaults to the oldest cohort's length.

    number
  • periodLabel

    Short column header for a period index. Defaults to `W0`, `W1`…

    ((index: number) => string)
  • periodName

    Long period name for the tooltip and aria labels. Defaults to `Week 0`…

    ((index: number) => string)
  • showAverage

    Show the "All cohorts" weighted average row.

    boolean

    默认值 true

  • onActiveCellChange

    Called when hover, focus or tap changes the active cell.

    ((cell: CohortGridCell | null) => void)
  • labels

    Copy overrides; anything omitted keeps the default.

    Partial<RetentionCohortsLabels>
  • className

    Classes for the card.

    string
RetentionCohortsFooter3 个属性
  • summary必填

    Stats for the selected metric.

    RetentionSummary
  • labels必填

    Footer and legend copy.

    Pick<RetentionCohortsLabels, "trend" | "averageFirst" | "best" | "trendUnit" | "legendLow" | "legendHigh">
  • delay

    Seconds before the footer blur-rises in.

    number

    默认值 0

RetentionCohortsHeader4 个属性
  • metrics必填

    Metrics shown as tabs.

    RetentionMetric[]
  • metric必填

    Id of the selected metric.

    string
  • onMetricChange必填

    Called with the metric id a tab selects.

    (metric: string) => void
  • labels必填

    Title, description and tab aria label.

    Pick<RetentionCohortsLabels, "title" | "description" | "metricsAriaLabel">
类型5 个类型

这些属性使用的对象类型及其字段。

RetentionCohort3 个字段
  • id必填

    Stable key for the cohort.

    string
  • label必填

    Short cohort name, e.g. the signup week "Sep 29".

    string
  • series必填

    Series per metric id, e.g. `{ users: …, revenue: … }`.

    Record<string, RetentionSeries>
RetentionMetric7 个字段
  • id必填

    Key into each cohort's `series`.

    string
  • label必填

    Tab label.

    string
  • unit

    Noun after amounts in the tooltip, e.g. "users". Empty for currency.

    string
  • color必填

    The single hue for this metric's cells. Any CSS color.

    string
  • strongTextClassName必填

    Text class for strong cells, dark enough to read on the full hue.

    string
  • maxRatio

    Share at which a cell reaches full strength. Defaults to 1.

    number
  • formatValue

    Formats an absolute amount for this metric.

    (value: number) => string
RetentionCohortsLabels12 个字段
  • title必填

    Card title.

    string
  • description必填

    One line under the title.

    string
  • metricsAriaLabel必填

    Accessible name of the metric tabs.

    string
  • gridAriaLabel必填

    Accessible name of the grid.

    string
  • cohortHeader必填

    Header over the cohort column.

    string
  • averageLabel必填

    Label of the average row.

    string
  • averageFirst必填

    Footer label for the average period-1 retention.

    string
  • best必填

    Footer label for the strongest cohort.

    string
  • trend必填

    Footer label for the change against the previous cohort.

    string
  • trendUnit必填

    Unit after the trend delta, e.g. "pts".

    string
  • legendLow必填

    Legend label at the weak end.

    string
  • legendHigh必填

    Legend label at the strong end.

    string
RetentionSeries2 个字段
  • base必填

    Starting amount in period 0 (signups, or revenue in that first week).

    number
  • values必填

    Amount retained in period 0, 1, 2… Newer cohorts have fewer periods.

    number[]
RetentionSummary3 个字段
  • averageFirst必填

    Weighted average share kept in period 1, or null with no period-1 data.

    number | null
  • best必填

    Cohort with the highest period-1 share.

    { label: string; ratio: number } | null
  • trend必填

    Newest period-1 share minus the one before it, in percentage points.

    number | null