{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-list",
  "type": "registry:ui",
  "title": "react-tw/list.tsx",
  "description": "The floating list of Dropdown, Combobox and MultiSelect (Carbon `list-box__menu`), the look of Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/list.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/list.tsx",
      "content": "import type { ComponentProps, ComponentType, ReactNode } from 'react';\n// the option parts are the same in every headless list box (Dropdown's are Combobox's and MultiSelect's)\nimport { Dropdown as Parts, isGroup, type ListItem, type ListOption } from '@purpurabog/ui/headless';\nimport { cn } from './lib/utils.ts';\n\n/**\n * The floating list of Dropdown, Combobox and MultiSelect (Carbon `list-box__menu`), the look of\n * the Lit `listboxStyles`: rows `--list-row` tall (the field height), a 1px divider inset 16px\n * between rows (hidden next to a hovered, highlighted or chosen row), the keyboard highlight as a\n * 2px focus outline (the mouse only tints), the chosen row on layer-selected with a check, groups\n * under a caption label, an optional second line per option.\n */\nexport { flattenOptions, type ListOption, type ListGroup, type ListItem } from '@purpurabog/ui/headless';\n\nexport const listMenuClasses = cn(\n    // Carbon: square, shadow only; the menu settings (--ui-menu-*) let a design inset the rows, round and outline it\n    'absolute inset-auto m-0 box-border list-none ui-menu-edge p-[var(--ui-menu-padding,0px)] rounded-[var(--ui-menu-radius,0px)]',\n    'bg-[var(--ui-overlay-background,var(--ui-surface-1))] text-ink type-body-sm shadow-[var(--ui-menu-shadow,0_2px_6px_rgb(0_0_0/0.3))]',\n    // no taller than the room left beside its field (--ui-available-height, core/popup placePopup): it scrolls instead\n    'max-h-[min(calc(var(--list-row)*var(--ui-menu-max-rows,5.5)),var(--ui-available-height,100vh))] overflow-y-auto overscroll-contain',\n    'forced-colors:border forced-colors:border-solid forced-colors:border-[CanvasText]',\n);\n\n/** The caption of a group of options. */\nexport const groupLabelClasses = 'box-border flex h-(--list-row) items-center border-0 border-t border-solid border-t-hairline px-4 type-caption text-ink-helper';\n\n/** The classes of a list row (also for rows outside ListRows, like the multi-select \"Select all\"). */\nexport const listRowClasses = cn(\n    // --ui-menu-item-*: Carbon rows are square, secondary text, divided; a design can round them and drop the rules\n    'relative box-border flex min-h-(--list-row) cursor-pointer items-center ps-4 pe-12 rounded-[var(--ui-menu-item-radius,0px)] text-[color:var(--ui-menu-item-ink,var(--ui-ink-muted))]',\n    // Carbon list-box__menu-item: background; its __option: text colour and divider, all at fast-01\n    'outline-[length:var(--ui-focus-width,2px)] -outline-offset-2 outline-transparent transition-[background-color,color] duration-(--ui-duration-fast) ease-carbon',\n    'before:transition-[background-color] before:duration-(--ui-duration-fast) before:ease-carbon',\n    // divider between rows, hidden next to a hovered, highlighted or chosen row\n    \"[[data-option]+&]:before:absolute [[data-option]+&]:before:inset-x-4 [[data-option]+&]:before:top-0 [[data-option]+&]:before:h-px [[data-option]+&]:before:bg-[color:var(--ui-menu-divider,var(--ui-row-divider))] [[data-option]+&]:before:content-['']\",\n    'hover:before:bg-transparent! data-highlighted:before:bg-transparent! [[data-option]:hover+&]:before:bg-transparent! [[data-highlighted]+&]:before:bg-transparent! [[aria-selected=true]+&]:before:bg-transparent!',\n    'hover:bg-ghost-hover hover:text-ink active:bg-[color:var(--ui-menu-item-pressed,var(--ui-surface-2))]',\n    // the keyboard highlight: Carbon's 2px focus outline; a design can show it as a fill instead (--ui-menu-item-active-*)\n    'data-highlighted:text-ink data-highlighted:outline-[color:var(--ui-menu-item-active-outline,var(--ui-focus))] data-highlighted:not-hover:not-aria-selected:bg-[color:var(--ui-menu-item-active-background,transparent)]',\n    // a list opened by a press: no keyboard ring until a key is pressed (headless lib/quiet; Kanok, --ui-pointer-focus)\n    '[[data-quiet]_&]:data-highlighted:outline-[color:var(--ui-pointer-focus,var(--ui-menu-item-active-outline,var(--ui-focus)))]',\n    'aria-selected:bg-[color:var(--ui-menu-item-selected,var(--ui-surface-2))] aria-selected:text-ink aria-selected:hover:bg-[color:var(--ui-menu-item-selected-hover,var(--ui-layer-selected-hover))]',\n    'aria-disabled:cursor-not-allowed aria-disabled:bg-transparent aria-disabled:text-ink-disabled aria-disabled:hover:bg-transparent aria-disabled:hover:text-ink-disabled aria-disabled:active:bg-transparent',\n    'forced-colors:data-highlighted:outline-[Highlight] forced-colors:aria-selected:bg-[Highlight] forced-colors:aria-selected:text-[HighlightText] forced-colors:aria-selected:[forced-color-adjust:none]',\n);\n\n/** The text of a row: one line, or the label over a caption description. */\nexport function OptionText({ option }: Readonly<{ option: ListOption }>) {\n    if (!option.description) return <span className=\"truncate\">{option.label}</span>;\n    return (\n        <span className=\"flex flex-col overflow-hidden py-2\">\n            <span className=\"truncate\">{option.label}</span>\n            <span className={cn('truncate type-caption text-ink-helper', option.disabled && 'text-inherit')}>{option.description}</span>\n        </span>\n    );\n}\n\n/** The check on the chosen row. */\nexport const checkMark = (\n    <svg className=\"absolute end-4 size-4 fill-current forced-colors:fill-[FieldText]\" viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n        <path d=\"m6.5 12.5-4-4 .7-.7 3.3 3.3 7.3-7.3.7.7z\" />\n    </svg>\n);\n\n/**\n * The rows of an open list box, group by group, on the headless option parts (shared by Dropdown,\n * Combobox and MultiSelect, which say what a click does): Carbon's divider, highlight and check.\n * `lead` puts something before the text (the multi-select checkbox); the chosen row gets the check\n * unless `lead` is given.\n */\nexport function ListRows({ items, isSelected, lead, rowClassName }: Readonly<{ items: ListItem[]; isSelected: (option: ListOption) => boolean; lead?: (option: ListOption, selected: boolean) => ReactNode; rowClassName?: string }>) {\n    const row = (option: ListOption) => {\n        const selected = isSelected(option);\n        return (\n            <Parts.Option key={option.value} value={option.value} data-option=\"\" className={cn(listRowClasses, rowClassName)}>\n                {lead?.(option, selected)}\n                <OptionText option={option} />\n                {selected && !lead ? checkMark : null}\n            </Parts.Option>\n        );\n    };\n    return (\n        <>\n            {items.map((item) =>\n                isGroup(item) ? (\n                    <Parts.Group key={`group-${item.label}`}>\n                        <Parts.GroupLabel className={groupLabelClasses}>{item.label}</Parts.GroupLabel>\n                        <Parts.GroupOptions className=\"m-0 list-none p-0\">{item.options.map(row)}</Parts.GroupOptions>\n                    </Parts.Group>\n                ) : (\n                    row(item)\n                ),\n            )}\n        </>\n    );\n}\n\n/**\n * Padding at the end of a text box with list controls (Carbon ComboBox): 48px, 70 with ×,\n * 64 with a status icon, 105 with both.\n */\nexport function controlsPadding(hasClear: boolean, hasStatus: boolean) {\n    if (hasClear && hasStatus) return 'pe-[105px]';\n    if (hasClear) return 'pe-[70px]';\n    if (hasStatus) return 'pe-16';\n    return 'pe-12';\n}\n\n/** A headless button part (Clear / Toggle of Combobox and MultiSelect) that FieldControls dresses. */\ntype ControlButton = ComponentType<Omit<ComponentProps<'button'>, 'type'>>;\n\n/**\n * The controls at the end of a text box with a list (Carbon ComboBox, filterable MultiSelect):\n * the status icon, × (a 24px box with a 1px divider after it, and before it next to a status icon;\n * not a Tab stop) and the 48px chevron toggle (not a Tab stop). Geometry as the Lit\n * `listboxControlStyles`, measured on Carbon React. The buttons are the headless parts (their\n * behaviour); `Clear` shows only when given.\n */\nexport function FieldControls({\n    status,\n    clearLabel,\n    Clear,\n    toggleLabel,\n    Toggle,\n    open,\n    disabled,\n    readOnly,\n    fluid,\n}: Readonly<{\n    status: ReactNode;\n    clearLabel?: string;\n    Clear?: ControlButton;\n    toggleLabel: string;\n    Toggle: ControlButton;\n    open: boolean;\n    disabled?: boolean;\n    readOnly?: boolean;\n    /** Carbon fluid: the 40px controls 22px down, a 40px chevron button (the status icon goes to the message row). */\n    fluid?: boolean;\n}>) {\n    const hasStatus = !!status;\n    const hasClear = !!Clear;\n    return (\n        <span /* NOSONAR: only keeps focus in the text box on a press; × is a button (not a Tab stop, as Carbon) */ className={cn('absolute inset-y-0 end-0 flex items-center', fluid && 'top-[22px] bottom-auto h-10')} onMouseDown={(event) => event.preventDefault()}>\n            <span className={cn('pointer-events-none flex items-center', hasClear ? 'pe-[13px]' : '-me-2')}>{status}</span>\n            {Clear ? (\n                <Clear\n                    aria-label={clearLabel}\n                    className={cn(\n                        \"relative z-1 -me-[3px] grid size-6 cursor-pointer place-items-center rounded-[var(--ui-icon-control-radius,0px)] border-0 bg-transparent p-0 text-ink after:absolute after:start-7 after:top-1 after:h-4 after:w-px after:bg-border-subtle-2 after:content-['']\",\n                        hasStatus && \"before:absolute before:-start-[5px] before:top-1 before:h-4 before:w-px before:bg-border-subtle-2 before:content-['']\",\n                        'focus-visible:outline-[length:var(--ui-focus-width,2px)] focus-visible:-outline-offset-2 focus-visible:outline-focus [&_svg]:size-4 [&_svg]:fill-current forced-colors:[&_svg]:fill-[FieldText]',\n                    )}\n                >\n                    <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n                        <path d=\"m12 4.7-.7-.7L8 7.3 4.7 4l-.7.7L7.3 8 4 11.3l.7.7L8 8.7l3.3 3.3.7-.7L8.7 8z\" />\n                    </svg>\n                </Clear>\n            ) : null}\n            <Toggle\n                aria-label={toggleLabel}\n                className={cn(\n                    'grid h-full w-12 cursor-pointer place-items-center rounded-[var(--ui-icon-control-radius,0px)] border-0 bg-transparent p-0 text-ink',\n                    fluid && 'w-10',\n                    'focus-visible:outline-[length:var(--ui-focus-width,2px)] focus-visible:-outline-offset-2 focus-visible:outline-focus [&_svg]:size-4 [&_svg]:fill-current forced-colors:[&_svg]:fill-[FieldText]',\n                    '[&_svg]:transition-transform [&_svg]:duration-(--ui-duration-fast) [&_svg]:ease-carbon',\n                    open && '[&_svg]:[transform:rotate(180deg)]',\n                    readOnly && 'text-ink-subtle',\n                    'disabled:cursor-default',\n                    disabled && 'text-ink-disabled',\n                )}\n            >\n                <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n                    <path d=\"M8 11 3 6l.7-.7L8 9.6l4.3-4.3.7.7z\" />\n                </svg>\n            </Toggle>\n        </span>\n    );\n}\n\n/** The \"Searching…\" / \"No matching items\" row (disabled, not announced: a status region says it). */\nexport function EmptyRow({ children }: Readonly<{ children: ReactNode }>) {\n    return (\n        <li /* NOSONAR: APG option of an aria-activedescendant listbox; the keyboard stays on the combobox */ role=\"option\" aria-disabled=\"true\" aria-selected=\"false\" className=\"box-border flex h-(--list-row) items-center px-4 text-ink-helper\">\n            {children}\n        </li>\n    );\n}\n\n/** What the open list says to screen readers (\"Loading…\", \"Searching…\", \"No matching items\"): its disabled rows are never announced. */\nexport function ListStatus({ children }: Readonly<{ children: ReactNode }>) {\n    return (\n        <span /* NOSONAR: role=status is a polite live region; <output> isn't announced by every screen reader */ className=\"sr-only\" role=\"status\">\n            {children}\n        </span>\n    );\n}\n"
    }
  ]
}
