import { FC } from "react"; import { Popover } from "../custom/Popover"; import { useLocal } from "lib/utils/use-local"; export type OptionItem = { value: string; label: string }; export const TypeaheadOptions: FC<{ popup?: boolean; open?: boolean; children: any; onOpenChange?: (open: boolean) => void; options: OptionItem[]; selected?: (arg: { item: OptionItem; options: OptionItem[]; idx: number; }) => boolean; onSelect?: (value: string) => void; searching?: boolean; width?: number; }> = ({ popup, children, open, onOpenChange, options, selected, onSelect, searching, width, }) => { if (!popup) return children; const local = useLocal({ selectedIdx: 0, }); return ( {options.map((item, idx) => { const is_selected = selected?.({ item, options, idx }); if (is_selected) { local.selectedIdx = idx; } return (
0 && "c-border-t" )} onClick={() => { onSelect?.(item.value); }} > {item.label || <> }
); })} {searching ? (
Loading...
) : ( <> {options.length === 0 && (
— Empty —
)} )} } > {children}
); };