{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radial-progress",
  "title": "Radial progress",
  "description": "Activity-style concentric goal rings that fill from 12 o'clock on view, spring to new values, dim the others when one is pointed at, and roll the center percentage.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/chart-legend.json",
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json",
    "https://goodui.dev/r/number-flow.json"
  ],
  "files": [
    {
      "path": "registry/components/charts/radial-progress.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { motion, useReducedMotion } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { ChartLegend } from \"@/components/goodui/chart-legend\"\nimport { NumberFlow } from \"@/components/goodui/number-flow\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { spring as springs, ease as easing } from \"@/lib/goodui-motion\"\n\nexport type RadialRing = {\n  /** Defaults to the label. */\n  key?: string\n  label: string\n  value: number\n  /** Value that closes the ring. */\n  max?: number\n  /** Any CSS color. Defaults to the theme chart colors in order (--chart-1 … --chart-5). */\n  color?: string\n  /** Formats this ring's \"value / max\" (e.g. money) instead of the component's formatValue. */\n  formatValue?: (value: number, max: number) => string\n}\n\nexport type RadialProgressLabels = {\n  /** Screen reader text per ring. */\n  ring: (label: string, value: string, max: string, percent: string) => string\n  summary: (name: string, parts: string) => string\n  legend: string\n}\nconst DEFAULT_LABELS: RadialProgressLabels = {\n  ring: (label, value, max, percent) => `${label}: ${value} of ${max}, ${percent}`,\n  summary: (name, parts) => `${name ? name + \": \" : \"\"}${parts}`,\n  legend: \"Goals\",\n}\n\nexport type RadialProgressProps = Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  /** Rings from the outside in. One ring makes a goal ring; several make activity-style concentric rings. */\n  rings: RadialRing[]\n  /** Name under the center number, used by screen readers too. */\n  title?: React.ReactNode\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  /** Replaces the rolling percentage in the middle. Pass null to leave the center empty. */\n  center?: React.ReactNode\n  /** Legend placement with each ring's value. */\n  legend?: \"end\" | \"bottom\" | \"none\"\n  /** Intl.NumberFormat options for the values. */\n  format?: Intl.NumberFormatOptions\n  locale?: string\n  /** Formats \"value / max\" for the legend and screen readers. */\n  formatValue?: (value: number, max: number) => string\n  /** Seconds the first ring takes to fill; inner rings start 0.12 s later each. */\n  duration?: number\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<RadialProgressLabels>\n}\n\nfunction useReduce() {\n  const prefers = useReducedMotion()\n  const [mounted, setMounted] = React.useState(false)\n  React.useEffect(() => setMounted(true), [])\n  return mounted && !!prefers\n}\n\nfunction useInView(ref: React.RefObject<Element | null>, threshold = 0.2) {\n  const [inView, setInView] = React.useState(false)\n  React.useEffect(() => {\n    const el = ref.current\n    if (!el || inView) return\n    if (typeof IntersectionObserver === \"undefined\") {\n      setInView(true)\n      return\n    }\n    const io = new IntersectionObserver(\n      ([e]) => {\n        if (e?.isIntersecting) {\n          setInView(true)\n          io.disconnect()\n        }\n      },\n      { threshold },\n    )\n    io.observe(el)\n    return () => io.disconnect()\n  }, [ref, inView, threshold])\n  return inView\n}\n\n/** Concentric goal rings (activity style) that fill on view, spring to new values and roll the center percentage of the ring you point at. */\nexport function RadialProgress({\n  rings,\n  title,\n  size = 160,\n  thickness = 12,\n  gap = 4,\n  center,\n  legend = \"end\",\n  format,\n  locale = \"en-US\",\n  formatValue,\n  duration = 1.2,\n  labels,\n  className,\n  \"aria-label\": ariaLabel,\n  ...props\n}: RadialProgressProps) {\n  const l = useLabels(\"radial-progress\", DEFAULT_LABELS, labels)\n  const reduce = useReduce()\n  const rootRef = React.useRef<HTMLDivElement>(null)\n  const inView = useInView(rootRef)\n  const [active, setActive] = React.useState<string | null>(null)\n  const [entered, setEntered] = React.useState(false)\n  React.useEffect(() => {\n    if (!inView) return\n    const id = window.setTimeout(() => setEntered(true), reduce ? 0 : duration * 1000 + rings.length * 120)\n    return () => window.clearTimeout(id)\n  }, [inView, reduce, duration, rings.length])\n\n  const nf = React.useMemo(() => new Intl.NumberFormat(locale, format), [locale, format])\n  const fmt = React.useMemo(() => formatValue ?? ((v: number, max: number) => `${nf.format(v)} / ${nf.format(max)}`), [formatValue, nf])\n  const pct = React.useMemo(() => new Intl.NumberFormat(locale, { style: \"percent\", maximumFractionDigits: 0 }), [locale])\n  const items = rings.map((r, i) => {\n    const max = r.max ?? 100\n    const ratio = max > 0 ? Math.max(0, r.value / max) : 0\n    return { ...r, key: r.key ?? r.label, max, ratio, color: r.color ?? `var(--chart-${(i % 5) + 1})`, radius: (size - thickness) / 2 - i * (thickness + gap) }\n  })\n  const c = size / 2\n  const focus = items.find((r) => r.key === active) ?? items[0]\n  const name = typeof title === \"string\" ? title : \"\"\n  const summary = ariaLabel ?? l.summary(name, items.map((r) => l.ring(r.label, nf.format(r.value), nf.format(r.max), pct.format(r.ratio))).join(\"; \"))\n  const announce = active && focus ? l.ring(focus.label, nf.format(focus.value), nf.format(focus.max), pct.format(focus.ratio)) : \"\"\n\n  const onKeyDown = (e: React.KeyboardEvent) => {\n    if (!items.length) return\n    if ([\"ArrowLeft\", \"ArrowRight\", \"ArrowUp\", \"ArrowDown\"].includes(e.key)) {\n      e.preventDefault()\n      const dir = e.key === \"ArrowLeft\" || e.key === \"ArrowUp\" ? -1 : 1\n      const i = items.findIndex((r) => r.key === active)\n      setActive(items[(i + dir + items.length) % items.length]?.key ?? null)\n    } else if (e.key === \"Escape\") setActive(null)\n  }\n\n  const ready = inView || reduce\n  const spring = reduce ? { duration: 0 } : springs.morph\n  const innerRadius = (items[items.length - 1]?.radius ?? c) - thickness / 2\n\n  return (\n    <div ref={rootRef} className={cn(\"pc-radial-progress flex w-full min-w-0 flex-wrap items-center justify-center gap-x-8 gap-y-4\", legend === \"bottom\" && \"flex-col\", className)} {...props}>\n      <div\n        role=\"group\"\n        aria-roledescription=\"progress rings\"\n        aria-label={summary}\n        tabIndex={0}\n        onKeyDown={onKeyDown}\n        onBlur={() => setActive(null)}\n        className=\"relative shrink-0 rounded-full outline-none focus-visible:ring-3 focus-visible:ring-ring/50\"\n        style={{ width: size, height: size }}\n      >\n        <svg width={size} height={size} viewBox={`0 0 ${size} ${size}`} className=\"overflow-visible\" aria-hidden=\"true\">\n          <g transform={`rotate(-90 ${c} ${c})`}>\n            {items.map((r, i) => {\n              const dim = active !== null && active !== r.key\n              return (\n                <g key={r.key} className=\"cursor-pointer\" onPointerEnter={() => setActive(r.key)} onPointerLeave={() => setActive(null)}>\n                  <circle cx={c} cy={c} r={r.radius} fill=\"none\" strokeWidth={thickness} style={{ stroke: `color-mix(in oklab, ${r.color} 18%, transparent)`, opacity: dim ? 0.5 : 1 }} />\n                  <motion.circle\n                    cx={c}\n                    cy={c}\n                    r={r.radius}\n                    fill=\"none\"\n                    style={{ stroke: r.color }}\n                    strokeWidth={thickness}\n                    strokeLinecap=\"round\"\n                    initial={false}\n                    animate={{ pathLength: ready ? Math.max(0.0001, Math.min(1, r.ratio)) : 0.0001, opacity: dim ? 0.35 : 1 }}\n                    transition={{\n                      pathLength: reduce ? { duration: 0 } : entered ? spring : { duration, delay: i * 0.12, ease: easing.outExpo },\n                      opacity: { duration: reduce ? 0 : 0.2 },\n                    }}\n                  />\n                </g>\n              )\n            })}\n          </g>\n        </svg>\n        {center !== null && (\n          <div className=\"pointer-events-none absolute inset-0 flex flex-col items-center justify-center gap-0.5 text-center\" style={{ padding: Math.max(0, c - innerRadius + 4) }}>\n            {center !== undefined ? (\n              center\n            ) : (\n              focus && (\n                <>\n                  <NumberFlow value={ready ? focus.ratio : 0} format={{ style: \"percent\", maximumFractionDigits: 0 }} locale={locale} className={cn(\"leading-none font-semibold tracking-tight\", innerRadius > 44 ? \"text-2xl\" : \"text-base\")} />\n                  {innerRadius > 36 && <span className=\"max-w-full truncate text-[11px] text-muted-foreground\">{active ? focus.label : (title ?? focus.label)}</span>}\n                </>\n              )\n            )}\n          </div>\n        )}\n        <span className=\"sr-only\" aria-live=\"polite\">\n          {announce}\n        </span>\n      </div>\n      {legend !== \"none\" && items.length > 0 && (\n        <ChartLegend\n          items={items.map((r) => ({ key: r.key, label: r.label, color: r.color, value: (r.formatValue ?? fmt)(r.value, r.max), shape: \"dot\" }))}\n          active={active}\n          onActiveChange={setActive}\n          layout={legend === \"end\" ? \"column\" : \"row\"}\n          size=\"sm\"\n          labels={{ legend: l.legend }}\n          className={legend === \"end\" ? \"min-w-36\" : \"justify-center\"}\n        />\n      )}\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/radial-progress.tsx"
    }
  ],
  "categories": [
    "components",
    "charts"
  ],
  "type": "registry:component"
}
