import Select, { MultiValue, components, OptionProps, MultiValueGenericProps } from 'react-select' interface OptionType { value: string label: string count?: number } interface MultiSelectProps { label: string options: OptionType[] selected: string[] onChange: (selected: string[]) => void placeholder?: string className?: string } // Custom option component to show counts const CustomOption = (props: OptionProps) => { const { data } = props return (
{data.label} {data.count !== undefined && ( ({data.count.toLocaleString()}) )}
) } // Custom multi-value label to show abbreviated text const CustomMultiValueLabel = (props: MultiValueGenericProps) => { return ( {props.data.label} ) } export default function MultiSelect({ label, options, selected, onChange, placeholder = 'Select...', className = '' }: MultiSelectProps) { const selectedOptions = options.filter(opt => selected.includes(opt.value)) const handleChange = (newValue: MultiValue) => { onChange(newValue.map(opt => opt.value)) } return (
isMulti options={options} value={selectedOptions} onChange={handleChange} placeholder={placeholder} components={{ Option: CustomOption, MultiValueLabel: CustomMultiValueLabel }} className="react-select-container" classNamePrefix="react-select" styles={{ control: (base, state) => ({ ...base, minHeight: '38px', borderColor: state.isFocused ? '#3b82f6' : '#d1d5db', boxShadow: state.isFocused ? '0 0 0 1px #3b82f6' : 'none', '&:hover': { borderColor: state.isFocused ? '#3b82f6' : '#9ca3af' } }), placeholder: (base) => ({ ...base, color: '#9ca3af' }), singleValue: (base) => ({ ...base, color: '#111827' }), input: (base) => ({ ...base, color: '#111827' }), menu: (base) => ({ ...base, zIndex: 50 }), menuList: (base) => ({ ...base, maxHeight: '320px' }), option: (base, state) => ({ ...base, color: '#111827', backgroundColor: state.isFocused ? '#f3f4f6' : 'white', '&:active': { backgroundColor: '#e5e7eb' } }), multiValue: (base) => ({ ...base, backgroundColor: '#dbeafe', borderRadius: '4px' }), multiValueLabel: (base) => ({ ...base, color: '#1e40af', fontSize: '0.875rem' }), multiValueRemove: (base) => ({ ...base, color: '#1e40af', ':hover': { backgroundColor: '#bfdbfe', color: '#1e3a8a' } }) }} />
) }