{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "animated-number",
  "type": "registry:ui",
  "title": "Animated Number",
  "dependencies": [
    "motion",
    "lucide-react"
  ],
  "files": [
    {
      "path": "components/ui/animated-number.tsx",
      "content": "\"use client\";\n\nimport React, { useEffect, useState } from \"react\";\nimport { motion, useSpring, useTransform } from \"motion/react\";\nimport { RefreshCw } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface AnimatedNumberProps {\n  value: number;\n  decimals?: number;\n  prefix?: string;\n  suffix?: string;\n  stiffness?: number;\n  damping?: number;\n  mass?: number;\n  useGrouping?: boolean;\n  className?: string;\n}\n\nfunction DigitColumn({\n  digit,\n  stiffness = 170,\n  damping = 22,\n  mass = 0.65,\n}: {\n  digit: string;\n  stiffness?: number;\n  damping?: number;\n  mass?: number;\n}) {\n  const num = Number.parseInt(digit, 10);\n  const isDigit = !Number.isNaN(num);\n\n  const spring = useSpring(isDigit ? num : 0, {\n    stiffness,\n    damping,\n    mass,\n  });\n  const y = useTransform(spring, (cur) => `-${cur * 10}%`);\n\n  useEffect(() => {\n    if (isDigit) spring.set(num);\n  }, [spring, num, isDigit]);\n\n  if (!isDigit) {\n    return <span className=\"inline-block px-[0.03em]\">{digit}</span>;\n  }\n\n  return (\n    <span className=\"relative inline-block h-[1.15em] w-[0.6em] overflow-hidden text-center leading-[1.15em]\">\n      <motion.span style={{ y }} className=\"flex flex-col select-none\">\n        {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map((n) => (\n          <span\n            key={n}\n            className=\"flex h-[1.15em] items-center justify-center\"\n          >\n            {n}\n          </span>\n        ))}\n      </motion.span>\n    </span>\n  );\n}\n\nexport function AnimatedNumberCounter({\n  value,\n  decimals = 0,\n  prefix = \"\",\n  suffix = \"\",\n  stiffness = 170,\n  damping = 22,\n  mass = 0.65,\n  useGrouping = true,\n  className,\n}: AnimatedNumberProps) {\n  const fixed = Math.abs(value).toFixed(decimals);\n  const [intPart, decPart] = fixed.split(\".\");\n  const groupedInt = useGrouping\n    ? intPart.replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\")\n    : intPart;\n  const sign = value < 0 ? \"-\" : \"\";\n  const formatted =\n    decPart !== undefined ? `${sign}${groupedInt}.${decPart}` : `${sign}${groupedInt}`;\n\n  return (\n    <span\n      className={cn(\n        \"inline-flex items-baseline font-mono tracking-tight text-zinc-50 select-none tabular-nums\",\n        className\n      )}\n      aria-label={`${prefix}${formatted}${suffix}`}\n    >\n      {prefix && <span className=\"mr-0.5 text-zinc-400\">{prefix}</span>}\n      <span className=\"inline-flex items-baseline overflow-hidden\">\n        {formatted.split(\"\").map((char, idx) => (\n          <DigitColumn\n            key={`${formatted.length - idx}-${char === \".\" || char === \",\" ? char : \"d\"}`}\n            digit={char}\n            stiffness={stiffness}\n            damping={damping}\n            mass={mass}\n          />\n        ))}\n      </span>\n      {suffix && <span className=\"ml-1 text-zinc-400\">{suffix}</span>}\n    </span>\n  );\n}\n\nconst PRESETS = [\n  { label: \"MRR\", value: 48290.5, prefix: \"$\", decimals: 2, suffix: \"\" },\n  { label: \"Users\", value: 12480, prefix: \"\", decimals: 0, suffix: \"active\" },\n  { label: \"Uptime\", value: 99.98, prefix: \"\", decimals: 2, suffix: \"%\" },\n];\n\nexport function AnimatedNumber({ className }: { className?: string }) {\n  const [presetIdx, setPresetIdx] = useState(0);\n  const [bump, setBump] = useState(0);\n  const current = PRESETS[presetIdx];\n  const displayValue = current.value + bump;\n\n  return (\n    <div\n      className={cn(\n        \"w-full max-w-sm rounded-2xl border border-white/10 bg-[#101013] p-5 shadow-[inset_0_1px_0_rgba(255,255,255,0.06)]\",\n        className\n      )}\n    >\n      <div className=\"flex items-center justify-between gap-2\">\n        <div className=\"inline-flex rounded-full border border-white/10 bg-zinc-950 p-0.5\">\n          {PRESETS.map((p, i) => (\n            <button\n              key={p.label}\n              type=\"button\"\n              onClick={() => {\n                setPresetIdx(i);\n                setBump(0);\n              }}\n              className={cn(\n                \"rounded-full px-2.5 py-1 text-[11px] font-medium cursor-pointer transition-colors\",\n                presetIdx === i\n                  ? \"bg-white/12 text-white\"\n                  : \"text-zinc-500 hover:text-zinc-300\"\n              )}\n            >\n              {p.label}\n            </button>\n          ))}\n        </div>\n\n        <button\n          type=\"button\"\n          onClick={() => setBump((b) => b + (current.decimals ? 42.15 : 318))}\n          className=\"inline-flex items-center gap-1 rounded-lg border border-white/10 bg-zinc-900 px-2.5 py-1 text-[11px] text-zinc-300 hover:bg-zinc-800 hover:text-white cursor-pointer transition-colors\"\n        >\n          <RefreshCw className=\"h-3 w-3\" />\n          Increment\n        </button>\n      </div>\n\n      <div className=\"mt-5 flex items-baseline justify-between\">\n        <AnimatedNumberCounter\n          value={displayValue}\n          prefix={current.prefix}\n          decimals={current.decimals}\n          suffix={current.suffix}\n          className=\"text-3xl font-semibold\"\n        />\n      </div>\n\n      <div className=\"mt-3 flex items-center gap-2\">\n        <button\n          type=\"button\"\n          onClick={() => setBump((b) => b - (current.decimals ? 15.4 : 120))}\n          className=\"flex-1 rounded-lg border border-white/10 bg-zinc-900/70 py-1.5 text-xs text-zinc-300 hover:bg-zinc-800 cursor-pointer transition-colors\"\n        >\n          − Decrease\n        </button>\n        <button\n          type=\"button\"\n          onClick={() => setBump((b) => b + (current.decimals ? 128.75 : 640))}\n          className=\"flex-1 rounded-lg border border-white/10 bg-zinc-900/70 py-1.5 text-xs text-zinc-300 hover:bg-zinc-800 cursor-pointer transition-colors\"\n        >\n          + Increase\n        </button>\n      </div>\n    </div>\n  );\n}\n\n",
      "type": "registry:ui"
    }
  ]
}