import * as React from 'react'; import { ChevronDown, Check } from 'lucide-react'; import { cn } from '@/lib/utils/cn'; import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu'; export interface MultiSelectOption { value: string; label: string; } export interface MultiSelectProps { options: MultiSelectOption[]; value: string[]; onChange: (value: string[]) => void; placeholder?: string; className?: string; } const MultiSelectCheckboxItem = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, children, checked, ...props }, ref) => ( {children} )); MultiSelectCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName; export function MultiSelect({ options, value, onChange, placeholder = 'Select...', className, }: MultiSelectProps) { const [open, setOpen] = React.useState(false); const handleSelect = (optionValue: string) => { const newValue = value.includes(optionValue) ? value.filter((v) => v !== optionValue) : [...value, optionValue]; onChange(newValue); }; const displayText = value.length === 0 ? placeholder : value.length === 1 ? options.find((opt) => opt.value === value[0])?.label || placeholder : `${value.length} selected`; return ( e.preventDefault()} > {options.map((option) => ( handleSelect(option.value)} onCheckedChange={() => handleSelect(option.value)} > {option.label} ))} ); }