{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"radial-progress","type":"registry:block","title":"Radial progress","description":"Three concentric rings draw in sequence with a glint at each end; hovering an objective lifts its ring and counts the centre value to it.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/radial-progress/radial-progress.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n  MotionConfig,\n  animate,\n  motion,\n  useInView,\n  useReducedMotion,\n} from \"motion/react\";\nimport { ArrowUpRight } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\nconst SIZE = 220;\nconst CENTER = SIZE / 2;\n\n/* ------------------------------------------------------------------ */\n/* types                                                               */\n/* ------------------------------------------------------------------ */\n\nexport type RadialProgressItem = {\n  id: string;\n  label: string;\n  /** Progress from 0 to 100. */\n  value: number;\n  /** One short line under the label. */\n  detail?: string;\n  /** Chart colour token 1–5. Defaults to the item index + 1. */\n  tone?: number;\n};\n\nexport type RadialProgressProps = {\n  className?: string;\n  title?: string;\n  description?: string;\n  items?: RadialProgressItem[];\n};\n\n/* ------------------------------------------------------------------ */\n/* deterministic demo data                                             */\n/* ------------------------------------------------------------------ */\n\nconst DEFAULT_ITEMS: RadialProgressItem[] = [\n  {\n    id: \"design\",\n    label: \"Design system\",\n    value: 82,\n    detail: \"14 of 17 components\",\n    tone: 1,\n  },\n  {\n    id: \"api\",\n    label: \"API v3\",\n    value: 64,\n    detail: \"9 of 14 endpoints\",\n    tone: 2,\n  },\n  {\n    id: \"mobile\",\n    label: \"Mobile beta\",\n    value: 47,\n    detail: \"5 of 11 screens\",\n    tone: 3,\n  },\n];\n\n/* ------------------------------------------------------------------ */\n/* helpers                                                             */\n/* ------------------------------------------------------------------ */\n\nfunction clamp(value: number, min: number, max: number) {\n  return Math.min(max, Math.max(min, value));\n}\n\nfunction average(items: RadialProgressItem[]) {\n  if (items.length === 0) return 0;\n  return items.reduce((sum, item) => sum + clamp(item.value, 0, 100), 0) / items.length;\n}\n\nfunction pointOnRing(radius: number, value: number) {\n  const angle = (-90 + (clamp(value, 0, 100) / 100) * 360) * (Math.PI / 180);\n  /* Round before rendering: the last digits of Math.cos/Math.sin are not\n     guaranteed to match between the server and the browser. */\n  const round = (n: number) => Math.round(n * 1000) / 1000;\n  return {\n    x: round(CENTER + Math.cos(angle) * radius),\n    y: round(CENTER + Math.sin(angle) * radius),\n  };\n}\n\nfunction useAnimatedValue(target: number, start: boolean, reduce: boolean) {\n  const [value, setValue] = useState(target);\n  const current = useRef(target);\n\n  useEffect(() => {\n    if (!start) return;\n    if (reduce) {\n      current.current = target;\n      setValue(target);\n      return;\n    }\n\n    const controls = animate(current.current, target, {\n      duration: 0.55,\n      ease: EASE,\n      onUpdate: (next) => {\n        current.current = next;\n        setValue(next);\n      },\n      onComplete: () => {\n        current.current = target;\n        setValue(target);\n      },\n    });\n    return () => controls.stop();\n  }, [target, start, reduce]);\n\n  return value;\n}\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function RadialProgress({\n  className,\n  title = \"Quarterly objectives\",\n  description = \"6 of 9 key results on track\",\n  items = DEFAULT_ITEMS,\n}: RadialProgressProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const inView = useInView(ref, { once: true, margin: \"-10% 0px\" });\n  const reduce = Boolean(useReducedMotion());\n\n  const safeItems = items.length > 0 ? items : DEFAULT_ITEMS;\n  const shown = safeItems.slice(0, 3);\n  const [activeId, setActiveId] = useState<string | null>(null);\n\n  const overall = average(shown);\n  const active = shown.find((item) => item.id === activeId) ?? null;\n  const displayTarget = active ? clamp(active.value, 0, 100) : overall;\n  const displayValue = useAnimatedValue(displayTarget, inView, reduce);\n\n  const ringGap = shown.length > 1 ? 22 : 0;\n  const outer = 94;\n  const radii = shown.map((_, index) => outer - index * ringGap);\n\n  const summary = `${title}. ${shown\n    .map((item) => `${item.label} ${Math.round(clamp(item.value, 0, 100))}%`)\n    .join(\", \")}.`;\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <motion.div\n        ref={ref}\n        initial={reduce ? false : { opacity: 0, y: 16 }}\n        animate={inView || reduce ? { opacity: 1, y: 0 } : { opacity: 0, y: 16 }}\n        transition={{ duration: reduce ? 0 : 0.6, ease: EASE }}\n        className={cn(\n          \"w-full rounded-xl border border-border bg-card p-5 text-card-foreground sm:p-6\",\n          className\n        )}\n      >\n        <div className=\"flex flex-wrap items-start justify-between gap-3\">\n          <div className=\"min-w-0\">\n            <h2 className=\"text-[15px] font-semibold tracking-tight\">{title}</h2>\n            <p className=\"mt-0.5 text-[13px] text-muted-foreground\">{description}</p>\n          </div>\n\n          <span className=\"inline-flex shrink-0 items-center gap-0.5 rounded-full border border-border px-2.5 py-1 text-[11.5px] font-medium text-success\">\n            <ArrowUpRight aria-hidden=\"true\" className=\"h-3 w-3\" />\n            <span className=\"tabular-nums\">12 pts</span>\n          </span>\n        </div>\n\n        <div className=\"mt-5 grid items-center gap-5 sm:grid-cols-[200px_minmax(0,1fr)] sm:gap-7\">\n          <div className=\"relative mx-auto w-full max-w-[220px]\">\n            <svg\n              viewBox={`0 0 ${SIZE} ${SIZE}`}\n              role=\"img\"\n              aria-label={summary}\n              className=\"h-auto w-full\"\n            >\n              {shown.map((item, index) => {\n                const radius = radii[index];\n                const tone = clamp(item.tone ?? index + 1, 1, 5);\n                const value = clamp(item.value, 0, 100);\n                const dim = activeId !== null && activeId !== item.id;\n                const end = pointOnRing(radius, value);\n\n                return (\n                  <g key={item.id}>\n                    <circle\n                      cx={CENTER}\n                      cy={CENTER}\n                      r={radius}\n                      fill=\"none\"\n                      stroke=\"var(--border)\"\n                      strokeWidth={7}\n                    />\n                    <motion.circle\n                      cx={CENTER}\n                      cy={CENTER}\n                      r={radius}\n                      fill=\"none\"\n                      stroke={`var(--chart-${tone})`}\n                      strokeWidth={7}\n                      strokeLinecap=\"round\"\n                      pathLength={100}\n                      strokeDasharray=\"100 100\"\n                      transform={`rotate(-90 ${CENTER} ${CENTER})`}\n                      initial={{\n                        strokeDashoffset: reduce ? 100 - value : 100,\n                        opacity: dim ? 0.3 : 1,\n                      }}\n                      animate={{\n                        strokeDashoffset: inView || reduce ? 100 - value : 100,\n                        opacity: dim ? 0.3 : 1,\n                      }}\n                      transition={{\n                        strokeDashoffset: {\n                          duration: reduce ? 0 : 1,\n                          ease: EASE,\n                          delay: reduce ? 0 : index * 0.13,\n                        },\n                        opacity: { duration: reduce ? 0 : 0.2, ease: EASE },\n                      }}\n                    />\n                    <motion.circle\n                      cx={end.x}\n                      cy={end.y}\n                      r={3}\n                      fill={`var(--chart-${tone})`}\n                      stroke=\"var(--card)\"\n                      strokeWidth={2}\n                      initial={{ opacity: 0 }}\n                      animate={{ opacity: inView || reduce ? (dim ? 0.35 : 1) : 0 }}\n                      transition={{\n                        duration: reduce ? 0 : 0.3,\n                        delay: reduce ? 0 : 0.6 + index * 0.13,\n                        ease: EASE,\n                      }}\n                    />\n                  </g>\n                );\n              })}\n            </svg>\n\n            <div className=\"pointer-events-none absolute inset-0 flex flex-col items-center justify-center px-6 text-center\">\n              <span className=\"text-[34px] font-semibold leading-none tracking-[-0.03em] tabular-nums text-foreground sm:text-[36px]\">\n                {Math.round(clamp(displayValue, 0, 100))}%\n              </span>\n              <span className=\"mt-1.5 max-w-[120px] truncate text-[11px] leading-4 text-muted-foreground\">\n                {active ? active.label : `across ${shown.length} ${shown.length === 1 ? \"objective\" : \"objectives\"}`}\n              </span>\n            </div>\n          </div>\n\n          <ul className=\"flex min-w-0 flex-col gap-1\" role=\"list\">\n            {shown.map((item, index) => {\n              const tone = clamp(item.tone ?? index + 1, 1, 5);\n              const value = clamp(item.value, 0, 100);\n              const selected = item.id === activeId;\n\n              return (\n                <li key={item.id}>\n                  <button\n                    type=\"button\"\n                    onMouseEnter={() => setActiveId(item.id)}\n                    onMouseLeave={() => setActiveId(null)}\n                    onFocus={() => setActiveId(item.id)}\n                    onBlur={() => setActiveId(null)}\n                    onClick={() =>\n                      setActiveId((current) =>\n                        current === item.id ? null : item.id\n                      )\n                    }\n                    aria-pressed={selected}\n                    className={cn(\n                      \"flex w-full items-center gap-3 rounded-lg px-2 py-2.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset motion-reduce:transition-none\",\n                      selected ? \"bg-muted/60\" : \"hover:bg-muted/40\"\n                    )}\n                  >\n                    <span\n                      aria-hidden=\"true\"\n                      className=\"h-2.5 w-2.5 shrink-0 rounded-full\"\n                      style={{ background: `var(--chart-${tone})` }}\n                    />\n                    <span className=\"min-w-0 flex-1\">\n                      <span className=\"block truncate text-[13px] font-medium text-foreground\">\n                        {item.label}\n                      </span>\n                      {item.detail ? (\n                        <span className=\"block truncate text-[11.5px] text-muted-foreground\">\n                          {item.detail}\n                        </span>\n                      ) : null}\n                    </span>\n                    <span className=\"shrink-0 text-[14px] font-semibold tabular-nums text-foreground\">\n                      {Math.round(value)}%\n                    </span>\n                  </button>\n                </li>\n              );\n            })}\n          </ul>\n        </div>\n\n        <div className=\"mt-4 flex flex-wrap items-center justify-between gap-2 border-t border-border pt-3.5\">\n          <span className=\"text-[11.5px] text-muted-foreground\">\n            Hover an objective to read its ring\n          </span>\n          <span className=\"inline-flex items-center gap-1.5 text-[11px] text-muted-foreground\">\n            <span aria-hidden=\"true\" className=\"h-1.5 w-1.5 rounded-full bg-foreground/70\" />\n            <span className=\"tabular-nums\">week 46</span>\n            <span aria-hidden=\"true\" className=\"text-border\">\n              /\n            </span>\n            <span className=\"tabular-nums\">3 weeks left</span>\n          </span>\n        </div>\n      </motion.div>\n    </MotionConfig>\n  );\n}\n\nexport default RadialProgress;\n"}]}