import { useSelect } from "downshift"; import { useState } from "react"; import { classNames } from "@calcom/lib"; type IItem = | { itemType: "ListItem"; title: string; description: string; value: string; } | { itemType: "Title"; title: string; value: string; } | { itemType: "NameCard"; img: string; value: string; name: string; } | { itemType: "Spacer"; }; interface SelectProps { items: IItem[]; } function itemToString(item: IItem | null) { return item && item.itemType !== "Spacer" && item?.value ? item.value : ""; } function Select({ items }: SelectProps) { const [selectedItems, setSelectedItems] = useState([]); const { isOpen, selectedItem, getToggleButtonProps, getLabelProps, getMenuProps, highlightedIndex, getItemProps, } = useSelect({ items, itemToString, selectedItem: null, onSelectedItemChange: ({ selectedItem }) => { if (!selectedItem) { return; } const index = selectedItems.indexOf(selectedItem); if (index > 0) { setSelectedItems([...selectedItems.slice(0, index), ...selectedItems.slice(index + 1)]); } else if (index === 0) { setSelectedItems([...selectedItems.slice(1)]); } else { setSelectedItems([...selectedItems, selectedItem]); } }, }); const buttonText = selectedItems.length ? `${selectedItems.length} elements selected` : "Elements"; return (
    {isOpen && items.map((item, index) => { if (item.itemType === "Spacer") return; // Return a spacer that isnt selectable return (
  • null} />
    {item.value} {/* {{item.description}} */}
  • ); })}
); } export default Select;