import React, { useState } from "react"; import { usePopper } from "react-popper"; import { Placement } from "@popperjs/core"; import { Combobox } from "@headlessui/react"; import { Check, ChevronDown, Search, User2 } from "lucide-react"; // components import { Tooltip } from "components/ui"; // ui import { Avatar, AvatarGroup } from "@plane/ui"; // types import { IUserLite } from "types"; type Props = { members: IUserLite[] | undefined; className?: string; buttonClassName?: string; optionsClassName?: string; placement?: Placement; hideDropdownArrow?: boolean; disabled?: boolean; } & ( | { value: string[]; onChange: (data: string[]) => void; multiple: true; } | { value: string; onChange: (data: string) => void; multiple: false; } ); export const MembersSelect: React.FC = ({ value, onChange, members, className = "", buttonClassName = "", optionsClassName = "", placement, hideDropdownArrow = false, disabled = false, multiple = true, }) => { const [query, setQuery] = useState(""); const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: placement ?? "bottom-start", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); const options = members?.map((member) => ({ value: member.id, query: member.display_name, content: (
{member.display_name}
), })); const filteredOptions = query === "" ? options : options?.filter((option) => option.query.toLowerCase().includes(query.toLowerCase())); const label = ( 0 ? members ?.filter((m) => value.includes(m.display_name)) .map((m) => m.display_name) .join(", ") : "No Assignee" } position="top" >
{value && value.length > 0 && Array.isArray(value) ? ( {value.map((assigneeId) => { const member = members?.find((m) => m.id === assigneeId); if (!member) return null; return ; })} ) : ( )}
); const comboboxProps: any = { value, onChange, disabled }; if (multiple) comboboxProps.multiple = true; return (
setQuery(e.target.value)} placeholder="Search" displayValue={(assigned: any) => assigned?.name} />
{filteredOptions ? ( filteredOptions.length > 0 ? ( filteredOptions.map((option) => ( `flex items-center justify-between gap-2 cursor-pointer select-none truncate rounded px-1 py-1.5 ${ active ? "bg-custom-background-80" : "" } ${selected ? "text-custom-text-100" : "text-custom-text-200"}` } > {({ selected }) => ( <> {option.content} {selected && } )} )) ) : (

No matching results

) ) : (

Loading...

)}
); };