{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "funnel-02",
  "description": "Stages as columns against a 0 to 100% axis, each topped by the share that left at that step, with the biggest drop named.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/funnel.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/funnel/funnel-02.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  chartAxisProps,\n  chartBarCursor,\n  chartFadedColor,\n  chartGridProps,\n  ChartTooltipFrame,\n  ChartTooltipItem,\n  chartValueAxisWidth,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelLegend,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport {\n  FUNNEL_COLOR,\n  type FunnelStage,\n  formatRate,\n  getBiggestDropIndex,\n  getFunnelSteps,\n} from '@/registry/components/dashboardblocks/funnel'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport { formatNumber } from '@/registry/lib/dashboardblocks/format'\nimport {\n  Bar,\n  BarChart,\n  CartesianGrid,\n  LabelList,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Funnel2Props extends BlockStateProps {\n  description: string\n  /** Leave out, or pass none, to show the empty state. */\n  stages?: FunnelStage[]\n  title: string\n}\n\nconst exampleProps: Funnel2Props = {\n  description: 'Sessions that reached each checkout step, last 7 days.',\n  stages: [\n    { label: 'Cart', value: 12_480 },\n    { label: 'Shipping', value: 7_730 },\n    { label: 'Payment', value: 5_910 },\n    { label: 'Review', value: 5_120 },\n    { label: 'Purchase', value: 4_380 },\n  ],\n  title: 'Checkout funnel',\n}\n\nconst DROPPED_COLOR = chartFadedColor(FUNNEL_COLOR)\n\nconst Funnel2 = (props: Funnel2Props) => {\n  const { description, stages = [], errorMessage, status, title } = props\n  const state = getBlockState(status, stages)\n  const steps = getFunnelSteps(stages)\n  const first = steps[0]\n  const last = steps.at(-1)\n  const biggestDrop = steps[getBiggestDropIndex(steps)]\n  const previousOfBiggest = steps[getBiggestDropIndex(steps) - 1]\n  const rows = steps.map((step, index) => ({\n    ...step,\n    lost: index === 0 ? 0 : steps[index - 1].fromStart - step.fromStart,\n    reached: step.fromStart,\n  }))\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            <dl className='flex flex-wrap items-start gap-x-10 gap-y-3 border-t pt-4'>\n              <div className='flex flex-col gap-1'>\n                <dt className='text-muted-foreground text-sm'>\n                  {first && last ? `${first.label} to ${last.label}` : 'Overall'}\n                </dt>\n                <dd>\n                  <KPIValue\n                    value={last?.fromStart}\n                    format={(value) => formatRate(value)}\n                  />\n                </dd>\n              </div>\n              {(state === 'loading' || (!state && biggestDrop && previousOfBiggest)) && (\n                <div className='flex flex-col gap-1'>\n                  <dt className='text-muted-foreground text-sm'>Biggest drop</dt>\n                  <dd>\n                    <KPIValue\n                      className='text-2xl'\n                      value={biggestDrop ? 1 - biggestDrop.fromPrevious : undefined}\n                      format={(value) => formatRate(value, 0)}\n                    />\n                  </dd>\n                  <BlockReady className='text-xs'>\n                    <dd className='text-muted-foreground text-xs'>\n                      left between {previousOfBiggest?.label} and {biggestDrop?.label}\n                    </dd>\n                  </BlockReady>\n                </div>\n              )}\n            </dl>\n            <ChartPanelLegend\n              items={[\n                { color: FUNNEL_COLOR, label: 'Reached the step' },\n                { color: DROPPED_COLOR, label: 'Left at the step' },\n              ]}\n            />\n            <ChartPanelFigure className='h-56'>\n              <ResponsiveContainer width='100%' height='100%'>\n                <BarChart\n                  aria-label={`${title} chart`}\n                  data={rows}\n                  margin={{ top: 20, right: 8, bottom: 0, left: 0 }}\n                >\n                  <CartesianGrid {...chartGridProps} />\n                  <XAxis {...chartAxisProps} dataKey='label' interval={0} />\n                  <YAxis\n                    {...chartAxisProps}\n                    domain={[0, 1]}\n                    tickFormatter={(value: number) => formatRate(value, 0)}\n                    ticks={[0, 0.25, 0.5, 0.75, 1]}\n                    width={chartValueAxisWidth}\n                  />\n                  <Tooltip\n                    content={({ active, payload }) => {\n                      const row = payload?.[0]?.payload as\n                        | (typeof rows)[number]\n                        | undefined\n                      if (!active || !row) return null\n                      return (\n                        <ChartTooltipFrame>\n                          <span className='font-medium'>{row.label}</span>\n                          <ChartTooltipItem\n                            color={FUNNEL_COLOR}\n                            name='Reached'\n                            value={formatNumber(row.value)}\n                          />\n                          {row.dropped > 0 && (\n                            <ChartTooltipItem\n                              color={DROPPED_COLOR}\n                              name='Left'\n                              value={formatNumber(row.dropped)}\n                            />\n                          )}\n                        </ChartTooltipFrame>\n                      )\n                    }}\n                    cursor={chartBarCursor}\n                  />\n                  <Bar\n                    dataKey='reached'\n                    fill={FUNNEL_COLOR}\n                    maxBarSize={56}\n                    stackId='funnel'\n                  >\n                    <LabelList\n                      dataKey='reached'\n                      content={({ x, y, width, index }) => {\n                        const row = index === undefined ? undefined : rows[index]\n                        if (!row) return null\n                        return (\n                          <text\n                            x={Number(x) + Number(width) / 2}\n                            y={Number(y) - 6}\n                            textAnchor='middle'\n                            fontSize={11}\n                            fontWeight={500}\n                            fill='var(--color-foreground)'\n                          >\n                            {formatRate(row.fromStart, 0)}\n                          </text>\n                        )\n                      }}\n                    />\n                  </Bar>\n                  <Bar\n                    dataKey='lost'\n                    fill={DROPPED_COLOR}\n                    maxBarSize={56}\n                    radius={[4, 4, 0, 0]}\n                    stackId='funnel'\n                  />\n                </BarChart>\n              </ResponsiveContainer>\n            </ChartPanelFigure>\n            <ChartPanelTable\n              caption={`${title}: ${description}`}\n              columns={[\n                { key: 'label', label: 'Step' },\n                { key: 'value', label: 'Sessions' },\n                { key: 'share', label: 'Share of first step' },\n                { key: 'left', label: 'Left at this step' },\n              ]}\n              rows={steps.map((step) => ({\n                label: step.label,\n                left: formatNumber(step.dropped),\n                share: formatRate(step.fromStart),\n                value: formatNumber(step.value),\n              }))}\n            />\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Funnel2, exampleProps as funnel2ExampleProps, type Funnel2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/funnel/funnel-02.tsx"
    }
  ],
  "meta": {
    "shows": "Stages as columns against a 0 to 100% axis, each topped by the share that left at that step, with the biggest drop named.",
    "size": "full",
    "usedWith": [
      "funnel-04",
      "data-table-03"
    ],
    "component": "Funnel2",
    "props": "{ description: string; stages?: { label: string; value: number }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
