import { Fragment, ReactNode, useRef, useState } from "react"; import { Combobox } from "@headlessui/react"; import { usePopper } from "react-popper"; import { Check, ChevronDown, Search } from "lucide-react"; import { useTheme } from "next-themes"; // hooks import { useDropdownKeyDown } from "hooks/use-dropdown-key-down"; import useOutsideClickDetector from "hooks/use-outside-click-detector"; // icons import { PriorityIcon, Tooltip } from "@plane/ui"; // helpers import { cn } from "helpers/common.helper"; // types import { TIssuePriorities } from "@plane/types"; import { TDropdownProps } from "./types"; // constants import { ISSUE_PRIORITIES } from "constants/issue"; type Props = TDropdownProps & { button?: ReactNode; dropdownArrow?: boolean; dropdownArrowClassName?: string; highlightUrgent?: boolean; onChange: (val: TIssuePriorities) => void; value: TIssuePriorities; }; type ButtonProps = { className?: string; dropdownArrow: boolean; dropdownArrowClassName: string; hideIcon?: boolean; hideText?: boolean; isActive?: boolean; highlightUrgent: boolean; priority: TIssuePriorities; tooltip: boolean; }; const BorderButton = (props: ButtonProps) => { const { className, dropdownArrow, dropdownArrowClassName, hideIcon = false, hideText = false, highlightUrgent, priority, tooltip, } = props; const priorityDetails = ISSUE_PRIORITIES.find((p) => p.key === priority); const priorityClasses = { urgent: "bg-red-500/20 text-red-950 border-red-500", high: "bg-orange-500/20 text-orange-950 border-orange-500", medium: "bg-yellow-500/20 text-yellow-950 border-yellow-500", low: "bg-custom-primary-100/20 text-custom-primary-950 border-custom-primary-100", none: "bg-custom-background-80 border-custom-border-300", }; return ( ); }; const BackgroundButton = (props: ButtonProps) => { const { className, dropdownArrow, dropdownArrowClassName, hideIcon = false, hideText = false, highlightUrgent, priority, tooltip, } = props; const priorityDetails = ISSUE_PRIORITIES.find((p) => p.key === priority); const priorityClasses = { urgent: "bg-red-500/20 text-red-950", high: "bg-orange-500/20 text-orange-950", medium: "bg-yellow-500/20 text-yellow-950", low: "bg-blue-500/20 text-blue-950", none: "bg-custom-background-80", }; return ( ); }; const TransparentButton = (props: ButtonProps) => { const { className, dropdownArrow, dropdownArrowClassName, hideIcon = false, hideText = false, isActive = false, highlightUrgent, priority, tooltip, } = props; const priorityDetails = ISSUE_PRIORITIES.find((p) => p.key === priority); const priorityClasses = { urgent: "text-red-950", high: "text-orange-950", medium: "text-yellow-950", low: "text-blue-950", none: "", }; return ( ); }; export const PriorityDropdown: React.FC = (props) => { const { button, buttonClassName, buttonContainerClassName, buttonVariant, className = "", disabled = false, dropdownArrow = false, dropdownArrowClassName = "", hideIcon = false, highlightUrgent = true, onChange, placement, tabIndex, tooltip = false, value, } = props; // states const [query, setQuery] = useState(""); const [isOpen, setIsOpen] = useState(false); // refs const dropdownRef = useRef(null); // popper-js refs const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); // popper-js init const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: placement ?? "bottom-start", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); // next-themes // TODO: remove this after new theming implementation const { resolvedTheme } = useTheme(); const options = ISSUE_PRIORITIES.map((priority) => ({ value: priority.key, query: priority.key, content: (
{priority.title}
), })); const filteredOptions = query === "" ? options : options.filter((o) => o.query.toLowerCase().includes(query.toLowerCase())); const openDropdown = () => { setIsOpen(true); if (referenceElement) referenceElement.focus(); }; const closeDropdown = () => setIsOpen(false); const handleKeyDown = useDropdownKeyDown(openDropdown, closeDropdown, isOpen); useOutsideClickDetector(dropdownRef, closeDropdown); return ( {button ? ( ) : ( )} {isOpen && (
setQuery(e.target.value)} placeholder="Search" displayValue={(assigned: any) => assigned?.name} />
{filteredOptions.length > 0 ? ( filteredOptions.map((option) => ( `w-full truncate flex items-center justify-between gap-2 rounded px-1 py-1.5 cursor-pointer select-none ${ active ? "bg-custom-background-80" : "" } ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } onClick={closeDropdown} > {({ selected }) => ( <> {option.content} {selected && } )} )) ) : (

No matching results

)}
)}
); };