import React, { useState } from "react"; import { usePopper } from "react-popper"; import { Combobox } from "@headlessui/react"; // icons import { Check, Search, XIcon } from "lucide-react"; // types import { ICustomAttribute } from "types"; type Props = { attributeDetails: ICustomAttribute; className?: string; onChange: (val: string | string[] | undefined) => void; } & ( | { multiple?: false; value: string | undefined; } | { multiple?: true; value: string[] | undefined } ); export const CustomSelectAttribute: React.FC = (props) => { const { attributeDetails, className = "", multiple = false, onChange, value } = props; const [query, setQuery] = useState(""); const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: "bottom-start", }); const options = attributeDetails.children.filter((option) => option.display_name.toLowerCase().includes(query.toLowerCase()) ); const comboboxProps: any = { onChange, value, }; if (multiple) comboboxProps.multiple = true; return (
setQuery(e.target.value)} placeholder="Type to search..." displayValue={(assigned: any) => assigned?.name} />
{(options ?? []).map((option) => ( `flex items-center justify-between gap-1 cursor-pointer select-none truncate rounded px-1 py-1.5 w-full ${ active ? "bg-custom-background-80" : "" }` } > {({ selected }) => ( <> {option.display_name} {selected && } )} ))}
); };