{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "number-stepper",
  "title": "Number Stepper",
  "description": "A quantity field whose digits roll the way you count, with a click per step, hold-to-accelerate, and a soft wall at the limits.",
  "dependencies": [
    "@number-flow/react",
    "@rexa-developer/tiks",
    "lucide-react",
    "motion",
    "web-haptics"
  ],
  "files": [
    {
      "path": "src/registry/components/number-stepper/number-stepper.tsx",
      "content": "\"use client\";\n\nimport NumberFlow, { type Format } from \"@number-flow/react\";\nimport { useTiks } from \"@rexa-developer/tiks/react\";\nimport { ChevronDown, ChevronUp, Minus, Plus } from \"lucide-react\";\nimport { animate, motion, useAnimate, useReducedMotion } from \"motion/react\";\nimport {\n\ttype ClipboardEvent,\n\ttype KeyboardEvent,\n\ttype MouseEvent,\n\ttype PointerEvent,\n\tuseEffect,\n\tuseId,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from \"react\";\nimport { useWebHaptics } from \"web-haptics/react\";\nimport { cn } from \"@/lib/utils\";\n\nconst digitTiming = {\n\tduration: 450,\n\teasing: \"cubic-bezier(.2,.8,.2,1)\",\n} as const;\nconst pressSpring = { type: \"spring\", stiffness: 600, damping: 30 } as const;\n\n/** Ms a press is held before it starts repeating. */\nconst REPEAT_DELAY = 400;\n/** Ms between repeats when repeating starts. */\nconst REPEAT_SLOW = 120;\n/** Fastest ms between repeats. */\nconst REPEAT_FAST = 40;\n/** Ms into a hold at which repeats reach `REPEAT_FAST`. */\nconst REPEAT_RAMP_END = 1500;\n/** Repeats before each step becomes `largeStep` steps. */\nconst ACCELERATE_AFTER = 10;\n/** Minimum ms between step sounds and haptics. */\nconst CUE_THROTTLE_MS = 35;\n/** Ms of quiet before the live region announces the value. */\nconst ANNOUNCE_DELAY = 300;\n/** Trackpad travel, in px, per wheel step. */\nconst WHEEL_STEP_PX = 50;\n\nconst sizes = {\n\tsm: {\n\t\troot: \"min-h-8 text-sm\",\n\t\tbutton: { outline: \"size-6\", pill: \"size-6\", ghost: \"size-8\" },\n\t\tverticalButton: \"h-6\",\n\t\ticon: \"[&_svg]:size-3.5\",\n\t},\n\tmd: {\n\t\troot: \"min-h-9 text-base\",\n\t\tbutton: { outline: \"size-7\", pill: \"size-8\", ghost: \"size-9\" },\n\t\tverticalButton: \"h-7\",\n\t\ticon: \"[&_svg]:size-4\",\n\t},\n\tlg: {\n\t\troot: \"min-h-11 text-xl\",\n\t\tbutton: { outline: \"size-9\", pill: \"size-10\", ghost: \"size-11\" },\n\t\tverticalButton: \"h-9\",\n\t\ticon: \"[&_svg]:size-5\",\n\t},\n} as const;\n\nconst variants = {\n\toutline: {\n\t\troot: \"rounded-md border border-input bg-transparent shadow-xs transition-[color,box-shadow] has-[input:focus-visible]:border-ring has-[input:focus-visible]:ring-3 has-[input:focus-visible]:ring-ring/50 data-invalid:border-destructive data-invalid:ring-3 data-invalid:ring-destructive/20 dark:bg-input/30 dark:data-invalid:ring-destructive/40\",\n\t\tbutton:\n\t\t\t\"rounded-[calc(var(--radius)-5px)] text-muted-foreground hover:bg-muted hover:text-foreground dark:hover:bg-input/50\",\n\t\tinput: \"\",\n\t},\n\tpill: {\n\t\troot: \"rounded-full border border-input bg-background p-1 shadow-xs transition-[color,box-shadow] has-[input:focus-visible]:ring-3 has-[input:focus-visible]:ring-ring/50 data-invalid:border-destructive data-invalid:ring-3 data-invalid:ring-destructive/20 dark:bg-input/30 dark:data-invalid:ring-destructive/40\",\n\t\tbutton:\n\t\t\t\"rounded-full bg-primary text-primary-foreground shadow-xs hover:bg-primary/85\",\n\t\tinput: \"\",\n\t},\n\tghost: {\n\t\troot: \"rounded-md\",\n\t\tbutton:\n\t\t\t\"rounded-md text-muted-foreground hover:bg-muted hover:text-foreground\",\n\t\tinput: \"rounded-sm focus-visible:ring-3 focus-visible:ring-ring/50\",\n\t},\n} as const;\n\ntype Direction = 1 | -1;\ntype StepKind = \"step\" | \"accelerate\";\ntype StepResult = \"moved\" | \"limit\" | \"blocked\";\n\nexport interface NumberStepperProps {\n\t/** Controlled value. */\n\tvalue?: number;\n\t/** Initial value when uncontrolled. */\n\tdefaultValue?: number;\n\t/** Called on every step, typed commit, and key press. */\n\tonValueChange?: (value: number) => void;\n\t/** Called when a press is released, a typed value commits, or a key steps. */\n\tonValueCommit?: (value: number) => void;\n\tmin?: number;\n\tmax?: number;\n\tstep?: number;\n\t/** Steps moved by `Shift`+arrows, `PageUp`/`PageDown`, and accelerated holds. */\n\tlargeStep?: number;\n\t/** After 10 repeats, a held button moves `largeStep` steps at a time. */\n\taccelerate?: boolean;\n\t/** `Intl.NumberFormat` options for the value, e.g. currency or percent. */\n\tformat?: Intl.NumberFormatOptions;\n\t/** Locale for formatting and parsing typed or pasted values. */\n\tlocale?: string;\n\t/** Let the wheel change the value while the input is focused. */\n\twheel?: boolean;\n\tsize?: keyof typeof sizes;\n\tvariant?: keyof typeof variants;\n\t/** `vertical` puts increase above the value and decrease below it. */\n\torientation?: \"horizontal\" | \"vertical\";\n\t/** Play a click per step and a pop at the limits. */\n\tsound?: boolean;\n\t/** Trigger haptics on supported devices. */\n\thaptics?: boolean;\n\tdisabled?: boolean;\n\treadOnly?: boolean;\n\t/** Submits the value with a native form through a hidden input. */\n\tname?: string;\n\t/** Accessible name for the input; the buttons read \"Increase {label}\". */\n\tlabel?: string;\n\tclassName?: string;\n}\n\nfunction decimalsOf(value: number) {\n\tif (!Number.isFinite(value)) return 0;\n\tconst text = String(value);\n\tif (text.includes(\"e-\")) return Number(text.split(\"e-\")[1]);\n\treturn text.split(\".\")[1]?.length ?? 0;\n}\n\nfunction clamp(value: number, min: number, max: number) {\n\treturn Math.min(Math.max(value, min), max);\n}\n\ntype Separators = { group: string; decimal: string };\n\nfunction getSeparators(locale?: string): Separators {\n\tconst parts = new Intl.NumberFormat(locale).formatToParts(12345.6);\n\treturn {\n\t\tgroup: parts.find((part) => part.type === \"group\")?.value ?? \",\",\n\t\tdecimal: parts.find((part) => part.type === \"decimal\")?.value ?? \".\",\n\t};\n}\n\n/** Reduces locale text to digits, `-`, and a `.` decimal point. */\nfunction normalizeNumber(text: string, { group, decimal }: Separators) {\n\treturn text\n\t\t.replace(/[\\s  ]/g, \"\")\n\t\t.split(group)\n\t\t.join(\"\")\n\t\t.split(decimal)\n\t\t.join(\".\")\n\t\t.replace(/[−‒-—]/g, \"-\")\n\t\t.replace(/[^\\d.-]/g, \"\");\n}\n\nfunction parseNumber(text: string, separators: Separators, percent: boolean) {\n\tconst clean = normalizeNumber(text, separators);\n\tconst negative = clean.startsWith(\"-\");\n\tconst [whole = \"\", ...fraction] = clean.replace(/-/g, \"\").split(\".\");\n\tconst digits = fraction.length ? `${whole}.${fraction.join(\"\")}` : whole;\n\tif (!/\\d/.test(digits)) return Number.NaN;\n\tconst parsed = Number(digits) * (negative ? -1 : 1);\n\t// Percent values are fractions: typing \"15\" in a percent field means 0.15.\n\treturn percent ? parsed / 100 : parsed;\n}\n\nexport function NumberStepper({\n\tvalue: valueProp,\n\tdefaultValue = 1,\n\tonValueChange,\n\tonValueCommit,\n\tmin = 0,\n\tmax = Number.POSITIVE_INFINITY,\n\tstep = 1,\n\tlargeStep = 10,\n\taccelerate = true,\n\tformat,\n\tlocale,\n\twheel = false,\n\tsize = \"md\",\n\tvariant = \"outline\",\n\torientation = \"horizontal\",\n\tsound = true,\n\thaptics = true,\n\tdisabled = false,\n\treadOnly = false,\n\tname,\n\tlabel = \"Value\",\n\tclassName,\n}: NumberStepperProps) {\n\tconst horizontal = orientation === \"horizontal\";\n\tconst inactive = disabled || readOnly;\n\tconst percent = format?.style === \"percent\";\n\n\t// Steps are anchored at `min`, and the top limit is the last step below `max`.\n\tconst anchor = Number.isFinite(min) ? min : 0;\n\tconst decimals = Math.max(decimalsOf(step), decimalsOf(anchor));\n\tconst lower = min;\n\tconst upper = Number.isFinite(max)\n\t\t? Math.max(anchor + Math.floor((max - anchor) / step + 1e-9) * step, lower)\n\t\t: max;\n\n\tconst snap = (raw: number) => {\n\t\tconst clamped = clamp(raw, lower, upper);\n\t\tif (!Number.isFinite(clamped)) return clamped;\n\t\t// The ratio is rounded first so 0.175 / 0.05 counts as 3.5, not 3.4999….\n\t\tconst steps = Math.round(Number(((clamped - anchor) / step).toFixed(9)));\n\t\tconst snapped = anchor + steps * step;\n\t\t// Round to the step's precision so 0.1 + 0.2 lands on 0.3.\n\t\treturn Number(clamp(snapped, lower, upper).toFixed(decimals));\n\t};\n\n\tconst controlled = valueProp !== undefined;\n\tconst [internalValue, setInternalValue] = useState(() => snap(defaultValue));\n\tconst value = controlled ? snap(valueProp) : internalValue;\n\n\t// Digits roll in the direction the value moved.\n\tconst [shown, setShown] = useState({ value, trend: 1 });\n\tif (shown.value !== value) {\n\t\tsetShown({ value, trend: value > shown.value ? 1 : -1 });\n\t}\n\n\tconst [draft, setDraftState] = useState<string | null>(null);\n\tconst [holding, setHolding] = useState<Direction | null>(null);\n\tconst [announcement, setAnnouncement] = useState(\"\");\n\n\tconst formatter = useMemo(\n\t\t() => new Intl.NumberFormat(locale, format),\n\t\t[locale, format],\n\t);\n\tconst separators = useMemo(() => getSeparators(locale), [locale]);\n\tconst formatValue = (next: number) => formatter.format(next);\n\tconst valueText = formatValue(value);\n\n\tconst draftValue =\n\t\tdraft === null ? null : parseNumber(draft, separators, percent);\n\tconst invalid =\n\t\tdraft !== null &&\n\t\tdraft.trim() !== \"\" &&\n\t\tdraftValue !== null &&\n\t\t(Number.isNaN(draftValue) || snap(draftValue) !== draftValue);\n\n\tconst shouldReduceMotion = useReducedMotion() ?? false;\n\tconst { trigger: haptic } = useWebHaptics();\n\tconst {\n\t\tclick: playClick,\n\t\tpop: playPop,\n\t\ttoggle: playToggle,\n\t\twarning: playWarning,\n\t} = useTiks({\n\t\t// Sound stays on under reduced motion; only movement is reduced.\n\t\trespectReducedMotion: false,\n\t});\n\n\tconst inputId = useId();\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\tconst [valueScope, animateValue] = useAnimate<HTMLDivElement>();\n\tconst buttonRefs = useRef<Record<Direction, HTMLButtonElement | null>>({\n\t\t1: null,\n\t\t[-1]: null,\n\t});\n\tconst ringRefs = useRef<Record<Direction, HTMLSpanElement | null>>({\n\t\t1: null,\n\t\t[-1]: null,\n\t});\n\tconst valueRef = useRef(value);\n\tconst draftRef = useRef<string | null>(null);\n\tconst lastEmittedRef = useRef(value);\n\tconst lastCueAtRef = useRef(Number.NEGATIVE_INFINITY);\n\tconst announcedRef = useRef(valueText);\n\tconst pressRef = useRef(false);\n\tconst pressedButtonRef = useRef<Direction | null>(null);\n\tconst holdRef = useRef<{\n\t\tdirection: Direction;\n\t\tstartedAt: number;\n\t\trepeats: number;\n\t\taccelerated: boolean;\n\t\ttimer: ReturnType<typeof setTimeout>;\n\t} | null>(null);\n\n\tuseLayoutEffect(() => {\n\t\tvalueRef.current = value;\n\t});\n\n\tconst setDraft = (next: string | null) => {\n\t\tdraftRef.current = next;\n\t\tsetDraftState(next);\n\t};\n\n\tconst cue = (kind: StepKind) => {\n\t\tconst now = performance.now();\n\t\tif (now - lastCueAtRef.current < CUE_THROTTLE_MS) return;\n\t\tlastCueAtRef.current = now;\n\t\tif (kind === \"accelerate\") {\n\t\t\tif (sound) playToggle(true);\n\t\t\tif (haptics) void haptic(\"light\");\n\t\t} else {\n\t\t\tif (sound) playClick();\n\t\t\tif (haptics) void haptic(\"selection\");\n\t\t}\n\t};\n\n\tconst warn = () => {\n\t\tlastCueAtRef.current = performance.now();\n\t\tif (sound) playWarning();\n\t\tif (haptics) void haptic(\"warning\");\n\t};\n\n\t// The soft wall: a pop, a rigid haptic, and a nudge toward the pressed side.\n\tconst hitWall = (direction: Direction) => {\n\t\tlastCueAtRef.current = performance.now();\n\t\tif (sound) playPop();\n\t\tif (haptics) void haptic(\"rigid\");\n\t\tif (shouldReduceMotion || !valueScope.current) return;\n\t\tconst offsets = [0, 4, -3, 0].map(\n\t\t\t(offset) => offset * (horizontal ? direction : -direction),\n\t\t);\n\t\tvoid animateValue(\n\t\t\tvalueScope.current,\n\t\t\thorizontal ? { x: offsets } : { y: offsets },\n\t\t\t{ duration: 0.22, ease: \"easeOut\" },\n\t\t);\n\t};\n\n\tconst emit = (next: number) => {\n\t\tvalueRef.current = next;\n\t\tlastEmittedRef.current = next;\n\t\tif (!controlled) setInternalValue(next);\n\t\tonValueChange?.(next);\n\t};\n\n\t/** Resolves a pending typed value and returns the value to build on. */\n\tconst commitDraft = () => {\n\t\tconst text = draftRef.current;\n\t\tconst current = valueRef.current;\n\t\tif (text === null) return current;\n\t\tsetDraft(null);\n\t\t// An emptied field goes back to the last valid value.\n\t\tif (text.trim() === \"\") return current;\n\t\tconst parsed = parseNumber(text, separators, percent);\n\t\tif (Number.isNaN(parsed)) {\n\t\t\twarn();\n\t\t\treturn current;\n\t\t}\n\t\tconst next = snap(parsed);\n\t\tif (next !== parsed) warn();\n\t\tif (next !== current) {\n\t\t\temit(next);\n\t\t\tonValueCommit?.(next);\n\t\t}\n\t\treturn next;\n\t};\n\n\tconst stepBy = (\n\t\tdirection: Direction,\n\t\tmultiplier = 1,\n\t\tkind: StepKind = \"step\",\n\t): StepResult => {\n\t\tconst current = commitDraft();\n\t\tconst next = snap(current + direction * step * multiplier);\n\t\tif (next === current) return \"blocked\";\n\t\temit(next);\n\t\tconst atLimit = direction > 0 ? next >= upper : next <= lower;\n\t\tif (atLimit) {\n\t\t\thitWall(direction);\n\t\t\treturn \"limit\";\n\t\t}\n\t\tcue(kind);\n\t\treturn \"moved\";\n\t};\n\n\tconst jumpTo = (target: number) => {\n\t\tconst current = commitDraft();\n\t\tconst next = snap(target);\n\t\tif (!Number.isFinite(next) || next === current) return;\n\t\temit(next);\n\t\thitWall(next > current ? 1 : -1);\n\t\tonValueCommit?.(next);\n\t};\n\n\tconst setRing = (\n\t\tdirection: Direction,\n\t\topacity: number | number[],\n\t\tms = 150,\n\t) => {\n\t\tconst ring = ringRefs.current[direction];\n\t\tif (ring)\n\t\t\tanimate(ring, { opacity }, { duration: ms / 1000, ease: \"easeOut\" });\n\t};\n\n\t// Scale is driven here rather than with `whileTap`: a button that reaches\n\t// its limit turns disabled mid-press and would never see the release.\n\tconst pressButton = (direction: Direction) => {\n\t\tpressedButtonRef.current = direction;\n\t\tconst button = buttonRefs.current[direction];\n\t\tif (button) animate(button, { scale: 0.92 }, pressSpring);\n\t};\n\n\tconst releaseButton = () => {\n\t\tconst direction = pressedButtonRef.current;\n\t\tif (direction === null) return;\n\t\tpressedButtonRef.current = null;\n\t\tconst button = buttonRefs.current[direction];\n\t\tif (button) animate(button, { scale: 1 }, pressSpring);\n\t};\n\n\tconst endPress = () => {\n\t\treleaseButton();\n\t\tconst hold = holdRef.current;\n\t\tif (hold) {\n\t\t\tclearTimeout(hold.timer);\n\t\t\tsetRing(hold.direction, 0);\n\t\t\tholdRef.current = null;\n\t\t\tsetHolding(null);\n\t\t}\n\t\tif (pressRef.current) {\n\t\t\tpressRef.current = false;\n\t\t\tonValueCommit?.(valueRef.current);\n\t\t}\n\t};\n\n\tconst repeat = () => {\n\t\tconst hold = holdRef.current;\n\t\tif (!hold) return;\n\t\thold.repeats += 1;\n\t\tconst accelerated = accelerate && hold.repeats > ACCELERATE_AFTER;\n\t\tconst kind = accelerated && !hold.accelerated ? \"accelerate\" : \"step\";\n\t\thold.accelerated = accelerated;\n\t\tif (hold.repeats === 1) setHolding(hold.direction);\n\t\tconst result = stepBy(hold.direction, accelerated ? largeStep : 1, kind);\n\t\tif (result !== \"moved\") {\n\t\t\tendPress();\n\t\t\treturn;\n\t\t}\n\t\tconst elapsed = performance.now() - hold.startedAt;\n\t\tconst ramp = clamp(\n\t\t\t(elapsed - REPEAT_DELAY) / (REPEAT_RAMP_END - REPEAT_DELAY),\n\t\t\t0,\n\t\t\t1,\n\t\t);\n\t\tconst interval = REPEAT_SLOW - (REPEAT_SLOW - REPEAT_FAST) * ramp;\n\t\t// The ring flashes on each repeat, so its pulse tracks the repeat rate.\n\t\tsetRing(hold.direction, shouldReduceMotion ? 0.6 : [0.9, 0.25], interval);\n\t\thold.timer = setTimeout(() => repeatRef.current(), interval);\n\t};\n\n\t// Timers call through refs so they always see the latest props.\n\tconst repeatRef = useRef(repeat);\n\tconst endPressRef = useRef(endPress);\n\tconst wheelStepRef = useRef((steps: number) => {\n\t\tvoid steps;\n\t});\n\tuseLayoutEffect(() => {\n\t\trepeatRef.current = repeat;\n\t\tendPressRef.current = endPress;\n\t\twheelStepRef.current = (steps: number) => {\n\t\t\tconst result = stepBy(steps > 0 ? 1 : -1, Math.abs(steps));\n\t\t\tif (result !== \"blocked\") onValueCommit?.(valueRef.current);\n\t\t};\n\t});\n\n\tconst handlePointerDown = (\n\t\tdirection: Direction,\n\t\tevent: PointerEvent<HTMLButtonElement>,\n\t) => {\n\t\tif (inactive || event.button !== 0) return;\n\t\t// Touch captures the pointer implicitly; release it so sliding off cancels.\n\t\tif (event.currentTarget.hasPointerCapture(event.pointerId)) {\n\t\t\tevent.currentTarget.releasePointerCapture(event.pointerId);\n\t\t}\n\t\tendPress();\n\t\tpressRef.current = true;\n\t\tpressButton(direction);\n\t\tif (stepBy(direction) !== \"moved\") return;\n\t\tholdRef.current = {\n\t\t\tdirection,\n\t\t\tstartedAt: performance.now(),\n\t\t\trepeats: 0,\n\t\t\taccelerated: false,\n\t\t\ttimer: setTimeout(() => repeatRef.current(), REPEAT_DELAY),\n\t\t};\n\t};\n\n\t// Keyboard and assistive tech activate the buttons with a click of detail 0.\n\tconst handleClick = (\n\t\tdirection: Direction,\n\t\tevent: MouseEvent<HTMLButtonElement>,\n\t) => {\n\t\tif (inactive || event.detail !== 0) return;\n\t\tif (stepBy(direction) !== \"blocked\") onValueCommit?.(valueRef.current);\n\t};\n\n\tconst handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n\t\tif (event.key === \"Escape\" && draftRef.current !== null) {\n\t\t\tevent.preventDefault();\n\t\t\tsetDraft(null);\n\t\t\treturn;\n\t\t}\n\t\tif (event.key === \"Enter\") {\n\t\t\tif (draftRef.current === null) return;\n\t\t\tevent.preventDefault();\n\t\t\tcommitDraft();\n\t\t\treturn;\n\t\t}\n\t\tif (inactive) return;\n\t\tlet direction: Direction | null = null;\n\t\tlet multiplier = 1;\n\t\tswitch (event.key) {\n\t\t\tcase \"ArrowUp\":\n\t\t\t\tdirection = 1;\n\t\t\t\tmultiplier = event.shiftKey ? largeStep : 1;\n\t\t\t\tbreak;\n\t\t\tcase \"ArrowDown\":\n\t\t\t\tdirection = -1;\n\t\t\t\tmultiplier = event.shiftKey ? largeStep : 1;\n\t\t\t\tbreak;\n\t\t\tcase \"PageUp\":\n\t\t\t\tdirection = 1;\n\t\t\t\tmultiplier = largeStep;\n\t\t\t\tbreak;\n\t\t\tcase \"PageDown\":\n\t\t\t\tdirection = -1;\n\t\t\t\tmultiplier = largeStep;\n\t\t\t\tbreak;\n\t\t\tcase \"Home\":\n\t\t\t\tif (!Number.isFinite(lower)) return;\n\t\t\t\tevent.preventDefault();\n\t\t\t\tjumpTo(lower);\n\t\t\t\treturn;\n\t\t\tcase \"End\":\n\t\t\t\tif (!Number.isFinite(upper)) return;\n\t\t\t\tevent.preventDefault();\n\t\t\t\tjumpTo(upper);\n\t\t\t\treturn;\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t\tevent.preventDefault();\n\t\tif (stepBy(direction, multiplier) !== \"blocked\") {\n\t\t\tonValueCommit?.(valueRef.current);\n\t\t}\n\t};\n\n\tconst handlePaste = (event: ClipboardEvent<HTMLInputElement>) => {\n\t\tif (inactive) return;\n\t\tevent.preventDefault();\n\t\tconst input = event.currentTarget;\n\t\tconst pasted = normalizeNumber(\n\t\t\tevent.clipboardData.getData(\"text\"),\n\t\t\tseparators,\n\t\t).replace(\".\", separators.decimal);\n\t\tconst text = input.value;\n\t\tconst start = input.selectionStart ?? text.length;\n\t\tconst end = input.selectionEnd ?? text.length;\n\t\tsetDraft(text.slice(0, start) + pasted + text.slice(end));\n\t};\n\n\t// A controlled value that changes mid-hold stops the repeat.\n\tuseEffect(() => {\n\t\tif (holdRef.current && valueProp !== lastEmittedRef.current) {\n\t\t\tendPressRef.current();\n\t\t}\n\t}, [valueProp]);\n\n\tuseEffect(() => {\n\t\tif (inactive) endPressRef.current();\n\t}, [inactive]);\n\n\t// Releasing outside the window never reaches the button.\n\tuseEffect(() => {\n\t\tif (holding === null) return;\n\t\tconst end = () => endPressRef.current();\n\t\twindow.addEventListener(\"blur\", end);\n\t\treturn () => window.removeEventListener(\"blur\", end);\n\t}, [holding]);\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (holdRef.current) clearTimeout(holdRef.current.timer);\n\t\t},\n\t\t[],\n\t);\n\n\t// Announce once the value settles, not on every repeat. A focused\n\t// spinbutton already reads its own changes, so skip those.\n\tuseEffect(() => {\n\t\tif (valueText === announcedRef.current) return;\n\t\tconst timer = setTimeout(() => {\n\t\t\tannouncedRef.current = valueText;\n\t\t\tif (document.activeElement !== inputRef.current) {\n\t\t\t\tsetAnnouncement(valueText);\n\t\t\t}\n\t\t}, ANNOUNCE_DELAY);\n\t\treturn () => clearTimeout(timer);\n\t}, [valueText]);\n\n\t// Wheel needs a non-passive listener to keep the page from scrolling.\n\tuseEffect(() => {\n\t\tconst input = inputRef.current;\n\t\tif (!input || !wheel || inactive) return;\n\t\tlet accumulated = 0;\n\t\tconst onWheel = (event: WheelEvent) => {\n\t\t\tif (document.activeElement !== input || event.deltaY === 0) return;\n\t\t\tevent.preventDefault();\n\t\t\tlet steps = 0;\n\t\t\tif (event.deltaMode !== 0 || Math.abs(event.deltaY) >= WHEEL_STEP_PX) {\n\t\t\t\t// One notch, one step.\n\t\t\t\tsteps = -Math.sign(event.deltaY);\n\t\t\t\taccumulated = 0;\n\t\t\t} else {\n\t\t\t\taccumulated += event.deltaY;\n\t\t\t\tsteps = -Math.trunc(accumulated / WHEEL_STEP_PX);\n\t\t\t\taccumulated += steps * WHEEL_STEP_PX;\n\t\t\t}\n\t\t\tif (steps !== 0) wheelStepRef.current(steps);\n\t\t};\n\t\tinput.addEventListener(\"wheel\", onWheel, { passive: false });\n\t\treturn () => input.removeEventListener(\"wheel\", onWheel);\n\t}, [wheel, inactive]);\n\n\tconst atMin = value <= lower;\n\tconst atMax = value >= upper;\n\tconst typing = draft !== null;\n\tconst sizeStyle = sizes[size];\n\tconst variantStyle = variants[variant];\n\tconst widthChars =\n\t\tMath.max(\n\t\t\t2,\n\t\t\t...[lower, upper, value]\n\t\t\t\t.filter(Number.isFinite)\n\t\t\t\t.map((bound) => formatValue(bound).length),\n\t\t) + 1;\n\tconst inputMode =\n\t\tlower < 0 ? \"text\" : decimals > 0 && !percent ? \"decimal\" : \"numeric\";\n\n\tconst renderButton = (direction: Direction) => {\n\t\tconst increase = direction === 1;\n\t\tconst blocked = increase ? atMax : atMin;\n\t\tconst Icon = horizontal\n\t\t\t? increase\n\t\t\t\t? Plus\n\t\t\t\t: Minus\n\t\t\t: increase\n\t\t\t\t? ChevronUp\n\t\t\t\t: ChevronDown;\n\t\treturn (\n\t\t\t<button\n\t\t\t\tref={(node) => {\n\t\t\t\t\tbuttonRefs.current[direction] = node;\n\t\t\t\t}}\n\t\t\t\ttype=\"button\"\n\t\t\t\ttabIndex={-1}\n\t\t\t\taria-label={`${increase ? \"Increase\" : \"Decrease\"} ${label}`}\n\t\t\t\taria-controls={inputId}\n\t\t\t\tdisabled={inactive || blocked}\n\t\t\t\tdata-slot={`number-stepper-${increase ? \"increment\" : \"decrement\"}`}\n\t\t\t\tdata-holding={holding === direction || undefined}\n\t\t\t\tonPointerDown={(event) => handlePointerDown(direction, event)}\n\t\t\t\tonPointerUp={endPress}\n\t\t\t\tonPointerLeave={endPress}\n\t\t\t\tonPointerCancel={endPress}\n\t\t\t\tonClick={(event) => handleClick(direction, event)}\n\t\t\t\t// Keep focus (and any draft) in the input.\n\t\t\t\tonMouseDown={(event) => event.preventDefault()}\n\t\t\t\tonContextMenu={(event) => event.preventDefault()}\n\t\t\t\tclassName={cn(\n\t\t\t\t\t\"relative inline-flex pointer-coarse:min-h-11 pointer-coarse:min-w-11 shrink-0 cursor-pointer touch-manipulation select-none items-center justify-center outline-none transition-[opacity,color,background-color] duration-150 disabled:pointer-events-none disabled:opacity-40\",\n\t\t\t\t\thorizontal\n\t\t\t\t\t\t? sizeStyle.button[variant]\n\t\t\t\t\t\t: cn(\"w-full\", sizeStyle.verticalButton),\n\t\t\t\t\tsizeStyle.icon,\n\t\t\t\t\tvariantStyle.button,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<Icon aria-hidden />\n\t\t\t\t<span\n\t\t\t\t\tref={(node) => {\n\t\t\t\t\t\tringRefs.current[direction] = node;\n\t\t\t\t\t}}\n\t\t\t\t\taria-hidden\n\t\t\t\t\tdata-slot=\"number-stepper-ring\"\n\t\t\t\t\tclassName=\"pointer-events-none absolute inset-0 rounded-[inherit] opacity-0 ring-2 ring-ring ring-offset-1 ring-offset-background\"\n\t\t\t\t/>\n\t\t\t</button>\n\t\t);\n\t};\n\n\treturn (\n\t\t<div\n\t\t\tdir=\"ltr\"\n\t\t\tdata-slot=\"number-stepper\"\n\t\t\tdata-variant={variant}\n\t\t\tdata-size={size}\n\t\t\tdata-orientation={orientation}\n\t\t\tdata-state={holding !== null ? \"holding\" : typing ? \"typing\" : \"idle\"}\n\t\t\tdata-bound={atMin ? \"min\" : atMax ? \"max\" : undefined}\n\t\t\tdata-invalid={invalid || undefined}\n\t\t\tdata-disabled={disabled || undefined}\n\t\t\tdata-readonly={readOnly || undefined}\n\t\t\tclassName={cn(\n\t\t\t\t\"inline-flex w-fit items-center font-medium tabular-nums data-disabled:cursor-not-allowed data-disabled:opacity-50\",\n\t\t\t\thorizontal ? \"flex-row gap-1\" : \"min-w-12 flex-col gap-0.5\",\n\t\t\t\tvariant === \"outline\" && (horizontal ? \"px-1\" : \"py-1\"),\n\t\t\t\tsizeStyle.root,\n\t\t\t\tvariantStyle.root,\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t>\n\t\t\t{renderButton(horizontal ? -1 : 1)}\n\t\t\t<motion.div\n\t\t\t\tref={valueScope}\n\t\t\t\tdata-slot=\"number-stepper-value\"\n\t\t\t\tclassName=\"grid place-items-center\"\n\t\t\t>\n\t\t\t\t<input\n\t\t\t\t\tref={inputRef}\n\t\t\t\t\tid={inputId}\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\trole=\"spinbutton\"\n\t\t\t\t\tinputMode={inputMode}\n\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\tautoCorrect=\"off\"\n\t\t\t\t\tspellCheck={false}\n\t\t\t\t\taria-label={label}\n\t\t\t\t\taria-valuenow={value}\n\t\t\t\t\taria-valuemin={Number.isFinite(lower) ? lower : undefined}\n\t\t\t\t\taria-valuemax={Number.isFinite(upper) ? upper : undefined}\n\t\t\t\t\taria-valuetext={valueText}\n\t\t\t\t\taria-invalid={invalid || undefined}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\tvalue={draft ?? valueText}\n\t\t\t\t\tonChange={(event) => setDraft(event.target.value)}\n\t\t\t\t\t// Show the real text where the click lands, ready to edit.\n\t\t\t\t\tonPointerDown={() => {\n\t\t\t\t\t\tif (!inactive && draftRef.current === null) setDraft(valueText);\n\t\t\t\t\t}}\n\t\t\t\t\tonBlur={commitDraft}\n\t\t\t\t\tonKeyDown={handleKeyDown}\n\t\t\t\t\tonPaste={handlePaste}\n\t\t\t\t\tstyle={{ width: `${widthChars}ch` }}\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\"col-start-1 row-start-1 h-full min-w-0 bg-transparent px-0.5 text-center outline-none disabled:cursor-not-allowed aria-invalid:text-destructive\",\n\t\t\t\t\t\t!horizontal && \"py-0.5\",\n\t\t\t\t\t\t// While NumberFlow shows the value, the input stays invisible.\n\t\t\t\t\t\t!typing &&\n\t\t\t\t\t\t\t\"text-transparent caret-transparent selection:bg-transparent\",\n\t\t\t\t\t\tvariantStyle.input,\n\t\t\t\t\t)}\n\t\t\t\t/>\n\t\t\t\t{typing ? null : (\n\t\t\t\t\t<NumberFlow\n\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\tvalue={value}\n\t\t\t\t\t\tlocales={locale}\n\t\t\t\t\t\tformat={format as Format | undefined}\n\t\t\t\t\t\ttrend={shown.trend}\n\t\t\t\t\t\tanimated={!shouldReduceMotion}\n\t\t\t\t\t\trespectMotionPreference={false}\n\t\t\t\t\t\ttransformTiming={digitTiming}\n\t\t\t\t\t\tspinTiming={digitTiming}\n\t\t\t\t\t\tclassName=\"pointer-events-none col-start-1 row-start-1\"\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</motion.div>\n\t\t\t{renderButton(horizontal ? 1 : -1)}\n\t\t\t{name ? (\n\t\t\t\t<input type=\"hidden\" name={name} value={value} disabled={disabled} />\n\t\t\t) : null}\n\t\t\t<span aria-live=\"polite\" aria-atomic className=\"sr-only\">\n\t\t\t\t{announcement}\n\t\t\t</span>\n\t\t</div>\n\t);\n}\n\nexport default NumberStepper;\n",
      "type": "registry:component",
      "target": "@components/number-stepper.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-10-24",
    "image": "https://cdn.tentui.com/images/components/number-stepper",
    "video": "https://cdn.tentui.com/videos/components/number-stepper"
  },
  "docs": "https://tentui.com/components/number-stepper",
  "categories": [
    "inputs"
  ],
  "type": "registry:component"
}