{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "number-flow",
  "title": "Number flow",
  "description": "Digits roll to the new value with locale formatting, prefixes and suffixes.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/numbers/number-flow.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { motion, useReducedMotion } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { useGooduiLocale } from \"@/lib/goodui-locale\"\nimport { spring } from \"@/lib/goodui-motion\"\n\nconst DIGITS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n// Every character sits in a box of the same height, so digits, separators and symbols share one baseline.\nconst BOX = \"inline-block h-[1.15em] overflow-hidden leading-[1.15em]\"\n\nfunction Digit({ value, reduce, fast, delay, enter }: { value: number; reduce: boolean; fast: boolean; delay: number; enter: boolean }) {\n  return (\n    <motion.span\n      className={cn(BOX, \"relative w-[1ch] [mask-image:linear-gradient(transparent,#000_14%,#000_86%,transparent)]\")}\n      aria-hidden=\"true\"\n      initial={enter && !reduce ? { opacity: 0, y: \"0.4em\" } : false}\n      animate={{ opacity: 1, y: 0 }}\n      transition={spring.ui}\n    >\n      <motion.span\n        className=\"absolute inset-x-0 top-0 flex flex-col\"\n        initial={false}\n        animate={{ y: `${-value * 1.15}em` }}\n        transition={reduce ? { duration: 0 } : fast ? spring.snap : { ...spring.morph, delay }}\n      >\n        {DIGITS.map((d) => (\n          <span key={d} className=\"h-[1.15em] text-center\">\n            {d}\n          </span>\n        ))}\n      </motion.span>\n    </motion.span>\n  )\n}\n\nexport type NumberFlowProps = {\n  /** Number to show. Changing it rolls each digit to its new value. */\n  value: number\n  /** Intl.NumberFormat options, e.g. { style: \"currency\", currency: \"USD\" }. */\n  format?: Intl.NumberFormatOptions\n  /** Locale passed to Intl.NumberFormat (\"de-DE\" gives 1.234,5). Defaults to the GooduiLocaleProvider language, else en-US. */\n  locale?: string\n  /** Text placed before the formatted number, e.g. \"~\". */\n  prefix?: string\n  /** Text placed after the formatted number, e.g. \" / mo\". */\n  suffix?: string\n  /** fast: snappier roll with no stagger, for values driven by a pointer (scrubbing a chart). */\n  speed?: \"smooth\" | \"fast\"\n  className?: string\n}\n\n/** Animated number: each digit rolls to its new value. Screen readers get the formatted value once. */\nexport function NumberFlow({ value, format, locale: localeProp, prefix = \"\", suffix = \"\", speed = \"smooth\", className }: NumberFlowProps) {\n  const reduce = useReducedMotion() ?? false\n  const { lang } = useGooduiLocale()\n  const locale = localeProp ?? lang\n  const formatter = React.useMemo(() => new Intl.NumberFormat(locale, format), [locale, format])\n  const text = `${prefix}${formatter.format(value)}${suffix}`\n\n  const mounted = React.useRef(false)\n  React.useEffect(() => {\n    mounted.current = true\n  }, [])\n\n  // Key characters by their distance from the end so digits keep their column as the length changes.\n  const chars = [...text]\n  return (\n    <span className={cn(\"inline-flex items-end tabular-nums\", className)}>\n      <span className=\"sr-only\">{text}</span>\n      {chars.map((ch, i) => {\n        const key = chars.length - i\n        return /\\d/.test(ch) ? (\n          <Digit key={key} value={Number(ch)} reduce={reduce} fast={speed === \"fast\"} delay={(key - 1) * 0.012} enter={mounted.current} />\n        ) : (\n          <span key={key} className={cn(BOX, \"whitespace-pre\")} aria-hidden=\"true\">\n            {ch}\n          </span>\n        )\n      })}\n    </span>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/number-flow.tsx"
    }
  ],
  "categories": [
    "components",
    "numbers"
  ],
  "type": "registry:component"
}