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 リファレンス

必須と記された props 以外はすべて省略できます。データ、文言、色はサンプルの内容が既定値です。

RetentionCohorts12 個の props
  • 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 個の props
  • 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 個の props
  • 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 個の型

これらの props が受け取るオブジェクト型とそのフィールド。

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