{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "retro-combobox",
  "title": "RetroCombobox",
  "description": "A Mac OS 9 styled searchable select / autocomplete combobox with inset bevel trigger, search input, gliding azul highlight, checkmark selection indicator, and group headings, built on UI SDK Combobox.",
  "dependencies": [
    "@ui-sdk/core@0.1.0-beta.1",
    "@ui-sdk/react@0.1.0-beta.1"
  ],
  "registryDependencies": [
    "https://nostalgia-ui.com/r/nostalgia-theme.json",
    "https://nostalgia-ui.com/r/retro-motion.json"
  ],
  "files": [
    {
      "path": "registry/new-york/ui/retro-combobox.tsx",
      "content": "\"use client\"\n\n/*\n * RetroCombobox: a Mac OS 9 searchable pop-up on UI SDK's Combobox. A button\n * shows the current choice; its popup holds a search field over the list.\n *\n * Crafted moment: the gliding azul highlight (modern flair). One highlight\n * layer slides between options as you type, arrow or point, and the row's\n * ink flips to white as it arrives, exactly like the menus. Classic flair\n * (and reduced motion) snaps row to row.\n */\n\nimport * as React from \"react\"\nimport {\n  Combobox as ComboboxPrimitive,\n  ComboboxContent as ComboboxContentPrimitive,\n  ComboboxEmpty as ComboboxEmptyPrimitive,\n  ComboboxGroup as ComboboxGroupPrimitive,\n  ComboboxGroupLabel as ComboboxGroupLabelPrimitive,\n  ComboboxInput as ComboboxInputPrimitive,\n  ComboboxItem as ComboboxItemPrimitive,\n  ComboboxItemIndicator as ComboboxItemIndicatorPrimitive,\n  ComboboxList as ComboboxListPrimitive,\n  ComboboxSeparator as ComboboxSeparatorPrimitive,\n  ComboboxTrigger as ComboboxTriggerPrimitive,\n} from \"@ui-sdk/react/combobox\"\n\nimport { cn } from \"@/lib/utils\"\nimport { popupClass, useGlide, useMergedRef } from \"@/registry/new-york/lib/retro-motion\"\n\n/* string class names and plain children, as shadcn-style parts take */\ntype WithClassName<P> = Omit<P, \"className\" | \"children\"> & {\n  className?: string\n  children?: React.ReactNode\n}\n\n/* ------------------------------------------------------------------ */\n/*  Glide CSS                                                          */\n/* ------------------------------------------------------------------ */\n\n/* Unlayered, so it beats the option utilities without !important. */\nconst COMBOBOX_CSS = `\n.os9-combobox:not([data-glide-off]) [role=\"option\"][data-highlighted] {\n  background-color: transparent;\n}\n.os9-combobox[data-glide-off] > [data-glide-layer] {\n  opacity: 0 !important;\n  transition: none !important;\n}\n.os9-combobox [role=\"option\"] { transition: color 0s linear 60ms; }\n.os9-combobox[data-glide-off] [role=\"option\"] { transition: none; }\n`\n\n/* ------------------------------------------------------------------ */\n/*  Helpers                                                            */\n/* ------------------------------------------------------------------ */\n\ninterface RetroComboboxOption {\n  value: string\n  label: string\n}\n\n/** Extract plain text from a React node (strings, numbers, nested elements). */\nfunction getNodeText(node: React.ReactNode): string {\n  if (node == null || typeof node === \"boolean\") return \"\"\n  if (typeof node === \"string\" || typeof node === \"number\") return String(node)\n  if (Array.isArray(node)) return node.map(getNodeText).join(\"\")\n  if (React.isValidElement<{ children?: React.ReactNode }>(node)) {\n    return getNodeText(node.props.children)\n  }\n  return \"\"\n}\n\n/* ------------------------------------------------------------------ */\n/*  Context                                                            */\n/* ------------------------------------------------------------------ */\n\ninterface ComboboxContextValue {\n  value: string\n  /** The trigger button: the popup anchors to it and focus returns to it. */\n  trigger: HTMLButtonElement | null\n  setTrigger: (node: HTMLButtonElement | null) => void\n  /** Register an item's label so the trigger can display it */\n  registerItem: (value: string, label: string) => void\n  getLabel: (value: string) => string | undefined\n  displayValue?: (value: string) => React.ReactNode\n}\n\nconst ComboboxContext = React.createContext<ComboboxContextValue | null>(null)\n\nfunction useCombobox() {\n  const ctx = React.useContext(ComboboxContext)\n  if (!ctx) {\n    throw new Error(\"Combobox compound components must be used within <RetroCombobox>\")\n  }\n  return ctx\n}\n\n/* ------------------------------------------------------------------ */\n/*  RetroCombobox (root)                                               */\n/* ------------------------------------------------------------------ */\n\ninterface RetroComboboxProps {\n  value?: string\n  defaultValue?: string\n  onValueChange?: (value: string) => void\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n  /** Disables the trigger. */\n  disabled?: boolean\n  /** The name the value submits under in a form. */\n  name?: string\n  /**\n   * Optional list of options. The most reliable source for resolving the\n   * selected value's label in the trigger (items inside the popup are not\n   * mounted while it is closed).\n   */\n  items?: RetroComboboxOption[]\n  /** Custom resolver for the trigger text. Takes precedence over all labels. */\n  displayValue?: (value: string) => React.ReactNode\n  className?: string\n  ref?: React.Ref<HTMLDivElement>\n  children: React.ReactNode\n}\n\nfunction RetroCombobox({\n  value: controlledValue,\n  defaultValue = \"\",\n  onValueChange,\n  open: controlledOpen,\n  defaultOpen = false,\n  onOpenChange,\n  disabled,\n  name,\n  items,\n  displayValue,\n  className,\n  ref,\n  children,\n}: RetroComboboxProps) {\n  const [uncontrolledValue, setUncontrolledValue] = React.useState(defaultValue)\n  const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen)\n  const [query, setQuery] = React.useState(\"\")\n  const [trigger, setTrigger] = React.useState<HTMLButtonElement | null>(null)\n\n  const value = controlledValue !== undefined ? controlledValue : uncontrolledValue\n  const open = controlledOpen !== undefined ? controlledOpen : uncontrolledOpen\n\n  // Labels registered by mounted items (kept in state so the trigger\n  // re-renders once they are known).\n  const [registeredLabels, setRegisteredLabels] = React.useState<Record<string, string>>({})\n\n  const registerItem = React.useCallback((itemValue: string, label: string) => {\n    setRegisteredLabels((prev) => (prev[itemValue] === label ? prev : { ...prev, [itemValue]: label }))\n  }, [])\n\n  // Labels discoverable synchronously from the JSX tree, so the trigger\n  // can show the selected label on first render without opening.\n  const childLabels = React.useMemo(() => collectItemLabels(children), [children])\n\n  const getLabel = React.useCallback(\n    (itemValue: string) =>\n      items?.find((item) => item.value === itemValue)?.label ??\n      registeredLabels[itemValue] ??\n      childLabels[itemValue],\n    [items, registeredLabels, childLabels]\n  )\n\n  const ctx = React.useMemo<ComboboxContextValue>(\n    () => ({ value, trigger, setTrigger, registerItem, getLabel, displayValue }),\n    [value, trigger, registerItem, getLabel, displayValue]\n  )\n\n  return (\n    <ComboboxContext.Provider value={ctx}>\n      <ComboboxPrimitive<string, false>\n        value={value === \"\" ? null : value}\n        onValueChange={(next) => {\n          if (controlledValue === undefined) setUncontrolledValue(next ?? \"\")\n          onValueChange?.(next ?? \"\")\n        }}\n        open={open}\n        onOpenChange={(next) => {\n          /* the search starts empty each time the list opens */\n          if (next) setQuery(\"\")\n          if (controlledOpen === undefined) setUncontrolledOpen(next)\n          onOpenChange?.(next)\n        }}\n        onOpenChangeComplete={(next) => {\n          if (!next) trigger?.focus()\n        }}\n        query={query}\n        onQueryChange={setQuery}\n        itemToLabel={(v) => getLabel(v) ?? v}\n        /* highlight the chosen item (or the first) when the list opens */\n        autoHighlight=\"always\"\n        disabled={disabled}\n        name={name}\n      >\n        <div ref={ref} className={cn(\"relative\", className)}>\n          {children}\n        </div>\n      </ComboboxPrimitive>\n    </ComboboxContext.Provider>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  RetroComboboxTrigger                                               */\n/* ------------------------------------------------------------------ */\n\ntype RetroComboboxTriggerProps = WithClassName<React.ComponentProps<typeof ComboboxTriggerPrimitive>> & {\n  placeholder?: string\n}\n\nfunction RetroComboboxTrigger({\n  className,\n  placeholder = \"Select...\",\n  ref,\n  ...props\n}: RetroComboboxTriggerProps) {\n  const { value, setTrigger, getLabel, displayValue } = useCombobox()\n\n  const label: React.ReactNode = value ? (displayValue?.(value) ?? getLabel(value) ?? value) : undefined\n  const hasLabel = label != null && label !== \"\"\n\n  return (\n    <ComboboxTriggerPrimitive\n      ref={useMergedRef(ref, setTrigger)}\n      type=\"button\"\n      className={cn(\n        \"inline-flex items-center justify-between\",\n        \"h-[22px] w-full\",\n        \"font-[family-name:var(--os9-font-sans)] text-[10px] leading-normal\",\n        \"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),-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        \"cursor-pointer select-none\",\n        \"focus-visible:os9-focus-ring\",\n        \"disabled:pointer-events-none disabled:opacity-50 disabled:bg-os9-gray-200 disabled:text-os9-gray-600\",\n        className\n      )}\n      {...props}\n    >\n      <span className={cn(\"truncate px-[5px]\", !hasLabel && \"text-os9-gray-600\")}>\n        {hasLabel ? label : placeholder}\n      </span>\n      {/* Down chevron */}\n      <span\n        className={cn(\n          \"flex h-full items-center justify-center\",\n          \"w-[18px] shrink-0\",\n          \"border-l border-os9-black\",\n          \"bg-os9-gray-300\",\n          \"shadow-[inset_1px_1px_0_var(--os9-white),inset_-1px_-1px_0_var(--os9-gray-700)]\"\n        )}\n      >\n        <svg width=\"8\" height=\"4\" viewBox=\"0 0 8 4\" fill=\"none\" aria-hidden>\n          <path d=\"M4 4L0 0H8L4 4Z\" fill=\"currentColor\" />\n        </svg>\n      </span>\n    </ComboboxTriggerPrimitive>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  RetroComboboxContent (the popup)                                   */\n/* ------------------------------------------------------------------ */\n\ntype RetroComboboxContentProps = WithClassName<React.ComponentProps<typeof ComboboxContentPrimitive>> & {\n  /**\n   * @deprecated Set `maxHeight` on `RetroComboboxList` instead.\n   */\n  maxHeight?: number\n}\n\n/* Appears with a 100ms fade (modern flair), at once in classic. Box\n * properties carry `!` so UI SDK's popup reset can't strip them in apps\n * that haven't declared `@layer ui-sdk;` first. */\nfunction RetroComboboxContent({\n  className,\n  children,\n  maxHeight: _maxHeight,\n  sideOffset = 2,\n  align = \"start\",\n  ...props\n}: RetroComboboxContentProps) {\n  const { trigger } = useCombobox()\n  return (\n    <ComboboxContentPrimitive\n      anchor={trigger}\n      sideOffset={sideOffset}\n      align={align}\n      className={popupClass(\n        cn(\n          \"z-50 flex flex-col outline-none\",\n          \"w-(--anchor-width)! m-0! p-0! border! border-os9-black! bg-os9-white! text-os9-black!\",\n          \"overflow-hidden! shadow-[2px_2px_0_var(--os9-black)]\",\n          \"transition-opacity duration-100 ease-out\",\n          \"data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-75\",\n          \"in-data-[flair=classic]:transition-none motion-reduce:transition-none\"\n        ),\n        className\n      )}\n      {...props}\n    >\n      {children}\n    </ComboboxContentPrimitive>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  RetroComboboxInput                                                 */\n/* ------------------------------------------------------------------ */\n\nfunction RetroComboboxInput({\n  className,\n  placeholder = \"Search...\",\n  ...props\n}: WithClassName<React.ComponentProps<typeof ComboboxInputPrimitive>>) {\n  return (\n    <div className=\"p-[3px] border-b border-os9-gray-700\">\n      <ComboboxInputPrimitive\n        autoFocus\n        aria-label={placeholder}\n        placeholder={placeholder}\n        className={cn(\n          \"w-full\",\n          \"h-[18px]\",\n          \"font-[family-name:var(--os9-font-sans)] text-[10px] leading-normal\",\n          \"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          \"placeholder:text-os9-gray-600\",\n          \"outline-none\",\n          \"px-[4px] py-0\",\n          className\n        )}\n        {...props}\n      />\n    </div>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  RetroComboboxEmpty (only renders when no items match)              */\n/* ------------------------------------------------------------------ */\n\n/* Place it next to RetroComboboxList, not inside it. */\nfunction RetroComboboxEmpty({\n  className,\n  children,\n  ...props\n}: WithClassName<React.ComponentProps<typeof ComboboxEmptyPrimitive>>) {\n  return (\n    <ComboboxEmptyPrimitive\n      className={cn(\n        /* stays mounted as a live region; only takes room while empty */\n        \"text-center data-empty:py-4 data-loading:py-4\",\n        \"font-[family-name:var(--os9-font-sans)] text-[10px] leading-normal\",\n        \"text-os9-gray-600\",\n        className\n      )}\n      {...props}\n    >\n      {children ?? \"No results found.\"}\n    </ComboboxEmptyPrimitive>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  RetroComboboxGroup                                                 */\n/* ------------------------------------------------------------------ */\n\nconst groupLabelClass = cn(\n  \"px-[6px] py-[2px] select-none\",\n  \"font-[family-name:var(--os9-font-heading)] text-[10px] tracking-[0.42px] leading-[0.98]\",\n  \"text-os9-gray-700\"\n)\n\ntype RetroComboboxGroupProps = WithClassName<React.ComponentProps<typeof ComboboxGroupPrimitive>> & {\n  /** The group's label. */\n  heading?: React.ReactNode\n}\n\nfunction RetroComboboxGroup({ className, heading, children, ...props }: RetroComboboxGroupProps) {\n  return (\n    <ComboboxGroupPrimitive className={cn(\"py-[2px]\", className)} {...props}>\n      {heading != null && (\n        <ComboboxGroupLabelPrimitive className={groupLabelClass}>{heading}</ComboboxGroupLabelPrimitive>\n      )}\n      {children}\n    </ComboboxGroupPrimitive>\n  )\n}\n\nfunction RetroComboboxSeparator({\n  className,\n  ...props\n}: WithClassName<React.ComponentProps<typeof ComboboxSeparatorPrimitive>>) {\n  return (\n    <ComboboxSeparatorPrimitive\n      className={cn(\"h-[2px] mx-[2px] my-[2px] border-t border-os9-gray-700 border-b border-b-os9-white\", className)}\n      {...props}\n    />\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  RetroComboboxItem                                                  */\n/* ------------------------------------------------------------------ */\n\ntype RetroComboboxItemProps = WithClassName<\n  Omit<React.ComponentProps<typeof ComboboxItemPrimitive<string>>, \"value\" | \"label\">\n> & {\n  value: string\n  /** Display label for the item. Falls back to text children. */\n  label?: string\n}\n\nfunction RetroComboboxItem({ className, value: itemValue, label, keywords, children, ...props }: RetroComboboxItemProps) {\n  const { registerItem } = useCombobox()\n\n  // Derive a text label from children if label prop is not provided\n  const textLabel = label ?? getNodeText(children)\n\n  // Register this item so the trigger can resolve the label from the value\n  React.useEffect(() => {\n    registerItem(itemValue, textLabel)\n  }, [itemValue, textLabel, registerItem])\n\n  return (\n    <ComboboxItemPrimitive\n      value={itemValue}\n      label={textLabel}\n      // Match the search against the value as well as the visible label\n      keywords={[itemValue, ...(keywords ?? [])]}\n      className={cn(\n        \"relative z-[1] flex shrink-0 items-center\",\n        \"h-[18px] w-full px-[14px]\",\n        \"font-[family-name:var(--os9-font-sans)] text-[10px] leading-normal\",\n        \"text-os9-black whitespace-nowrap\",\n        \"cursor-pointer select-none outline-none\",\n        /* Highlighted (keyboard or pointer): OS9 menu highlight */\n        \"data-highlighted:bg-os9-azul data-highlighted:text-os9-white\",\n        \"data-selected:font-bold\",\n        \"data-disabled:pointer-events-none data-disabled:text-os9-gray-600\",\n        className\n      )}\n      {...props}\n    >\n      {/* Checkmark indicator */}\n      <span className=\"absolute left-[2px] flex h-[8px] w-[8px] items-center justify-center\">\n        <ComboboxItemIndicatorPrimitive>\n          <svg width=\"8\" height=\"8\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden>\n            <path\n              d=\"M3 8.5L6.5 12L13 4\"\n              stroke=\"currentColor\"\n              strokeWidth=\"2.5\"\n              strokeLinecap=\"square\"\n              strokeLinejoin=\"miter\"\n            />\n          </svg>\n        </ComboboxItemIndicatorPrimitive>\n      </span>\n      {children}\n    </ComboboxItemPrimitive>\n  )\n}\n\n/** Walk a JSX tree and collect `value -> label` for every RetroComboboxItem. */\nfunction collectItemLabels(node: React.ReactNode, acc: Record<string, string> = {}): Record<string, string> {\n  React.Children.forEach(node, (child) => {\n    if (!React.isValidElement<{ children?: React.ReactNode }>(child)) return\n    if (child.type === RetroComboboxItem) {\n      const { value, label, children } = child.props as RetroComboboxItemProps\n      acc[value] = label ?? getNodeText(children)\n      return\n    }\n    collectItemLabels(child.props.children, acc)\n  })\n  return acc\n}\n\n/* ------------------------------------------------------------------ */\n/*  RetroComboboxList (scrollable container for items)                 */\n/* ------------------------------------------------------------------ */\n\ntype RetroComboboxListProps = WithClassName<React.ComponentProps<typeof ComboboxListPrimitive>> & {\n  maxHeight?: number\n  style?: React.CSSProperties\n}\n\nfunction RetroComboboxList({ className, maxHeight = 200, style, children, ref, ...props }: RetroComboboxListProps) {\n  const glideRef = useGlide(ref)\n  return (\n    <ComboboxListPrimitive\n      ref={glideRef}\n      className={cn(\"os9-combobox relative overflow-y-auto overflow-x-hidden py-[2px]\", className)}\n      style={{ maxHeight, ...style }}\n      {...props}\n    >\n      <style href=\"os9-combobox\" precedence=\"default\">\n        {COMBOBOX_CSS}\n      </style>\n      <span\n        aria-hidden\n        data-glide-layer\n        className=\"pointer-events-none absolute top-0 left-0 bg-os9-azul opacity-0\"\n      />\n      {children}\n    </ComboboxListPrimitive>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  Exports                                                            */\n/* ------------------------------------------------------------------ */\n\nexport {\n  RetroCombobox,\n  RetroComboboxTrigger,\n  RetroComboboxContent,\n  RetroComboboxInput,\n  RetroComboboxEmpty,\n  RetroComboboxGroup,\n  RetroComboboxItem,\n  RetroComboboxList,\n  RetroComboboxSeparator,\n}\nexport type {\n  RetroComboboxProps,\n  RetroComboboxOption,\n  RetroComboboxTriggerProps,\n  RetroComboboxContentProps,\n  RetroComboboxItemProps,\n  RetroComboboxListProps,\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}