import { Close, ExpandMore } from '@mui/icons-material'; import { Chip, Autocomplete as MuiAutocomplete, AutocompleteProps as MuiAutocompleteProps, TextField, Tooltip } from '@mui/material'; import React from 'react'; import './autocomplete.scss'; export type AutocompleteOption = { label: string, value: string, }; export interface AutocompleteProps extends MuiAutocompleteProps { label?: string; width?: string; height?: string; defaultValues?: AutocompleteOption[]; variant?: 'outlined' | 'standard' | 'filled'; onOptionChange?: (values: string[]) => void; } export const Autocomplete = ({ options, defaultValues, label, width, variant, size, onOptionChange, ...rest }: AutocompleteProps) => { const [selectedOptions, setSelectedOptions] = React.useState(defaultValues ? defaultValues as any[] : []); const handleSelection = (e: any, selected: any) => { const selectedValues = selected?.map((item: any) => { if (typeof item === 'object' && item.value) { return item.value; } else if (typeof item === 'string') { const existingOption = options?.find(({label}) => label === item); return existingOption?.value || item; } }); if (onOptionChange) { onOptionChange(selectedValues); } }; return ( } onChange={handleSelection} defaultValue={selectedOptions} renderTags={(options: readonly any[], getTagProps) => ( options.map((option: any, index: number) => ( } /> )) )} renderInput={(params) => ( )} > ); }