{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"funnel-chart","type":"registry:component","title":"Funnel Chart","description":"Horizontal funnel whose centred bars grow in stage by stage, with conversion from the top and drop-off labelled between stages.","author":"GetUrUI <hello@geturui.dev>","dependencies":["motion"],"registryDependencies":[],"files":[{"path":"registry/geturui/charts/funnel-chart.tsx","type":"registry:component","target":"components/charts/funnel-chart.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface FunnelStage {\n  label: string;\n  value: number;\n}\n\nexport interface FunnelChartProps {\n  stages: FunnelStage[];\n  /** Bar height in px. */\n  barHeight?: number;\n  /** Gap between bars, where drop-off is labelled. */\n  gap?: number;\n  valueFormatter?: (n: number) => string;\n  title?: string;\n  className?: string;\n}\n\nfunction useWidth<T extends HTMLElement>(fallback = 640) {\n  const ref = React.useRef<T>(null);\n  const [w, setW] = React.useState(fallback);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const ro = new ResizeObserver(([e]) => setW(Math.max(240, e.contentRect.width)));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n  return [ref, w] as const;\n}\n\nconst fmtPct = (n: number) => `${(n * 100).toFixed(n < 0.1 ? 1 : 0)}%`;\n\n/** Horizontal funnel: centred bars grow in per stage, with conversion from the top and drop-off between stages. */\nexport function FunnelChart({\n  stages,\n  barHeight = 38,\n  gap = 24,\n  valueFormatter = (n) => n.toLocaleString(\"en-US\"),\n  title,\n  className,\n}: FunnelChartProps) {\n  const reduce = useReducedMotion();\n  const [wrapRef, width] = useWidth<HTMLDivElement>();\n  const [active, setActive] = React.useState<number | null>(null);\n  const refs = React.useRef<(SVGRectElement | null)[]>([]);\n\n  const compact = width < 480;\n  const L = compact ? 0 : Math.min(150, width * 0.26);\n  const R = 64;\n  const B = width - L - R;\n  const labelRow = compact ? 18 : 0;\n  const top = stages[0]?.value || 1;\n  const rows = stages.map((s, i) => {\n    const w = Math.max(4, (B * s.value) / top);\n    const y = i * (barHeight + gap + labelRow) + labelRow;\n    return { ...s, w, x: L + (B - w) / 2, y, conv: s.value / top, step: i ? s.value / (stages[i - 1].value || 1) : 1 };\n  });\n  const height = rows.length ? rows[rows.length - 1].y + barHeight + 2 : 0;\n\n  const focusRow = (i: number) => refs.current[(i + rows.length) % rows.length]?.focus();\n  const tip = active !== null ? rows[active] : null;\n\n  return (\n    <figure className={cn(\"w-full rounded-lg border border-border bg-surface-raised p-4 shadow-sm sm:p-5\", className)}>\n      {title && <figcaption className=\"mb-4 text-[14.5px] font-semibold text-ink\">{title}</figcaption>}\n      <div ref={wrapRef} className=\"relative\" onPointerLeave={() => setActive(null)}>\n        <svg width={width} height={height} className=\"block overflow-visible\" role=\"group\" aria-label={title ?? \"Funnel chart\"}>\n          {rows.slice(0, -1).map((r, i) => {\n            const n = rows[i + 1];\n            const y0 = r.y + barHeight;\n            const y1 = n.y;\n            const drop = 1 - n.step;\n            return (\n              <g key={`c-${r.label}`}>\n                <motion.polygon\n                  points={`${r.x},${y0} ${r.x + r.w},${y0} ${n.x + n.w},${y1} ${n.x},${y1}`}\n                  className=\"fill-volt-soft\"\n                  initial={{ opacity: 0 }}\n                  animate={{ opacity: active === null || active === i || active === i + 1 ? 1 : 0.4 }}\n                  transition={{ duration: 0.4, delay: reduce ? 0 : 0.25 + i * 0.08 }}\n                />\n                <motion.text\n                  x={width - 2}\n                  y={(y0 + y1 - labelRow) / 2 + labelRow / 2}\n                  dy=\"0.32em\"\n                  textAnchor=\"end\"\n                  className=\"fill-danger text-[11px] tabular-nums\"\n                  initial={{ opacity: 0 }}\n                  animate={{ opacity: 1 }}\n                  transition={{ delay: reduce ? 0 : 0.6 + i * 0.08 }}\n                >\n                  ↓ {fmtPct(drop)} drop\n                </motion.text>\n              </g>\n            );\n          })}\n\n          {rows.map((r, i) => {\n            const on = active === null || active === i;\n            const inside = r.w > 70;\n            return (\n              <g key={r.label}>\n                {compact ? (\n                  <text x={0} y={r.y - 6} className=\"fill-ink text-[12px] font-medium\">\n                    {r.label} <tspan className=\"fill-ink-subtle font-normal\">· {valueFormatter(r.value)}</tspan>\n                  </text>\n                ) : (\n                  <>\n                    <text x={0} y={r.y + barHeight / 2 - 7} dy=\"0.32em\" className=\"fill-ink text-[12.5px] font-medium\">\n                      {r.label}\n                    </text>\n                    <text x={0} y={r.y + barHeight / 2 + 9} dy=\"0.32em\" className=\"fill-ink-subtle text-[11.5px] tabular-nums\">\n                      {valueFormatter(r.value)}\n                    </text>\n                  </>\n                )}\n                <motion.rect\n                  ref={(el) => {\n                    refs.current[i] = el;\n                  }}\n                  y={r.y}\n                  height={barHeight}\n                  rx={8}\n                  style={{ fill: \"var(--volt)\" }}\n                  tabIndex={0}\n                  role=\"img\"\n                  aria-label={`${r.label}: ${valueFormatter(r.value)}, ${fmtPct(r.conv)} of ${rows[0].label}${i ? `, ${fmtPct(r.step)} from ${rows[i - 1].label}` : \"\"}`}\n                  initial={{ width: 0, x: L + B / 2 }}\n                  animate={{ width: r.w, x: r.x, opacity: on ? 1 - i * (0.4 / Math.max(1, rows.length - 1)) : 0.3 }}\n                  transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 120, damping: 20, delay: i * 0.08 }}\n                  onPointerEnter={() => setActive(i)}\n                  onFocus={() => setActive(i)}\n                  onBlur={() => setActive(null)}\n                  onKeyDown={(e) => {\n                    if (e.key === \"ArrowDown\" || e.key === \"ArrowRight\") {\n                      e.preventDefault();\n                      focusRow(i + 1);\n                    } else if (e.key === \"ArrowUp\" || e.key === \"ArrowLeft\") {\n                      e.preventDefault();\n                      focusRow(i - 1);\n                    }\n                  }}\n                  className=\"cursor-pointer outline-none [&:focus-visible]:stroke-volt-ink [&:focus-visible]:[stroke-width:2]\"\n                />\n                {inside && (\n                  <motion.text\n                    x={L + B / 2}\n                    y={r.y + barHeight / 2}\n                    dy=\"0.32em\"\n                    textAnchor=\"middle\"\n                    pointerEvents=\"none\"\n                    className=\"fill-on-volt text-[12px] font-semibold tabular-nums\"\n                    initial={{ opacity: 0 }}\n                    animate={{ opacity: 1 }}\n                    transition={{ delay: reduce ? 0 : 0.35 + i * 0.08 }}\n                  >\n                    {valueFormatter(r.value)}\n                  </motion.text>\n                )}\n                <text x={width - 2} y={r.y + barHeight / 2} dy=\"0.32em\" textAnchor=\"end\" className=\"fill-ink text-[13px] font-semibold tabular-nums\">\n                  {fmtPct(r.conv)}\n                </text>\n              </g>\n            );\n          })}\n        </svg>\n\n        <AnimatePresence>\n          {tip && active !== null && (\n            <motion.div\n              key=\"tip\"\n              aria-hidden\n              initial={{ opacity: 0, y: 4, top: tip.y + barHeight + 6 }}\n              animate={{ opacity: 1, y: 0, top: tip.y + barHeight + 6 }}\n              exit={{ opacity: 0, transition: { duration: 0.1 } }}\n              transition={{ type: \"spring\", stiffness: 500, damping: 36 }}\n              style={{ left: L + B / 2, x: \"-50%\" }}\n              className=\"pointer-events-none absolute z-10 min-w-48 rounded-sm border border-border bg-surface-raised px-3 py-2 text-xs shadow-md\"\n            >\n              <p className=\"mb-1 font-semibold text-ink\">{tip.label}</p>\n              <p className=\"flex justify-between gap-4 text-ink-muted\">\n                Count <span className=\"font-mono tabular-nums text-ink\">{valueFormatter(tip.value)}</span>\n              </p>\n              <p className=\"flex justify-between gap-4 text-ink-muted\">\n                Of {rows[0].label.toLowerCase()} <span className=\"font-mono tabular-nums text-ink\">{fmtPct(tip.conv)}</span>\n              </p>\n              {active > 0 && (\n                <p className=\"flex justify-between gap-4 text-ink-muted\">\n                  From previous <span className=\"font-mono tabular-nums text-ink\">{fmtPct(tip.step)}</span>\n                </p>\n              )}\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n    </figure>\n  );\n}\n"},{"path":"LICENSE-geturui.md","type":"registry:file","target":"LICENSE-geturui.md","content":"MIT License\n\nCopyright (c) 2026 geturui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"}],"categories":["charts","chart","funnel","conversion","drop-off","analytics","svg"],"meta":{"tier":"free","license":"MIT","docs":"https://geturui.com/docs/funnel-chart"}}