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"; import { PriorityIcon, Tooltip } from "@plane/ui"; // helpers import { capitalizeFirstLetter } from "helpers/string.helper"; // types import { TIssuePriorities } from "types"; // constants import { ISSUE_PRIORITIES } from "constants/issue"; type Props = { value: TIssuePriorities; onChange: (data: TIssuePriorities) => void; className?: string; buttonClassName?: string; optionsClassName?: string; placement?: Placement; showTitle?: boolean; highlightUrgentPriority?: boolean; hideDropdownArrow?: boolean; disabled?: boolean; }; export const PrioritySelect: React.FC = ({ value, onChange, className = "", buttonClassName = "", optionsClassName = "", placement, showTitle = false, highlightUrgentPriority = true, hideDropdownArrow = false, disabled = false, }) => { 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 = ISSUE_PRIORITIES?.map((priority) => ({ value: priority.key, query: priority.key, content: (
{priority.title}
), })); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); const selectedOption = value ? capitalizeFirstLetter(value) : "None"; const label = (
{showTitle && {value}}
); 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...

)}
); };