{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "kpi-count-up",
  "title": "KPI Count Up",
  "description": "A KPI that counts up to a new value, skips the animation for reduced motion, and announces only the final value once.",
  "registryDependencies": [
    "card"
  ],
  "files": [
    {
      "path": "registry/patterns/kpi-count-up/kpi-count-up.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { Card, CardContent } from \"@/components/ui/card\"\n\nexport interface KpiCountUpProps {\n  label: string\n  value: number\n  durationMs?: number\n  /** Force reduced motion; otherwise read from prefers-reduced-motion. */\n  reducedMotion?: boolean\n  format?: (n: number) => string\n}\n\n/** Ease-out interpolation, t in 0..1. */\nexport function easeValue(from: number, to: number, t: number): number {\n  const k = Math.min(1, Math.max(0, t))\n  return from + (to - from) * (1 - Math.pow(1 - k, 3))\n}\n\nfunction prefersReduced(): boolean {\n  return (\n    typeof window !== \"undefined\" &&\n    typeof window.matchMedia === \"function\" &&\n    window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n  )\n}\n\n/** A KPI that counts to its new value; the final value is announced once. */\nexport function KpiCountUp({\n  label,\n  value,\n  durationMs = 800,\n  reducedMotion,\n  format = (n) => new Intl.NumberFormat(\"en-US\").format(Math.round(n)),\n}: KpiCountUpProps) {\n  const [shown, setShown] = React.useState(value)\n  const [announce, setAnnounce] = React.useState(\"\")\n  const from = React.useRef(value)\n\n  React.useEffect(() => {\n    const reduce = reducedMotion ?? prefersReduced()\n    const start = from.current\n    if (\n      reduce ||\n      start === value ||\n      typeof requestAnimationFrame !== \"function\"\n    ) {\n      from.current = value\n      setShown(value)\n      setAnnounce(`${label}: ${format(value)}`)\n      return\n    }\n    let raf = 0\n    let t0: number | null = null\n    const step = (ts: number) => {\n      if (t0 === null) t0 = ts\n      const t = (ts - t0) / durationMs\n      setShown(easeValue(start, value, t))\n      if (t < 1) raf = requestAnimationFrame(step)\n      else {\n        from.current = value\n        setAnnounce(`${label}: ${format(value)}`)\n      }\n    }\n    raf = requestAnimationFrame(step)\n    return () => cancelAnimationFrame(raf)\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [value, durationMs, reducedMotion, label])\n\n  return (\n    <Card>\n      <CardContent className=\"space-y-1 p-5\">\n        <p className=\"text-muted-foreground text-sm\">{label}</p>\n        <p aria-hidden=\"true\" className=\"text-3xl font-semibold tabular-nums\">\n          {format(shown)}\n        </p>\n        <p role=\"status\" className=\"sr-only\">\n          {announce}\n        </p>\n      </CardContent>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}