import React, { useRef, useState } from "react"; // hooks import useDynamicDropdownPosition from "hooks/use-dynamic-dropdown"; // headless ui import { Combobox } from "@headlessui/react"; // icons import { ChevronDownIcon } from "@heroicons/react/20/solid"; import { CheckIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; import { PriorityIcon } from "components/icons"; // components import { Tooltip } from "components/ui"; // types import { TIssuePriorities } from "types"; // constants import { PRIORITIES } from "constants/project"; type Props = { value: TIssuePriorities; onChange: (data: any) => void; className?: string; buttonClassName?: string; optionsClassName?: string; hideDropdownArrow?: boolean; disabled?: boolean; }; export const PrioritySelect: React.FC = ({ value, onChange, className = "", buttonClassName = "", optionsClassName = "", hideDropdownArrow = false, disabled = false, }) => { const [query, setQuery] = useState(""); const [isOpen, setIsOpen] = useState(false); const dropdownBtn = useRef(null); const dropdownOptions = useRef(null); const options = PRIORITIES?.map((priority) => ({ value: priority, query: priority, content: (
{priority ?? "None"}
), })); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); const selectedOption = value ?? "None"; const label = (
); useDynamicDropdownPosition(isOpen, () => setIsOpen(false), dropdownBtn, dropdownOptions); return ( {({ open }: { open: boolean }) => { if (open) { if (!isOpen) setIsOpen(true); } else if (isOpen) setIsOpen(false); return ( <> {label} {!hideDropdownArrow && !disabled && (
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 && !selected ? "bg-custom-background-80" : "" } ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ selected }) => ( <> {option.content} {selected && } )} )) ) : (

No matching results

) ) : (

Loading...

)}
); }}
); };