{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "activity-rings",
  "type": "registry:component",
  "title": "Goal rings",
  "description": "Track several delivery goals together, each with its own target and progress.",
  "categories": [
    "metrics"
  ],
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/activity-rings.tsx",
      "type": "registry:component",
      "target": "components/overtrue/activity-rings.tsx",
      "content": "/** Adapted from dashboardcn (MIT), copyright 2026 dashboardcn contributors.\n * Source: https://github.com/NoahGdev/dashboardcn/tree/b1ffacbca0f7a0be60135c8665b9e8c267205c48\n *\n * MIT License\n *\n * Copyright (c) 2026 dashboardcn contributors\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n * ---\n *\n * Portions of this project are derived from shadcn/ui and shadcn/registry-template\n * (https://github.com/shadcn-ui/ui), Copyright (c) 2023 shadcn, licensed under the\n * MIT License. The notice above applies to those portions as well.\n */\n\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface ActivityRing {\n  label: string;\n  /** Progress toward `max`. Values past `max` draw a full ring. */\n  value: number;\n  /** Goal for the ring. Defaults to 100. */\n  max?: number;\n  /** Any CSS color. Defaults to chart-1 through chart-5 in order. */\n  color?: string;\n}\n\nexport interface ActivityRingsProps extends Omit<\n  React.ComponentProps<\"div\">,\n  \"children\"\n> {\n  /** Outermost ring first. */\n  rings: ActivityRing[];\n  /** Diameter in pixels. */\n  size?: number;\n  /** Stroke width of each ring in pixels. */\n  thickness?: number;\n  /** Space between rings in pixels. */\n  gap?: number;\n  /** Opacity of the unfilled track, drawn in the ring's color. */\n  trackOpacity?: number;\n  /** Ring drawn at full strength while the rest dim. `null` shows every ring. */\n  activeIndex?: number | null;\n  onActiveIndexChange?: (index: number | null) => void;\n  /** Content rendered in the middle. */\n  children?: React.ReactNode;\n}\n\nconst defaultColors = [\n  \"var(--color-chart-1)\",\n  \"var(--color-chart-2)\",\n  \"var(--color-chart-3)\",\n  \"var(--color-chart-4)\",\n  \"var(--color-chart-5)\",\n];\nconst EASE = \"cubic-bezier(0.22,1,0.36,1)\";\n\n// Round so server and client render identical attributes.\nconst round = (n: number) => Math.round(n * 1000) / 1000;\n\n/** Keeps the center content inside the innermost ring: it wraps first, then scales down. */\nfunction CenterFit({\n  diameter,\n  children,\n}: {\n  diameter: number;\n  children: React.ReactNode;\n}) {\n  const ref = React.useRef<HTMLDivElement>(null);\n  const [scale, setScale] = React.useState(1);\n  React.useLayoutEffect(() => {\n    const element = ref.current;\n    if (!element) return;\n    const measure = () => {\n      // A box fits a circle when its diagonal does.\n      const diagonal = Math.hypot(element.offsetWidth, element.offsetHeight);\n      setScale(diagonal > diameter && diagonal > 0 ? diameter / diagonal : 1);\n    };\n    measure();\n    const observer = new ResizeObserver(measure);\n    observer.observe(element);\n    return () => observer.disconnect();\n  }, [diameter]);\n  return (\n    <div\n      ref={ref}\n      data-slot=\"activity-rings-content\"\n      className=\"flex flex-col items-center justify-center text-center leading-tight text-balance\"\n      style={{ maxWidth: Math.max(0, diameter * 0.84), scale }}\n    >\n      {children}\n    </div>\n  );\n}\n\n/** Concentric progress rings, one per goal, in the style of a fitness watch. */\nfunction ActivityRings({\n  rings,\n  size = 160,\n  thickness = 12,\n  gap = 4,\n  trackOpacity = 0.2,\n  activeIndex: activeProp,\n  onActiveIndexChange,\n  className,\n  style,\n  children,\n  ...props\n}: ActivityRingsProps) {\n  const [activeState, setActiveState] = React.useState<number | null>(null);\n  const active = activeProp === undefined ? activeState : activeProp;\n  const setActive = (index: number | null) => {\n    setActiveState(index);\n    onActiveIndexChange?.(index);\n  };\n\n  const center = size / 2;\n  const label = rings\n    .map((ring) => {\n      const max = ring.max ?? 100;\n      return `${ring.label} ${Math.round((ring.value / (max || 1)) * 100)}%`;\n    })\n    .join(\", \");\n  const geometry = rings.map((ring, index) => {\n    const max = ring.max ?? 100;\n    const value = Number.isFinite(ring.value) ? ring.value : 0;\n    const fraction = Math.min(1, Math.max(0, value / (max || 1)));\n    const r = center - thickness / 2 - index * (thickness + gap);\n    const color = ring.color ?? defaultColors[index % defaultColors.length];\n    return { ring, index, fraction, r, color };\n  });\n  const drawn = geometry.filter((item) => item.r > 0);\n  // Clear space inside the innermost ring, less a margin as wide as the gap.\n  const innermost = drawn.length\n    ? drawn[drawn.length - 1].r - thickness / 2\n    : 0;\n  const hole = Math.max(0, (innermost - Math.max(3, gap)) * 2);\n\n  return (\n    <div\n      data-slot=\"activity-rings\"\n      className={cn(\"relative inline-flex shrink-0\", className)}\n      style={{ ...style, width: size, height: size }}\n      {...props}\n    >\n      <svg\n        width={size}\n        height={size}\n        viewBox={`0 0 ${size} ${size}`}\n        role=\"img\"\n        aria-label={label}\n        className=\"absolute inset-0 overflow-visible\"\n      >\n        {drawn.map(({ ring, index, r, color }) => {\n          const dimmed = active !== null && active !== index;\n          return (\n            <g\n              key={ring.label}\n              data-ring=\"\"\n              data-active={active === index || undefined}\n              onMouseEnter={() => setActive(index)}\n              onMouseLeave={() => setActive(null)}\n              className=\"transition-opacity duration-200\"\n              style={{ opacity: dimmed ? 0.4 : 1 }}\n            >\n              <circle\n                cx={center}\n                cy={center}\n                r={round(r)}\n                fill=\"none\"\n                stroke={color}\n                strokeOpacity={trackOpacity}\n                strokeWidth={thickness}\n              />\n            </g>\n          );\n        })}\n      </svg>\n      {drawn.map(({ ring, index, fraction, r, color }) => {\n        if (fraction <= 0) return null;\n        const dimmed = active !== null && active !== index;\n        const capDeg = ((thickness / 2 / r) * 180) / Math.PI;\n        // The arc brightens from its start to its leading edge.\n        const fade = `conic-gradient(from ${round(-capDeg - 2)}deg, rgb(0 0 0 / 0.62) 0deg, #000 ${round(fraction * 360 + capDeg + 2)}deg, #000 360deg)`;\n        const delay = `${index * 90}ms`;\n        return (\n          <div\n            key={ring.label}\n            aria-hidden=\"true\"\n            data-slot=\"activity-rings-fill\"\n            data-active={active === index || undefined}\n            className=\"pointer-events-none absolute inset-0 transition-opacity duration-200 dark:drop-shadow-[0_0_6px_color-mix(in_oklab,var(--ring-color)_55%,transparent)]\"\n            style={\n              {\n                opacity: dimmed ? 0.4 : 1,\n                \"--ring-color\": color,\n                \"--ring-angle\": `${round(fraction * 360)}deg`,\n              } as React.CSSProperties\n            }\n          >\n            <svg\n              width={size}\n              height={size}\n              viewBox={`0 0 ${size} ${size}`}\n              className=\"absolute inset-0 overflow-visible\"\n              style={{ maskImage: fade, WebkitMaskImage: fade }}\n            >\n              <circle\n                cx={center}\n                cy={center}\n                r={round(r)}\n                fill=\"none\"\n                stroke={color}\n                strokeWidth={thickness}\n                strokeLinecap=\"round\"\n                pathLength={1}\n                strokeDasharray=\"1 1\"\n                strokeDashoffset={round(1 - fraction)}\n                transform={`rotate(-90 ${center} ${center})`}\n                className=\"transition-[stroke-dashoffset] duration-700 starting:[stroke-dashoffset:1] motion-reduce:transition-none\"\n                style={{\n                  transitionTimingFunction: EASE,\n                  transitionDelay: delay,\n                }}\n              />\n            </svg>\n            {/* The head sits above the faded start, so a full ring still closes cleanly. */}\n            <div\n              className=\"absolute top-1/2 left-1/2 size-0 [rotate:var(--ring-angle)] transition-[rotate] duration-700 starting:[rotate:0deg] motion-reduce:transition-none\"\n              style={{ transitionTimingFunction: EASE, transitionDelay: delay }}\n            >\n              <span\n                className={cn(\n                  \"absolute rounded-full\",\n                  fraction > 0.92 &&\n                    \"shadow-[0_0_4px_1px_rgb(0_0_0/0.18)] dark:shadow-[0_0_5px_1px_rgb(0_0_0/0.5)]\",\n                )}\n                style={{\n                  width: thickness,\n                  height: thickness,\n                  left: -thickness / 2,\n                  top: -r - thickness / 2,\n                  backgroundColor: color,\n                }}\n              />\n            </div>\n          </div>\n        );\n      })}\n      {children ? (\n        <div className=\"pointer-events-none absolute inset-0 flex items-center justify-center\">\n          <CenterFit diameter={hole}>{children}</CenterFit>\n        </div>\n      ) : null}\n    </div>\n  );\n}\n\nexport { ActivityRings };\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/activity-rings. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
