import { FC } from "react"; import { CheckIcon, Combobox, ComboboxChevron, ComboboxClearButton, Group, Pill, PillsInput, useCombobox, } from "@mantine/core"; import { IconHeartRateMonitor } from "@tabler/icons-react"; import { inputIconStyle } from "../styles"; interface StatePillProps extends React.ComponentPropsWithoutRef<"div"> { value: string; onRemove?: () => void; } export function StatePill({ value, onRemove, ...others }: StatePillProps) { return ( {value} ); } interface StateMultiSelectProps { options: string[]; optionClass: (option: string) => string; optionCount?: (option: string) => number; placeholder: string; values: string[]; onChange: (values: string[]) => void; } export const StateMultiSelect: FC = ({ options, optionClass, optionCount, placeholder, values, onChange, }) => { const combobox = useCombobox({ onDropdownClose: () => combobox.resetSelectedOption(), onDropdownOpen: () => combobox.updateSelectedOptionIndex("active"), }); const handleValueSelect = (val: string) => onChange( values.includes(val) ? values.filter((v) => v !== val) : [...values, val] ); const handleValueRemove = (val: string) => onChange(values.filter((v) => v !== val)); const renderedValues = values.map((item) => ( handleValueRemove(item)} key={item} /> )); return ( combobox.toggleDropdown()} miw={200} leftSection={} rightSection={ values.length > 0 ? ( onChange([])} /> ) : ( ) } > {renderedValues.length > 0 ? ( renderedValues ) : ( )} combobox.closeDropdown()} onKeyDown={(event) => { if (event.key === "Backspace") { event.preventDefault(); handleValueRemove(values[values.length - 1]); } }} /> {options.map((value) => { return ( {values.includes(value) ? ( ) : null} ); })} ); };