{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "funnel",
  "title": "Funnel",
  "description": "Primitives for conversion funnels: step conversion maths, the biggest drop and a stage bar.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/use-reveal.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/funnel.tsx",
      "content": "'use client'\n\nimport { useBlockState } from '@/registry/components/dashboardblocks/block-state'\nimport { useReveal } from '@/registry/hooks/use-reveal'\nimport { formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { cn } from '@/lib/utils'\n\ninterface FunnelStage {\n  label: string\n  value: number\n}\n\ninterface FunnelStep extends FunnelStage {\n  dropped: number\n  /** Share of the first stage that reached this one (0–1). */\n  fromStart: number\n  /** Share of the previous stage that reached this one (0–1). */\n  fromPrevious: number\n}\n\nconst FUNNEL_COLOR = 'var(--color-chart-2)'\n\nconst FUNNEL_TRACK_COLOR = 'color-mix(in oklab, var(--color-chart-2) 14%, transparent)'\n\nfunction getFunnelSteps(stages: FunnelStage[]): FunnelStep[] {\n  const first = stages[0]?.value ?? 0\n  return stages.map((stage, index) => {\n    const previous = index === 0 ? stage.value : stages[index - 1].value\n    return {\n      ...stage,\n      dropped: Math.max(0, previous - stage.value),\n      fromPrevious: previous > 0 ? stage.value / previous : 0,\n      fromStart: first > 0 ? stage.value / first : 0,\n    }\n  })\n}\n\nfunction formatRate(rate: number, fractionDigits = 1) {\n  return formatPercent(rate, {\n    maximumFractionDigits: fractionDigits,\n    minimumFractionDigits: fractionDigits,\n  })\n}\n\nfunction getBiggestDropIndex(steps: FunnelStep[]) {\n  let index = -1\n  for (let i = 1; i < steps.length; i++) {\n    if (index === -1 || steps[i].fromPrevious < steps[index].fromPrevious) index = i\n  }\n  return index\n}\n\ninterface FunnelBarProps {\n  animated?: boolean\n  className?: string\n  color?: string\n  delay?: number\n  /** Fill as a percentage of the track (0–100). */\n  value: number\n}\n\nfunction FunnelBar({\n  animated = true,\n  className,\n  color = FUNNEL_COLOR,\n  delay = 0,\n  value,\n}: FunnelBarProps) {\n  const { ref, revealed } = useReveal<HTMLDivElement>(animated)\n  const state = useBlockState()\n  const size = Math.min(100, Math.max(0, Number.isFinite(value) ? value : 0))\n\n  return (\n    <div\n      ref={ref}\n      aria-hidden\n      className={cn(\n        'h-2 w-full overflow-hidden rounded-full',\n        state === 'loading' && 'animate-pulse motion-reduce:animate-none',\n        className,\n      )}\n      style={{ backgroundColor: FUNNEL_TRACK_COLOR }}\n    >\n      <div\n        className='h-full rounded-full transition-[width] duration-1000 ease-[cubic-bezier(0.33,1,0.68,1)] motion-reduce:transition-none'\n        style={{\n          backgroundColor: color,\n          transitionDelay: animated ? `${delay}ms` : undefined,\n          width: `${revealed && !state ? size : 0}%`,\n        }}\n      />\n    </div>\n  )\n}\n\nexport {\n  FUNNEL_COLOR,\n  FUNNEL_TRACK_COLOR,\n  FunnelBar,\n  formatRate,\n  getBiggestDropIndex,\n  getFunnelSteps,\n}\n\nexport type { FunnelBarProps, FunnelStage, FunnelStep }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/funnel.tsx"
    }
  ],
  "type": "registry:component"
}
