import { CheckIcon, PlusCircledIcon } from '@radix-ui/react-icons'; import { ReactNode, useCallback } from 'react'; import { Badge, Button, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandLoading, CommandSeparator, ctw, Popover, PopoverContent, PopoverTrigger, } from '@ballerine/ui'; import { Separator } from '@/common/components/atoms/Separator/Separator'; interface IMultiSelectProps< TOption extends { label: string; value: unknown; icon?: ReactNode; }, > { title: string; isLoading?: boolean; selectedValues: Array; onSelect: (value: Array) => void; onClearSelect: () => void; options: TOption[]; props?: { content?: { className?: string; }; trigger?: { leftIcon?: JSX.Element; rightIcon?: JSX.Element; className?: string; title?: { className?: string; }; }; }; } export const MultiSelect = < TOption extends { label: string; value: unknown; icon?: ReactNode; }, >({ title, isLoading, selectedValues: selected, onSelect, onClearSelect, options, props, }: IMultiSelectProps) => { const onSelectChange = useCallback( (value: TOption['value']) => { const isSelected = selected.some(selectedValue => selectedValue === value); const nextSelected = isSelected ? selected.filter(selectedValue => selectedValue !== value) : [...selected, value]; onSelect(nextSelected); }, [onSelect, selected], ); const TriggerLeftIcon = props?.trigger?.leftIcon ?? ; return ( (value.includes(search) ? 1 : 0)}> {isLoading && ( Loading... )} {!isLoading && options.length === 0 && No results found.} {!isLoading && options.length > 0 && (
{options.map(option => { const isSelected = selected.some(value => value === option.value); return ( onSelectChange(option.value)} >
{option.icon} {option.label}
); })}
)}
Clear filters
); };