"use client"; import { Badge } from "@/components/ui/badge"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; import { Check, ChevronsUpDown } from "lucide-react"; import * as React from "react"; export function MultiSelect({ options, value, onChange, placeholder = 'Select...', }: { options: { label: string; value: string }[]; value: string[]; onChange: (values: string[]) => void; placeholder?: string; }) { const [open, setOpen] = React.useState(false); const toggleValue = (val: string) => { if (value.includes(val)) { onChange(value.filter((v) => v !== val)); } else { onChange([...value, val]); } // Don't close the popover - keep it open for multiple selections }; return (
{value.length === 0 ? ( {placeholder} ) : ( value.map((val) => ( {val} )) )}
No results found. {options.map((option) => { const selected = value.includes(option.value); return ( toggleValue(option.value)} className="flex items-center gap-2 cursor-pointer" >
{selected && }
{option.label}
); })}
); }