import React, { useState } from 'react'; import { View, Text, TouchableOpacity } from 'react-native'; import { FlatList } from 'react-native'; import ChevronDownIcon from '../icons/chevron-down.svg'; import ChevronUpIcon from '../icons/chevron-up.svg'; import { classNames } from '../utils'; import { Checkbox } from './Checkbox'; import InformationGray from '../icons/information-gray.svg'; import Close from '../icons/close.svg'; export interface MultiSelectDropdownProps { label?: string; disabled?: boolean; caption?: string; options: { label: string; value: string | number }[]; onSelect: ( selectedValues: { label: string; value: string | number }[] ) => void; selectedValues?: { label: string; value: string | number }[]; placeholder?: string; showCloseIcon?: boolean; } export const MultiSelectDropdown: React.FC = ({ label, options, disabled = false, caption, onSelect, selectedValues = [], placeholder = 'Select options', showCloseIcon, }) => { const [dropdownVisible, setDropdownVisible] = useState(false); const handleSelect = (item: { label: string; value: string | number }) => { const updatedValues = selectedValues.some((v) => v?.value === item?.value) ? selectedValues.filter((v) => v.value !== item?.value) : [...selectedValues, options.find((opt) => opt.value === item?.value)!]; onSelect(updatedValues); }; return ( {label && ( {label} )} !disabled ? setDropdownVisible(!dropdownVisible) : undefined } className={classNames( 'p-4 rounded-2xl flex flex-row items-center justify-between', `${ dropdownVisible ? 'border-brand-500 border-[1.5px]' : 'border-neutral-500 border' }`, `${disabled ? 'bg-neutral-50' : ''}` )} activeOpacity={disabled ? 1 : 0.5} > {placeholder} } renderItem={({ item }) => ( handleSelect(item)} className="bg-brand-50 flex- items-center flex-row rounded-lg px-2 py-1 mr-2" > {item?.label} {showCloseIcon && ( )} )} /> {dropdownVisible ? : } {caption && ( {caption} )} {dropdownVisible && ( String(item?.value)} renderItem={({ item, index }) => ( v?.value === item?.value) && 'bg-brand-50' }`, `${index !== options?.length - 1 ? 'mb-2' : ''}` )} > handleSelect(item)} checked={selectedValues.some( (v) => v?.value === item?.value )} /> {item?.label} )} /> )} ); };