import { Fragment, useState } from "react"; // headless ui import { Menu, Transition } from "@headlessui/react"; // ui import { Loader } from "@plane/ui"; // icons import { Check, ChevronDown, ChevronLeft, ChevronRight } from "lucide-react"; type MultiLevelDropdownProps = { label: string; options: { id: string; children?: { id: string; label: string | JSX.Element; value: any; selected?: boolean; element?: JSX.Element; }[]; hasChildren: boolean; label: string; onClick?: () => void; selected?: boolean; value: any; }[]; onSelect: (value: any) => void; direction?: "left" | "right"; height?: "sm" | "md" | "rg" | "lg"; }; export const MultiLevelDropdown: React.FC = ({ label, options, onSelect, direction = "right", height = "md", }) => { const [openChildFor, setOpenChildFor] = useState(null); return ( <> {({ open }) => ( <>
setOpenChildFor(null)} className={`group flex items-center justify-between gap-2 rounded-md border border-custom-border-200 px-3 py-1.5 text-xs shadow-sm duration-300 hover:bg-custom-background-90 hover:text-custom-text-100 focus:outline-none ${ open ? "bg-custom-background-90 text-custom-text-100" : "text-custom-text-200" }`} > {label}
{options.map((option) => (
{ if (option.hasChildren) { e.stopPropagation(); e.preventDefault(); if (option.onClick) option.onClick(); if (openChildFor === option.id) setOpenChildFor(null); else setOpenChildFor(option.id); } else onSelect(option.value); }} className="w-full" > {({ active }) => ( <>
{direction === "left" && option.hasChildren && } {option.label} {direction === "right" && option.hasChildren && }
)}
{option.hasChildren && option.id === openChildFor && (
{option.children ? (
{option.children.length === 0 ? (

No {option.label} found

//if no children found, show this message. ) : ( option.children.map((child) => { if (child.element) return child.element; else return ( ); }) )}
) : ( )}
)}
))}
)}
); };