{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "counter-up",
  "title": "Counter up",
  "description": "Counts from 0 (or from) to the value with an ease-out curve when it scrolls into view, with locale formatting, once or replay-on-return, and counts from the current value when it changes.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/numbers/counter-up.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { animate, useInView, useReducedMotion, type Easing } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { useGooduiLocale } from \"@/lib/goodui-locale\"\n\nexport type CounterUpProps = Omit<React.ComponentProps<\"span\">, \"children\" | \"prefix\"> & {\n  /** Target value. Changing it later counts from the current value to the new one. */\n  value: number\n  /** Start value for the first count. */\n  from?: number\n  /** Seconds the count takes. */\n  duration?: number\n  /** Seconds to wait after the element enters the viewport. */\n  delay?: number\n  /** motion easing for the count; defaults to a strong ease-out [0.16, 1, 0.3, 1]. */\n  ease?: Easing | Easing[]\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. */\n  prefix?: string\n  /** Text placed after the formatted number, e.g. \"%\" or \" / 5\". */\n  suffix?: string\n  /** Count only the first time it scrolls into view. With false it resets when it leaves and replays on return. */\n  once?: boolean\n  /** Share of the element that must be visible before it starts, 0 to 1. */\n  amount?: number\n  /** Scroll container to observe instead of the viewport. */\n  root?: React.RefObject<Element | null>\n  /** Called when a count finishes (also right away when reduced motion skips it). */\n  onComplete?: () => void\n}\n\nfunction decimalsOf(n: number) {\n  if (!Number.isFinite(n)) return 0\n  const s = String(n)\n  const i = s.indexOf(\".\")\n  return i === -1 ? 0 : Math.min(s.length - i - 1, 6)\n}\n\n/** Counts up to `value` once it scrolls into view. Updates the DOM directly, so a count never re-renders React. */\nexport function CounterUp({\n  value,\n  from = 0,\n  duration = 1.6,\n  delay = 0,\n  ease = [0.16, 1, 0.3, 1],\n  format,\n  locale: localeProp,\n  prefix = \"\",\n  suffix = \"\",\n  once = true,\n  amount = 0.5,\n  root,\n  onComplete,\n  className,\n  ...props\n}: CounterUpProps) {\n  const reduce = useReducedMotion() ?? false\n  const { lang } = useGooduiLocale()\n  const locale = localeProp ?? lang\n  const ref = React.useRef<HTMLSpanElement>(null)\n  const textRef = React.useRef<HTMLSpanElement>(null)\n  const current = React.useRef(from)\n  const inView = useInView(ref, { once, amount, root })\n\n  const formatter = React.useMemo(() => {\n    const hasDigits = format?.minimumFractionDigits !== undefined || format?.maximumFractionDigits !== undefined\n    if (hasDigits || format?.style === \"currency\") return new Intl.NumberFormat(locale, format)\n    // Intermediate frames keep the precision of the target, so 4.9 never flickers through 4.8731.\n    const d = decimalsOf(value)\n    return new Intl.NumberFormat(locale, { ...format, minimumFractionDigits: d, maximumFractionDigits: d })\n  }, [locale, format, value])\n\n  const fmt = React.useCallback((n: number) => `${prefix}${formatter.format(n)}${suffix}`, [formatter, prefix, suffix])\n  const completeRef = React.useRef(onComplete)\n  React.useEffect(() => {\n    completeRef.current = onComplete\n  })\n\n  React.useEffect(() => {\n    const el = textRef.current\n    if (!el) return\n    if (!inView) {\n      if (!once) {\n        current.current = from\n        el.textContent = fmt(from)\n      }\n      return\n    }\n    if (reduce || current.current === value) {\n      current.current = value\n      el.textContent = fmt(value)\n      completeRef.current?.()\n      return\n    }\n    const controls = animate(current.current, value, {\n      duration,\n      delay,\n      ease,\n      onUpdate: (v) => {\n        current.current = v\n        el.textContent = fmt(v)\n      },\n      onComplete: () => completeRef.current?.(),\n    })\n    return () => controls.stop()\n    // `ease` is usually an inline array; it is read once per count.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [inView, value, reduce, once, from, duration, delay, fmt])\n\n  return (\n    <span ref={ref} className={cn(\"inline-block tabular-nums\", className)} {...props}>\n      <span ref={textRef} aria-hidden=\"true\">\n        {fmt(from)}\n      </span>\n      <span className=\"sr-only\">{fmt(value)}</span>\n    </span>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/counter-up.tsx"
    }
  ],
  "categories": [
    "components",
    "numbers"
  ],
  "type": "registry:component"
}