{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "number-input",
  "title": "Number Input",
  "description": "A numeric field with minus/plus steppers, press-and-hold auto repeat, min/max clamping, decimal precision, prefix and suffix, thousand separators and full keyboard support.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/number-input/number-input.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type NumberInputSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface NumberInputProps {\n  value?: number | null;\n  defaultValue?: number | null;\n  onValueChange?: (value: number | null) => void;\n  min?: number;\n  max?: number;\n  step?: number;\n  precision?: number;\n  prefix?: string;\n  suffix?: string;\n  thousandSeparator?: boolean;\n  locale?: string;\n  layout?: \"split\" | \"stacked\";\n  allowEmpty?: boolean;\n  placeholder?: string;\n  label?: string;\n  helperText?: string;\n  size?: NumberInputSize;\n  theme?: \"dark\" | \"light\";\n  width?: number | string;\n  disabled?: boolean;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", faint: \"rgba(245,244,241,0.28)\", bg: \"rgba(255,255,255,0.03)\", btn: \"rgba(255,255,255,0.06)\", btnHover: \"rgba(255,255,255,0.13)\", border: \"rgba(255,255,255,0.12)\", borderHover: \"rgba(255,255,255,0.24)\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", faint: \"rgba(10,10,10,0.28)\", bg: \"#FFFFFF\", btn: \"rgba(10,10,10,0.05)\", btnHover: \"rgba(10,10,10,0.1)\", border: \"rgba(10,10,10,0.16)\", borderHover: \"rgba(10,10,10,0.3)\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nconst SIZES: Record<NumberInputSize, { font: number; height: number; radius: number; btn: number; icon: number }> = {\n  sm: { font: 13, height: 36, radius: 11, btn: 26, icon: 12 },\n  md: { font: 14.5, height: 44, radius: 13, btn: 32, icon: 14 },\n  lg: { font: 16.5, height: 52, radius: 15, btn: 38, icon: 16 },\n};\n\nfunction Icon({ kind, size }: { kind: \"minus\" | \"plus\" | \"up\" | \"down\"; size: number }) {\n  const d = { minus: \"M3.5 8H12.5\", plus: \"M3.5 8H12.5M8 3.5V12.5\", up: \"M4 10L8 6L12 10\", down: \"M4 6L8 10L12 6\" }[kind];\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d={d} />\n    </svg>\n  );\n}\n\nconst decimals = (n: number) => (String(n).split(\".\")[1] ?? \"\").length;\n\nexport function NumberInput({\n  value,\n  defaultValue = null,\n  onValueChange,\n  min,\n  max,\n  step = 1,\n  precision,\n  prefix,\n  suffix,\n  thousandSeparator = false,\n  locale = \"en-US\",\n  layout = \"split\",\n  allowEmpty = true,\n  placeholder = \"0\",\n  label,\n  helperText,\n  size = \"md\",\n  theme = \"dark\",\n  width = 220,\n  disabled = false,\n  className,\n}: NumberInputProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const uid = React.useId();\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const controlled = value !== undefined;\n  const [internal, setInternal] = React.useState<number | null>(defaultValue);\n  const [draft, setDraft] = React.useState<string | null>(null);\n  const [focused, setFocused] = React.useState(false);\n  const [hovered, setHovered] = React.useState(false);\n  const current = controlled ? value : internal;\n  const valueRef = React.useRef<number | null>(current);\n  React.useEffect(() => {\n    valueRef.current = current;\n  }, [current]);\n  const timers = React.useRef<{ t?: ReturnType<typeof setTimeout>; i?: ReturnType<typeof setInterval> }>({});\n\n  const prec = precision ?? Math.max(decimals(step), 0);\n  const clamp = React.useCallback(\n    (n: number) => {\n      let r = n;\n      if (min !== undefined) r = Math.max(min, r);\n      if (max !== undefined) r = Math.min(max, r);\n      return Number(r.toFixed(prec));\n    },\n    [min, max, prec],\n  );\n  const fmt = React.useMemo(() => new Intl.NumberFormat(locale, { minimumFractionDigits: prec, maximumFractionDigits: prec, useGrouping: thousandSeparator }), [locale, prec, thousandSeparator]);\n\n  const commit = React.useCallback(\n    (next: number | null) => {\n      if (next === valueRef.current) return;\n      valueRef.current = next;\n      if (!controlled) setInternal(next);\n      onValueChange?.(next);\n    },\n    [controlled, onValueChange],\n  );\n\n  const stepBy = React.useCallback(\n    (dir: 1 | -1, mult = 1) => {\n      const base = valueRef.current ?? (min !== undefined && dir === 1 ? min - step * mult : max !== undefined && dir === -1 ? max + step * mult : 0);\n      commit(clamp(base + dir * step * mult));\n      setDraft(null);\n    },\n    [clamp, commit, min, max, step],\n  );\n\n  const stopRepeat = React.useCallback(() => {\n    clearTimeout(timers.current.t);\n    clearInterval(timers.current.i);\n  }, []);\n  React.useEffect(() => stopRepeat, [stopRepeat]);\n\n  const startRepeat = (dir: 1 | -1) => {\n    if (disabled) return;\n    stepBy(dir);\n    stopRepeat();\n    timers.current.t = setTimeout(() => {\n      let ticks = 0;\n      timers.current.i = setInterval(() => {\n        ticks++;\n        stepBy(dir, ticks > 25 ? 10 : 1);\n      }, 65);\n    }, 380);\n  };\n\n  const parse = (raw: string) => {\n    const cleaned = raw.replace(/,/g, \"\").replace(/[^\\d.\\-]/g, \"\");\n    if (cleaned === \"\" || cleaned === \"-\" || cleaned === \".\") return null;\n    const n = parseFloat(cleaned);\n    return Number.isFinite(n) ? n : null;\n  };\n\n  const finish = () => {\n    if (draft !== null) {\n      const n = parse(draft);\n      if (n === null) commit(allowEmpty && draft.trim() === \"\" ? null : valueRef.current);\n      else commit(clamp(n));\n    }\n    setDraft(null);\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n    const mult = e.shiftKey ? 10 : e.altKey ? 0.1 : 1;\n    if (e.key === \"ArrowUp\") { e.preventDefault(); finishDraftThen(() => stepBy(1, mult)); }\n    else if (e.key === \"ArrowDown\") { e.preventDefault(); finishDraftThen(() => stepBy(-1, mult)); }\n    else if (e.key === \"PageUp\") { e.preventDefault(); finishDraftThen(() => stepBy(1, 10)); }\n    else if (e.key === \"PageDown\") { e.preventDefault(); finishDraftThen(() => stepBy(-1, 10)); }\n    else if (e.key === \"Home\" && min !== undefined && draft === null) { e.preventDefault(); commit(min); }\n    else if (e.key === \"End\" && max !== undefined && draft === null) { e.preventDefault(); commit(max); }\n    else if (e.key === \"Enter\") finish();\n    else if (e.key === \"Escape\") setDraft(null);\n  };\n\n  // apply a pending typed draft first so arrow stepping continues from what the user typed\n  const finishDraftThen = (fn: () => void) => {\n    if (draft !== null) {\n      const n = parse(draft);\n      if (n !== null) valueRef.current = clamp(n);\n    }\n    fn();\n  };\n\n  const display = draft ?? (current === null ? \"\" : fmt.format(current));\n  const atMin = current !== null && min !== undefined && current <= min;\n  const atMax = current !== null && max !== undefined && current >= max;\n  const borderColor = focused ? p.focus : hovered ? p.borderHover : p.border;\n\n  const stepBtn = (kind: \"minus\" | \"plus\", blocked: boolean, extra?: React.CSSProperties) => (\n    <motion.button\n      type=\"button\"\n      tabIndex={-1}\n      aria-label={kind === \"plus\" ? \"Increase\" : \"Decrease\"}\n      disabled={disabled || blocked}\n      onPointerDown={(e) => {\n        e.preventDefault();\n        inputRef.current?.focus();\n        startRepeat(kind === \"plus\" ? 1 : -1);\n      }}\n      onPointerUp={stopRepeat}\n      onPointerLeave={stopRepeat}\n      onPointerCancel={stopRepeat}\n      whileTap={{ scale: 0.9 }}\n      className=\"flex shrink-0 cursor-pointer items-center justify-center border-none outline-none disabled:cursor-default disabled:opacity-30\"\n      style={{ width: s.btn, height: s.btn, borderRadius: s.radius - 5, background: p.btn, color: p.text, transition: \"background 0.14s ease\", ...extra }}\n      onMouseEnter={(e) => !blocked && (e.currentTarget.style.background = p.btnHover)}\n      onMouseLeave={(e) => (e.currentTarget.style.background = p.btn)}\n    >\n      <Icon kind={layout === \"stacked\" ? (kind === \"plus\" ? \"up\" : \"down\") : kind} size={layout === \"stacked\" ? s.icon - 2 : s.icon} />\n    </motion.button>\n  );\n\n  const stacked = layout === \"stacked\";\n\n  return (\n    <div className={cn(\"inline-flex flex-col gap-2\", className)} style={{ width, maxWidth: \"100%\", fontFamily: \"Inter, sans-serif\", opacity: disabled ? 0.5 : 1 }}>\n      {label && (\n        <label htmlFor={`${uid}-input`} className=\"font-semibold tracking-[-0.01em]\" style={{ color: p.text, fontSize: s.font }}>\n          {label}\n        </label>\n      )}\n\n      <div\n        onMouseEnter={() => setHovered(true)}\n        onMouseLeave={() => setHovered(false)}\n        onClick={() => inputRef.current?.focus()}\n        className=\"flex items-center\"\n        style={{ height: s.height, padding: stacked ? `0 4px 0 14px` : \"0 5px\", gap: 6, borderRadius: s.radius, background: p.bg, border: `1px solid ${borderColor}`, boxShadow: focused ? `0 0 0 3px color-mix(in srgb, ${p.focus} 14%, transparent)` : \"0 0 0 0 transparent\", transition: \"border-color 0.18s ease, box-shadow 0.18s ease\", cursor: disabled ? \"default\" : \"text\" }}\n      >\n        {!stacked && stepBtn(\"minus\", atMin)}\n\n        <div className=\"flex min-w-0 flex-1 items-center justify-center\" style={{ gap: 4, fontSize: s.font, color: p.text }}>\n          {prefix && <span style={{ color: p.muted, fontWeight: 500 }}>{prefix}</span>}\n          <input\n            ref={inputRef}\n            id={`${uid}-input`}\n            role=\"spinbutton\"\n            type=\"text\"\n            inputMode={prec > 0 || (min !== undefined && min < 0) ? \"decimal\" : \"numeric\"}\n            autoComplete=\"off\"\n            disabled={disabled}\n            value={display}\n            placeholder={placeholder}\n            aria-valuenow={current ?? undefined}\n            aria-valuemin={min}\n            aria-valuemax={max}\n            aria-describedby={helperText ? `${uid}-help` : undefined}\n            onChange={(e) => setDraft(e.target.value)}\n            onFocus={() => setFocused(true)}\n            onBlur={() => {\n              setFocused(false);\n              stopRepeat();\n              finish();\n            }}\n            onKeyDown={onKeyDown}\n            className={cn(\"min-w-0 border-none bg-transparent p-0 font-semibold tabular-nums outline-none\", stacked && \"flex-1\")}\n            style={{ color: p.text, fontSize: s.font, textAlign: stacked ? \"left\" : \"center\", width: stacked ? \"100%\" : `${Math.max(display.length, placeholder.length, 1) + 0.5}ch`, maxWidth: \"100%\" }}\n          />\n          {suffix && <span style={{ color: p.muted, fontWeight: 500 }}>{suffix}</span>}\n        </div>\n\n        {stacked ? (\n          <div className=\"flex flex-col\" style={{ gap: 2 }}>\n            {stepBtn(\"plus\", atMax, { width: s.btn - 4, height: (s.height - 12) / 2, borderRadius: s.radius - 7 })}\n            {stepBtn(\"minus\", atMin, { width: s.btn - 4, height: (s.height - 12) / 2, borderRadius: s.radius - 7 })}\n          </div>\n        ) : (\n          stepBtn(\"plus\", atMax)\n        )}\n      </div>\n\n      {helperText && (\n        <span id={`${uid}-help`} style={{ color: p.muted, fontSize: s.font - 1.5, lineHeight: 1.4 }}>\n          {helperText}\n        </span>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}