import { Fragment, ReactNode, useRef, useState } from "react"; import { observer } from "mobx-react-lite"; import { ChevronDown } from "lucide-react"; import { Combobox } from "@headlessui/react"; // ui import { ContrastIcon } from "@plane/ui"; // helpers import { cn } from "@/helpers/common.helper"; // hooks import { useCycle } from "@/hooks/store"; import { useDropdown } from "@/hooks/use-dropdown"; // local components and constants import { DropdownButton } from "../buttons"; import { BUTTON_VARIANTS_WITH_TEXT } from "../constants"; import { TDropdownProps } from "../types"; import { CycleOptions } from "./cycle-options"; type Props = TDropdownProps & { button?: ReactNode; dropdownArrow?: boolean; dropdownArrowClassName?: string; onChange: (val: string | null) => void; onClose?: () => void; projectId: string; value: string | null; }; export const CycleDropdown: React.FC = observer((props) => { const { button, buttonClassName, buttonContainerClassName, buttonVariant, className = "", disabled = false, dropdownArrow = false, dropdownArrowClassName = "", hideIcon = false, onChange, onClose, placeholder = "", placement, projectId, showTooltip = false, tabIndex, value, } = props; // states const [isOpen, setIsOpen] = useState(false); const { getCycleNameById } = useCycle(); // refs const dropdownRef = useRef(null); // popper-js refs const [referenceElement, setReferenceElement] = useState(null); const selectedName = value ? getCycleNameById(value) : null; const { handleClose, handleKeyDown, handleOnClick } = useDropdown({ dropdownRef, isOpen, onClose, setIsOpen, }); const dropdownOnChange = (val: string | null) => { onChange(val); handleClose(); }; return ( {button ? ( ) : ( )} {isOpen && ( )} ); });