import { FC, Fragment, ReactNode, useRef, useState } from "react"; import { Combobox } from "@headlessui/react"; import { usePopper } from "react-popper"; import { Placement } from "@popperjs/core"; import { Plus, Search } from "lucide-react"; // hooks import useOutsideClickDetector from "hooks/use-outside-click-detector"; import { useView } from "hooks/store"; // components import { ViewDropdownItem } from ".."; // types import { TViewTypes } from "@plane/types"; import { TViewOperations } from "../types"; type TViewDropdown = { workspaceSlug: string; projectId: string | undefined; viewId: string; viewType: TViewTypes; viewOperations: TViewOperations; children?: ReactNode; baseRoute: string; dropdownPlacement?: Placement; }; export const ViewDropdown: FC = (props) => { const { workspaceSlug, projectId, viewId: currentViewId, viewType, viewOperations, children, baseRoute, dropdownPlacement = "bottom-start", } = props; // hooks const viewStore = useView(workspaceSlug, projectId, viewType); // states const [dropdownToggle, setDropdownToggle] = useState(false); const [query, setQuery] = useState(""); // 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: dropdownPlacement, modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, { name: "offset", options: { offset: [0, 10], }, }, ], }); const handleDropdownOpen = () => setDropdownToggle(true); const handleDropdownClose = () => setDropdownToggle(false); const handleDropdownToggle = (event: React.MouseEvent) => { event.preventDefault(); event.stopPropagation(); if (!dropdownToggle) handleDropdownOpen(); else handleDropdownClose(); }; useOutsideClickDetector(dropdownRef, handleDropdownClose); return ( {dropdownToggle && (
setQuery(e.target.value)} placeholder="Search for a view..." displayValue={(assigned: any) => assigned?.name} autoFocus />
{viewStore?.viewIds && viewStore?.viewIds.length > 0 && viewStore?.viewIds.map((viewId) => ( ))}
viewOperations?.localViewCreateEdit(undefined)} >
New view
)}
); };