import { Fragment, ReactNode, useEffect, useRef, useState } from "react"; import { observer } from "mobx-react-lite"; import { ChevronDown, X } from "lucide-react"; import { Combobox } from "@headlessui/react"; // hooks import { DiceIcon, Tooltip } from "@plane/ui"; import { cn } from "@/helpers/common.helper"; import { useModule } from "@/hooks/store"; import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down"; import useOutsideClickDetector from "@/hooks/use-outside-click-detector"; import { usePlatformOS } from "@/hooks/use-platform-os"; // components import { DropdownButton } from "../buttons"; // icons // helpers // types import { BUTTON_VARIANTS_WITHOUT_TEXT } from "../constants"; import { TDropdownProps } from "../types"; // constants import { ModuleOptions } from "./module-options"; type Props = TDropdownProps & { button?: ReactNode; dropdownArrow?: boolean; dropdownArrowClassName?: string; projectId: string; showCount?: boolean; onClose?: () => void; } & ( | { multiple: false; onChange: (val: string | null) => void; value: string | null; } | { multiple: true; onChange: (val: string[]) => void; value: string[]; } ); type ButtonContentProps = { disabled: boolean; dropdownArrow: boolean; dropdownArrowClassName: string; hideIcon: boolean; hideText: boolean; onChange: (moduleIds: string[]) => void; placeholder?: string; showCount: boolean; showTooltip?: boolean; value: string | string[] | null; }; const ButtonContent: React.FC = (props) => { const { disabled, dropdownArrow, dropdownArrowClassName, hideIcon, hideText, onChange, placeholder, showCount, showTooltip = false, value, } = props; // store hooks const { getModuleById } = useModule(); const { isMobile } = usePlatformOS(); if (Array.isArray(value)) return ( <> {showCount ? (
{!hideIcon && } {(value.length > 0 || !!placeholder) && (
{value.length > 0 ? value.length === 1 ? `${getModuleById(value[0])?.name || "module"}` : `${value.length} Module${value.length === 1 ? "" : "s"}` : placeholder}
)}
) : value.length > 0 ? (
{value.map((moduleId) => { const moduleDetails = getModuleById(moduleId); return (
{!hideIcon && } {!hideText && ( {moduleDetails?.name} )} {!disabled && ( )}
); })}
) : ( <> {!hideIcon && } {placeholder} )} {dropdownArrow && (