import React, { useState } from "react"; import { usePopper } from "react-popper"; import { Placement } from "@popperjs/core"; import { Combobox } from "@headlessui/react"; import { Check, ChevronDown, Search } from "lucide-react"; // ui import { Tooltip } from "components/ui"; // types import { IIssueLabels } from "types"; type Props = { value: string[]; onChange: (data: string[]) => void; labels: IIssueLabels[] | undefined; className?: string; buttonClassName?: string; optionsClassName?: string; maxRender?: number; placement?: Placement; hideDropdownArrow?: boolean; disabled?: boolean; }; export const LabelSelect: React.FC = (props) => { const { value, onChange, labels, className = "", buttonClassName = "", optionsClassName = "", maxRender = 2, placement, hideDropdownArrow = false, disabled = false, } = props; const [query, setQuery] = useState(""); const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: placement ?? "bottom-start", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); const options = labels?.map((label) => ({ value: label.id, query: label.name, content: (
{label.name}
), })); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); return (
setQuery(e.target.value)} placeholder="Search" displayValue={(assigned: any) => assigned?.name} />
{filteredOptions ? ( filteredOptions.length > 0 ? ( filteredOptions.map((option) => ( `flex items-center justify-between gap-2 cursor-pointer select-none truncate rounded px-1 py-1.5 ${ active ? "bg-custom-background-80" : "" } ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ selected }) => ( <> {option.content} {selected && } )} )) ) : (

No matching results

) ) : (

Loading...

)}
); };