import React, { useState, useRef } from 'react'; import CheckMark from '../svg/CheckMark.jsx'; import useOnClickOutside from '~/hooks/useOnClickOutside.js'; import { Listbox, Transition } from '@headlessui/react'; import { Wrench, ArrowRight } from 'lucide-react'; import { cn } from '~/utils/'; function MultiSelectDropDown({ title = 'Plugins', value, disabled, setSelected, availableValues, showAbove = false, showLabel = true, containerClassName, isSelected, className, optionValueKey = 'value', }) { const [isOpen, setIsOpen] = useState(false); const menuRef = useRef(null); const excludeIds = ['select-plugin', 'plugins-label', 'selected-plugins']; useOnClickOutside(menuRef, () => setIsOpen(false), excludeIds); const handleSelect = (option) => { setSelected(option); setIsOpen(true); }; return (
{() => ( <> setIsOpen((prev) => !prev)} open={isOpen} > {' '} {showLabel && ( {title} )} {!showLabel && title.length > 0 && ( {title}: )}
{value.map((v, i) => (
{v.icon ? ( {`${v} ) : ( )}
))}
{availableValues.map((option, i) => { 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;