{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "retro-date-picker",
  "title": "RetroDatePicker",
  "description": "A Mac OS 9 styled date picker with inline text input (MM/DD/YYYY), calendar icon trigger button, and popover calendar dropdown, composed from RetroPopover and RetroCalendar.",
  "dependencies": [
    "date-fns",
    "react-day-picker"
  ],
  "registryDependencies": [
    "https://nostalgia-ui.com/r/nostalgia-theme.json",
    "https://nostalgia-ui.com/r/retro-popover.json",
    "https://nostalgia-ui.com/r/retro-calendar.json"
  ],
  "files": [
    {
      "path": "registry/new-york/ui/retro-date-picker.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { format, parse, isValid } from \"date-fns\"\n\nimport { cn } from \"@/lib/utils\"\nimport { RetroCalendar } from \"@/registry/new-york/ui/retro-calendar\"\nimport {\n  RetroPopover,\n  RetroPopoverTrigger,\n  RetroPopoverContent,\n} from \"@/registry/new-york/ui/retro-popover\"\n\n// Spread rather than a literal `asChild` attribute: the shadcn CLI rewrites\n// literal `asChild` to Base UI's `render` prop in base-* projects, which\n// breaks these Radix-based components.\nconst AS_CHILD = { asChild: true } as const\n\ninterface RetroDatePickerProps {\n  /** The selected date (controlled) */\n  value?: Date\n  /** Callback when the date changes */\n  onChange?: (date: Date | undefined) => void\n  /** Placeholder text when no date is selected */\n  placeholder?: string\n  /** Date display format (date-fns format string) */\n  displayFormat?: string\n  /** Whether the date picker is disabled */\n  disabled?: boolean\n  /** Additional class names for the root container */\n  className?: string\n}\n\nconst CalendarIcon = React.forwardRef<\n  SVGSVGElement,\n  React.SVGProps<SVGSVGElement>\n>(function CalendarIcon(props, ref) {\n  return (\n    <svg\n      ref={ref}\n      width=\"14\"\n      height=\"14\"\n      viewBox=\"0 0 12 12\"\n      fill=\"none\"\n      xmlns=\"http://www.w3.org/2000/svg\"\n      aria-hidden=\"true\"\n      {...props}\n    >\n      {/* Outer frame */}\n      <rect x=\"1\" y=\"2\" width=\"10\" height=\"9\" stroke=\"currentColor\" strokeWidth=\"1\" fill=\"none\" />\n      {/* Top bar (header) */}\n      <rect x=\"1\" y=\"2\" width=\"10\" height=\"3\" fill=\"currentColor\" />\n      {/* Calendar pins */}\n      <rect x=\"3\" y=\"1\" width=\"1\" height=\"2\" fill=\"currentColor\" />\n      <rect x=\"8\" y=\"1\" width=\"1\" height=\"2\" fill=\"currentColor\" />\n      {/* Grid dots (day cells) */}\n      <rect x=\"3\" y=\"7\" width=\"1\" height=\"1\" fill=\"currentColor\" />\n      <rect x=\"5\" y=\"7\" width=\"1\" height=\"1\" fill=\"currentColor\" />\n      <rect x=\"7\" y=\"7\" width=\"1\" height=\"1\" fill=\"currentColor\" />\n      <rect x=\"3\" y=\"9\" width=\"1\" height=\"1\" fill=\"currentColor\" />\n      <rect x=\"5\" y=\"9\" width=\"1\" height=\"1\" fill=\"currentColor\" />\n      <rect x=\"7\" y=\"9\" width=\"1\" height=\"1\" fill=\"currentColor\" />\n    </svg>\n  )\n})\nCalendarIcon.displayName = \"CalendarIcon\"\n\nconst DATE_FORMAT = \"MM/dd/yyyy\"\n\nconst RetroDatePicker = React.forwardRef<HTMLDivElement, RetroDatePickerProps>(\n  function RetroDatePicker(\n    {\n      value,\n      onChange,\n      placeholder = \"MM/DD/YYYY\",\n      displayFormat = DATE_FORMAT,\n      disabled = false,\n      className,\n    },\n    ref\n  ) {\n    const [open, setOpen] = React.useState(false)\n    const [internalDate, setInternalDate] = React.useState<Date | undefined>(\n      undefined\n    )\n    const [inputValue, setInputValue] = React.useState(\"\")\n\n    const isControlled = value !== undefined\n    const selectedDate = isControlled ? value : internalDate\n\n    // Depend on the timestamp (not Date identity) so a parent passing a new\n    // Date instance with the same value on every render doesn't clobber typing.\n    const selectedTime = selectedDate?.getTime()\n\n    // Sync input text with the selected date\n    React.useEffect(() => {\n      setInputValue(\n        selectedTime !== undefined ? format(new Date(selectedTime), displayFormat) : \"\"\n      )\n    }, [selectedTime, displayFormat])\n\n    function commitDate(date: Date | undefined) {\n      if (!isControlled) {\n        setInternalDate(date)\n      }\n      onChange?.(date)\n    }\n\n    function handleCalendarSelect(date: Date | undefined) {\n      commitDate(date)\n      setOpen(false)\n    }\n\n    function handleInputChange(e: React.ChangeEvent<HTMLInputElement>) {\n      setInputValue(e.target.value)\n    }\n\n    function parseInput(text: string): Date | undefined {\n      // Parse using the display format first, then fall back to MM/dd/yyyy\n      for (const fmt of [displayFormat, DATE_FORMAT]) {\n        const parsed = parse(text, fmt, new Date())\n        if (isValid(parsed) && parsed.getFullYear() > 1900 && parsed.getFullYear() < 2100) {\n          return parsed\n        }\n      }\n      return undefined\n    }\n\n    function handleInputCommit() {\n      if (inputValue.trim() === \"\") {\n        if (selectedTime !== undefined) commitDate(undefined)\n        return\n      }\n      const parsed = parseInput(inputValue.trim())\n      if (parsed) {\n        if (parsed.getTime() !== selectedTime) {\n          commitDate(parsed)\n        } else {\n          // Unchanged: normalise the text back to the display format\n          setInputValue(format(parsed, displayFormat))\n        }\n      } else {\n        // Reset to last valid value\n        setInputValue(selectedDate ? format(selectedDate, displayFormat) : \"\")\n      }\n    }\n\n    function handleInputKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\n      if (e.key === \"Enter\") {\n        handleInputCommit()\n      }\n    }\n\n    return (\n      <RetroPopover open={open} onOpenChange={setOpen}>\n        <div\n          ref={ref}\n          className={cn(\"inline-flex items-center\", className)}\n        >\n          <input\n            type=\"text\"\n            value={inputValue}\n            onChange={handleInputChange}\n            onBlur={handleInputCommit}\n            onKeyDown={handleInputKeyDown}\n            placeholder={placeholder}\n            disabled={disabled}\n            aria-label=\"Date\"\n            className={cn(\n              \"h-[24px] w-[110px] px-[5px]\",\n              \"font-[family-name:var(--os9-font-sans)] text-[11px] text-os9-black\",\n              \"border border-os9-black bg-os9-white\",\n              \"shadow-[inset_1px_1px_0_var(--os9-gray-700),inset_-1px_-1px_0_var(--os9-white)]\",\n              \"outline-none transition-none\",\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            )}\n          />\n          <RetroPopoverTrigger {...AS_CHILD}>\n            <button\n              type=\"button\"\n              disabled={disabled}\n              aria-label=\"Choose date\"\n              className={cn(\n                \"inline-flex items-center justify-center\",\n                \"h-[24px] w-[28px] p-0 -ml-px\",\n                \"border border-os9-black bg-os9-gray-300\",\n                \"shadow-[inset_1px_1px_0_var(--os9-white),inset_-1px_-1px_0_var(--os9-gray-700)]\",\n                \"cursor-pointer select-none transition-none\",\n                \"active:shadow-[inset_1px_1px_0_var(--os9-gray-700),inset_-1px_-1px_0_var(--os9-white)]\",\n                \"focus-visible:os9-focus-ring\",\n                \"disabled:pointer-events-none disabled:opacity-50\"\n              )}\n            >\n              <CalendarIcon />\n            </button>\n          </RetroPopoverTrigger>\n        </div>\n        <RetroPopoverContent className=\"w-auto p-0\" align=\"start\">\n          <RetroCalendar\n            mode=\"single\"\n            selected={selectedDate}\n            onSelect={handleCalendarSelect}\n            defaultMonth={selectedDate}\n            autoFocus\n          />\n        </RetroPopoverContent>\n      </RetroPopover>\n    )\n  }\n)\nRetroDatePicker.displayName = \"RetroDatePicker\"\n\nexport { RetroDatePicker, CalendarIcon }\nexport type { RetroDatePickerProps }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}