import React, { useState, useRef } from 'react'; import { Listbox, Transition } from '@headlessui/react'; import { Wrench, ArrowRight } from 'lucide-react'; import { CheckMark } from '~/components/svg'; import useOnClickOutside from '~/hooks/useOnClickOutside'; import { cn } from '~/utils/'; import type { TPlugin } from 'librechat-data-provider'; export type TMultiSelectDropDownProps = { title?: string; value: Array<{ icon?: string; name?: string; isButton?: boolean }>; disabled?: boolean; setSelected: (option: string) => void; availableValues: TPlugin[]; showAbove?: boolean; showLabel?: boolean; containerClassName?: string; isSelected: (value: string) => boolean; className?: string; optionValueKey?: string; }; function MultiSelectDropDown({ title = 'Plugins', value, disabled, setSelected, availableValues, showAbove = false, showLabel = true, containerClassName, isSelected, className, optionValueKey = 'value', }: TMultiSelectDropDownProps) { const [isOpen, setIsOpen] = useState(false); const menuRef = useRef(null); const excludeIds = ['select-plugin', 'plugins-label', 'selected-plugins']; useOnClickOutside(menuRef, () => setIsOpen(false), excludeIds); const handleSelect: (value: string) => void = (option) => { setSelected(option); setIsOpen(true); }; const transitionProps = { className: 'top-full mt-3' }; if (showAbove) { transitionProps.className = 'bottom-full mb-3'; } const openProps = { open: isOpen }; return (
{/* the function typing is correct but there's still an issue here */} {() => ( <> setIsOpen((prev) => !prev)} {...openProps} > {' '} {showLabel && ( {title} )} {!showLabel && title.length > 0 && ( {title}: )}
{value.map((v, i) => (
{v.icon ? ( {`${v} ) : ( )}
))}
{availableValues.map((option, i: number) => { if (!option) { return null; } const selected = isSelected(option[optionValueKey]); return ( {!option.isButton && (
{option.icon ? ( {`${option.name} ) : ( )}
)} {option.name} {option.isButton && ( )} {selected && !option.isButton && ( )}
); })}
)}
); } export default MultiSelectDropDown;