{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "retro-little-arrows",
  "title": "RetroLittleArrows",
  "description": "Mac OS 9 little arrows stepper with press-and-hold repeat, plus RetroNumberField: an inset spinbutton field with min/max/step, keyboard stepping and controlled/uncontrolled value.",
  "registryDependencies": [
    "https://nostalgia-ui.com/r/nostalgia-theme.json"
  ],
  "files": [
    {
      "path": "registry/new-york/ui/retro-little-arrows.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/* ------------------------------------------------------------------ */\n/*  Press-and-hold repeat                                              */\n/* ------------------------------------------------------------------ */\n\n/** Delay before auto-repeat kicks in, then the repeat interval (ms). */\nconst REPEAT_DELAY = 400\nconst REPEAT_INTERVAL = 60\n\n/**\n * Returns pointer handlers that fire `action` once on press, then keep\n * firing while held. Always calls the latest `action`, and clears its\n * timers on release, cancel, blur and unmount.\n */\nfunction useAutoRepeat(action: (() => void) | undefined, disabled: boolean) {\n  const actionRef = React.useRef(action)\n  const timeoutRef = React.useRef<ReturnType<typeof setTimeout> | null>(null)\n  const intervalRef = React.useRef<ReturnType<typeof setInterval> | null>(null)\n\n  React.useLayoutEffect(() => {\n    actionRef.current = action\n  })\n\n  const stop = React.useCallback(() => {\n    if (timeoutRef.current) clearTimeout(timeoutRef.current)\n    if (intervalRef.current) clearInterval(intervalRef.current)\n    timeoutRef.current = null\n    intervalRef.current = null\n  }, [])\n\n  React.useEffect(() => stop, [stop])\n  React.useEffect(() => {\n    if (disabled) stop()\n  }, [disabled, stop])\n\n  const onPointerDown = (event: React.PointerEvent<HTMLButtonElement>) => {\n    if (disabled || event.button !== 0) return\n    // Keep focus on whatever owns it (e.g. the number field input)\n    event.preventDefault()\n    stop()\n    actionRef.current?.()\n    timeoutRef.current = setTimeout(() => {\n      intervalRef.current = setInterval(() => {\n        actionRef.current?.()\n      }, REPEAT_INTERVAL)\n    }, REPEAT_DELAY)\n  }\n\n  // Keyboard activation (Enter / Space) produces a click with detail 0;\n  // pointer presses were already handled in onPointerDown.\n  const onClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n    if (!disabled && event.detail === 0) actionRef.current?.()\n  }\n\n  return {\n    onPointerDown,\n    onPointerUp: stop,\n    onPointerLeave: stop,\n    onPointerCancel: stop,\n    onBlur: stop,\n    onClick,\n  }\n}\n\n/* ------------------------------------------------------------------ */\n/*  Arrow half                                                         */\n/* ------------------------------------------------------------------ */\n\nfunction LittleArrowButton({\n  direction,\n  onStep,\n  disabled,\n  label,\n  tabIndex,\n}: {\n  direction: \"up\" | \"down\"\n  onStep?: () => void\n  disabled: boolean\n  label: string\n  tabIndex?: number\n}) {\n  const handlers = useAutoRepeat(onStep, disabled)\n\n  return (\n    <button\n      type=\"button\"\n      aria-label={label}\n      disabled={disabled}\n      tabIndex={tabIndex}\n      data-direction={direction}\n      className={cn(\n        \"flex flex-1 items-center justify-center p-0\",\n        \"bg-os9-gray-300 text-os9-black\",\n        \"shadow-[inset_1px_1px_0_var(--os9-white),inset_-1px_-1px_0_var(--os9-gray-700)]\",\n        \"active:bg-os9-gray-700 active:text-os9-white\",\n        \"active:shadow-[inset_1px_1px_0_var(--os9-gray-800),inset_-1px_-1px_0_var(--os9-gray-500)]\",\n        \"cursor-pointer select-none touch-none transition-none\",\n        \"focus-visible:relative focus-visible:z-10 focus-visible:os9-focus-ring\",\n        \"disabled:cursor-not-allowed disabled:text-os9-gray-600\",\n        direction === \"up\" && \"border-b border-os9-black\"\n      )}\n      {...handlers}\n    >\n      <svg width=\"7\" height=\"4\" viewBox=\"0 0 7 4\" aria-hidden=\"true\">\n        <path\n          d={direction === \"up\" ? \"M3.5 0L7 4H0Z\" : \"M0 0H7L3.5 4Z\"}\n          fill=\"currentColor\"\n        />\n      </svg>\n    </button>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  RetroLittleArrows                                                  */\n/* ------------------------------------------------------------------ */\n\ninterface RetroLittleArrowsProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  /** Called on press of the up arrow, and repeatedly while held. */\n  onIncrement?: () => void\n  /** Called on press of the down arrow, and repeatedly while held. */\n  onDecrement?: () => void\n  /** Disables both arrows. */\n  disabled?: boolean\n  /** Disables only the up arrow (e.g. value is at max). */\n  incrementDisabled?: boolean\n  /** Disables only the down arrow (e.g. value is at min). */\n  decrementDisabled?: boolean\n  /** Accessible label for the up arrow. */\n  incrementLabel?: string\n  /** Accessible label for the down arrow. */\n  decrementLabel?: string\n  /**\n   * Tab index for both arrow buttons. Pass -1 when the arrows accompany a\n   * field that already handles ArrowUp / ArrowDown (as RetroNumberField does).\n   */\n  buttonTabIndex?: number\n}\n\nconst RetroLittleArrows = React.forwardRef<\n  HTMLDivElement,\n  RetroLittleArrowsProps\n>(function RetroLittleArrows(\n  {\n    className,\n    onIncrement,\n    onDecrement,\n    disabled = false,\n    incrementDisabled = false,\n    decrementDisabled = false,\n    incrementLabel = \"Increment\",\n    decrementLabel = \"Decrement\",\n    buttonTabIndex,\n    ...props\n  },\n  ref\n) {\n  return (\n    <div\n      ref={ref}\n      role=\"group\"\n      data-disabled={disabled ? \"\" : undefined}\n      className={cn(\n        \"inline-flex h-[23px] w-[13px] shrink-0 flex-col\",\n        \"border border-os9-black bg-os9-gray-300\",\n        \"shadow-[1px_1px_0_rgba(38,38,38,0.3)]\",\n        disabled && \"opacity-50\",\n        className\n      )}\n      {...props}\n    >\n      <LittleArrowButton\n        direction=\"up\"\n        label={incrementLabel}\n        onStep={onIncrement}\n        disabled={disabled || incrementDisabled}\n        tabIndex={buttonTabIndex}\n      />\n      <LittleArrowButton\n        direction=\"down\"\n        label={decrementLabel}\n        onStep={onDecrement}\n        disabled={disabled || decrementDisabled}\n        tabIndex={buttonTabIndex}\n      />\n    </div>\n  )\n})\nRetroLittleArrows.displayName = \"RetroLittleArrows\"\n\n/* ------------------------------------------------------------------ */\n/*  RetroNumberField                                                   */\n/* ------------------------------------------------------------------ */\n\nfunction decimalsOf(n: number) {\n  if (!Number.isFinite(n)) return 0\n  const s = String(n)\n  const e = s.indexOf(\"e-\")\n  if (e !== -1) return parseInt(s.slice(e + 2), 10)\n  const dot = s.indexOf(\".\")\n  return dot === -1 ? 0 : s.length - dot - 1\n}\n\ninterface RetroNumberFieldProps\n  extends Omit<\n    React.InputHTMLAttributes<HTMLInputElement>,\n    \"value\" | \"defaultValue\" | \"onChange\" | \"type\" | \"min\" | \"max\" | \"step\" | \"size\"\n  > {\n  /** Controlled value. */\n  value?: number\n  /** Initial value when uncontrolled. Defaults to `min` or 0. */\n  defaultValue?: number\n  /** Fires with the committed, clamped value. */\n  onValueChange?: (value: number) => void\n  min?: number\n  max?: number\n  /** Amount per arrow press / ArrowUp / ArrowDown. PageUp/Down use step × 10. */\n  step?: number\n  /** Custom display formatting (e.g. units). Parsing uses parseFloat. */\n  formatValue?: (value: number) => string\n  /** Classes for the wrapper (the input + arrows row). */\n  className?: string\n  /** Classes for the inset text input. */\n  inputClassName?: string\n  /** Field text size. \"default\" = Charcoal 12px, \"sm\" = Geneva 10px. */\n  size?: \"default\" | \"sm\"\n}\n\nconst RetroNumberField = React.forwardRef<\n  HTMLInputElement,\n  RetroNumberFieldProps\n>(function RetroNumberField(\n  {\n    value: valueProp,\n    defaultValue,\n    onValueChange,\n    min,\n    max,\n    step = 1,\n    formatValue,\n    className,\n    inputClassName,\n    size = \"default\",\n    disabled,\n    readOnly,\n    onKeyDown,\n    onBlur,\n    onFocus,\n    ...props\n  },\n  ref\n) {\n  const precision = decimalsOf(step)\n  const clamp = React.useCallback(\n    (n: number) => {\n      let next = n\n      if (min !== undefined) next = Math.max(min, next)\n      if (max !== undefined) next = Math.min(max, next)\n      return Number(next.toFixed(precision))\n    },\n    [min, max, precision]\n  )\n\n  const [uncontrolled, setUncontrolled] = React.useState(() =>\n    clamp(defaultValue ?? min ?? 0)\n  )\n  const isControlled = valueProp !== undefined\n  const value = isControlled ? valueProp : uncontrolled\n\n  /** Text being typed; null when not editing (the formatted value shows). */\n  const [draft, setDraft] = React.useState<string | null>(null)\n\n  const format = (n: number) =>\n    formatValue ? formatValue(n) : n.toFixed(precision)\n\n  const commit = (n: number) => {\n    const next = clamp(n)\n    if (!isControlled) setUncontrolled(next)\n    if (next !== value) onValueChange?.(next)\n  }\n\n  const stepBy = (delta: number) => {\n    if (disabled || readOnly) return\n    // Step from whatever is typed, if it parses; otherwise the last value\n    const typed = draft === null ? NaN : parseFloat(draft)\n    setDraft(null)\n    commit((Number.isNaN(typed) ? value : typed) + delta)\n  }\n\n  const commitDraft = () => {\n    if (draft === null) return\n    const parsed = parseFloat(draft)\n    setDraft(null)\n    if (!Number.isNaN(parsed)) commit(parsed)\n  }\n\n  const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n    onKeyDown?.(event)\n    if (event.defaultPrevented) return\n    switch (event.key) {\n      case \"ArrowUp\":\n        event.preventDefault()\n        stepBy(step)\n        break\n      case \"ArrowDown\":\n        event.preventDefault()\n        stepBy(-step)\n        break\n      case \"PageUp\":\n        event.preventDefault()\n        stepBy(step * 10)\n        break\n      case \"PageDown\":\n        event.preventDefault()\n        stepBy(-step * 10)\n        break\n      case \"Home\":\n        if (min !== undefined) {\n          event.preventDefault()\n          setDraft(null)\n          commit(min)\n        }\n        break\n      case \"End\":\n        if (max !== undefined) {\n          event.preventDefault()\n          setDraft(null)\n          commit(max)\n        }\n        break\n      case \"Enter\":\n        commitDraft()\n        break\n      case \"Escape\":\n        setDraft(null)\n        break\n    }\n  }\n\n  const atMin = min !== undefined && value <= min\n  const atMax = max !== undefined && value >= max\n\n  return (\n    <div\n      className={cn(\"inline-flex items-center gap-[3px]\", className)}\n      data-disabled={disabled ? \"\" : undefined}\n    >\n      <input\n        ref={ref}\n        type=\"text\"\n        inputMode={precision > 0 ? \"decimal\" : \"numeric\"}\n        autoComplete=\"off\"\n        role=\"spinbutton\"\n        aria-valuenow={value}\n        aria-valuemin={min}\n        aria-valuemax={max}\n        aria-valuetext={format(value)}\n        disabled={disabled}\n        readOnly={readOnly}\n        value={draft ?? format(value)}\n        onChange={(event) => setDraft(event.target.value)}\n        onKeyDown={handleKeyDown}\n        onFocus={(event) => {\n          onFocus?.(event)\n          event.currentTarget.select()\n        }}\n        onBlur={(event) => {\n          commitDraft()\n          onBlur?.(event)\n        }}\n        className={cn(\n          \"w-[56px] min-w-0 text-right\",\n          \"border border-os9-black bg-os9-white text-os9-black\",\n          \"outline-none transition-none\",\n          \"shadow-[inset_1px_1px_0_var(--os9-gray-700),inset_-1px_-1px_0_var(--os9-white),-1px_0_0_var(--os9-gray-700),0_-1px_0_var(--os9-gray-700),1px_0_0_var(--os9-white),0_1px_0_var(--os9-white)]\",\n          \"focus:shadow-[0_2px_0_0_var(--os9-focus),2px_0_0_0_var(--os9-focus),0_-2px_0_0_var(--os9-focus),-2px_0_0_0_var(--os9-focus),0_0_0_1px_var(--os9-focus)]\",\n          \"disabled:cursor-not-allowed disabled:opacity-50 disabled:bg-os9-gray-200 disabled:text-os9-gray-600\",\n          size === \"sm\"\n            ? \"h-[19px] px-[4px] font-[family-name:var(--os9-font-sans)] text-[10px] leading-normal\"\n            : \"h-[22px] px-[5px] font-[family-name:var(--os9-font-heading)] text-[12px] tracking-[0.42px] leading-[0.98]\",\n          inputClassName\n        )}\n        {...props}\n      />\n      <RetroLittleArrows\n        aria-hidden=\"true\"\n        buttonTabIndex={-1}\n        disabled={disabled || readOnly}\n        incrementDisabled={atMax}\n        decrementDisabled={atMin}\n        onIncrement={() => stepBy(step)}\n        onDecrement={() => stepBy(-step)}\n      />\n    </div>\n  )\n})\nRetroNumberField.displayName = \"RetroNumberField\"\n\nexport { RetroLittleArrows, RetroNumberField }\nexport type { RetroLittleArrowsProps, RetroNumberFieldProps }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}