{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"goal-ring","type":"registry:ui","title":"Goal Ring","description":"Concentric progress rings that fill when they scroll into view, each a beat after the last, while the center counts up to the outer ring's percent. With a legend.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/ui/goal-ring.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { MotionConfig, animate, motion, useInView, useMotionValue, useTransform } from \"motion/react\";\nimport { useEffect, useRef } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface Ring {\n  label: string;\n  value: number;\n  goal: number;\n  color: string;\n  /** Unit shown in the legend, e.g. \"kcal\". */\n  unit?: string;\n}\n\nexport interface GoalRingProps {\n  rings?: Ring[];\n  /** Diameter in px. */\n  size?: number;\n  /** Ring thickness in px. */\n  thickness?: number;\n  /** Space between rings in px. */\n  gap?: number;\n  /** Fill length in seconds. */\n  duration?: number;\n  /** List each ring's label and progress below. */\n  showLegend?: boolean;\n  className?: string;\n}\n\nconst DEFAULT_RINGS: Ring[] = [\n  { label: \"Move\", value: 420, goal: 500, color: \"#f43f5e\", unit: \"kcal\" },\n  { label: \"Exercise\", value: 24, goal: 30, color: \"#b5e61d\", unit: \"min\" },\n  { label: \"Stand\", value: 10, goal: 12, color: \"#38bdf8\", unit: \"hr\" },\n];\n\n/**\n * Concentric progress rings that fill when they scroll into view, each one a\n * beat after the last, while the center counts up to the outer ring's percent.\n */\nexport function GoalRing({\n  rings = DEFAULT_RINGS,\n  size = 200,\n  thickness = 16,\n  gap = 5,\n  duration = 1.4,\n  showLegend = true,\n  className,\n}: GoalRingProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const seen = useInView(ref, { once: true, amount: 0.4 });\n  const lead = rings[0];\n  const target = lead ? Math.round((lead.value / lead.goal) * 100) : 0;\n  const count = useMotionValue(0);\n  const shown = useTransform(count, (v) => `${Math.round(v)}%`);\n\n  useEffect(() => {\n    if (!seen) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const c = animate(count, target, { duration: reduce ? 0 : duration, ease: [0.22, 1, 0.36, 1] });\n    return () => c.stop();\n  }, [seen, target, duration, count]);\n\n  const c = size / 2;\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <div ref={ref} className={cn(\"grid max-w-full justify-items-center gap-5\", className)}>\n        {/* Shrinks with its container; the SVG scales through its viewBox. */}\n        <div className=\"relative aspect-square max-w-full\" style={{ width: size, containerType: \"inline-size\" }}>\n          <svg viewBox={`0 0 ${size} ${size}`} className=\"size-full -rotate-90\" aria-hidden>\n            {rings.map((r, i) => {\n              const radius = c - thickness / 2 - i * (thickness + gap);\n              if (radius <= thickness / 2) return null;\n              const p = Math.min(1, r.value / r.goal);\n              return (\n                <g key={r.label}>\n                  <circle cx={c} cy={c} r={radius} fill=\"none\" stroke={r.color} strokeOpacity={0.16} strokeWidth={thickness} />\n                  <motion.circle\n                    cx={c}\n                    cy={c}\n                    r={radius}\n                    fill=\"none\"\n                    stroke={r.color}\n                    strokeWidth={thickness}\n                    strokeLinecap=\"round\"\n                    initial={{ pathLength: 0 }}\n                    animate={{ pathLength: seen ? p : 0 }}\n                    transition={{ duration, delay: i * 0.15, ease: [0.22, 1, 0.36, 1] }}\n                    style={{ filter: `drop-shadow(0 0 6px ${r.color}55)` }}\n                  />\n                </g>\n              );\n            })}\n          </svg>\n          {lead && (\n            <div className=\"absolute inset-0 grid place-content-center text-center\">\n              <motion.span className=\"font-bold tabular-nums text-foreground\" style={{ fontSize: \"max(18px, 15cqw)\" }}>\n                {shown}\n              </motion.span>\n              <span className=\"text-xs text-muted-foreground\">{lead.label}</span>\n            </div>\n          )}\n        </div>\n        {showLegend && (\n          <ul className=\"grid w-full gap-1.5\">\n            {rings.map((r) => (\n              <li key={r.label} className=\"flex items-center gap-2 text-sm\">\n                <span className=\"size-2.5 rounded-full\" style={{ background: r.color }} aria-hidden />\n                <span className=\"flex-1 text-foreground\">{r.label}</span>\n                <span className=\"tabular-nums text-muted-foreground\">\n                  {r.value}/{r.goal}\n                  {r.unit ? ` ${r.unit}` : \"\"}\n                </span>\n              </li>\n            ))}\n          </ul>\n        )}\n      </div>\n    </MotionConfig>\n  );\n}\n"}]}