{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "retro-list-box",
  "title": "RetroListBox",
  "description": "Mac OS 9 inset list box with single or multiple selection, azul highlight, arrow/Home/End navigation, type-ahead and listbox/option semantics.",
  "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-list-box.tsx",
      "content": "\"use client\"\n\n/*\n * RetroListBox: a Mac OS 9 inset list box on UI SDK's Listbox.\n *\n * Crafted moment: the gliding selection (modern flair, single selection).\n * The azul selection bar slides to the newly chosen row as you click or\n * arrow through the list, and the row's ink flips to white as it arrives.\n * Classic flair, reduced motion and multiple selection paint each selected\n * row in place, as OS 9 did.\n *\n * Keyboard (from UI SDK): arrows, Home/End and type-ahead move the selection;\n * with `multiple`, Shift extends a range, Cmd/Ctrl toggles a row or moves\n * without selecting, Space toggles, Cmd/Ctrl+A selects all.\n */\n\nimport * as React from \"react\"\nimport {\n  Listbox as ListboxPrimitive,\n  ListboxItem as ListboxItemPrimitive,\n} from \"@ui-sdk/react/listbox\"\n\nimport { cn } from \"@/lib/utils\"\nimport { useGlide } from \"@/registry/new-york/lib/retro-motion\"\n\n/* Unlayered, so it beats the row utilities without !important. */\nconst LIST_BOX_CSS = `\n.os9-list-box[data-glide]:not([data-glide-off]) [role=\"option\"][data-selected] {\n  background-color: transparent;\n}\n.os9-list-box[data-glide-off] > [data-glide-layer] {\n  opacity: 0 !important;\n  transition: none !important;\n}\n.os9-list-box[data-glide] [role=\"option\"] { transition: color 0s linear 60ms; }\n.os9-list-box[data-glide-off] [role=\"option\"] { transition: none; }\n`\n\n/* the selected row that belongs to this list */\nfunction findSelectedRow(root: HTMLElement) {\n  return root.querySelector<HTMLElement>('[role=\"option\"][data-selected]')\n}\nconst WATCH_SELECTED = [\"data-selected\"]\n\n/* ------------------------------------------------------------------ */\n/*  Types                                                              */\n/* ------------------------------------------------------------------ */\n\ntype ListBoxBaseProps = Omit<\n  React.ComponentProps<\"div\">,\n  \"defaultValue\" | \"onChange\" | \"children\"\n> & {\n  children?: React.ReactNode\n  /** Disables the whole list. */\n  disabled?: boolean\n  /** Slide the selection between rows (single selection, modern flair). Default true. */\n  glide?: boolean\n}\n\ntype ListBoxSingleProps = {\n  multiple?: false\n  /** Controlled selected value (null = nothing selected). */\n  value?: string | null\n  defaultValue?: string | null\n  onValueChange?: (value: string | null) => void\n}\n\ntype ListBoxMultipleProps = {\n  multiple: true\n  /** Controlled selected values. */\n  value?: string[]\n  defaultValue?: string[]\n  onValueChange?: (value: string[]) => void\n}\n\ntype RetroListBoxProps = ListBoxBaseProps & (ListBoxSingleProps | ListBoxMultipleProps)\n\n/* ------------------------------------------------------------------ */\n/*  RetroListBox                                                       */\n/* ------------------------------------------------------------------ */\n\nfunction RetroListBox({\n  className,\n  children,\n  disabled = false,\n  glide = true,\n  multiple = false,\n  value,\n  defaultValue,\n  onValueChange,\n  ref,\n  ...props\n}: RetroListBoxProps) {\n  const glides = glide && !multiple\n  const glideRef = useGlide(ref, findSelectedRow, WATCH_SELECTED)\n\n  const shared = {\n    ...props,\n    ref: glides ? glideRef : ref,\n    disabled,\n    /* selection follows the keyboard, and a click replaces it (Cmd/Ctrl adds) */\n    activation: \"automatic\" as const,\n    \"data-glide\": glides ? \"\" : undefined,\n    className: cn(\n      \"os9-list-box group/listbox relative flex flex-col overflow-y-auto\",\n      \"border border-os9-black bg-os9-white text-os9-black\",\n      \"shadow-[inset_1px_1px_0_var(--os9-gray-700),inset_-1px_-1px_0_var(--os9-white)]\",\n      \"p-[2px] outline-none\",\n      \"font-[family-name:var(--os9-font-sans)] text-[10px]\",\n      \"has-[:focus-visible]:os9-focus-ring\",\n      \"data-disabled:cursor-not-allowed data-disabled:opacity-50\",\n      className\n    ),\n  }\n\n  const content = (\n    <>\n      <style href=\"os9-list-box\" precedence=\"default\">\n        {LIST_BOX_CSS}\n      </style>\n      {glides && (\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      )}\n      {children}\n    </>\n  )\n\n  if (multiple) {\n    return (\n      <ListboxPrimitive<string, true>\n        {...shared}\n        multiple\n        value={value as string[] | undefined}\n        defaultValue={defaultValue as string[] | undefined}\n        onValueChange={(next) => (onValueChange as ((v: string[]) => void) | undefined)?.(next)}\n      >\n        {content}\n      </ListboxPrimitive>\n    )\n  }\n  return (\n    <ListboxPrimitive<string, false>\n      {...shared}\n      value={value as string | null | undefined}\n      defaultValue={defaultValue as string | null | undefined}\n      onValueChange={(next) => (onValueChange as ((v: string | null) => void) | undefined)?.(next)}\n    >\n      {content}\n    </ListboxPrimitive>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  RetroListBoxItem                                                   */\n/* ------------------------------------------------------------------ */\n\ntype RetroListBoxItemProps = Omit<\n  React.ComponentProps<typeof ListboxItemPrimitive<string>>,\n  \"className\" | \"children\" | \"label\"\n> & {\n  className?: string\n  children?: React.ReactNode\n  /** Text used for type-ahead when children aren't plain text. */\n  textValue?: string\n}\n\nfunction RetroListBoxItem({ className, textValue, ...props }: RetroListBoxItemProps) {\n  return (\n    <ListboxItemPrimitive\n      label={textValue}\n      className={cn(\n        \"relative z-[1] flex h-[16px] shrink-0 items-center gap-[4px] px-[4px]\",\n        \"cursor-default select-none whitespace-nowrap outline-none\",\n        \"data-selected:bg-os9-azul data-selected:text-os9-white\",\n        /* keyboard cursor: a dotted outline on the focused row */\n        \"focus-visible:outline-1 focus-visible:outline-dotted focus-visible:-outline-offset-1 focus-visible:outline-os9-black\",\n        \"data-selected:focus-visible:outline-os9-white\",\n        \"data-disabled:text-os9-gray-600\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nexport { RetroListBox, RetroListBoxItem }\nexport type { RetroListBoxProps, RetroListBoxItemProps }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}