import { VirtualizedListItem } from "../list/VirtualizedList"; import { SelectOptionWithGroup } from "./SelectOption"; import { SelectProps, SelectMultipleProps } from "./SelectProps"; export function getListItems({ tips, bottomTips, options, groups, allOption, }: Pick & Pick): VirtualizedListItem< SelectOptionWithGroup >[] { const items: VirtualizedListItem[] = []; // allOption if (allOption && options.length > 0) { items.push({ type: "option", key: allOption.value, text: typeof allOption.text === "undefined" ? allOption.value : allOption.text, option: allOption, }); } // tips if (tips) { items.push({ type: "tips", key: "__tips", text: tips }); } // option/group options.forEach((option, index) => { if ( option.groupKey && (index === 0 || option.groupKey !== options[index - 1].groupKey) ) { if (groups) { items.push({ type: "group", key: `${option.groupKey}-${option.value}`, text: groups[option.groupKey], }); } else if (items.length > 0) { items.push({ type: "divider", key: `${option.groupKey}-${option.value}`, text: "", }); } } items.push({ type: "option", key: option.value, text: typeof option.text === "undefined" ? option.value : option.text, option, }); }); // bottomTips if (bottomTips) { items.push({ type: "tips", key: "__bottom_tips", text: bottomTips }); } return items; }