import type { JSX } from "@solidjs/web"; import { For } from "solid-js"; import { useComboboxRootContext } from "../root/combobox-root-context"; import { useGroupCollectionContext } from "./group-collection-context"; export type ComboboxCollectionState = Record; export interface ComboboxCollectionProps { /** * Per-item render function. Receives `(item, index)` and returns the * JSX for that item (typically a ``). */ children: (item: Item, index: number) => JSX.Element; } /** * Renders filtered list items. Doesn't render its own HTML element. * * When placed inside a `` context that publishes its own * sub-items, iterates those; otherwise iterates the root's * `filteredItems()` (flat). For grouped items, callers typically render a * `` per group and put a `` inside * each — or use the `` render-function shorthand which * React also exposes. */ export function ComboboxCollection( props: ComboboxCollectionProps, ): JSX.Element { const root = useComboboxRootContext(); const groupContext = useGroupCollectionContext(); const items = (): Item[] => { if (groupContext) return groupContext.items() as Item[]; return root.flatFilteredItems() as Item[]; }; return ( {(item, index) => props.children(item as Item, index())} ); }