{
  "schemaVersion": 1,
  "target": "react",
  "name": "number-input",
  "version": "0.1.0",
  "category": "forms",
  "title": "Number Input",
  "description": "A number field with steppers, press-and-hold repeat, scrubbing on the label, and Intl formatting for currency, percent, and units, whose digits roll to each new value.",
  "tags": [
    "form",
    "number",
    "stepper",
    "currency",
    "percent",
    "scrub",
    "base-ui"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0",
    "motion": "^14.14.0"
  },
  "registryDependencies": [],
  "docsPath": "/components/number-input",
  "props": [
    {
      "name": "value / defaultValue",
      "type": "number | null",
      "description": "The value, controlled or starting. null is an empty field."
    },
    {
      "name": "onValueChange",
      "type": "(value, details) => void",
      "description": "Called on typing, stepping, scrubbing, and the wheel."
    },
    {
      "name": "min / max",
      "type": "number",
      "description": "Bounds. The matching button disables at each bound."
    },
    {
      "name": "step",
      "type": "number",
      "default": "1",
      "description": "Step for the buttons and arrow keys."
    },
    {
      "name": "largeStep",
      "type": "number",
      "default": "10",
      "description": "Step with Shift held, and for Page Up and Page Down."
    },
    {
      "name": "format",
      "type": "Intl.NumberFormatOptions",
      "description": "Display format, for example { style: \"currency\", currency: \"USD\" }, { style: \"percent\" }, or { style: \"unit\", unit: \"second\" }."
    },
    {
      "name": "locale",
      "type": "Intl.LocalesArgument",
      "description": "Locale for formatting and parsing."
    },
    {
      "name": "scrub",
      "type": "boolean",
      "default": "true",
      "description": "Drag horizontally on the label to change the value."
    },
    {
      "name": "scrubSensitivity",
      "type": "number",
      "default": "4",
      "description": "Pixels of pointer travel per step while scrubbing."
    },
    {
      "name": "label / description / error",
      "type": "ReactNode",
      "description": "Label, helper text, and an error that marks the field invalid."
    },
    {
      "name": "disabled / readOnly",
      "type": "boolean",
      "default": "false",
      "description": "Blocks changes; both disable the steppers."
    }
  ],
  "accessibility": [
    "Built on Base UI NumberField: the input has inputmode set for numbers and its label points at it; Decrease and Increase are labeled buttons.",
    "Arrow keys step, Shift+Arrow and Page Up/Page Down step by largeStep, Alt+Arrow by the small step, and Home/End jump to min and max when set.",
    "Holding a stepper repeats. Scrubbing on the label is a pointer enhancement; the keyboard reaches every value without it.",
    "The rolling digits are an aria-hidden overlay on the real input, so screen readers and copy and paste always read the input's own text.",
    "Digits roll only for pointer-driven changes; keyboard steps update instantly, and with reduced motion preferred nothing rolls.",
    "Errors set aria-invalid and are linked with aria-describedby."
  ],
  "states": [
    "empty",
    "default",
    "at limit",
    "scrubbing",
    "invalid",
    "read only",
    "disabled"
  ],
  "files": [
    {
      "path": "ui/number-input.tsx",
      "content": "\"use client\";\n\nimport { NumberField } from \"@base-ui/react/number-field\";\nimport { AnimatePresence, motion, useReducedMotion, type Variants } from \"motion/react\";\nimport { type KeyboardEvent, type ReactNode, useId, useMemo, useRef, useState } from \"react\";\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\ntype RootProps = NumberField.Root.Props;\ntype ChangeDetails = NumberField.Root.ChangeEventDetails;\n\nexport interface NumberInputProps\n  extends Omit<RootProps, \"className\" | \"render\" | \"children\" | \"value\" | \"defaultValue\" | \"onValueChange\" | \"style\"> {\n  /** Visible label. Drag on it horizontally to scrub the value. Pass `aria-label` instead when the label is shown elsewhere. */\n  label?: ReactNode;\n  /** Helper text below the field. */\n  description?: ReactNode;\n  /** Error message. Marks the field invalid and replaces the description. */\n  error?: ReactNode;\n  /** The value. Pass with `onValueChange` to control it. `null` is an empty field. */\n  value?: number | null;\n  /** The starting value when uncontrolled. */\n  defaultValue?: number | null;\n  /** Called on every change: typing, stepping, scrubbing, or the wheel. */\n  onValueChange?: (value: number | null, details: ChangeDetails | null) => void;\n  /** Lets the user drag horizontally on the label to change the value. */\n  scrub?: boolean;\n  /** Pixels of pointer travel per step while scrubbing. */\n  scrubSensitivity?: number;\n  /** Placeholder for an empty field. */\n  placeholder?: string;\n  /** Names the field for screen readers when there is no visible label. */\n  \"aria-label\"?: string;\n  /** Classes for the wrapping element. */\n  className?: string;\n  /** Classes for the bordered group that holds the buttons and the input. */\n  fieldClassName?: string;\n}\n\nconst ease = [0.23, 1, 0.32, 1] as const;\n\n// The outgoing digit leaves in the direction of travel and the new one arrives from the other side,\n// like a counter wheel: going up, digits move up.\nconst digitVariants: Variants = {\n  enter: (direction: number) => ({ y: direction >= 0 ? \"70%\" : \"-70%\", opacity: 0, filter: \"blur(2px)\" }),\n  center: { y: \"0%\", opacity: 1, filter: \"blur(0px)\" },\n  exit: (direction: number) => ({ y: direction >= 0 ? \"-70%\" : \"70%\", opacity: 0, filter: \"blur(2px)\" }),\n};\n\nfunction RollingDigit({ digit, direction }: { digit: string; direction: number }) {\n  return (\n    <span className=\"relative inline-block\">\n      <AnimatePresence initial={false} mode=\"popLayout\" custom={direction}>\n        <motion.span\n          key={digit}\n          custom={direction}\n          variants={digitVariants}\n          initial=\"enter\"\n          animate=\"center\"\n          exit=\"exit\"\n          transition={{ duration: 0.24, ease }}\n          className=\"inline-block\"\n        >\n          {digit}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\n/**\n * Draws the formatted value over the input, one slot per character. Slots are keyed from the\n * right so the ones digit stays put when the number grows a column.\n */\nfunction RollingValue({ text, direction, animate }: { text: string; direction: number; animate: boolean }) {\n  const chars = Array.from(text);\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"pointer-events-none absolute inset-0 flex items-center justify-center overflow-hidden whitespace-pre\"\n    >\n      {chars.map((char, index) => {\n        const key = chars.length - index;\n        if (animate && /\\d/.test(char)) return <RollingDigit key={key} digit={char} direction={direction} />;\n        return <span key={key}>{char}</span>;\n      })}\n    </span>\n  );\n}\n\nfunction MinusIcon() {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M4 8h8\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n\nfunction PlusIcon() {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M8 4v8M4 8h8\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n\nconst stepButton = cx(\n  \"group/step flex h-full w-9 shrink-0 cursor-default items-center justify-center text-zinc-500 select-none dark:text-zinc-400\",\n  \"transition-colors duration-150 ease-out motion-reduce:transition-none\",\n  \"hover:bg-zinc-950/[0.04] hover:text-zinc-950 dark:hover:bg-white/[0.06] dark:hover:text-white\",\n  \"data-[disabled]:pointer-events-none data-[disabled]:opacity-35\",\n  \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-sky-500\",\n  \"[&_svg]:size-4 [&_svg]:transition-transform [&_svg]:duration-100 [&_svg]:ease-out motion-safe:active:[&_svg]:scale-[0.85] motion-reduce:[&_svg]:transition-none\",\n);\n\n/**\n * A number field with steppers. Hold a button to repeat, hold Shift for the large step, drag on\n * the label to scrub, and use the arrow keys, Page Up and Page Down, Home and End. Values are\n * formatted with `Intl.NumberFormat` (currency, percent, units), and digits roll to their new\n * value when a step changes them.\n */\nexport function NumberInput({\n  label,\n  description,\n  error,\n  value: valueProp,\n  defaultValue = null,\n  onValueChange,\n  scrub = true,\n  scrubSensitivity = 4,\n  placeholder,\n  min,\n  max,\n  step = 1,\n  largeStep = 10,\n  format,\n  locale,\n  disabled,\n  readOnly,\n  id,\n  className,\n  fieldClassName,\n  \"aria-label\": ariaLabel,\n  ...props\n}: NumberInputProps) {\n  const generatedId = useId();\n  const inputId = id ?? generatedId;\n  const messageId = `${inputId}-message`;\n  const invalid = error != null && error !== false;\n  const message = invalid ? error : description;\n  const reduceMotion = useReducedMotion();\n\n  const [innerValue, setInnerValue] = useState<number | null>(defaultValue);\n  const controlled = valueProp !== undefined;\n  const value = controlled ? valueProp : innerValue;\n\n  // While the user is typing, the real input text shows. After a step, scrub, wheel, or blur, the\n  // rolling overlay takes over and the input text goes transparent underneath it.\n  const [editing, setEditing] = useState(false);\n  const [roll, setRoll] = useState<{ direction: number; animate: boolean }>({ direction: 1, animate: false });\n\n  const formatter = useMemo(() => new Intl.NumberFormat(locale, format), [locale, format]);\n  const text = value == null ? \"\" : formatter.format(value);\n  const lastValue = useRef(value);\n  lastValue.current = value;\n\n  function commit(next: number | null, details: ChangeDetails | null) {\n    const reason = details?.reason;\n    const typed = reason === \"input-change\" || reason === \"input-paste\" || reason === \"input-clear\";\n    setEditing(typed);\n    if (!typed) {\n      const previous = lastValue.current;\n      // Keyboard steps change instantly; only pointer-driven changes roll.\n      const pointerDriven = reason === \"increment-press\" || reason === \"decrement-press\" || reason === \"scrub\" || reason === \"wheel\";\n      setRoll({\n        direction: previous == null || next == null ? 1 : Math.sign(next - previous) || 1,\n        animate: pointerDriven && !reduceMotion,\n      });\n    }\n    if (!controlled) setInnerValue(next);\n    onValueChange?.(next, details);\n  }\n\n  // Page Up and Page Down step by `largeStep`, the same as Shift with the arrow keys. Re-dispatching\n  // as Shift+Arrow lets the field handle clamping, snapping, and any half-typed text.\n  function handleKeyDown(event: KeyboardEvent<HTMLInputElement>) {\n    if (event.key !== \"PageUp\" && event.key !== \"PageDown\") return;\n    event.preventDefault();\n    if (disabled || readOnly) return;\n    event.currentTarget.dispatchEvent(\n      new window.KeyboardEvent(\"keydown\", {\n        key: event.key === \"PageUp\" ? \"ArrowUp\" : \"ArrowDown\",\n        shiftKey: true,\n        bubbles: true,\n        cancelable: true,\n      }),\n    );\n  }\n\n  const atMin = min != null && value != null && value <= min;\n  const atMax = max != null && value != null && value >= max;\n  const showOverlay = !editing && text !== \"\";\n\n  const labelNode = label ? (\n    <label\n      htmlFor={inputId}\n      className={cx(\n        \"text-sm font-medium text-zinc-900 transition-colors duration-150 ease-out select-none motion-reduce:transition-none dark:text-zinc-100\",\n        scrub && !disabled && !readOnly && \"cursor-ew-resize\",\n      )}\n    >\n      {label}\n    </label>\n  ) : null;\n\n  return (\n    <NumberField.Root\n      id={inputId}\n      value={value}\n      onValueChange={(next, details) => commit(next, details)}\n      min={min}\n      max={max}\n      step={step}\n      largeStep={largeStep}\n      format={format}\n      locale={locale}\n      disabled={disabled}\n      readOnly={readOnly}\n      className={cx(\"group/number grid w-full gap-1.5\", className)}\n      {...props}\n    >\n      {labelNode && scrub && !disabled && !readOnly ? (\n        <NumberField.ScrubArea direction=\"horizontal\" pixelSensitivity={scrubSensitivity} className=\"flex w-fit\">\n          {labelNode}\n          <NumberField.ScrubAreaCursor className=\"drop-shadow-[0_1px_1px_rgb(0_0_0/0.25)]\">\n            <svg aria-hidden=\"true\" viewBox=\"0 0 24 16\" fill=\"none\" className=\"h-4 w-6 text-zinc-950 dark:text-white\">\n              <path d=\"M7 4L3 8l4 4M17 4l4 4-4 4M3 8h18\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n            </svg>\n          </NumberField.ScrubAreaCursor>\n        </NumberField.ScrubArea>\n      ) : (\n        labelNode\n      )}\n      <NumberField.Group\n        className={cx(\n          \"flex h-9 w-full items-stretch overflow-hidden rounded-lg border bg-white shadow-[0_1px_2px_rgb(0_0_0/0.04)] dark:bg-black dark:shadow-none\",\n          \"transition-[border-color,box-shadow] duration-150 ease-out motion-reduce:transition-none\",\n          invalid\n            ? \"border-red-500/60 focus-within:border-red-500 focus-within:ring-3 focus-within:ring-red-500/20\"\n            : cx(\n                \"border-zinc-950/15 hover:border-zinc-950/25 dark:border-white/15 dark:hover:border-white/25\",\n                \"focus-within:border-sky-500 focus-within:ring-3 focus-within:ring-sky-500/20 dark:focus-within:border-sky-500\",\n                \"group-data-[scrubbing]/number:border-sky-500 group-data-[scrubbing]/number:ring-3 group-data-[scrubbing]/number:ring-sky-500/20\",\n              ),\n          \"group-data-[disabled]/number:cursor-not-allowed group-data-[disabled]/number:opacity-60\",\n          fieldClassName,\n        )}\n      >\n        <NumberField.Decrement\n          aria-label=\"Decrease\"\n          disabled={disabled || readOnly || atMin}\n          className={cx(stepButton, \"border-r border-zinc-950/[0.07] dark:border-white/[0.08]\")}\n        >\n          <MinusIcon />\n        </NumberField.Decrement>\n        <div className=\"relative min-w-0 flex-1 text-sm font-medium tabular-nums text-zinc-950 dark:text-white\">\n          <NumberField.Input\n            aria-label={label ? undefined : ariaLabel}\n            aria-invalid={invalid || undefined}\n            aria-describedby={message ? messageId : undefined}\n            placeholder={placeholder}\n            onKeyDown={handleKeyDown}\n            onBlur={() => setEditing(false)}\n            className={cx(\n              \"h-full w-full min-w-0 bg-transparent px-2 text-center outline-hidden placeholder:font-normal placeholder:text-zinc-400 disabled:cursor-not-allowed dark:placeholder:text-zinc-500\",\n              \"caret-zinc-950 dark:caret-white\",\n              showOverlay && \"text-transparent\",\n            )}\n          />\n          {showOverlay ? <RollingValue text={text} direction={roll.direction} animate={roll.animate} /> : null}\n        </div>\n        <NumberField.Increment\n          aria-label=\"Increase\"\n          disabled={disabled || readOnly || atMax}\n          className={cx(stepButton, \"border-l border-zinc-950/[0.07] dark:border-white/[0.08]\")}\n        >\n          <PlusIcon />\n        </NumberField.Increment>\n      </NumberField.Group>\n      {message ? (\n        <p id={messageId} className={invalid ? \"text-sm text-red-600 dark:text-red-400\" : \"text-sm text-zinc-500 dark:text-zinc-400\"}>\n          {message}\n        </p>\n      ) : null}\n    </NumberField.Root>\n  );\n}\n"
    }
  ],
  "example": {
    "content": "\"use client\";\n\nimport { useState } from \"react\";\nimport { NumberInput } from \"@/components/shaken/ui/number-input\";\n\nconst seatPrice = 24;\n\nexport default function NumberInputExample() {\n  const [seats, setSeats] = useState<number | null>(12);\n\n  return (\n    <div className=\"grid w-full max-w-md gap-x-4 gap-y-5 sm:grid-cols-2\">\n      <NumberInput\n        label=\"Seats\"\n        value={seats}\n        onValueChange={setSeats}\n        min={1}\n        max={500}\n        description={seats ? `${new Intl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\", maximumFractionDigits: 0 }).format(seats * seatPrice)} per month` : \"At least one seat\"}\n      />\n      <NumberInput\n        label=\"Monthly spend limit\"\n        defaultValue={1200}\n        min={0}\n        step={50}\n        largeStep={500}\n        format={{ style: \"currency\", currency: \"USD\", maximumFractionDigits: 0 }}\n        description=\"Shift steps by $500\"\n      />\n      <NumberInput\n        label=\"Canary traffic\"\n        defaultValue={0.25}\n        min={0}\n        max={1}\n        step={0.05}\n        largeStep={0.25}\n        format={{ style: \"percent\", maximumFractionDigits: 0 }}\n      />\n      <NumberInput\n        label=\"Request timeout\"\n        defaultValue={30}\n        min={1}\n        max={300}\n        step={5}\n        format={{ style: \"unit\", unit: \"second\", unitDisplay: \"short\" }}\n      />\n    </div>\n  );\n}\n"
  }
}
