{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"percentage-counter-with-progress-ring-filling-in-step","type":"registry:component","title":"Percentage Counter With Progress Ring","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/percentage-counter-with-progress-ring-filling-in-step.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n// Sample figures for a made-up garden care firm. The first is the big ring.\nconst rings = [\n  { value: 94, label: \"Visits done on the booked day\" },\n  { value: 81, label: \"Clients who rebook within a year\" },\n  { value: 67, label: \"Green waste composted on site\" },\n];\nconst DURATION = 1600; // ms for a ring to fill\nconst STAGGER = 180;\nconst TICKS = 50;\n\nconst pct = new Intl.NumberFormat(\"en-US\", { style: \"percent\", maximumFractionDigits: 0 });\nconst easeOut = (t: number) => 1 - Math.pow(1 - t, 3);\n\nfunction Ring({ value, size, big }: { value: number; size: number; big?: boolean }) {\n  const r = 42;\n  const c = 2 * Math.PI * r;\n  return (\n    <svg viewBox=\"0 0 100 100\" width={size} height={size} aria-hidden=\"true\" className=\"-rotate-90\">\n      <circle cx=\"50\" cy=\"50\" r={r} fill=\"none\" stroke=\"rgba(233,240,220,.12)\" strokeWidth={big ? 5 : 7} />\n      <circle\n        cx=\"50\"\n        cy=\"50\"\n        r={r}\n        fill=\"none\"\n        stroke=\"url(#pcr-grad)\"\n        strokeWidth={big ? 5 : 7}\n        strokeLinecap=\"round\"\n        strokeDasharray={c}\n        strokeDashoffset={c * (1 - value / 100)}\n        opacity={value > 0.2 ? 1 : 0}\n      />\n      {big &&\n        Array.from({ length: TICKS }, (_, i) => {\n          const a = (i / TICKS) * Math.PI * 2;\n          const lit = (i / TICKS) * 100 < value;\n          return (\n            <line\n              key={i}\n              x1={50 + Math.cos(a) * 47.5}\n              y1={50 + Math.sin(a) * 47.5}\n              x2={50 + Math.cos(a) * 49.5}\n              y2={50 + Math.sin(a) * 49.5}\n              stroke={lit ? \"#d9e7a6\" : \"rgba(233,240,220,.18)\"}\n              strokeWidth=\"0.7\"\n            />\n          );\n        })}\n    </svg>\n  );\n}\n\nexport default function PercentageRingCounter() {\n  const reduce = useReducedMotion();\n  const rootRef = useRef<HTMLElement>(null);\n  const [vals, setVals] = useState(rings.map((r) => r.value));\n\n  useEffect(() => {\n    const el = rootRef.current;\n    if (!el || reduce) {\n      setVals(rings.map((r) => r.value));\n      return;\n    }\n    setVals(rings.map(() => 0));\n    let raf = 0;\n    let start = 0;\n    let elapsed = 0;\n    let visible = false;\n    const tick = (now: number) => {\n      if (!start) start = now - elapsed;\n      elapsed = now - start;\n      const ps = rings.map((_, i) => Math.min(1, Math.max(0, (elapsed - i * STAGGER) / DURATION)));\n      setVals(rings.map((r, i) => r.value * easeOut(ps[i])));\n      if (ps.some((p) => p < 1) && visible) raf = requestAnimationFrame(tick);\n    };\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        visible = entry.isIntersecting;\n        cancelAnimationFrame(raf);\n        start = 0;\n        if (visible) raf = requestAnimationFrame(tick);\n      },\n      { threshold: 0.3 },\n    );\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(raf);\n    };\n  }, [reduce]);\n\n  const [main, ...rest] = rings;\n  return (\n    <section ref={rootRef} className=\"relative overflow-hidden bg-[#13261d] px-5 py-16 text-[#eef3e4] sm:py-20\">\n      <svg width=\"0\" height=\"0\" className=\"absolute\" aria-hidden=\"true\">\n        <defs>\n          <linearGradient id=\"pcr-grad\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\">\n            <stop offset=\"0\" stopColor=\"#a9c97a\" />\n            <stop offset=\"1\" stopColor=\"#e6eeb8\" />\n          </linearGradient>\n        </defs>\n      </svg>\n      <div\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0\"\n        style={{ background: \"radial-gradient(60% 70% at 30% 40%, rgba(169,201,122,.12), rgba(0,0,0,0) 70%)\" }}\n      />\n      <div className=\"relative mx-auto grid max-w-5xl items-center gap-12 md:grid-cols-[auto_1fr]\">\n        <figure className=\"relative mx-auto h-[min(72vw,280px)] w-[min(72vw,280px)]\">\n          <div className=\"h-full w-full [&>svg]:h-full [&>svg]:w-full\">\n            <Ring value={vals[0]} size={280} big />\n          </div>\n          <figcaption className=\"absolute inset-0 flex flex-col items-center justify-center text-center\">\n            <span className=\"text-6xl font-light tabular-nums tracking-tight sm:text-7xl\">\n              <span className=\"sr-only\">{pct.format(main.value / 100)}</span>\n              <span aria-hidden=\"true\" className=\"grid justify-items-center\">\n                <span className=\"invisible col-start-1 row-start-1\">{pct.format(main.value / 100)}</span>\n                <span className=\"col-start-1 row-start-1\">{pct.format(Math.round(vals[0]) / 100)}</span>\n              </span>\n            </span>\n            <span className=\"mt-2 max-w-[11rem] text-sm leading-snug text-[#c3cfb3]\">{main.label}</span>\n          </figcaption>\n        </figure>\n        <div>\n          <p className=\"text-sm font-medium uppercase tracking-[0.18em] text-[#b8d38a]\">Fernway Garden Care</p>\n          <h2 className=\"mt-3 max-w-md text-3xl font-semibold leading-tight tracking-tight sm:text-4xl\">Turning up when we said we would.</h2>\n          <ul className=\"mt-8 grid gap-5 sm:grid-cols-2\">\n            {rest.map((r, i) => (\n              <li key={r.label} className=\"flex items-center gap-4\">\n                <span className=\"relative h-16 w-16 shrink-0\">\n                  <Ring value={vals[i + 1]} size={64} />\n                </span>\n                <span>\n                  <span className=\"block text-2xl font-medium tabular-nums\">\n                    <span className=\"sr-only\">{pct.format(r.value / 100)}</span>\n                    <span aria-hidden=\"true\" className=\"grid\">\n                      <span className=\"invisible col-start-1 row-start-1\">{pct.format(r.value / 100)}</span>\n                      <span className=\"col-start-1 row-start-1\">{pct.format(Math.round(vals[i + 1]) / 100)}</span>\n                    </span>\n                  </span>\n                  <span className=\"block text-sm leading-snug text-[#c3cfb3]\">{r.label}</span>\n                </span>\n              </li>\n            ))}\n          </ul>\n          <p className=\"mt-8 text-xs text-[#a9b79a]\">Sample percentages for a made-up business. Ring and number are drawn from the same value each frame.</p>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
