import { useTheme } from '@emotion/react'; import { Close, ExpandMore } from '@mui/icons-material'; import { Box, Checkbox, Chip, FormControl, InputLabel, ListItemText, MenuItem, Select as MuiSelect, SelectProps as MuiSelectProps, OutlinedInput, SelectChangeEvent, Theme } from '@mui/material'; import _without from "lodash/without"; import React from 'react'; import './mulitSelect.css'; export interface SelectProps extends MuiSelectProps { label?: string, name?: string, height?: string, width?: string, options: string[], defaultValue?: string[] } const ITEM_HEIGHT = 48; const ITEM_PADDING_TOP = 8; const MenuProps = { PaperProps: { style: { maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP, width: 250, }, }, }; const names = [ 'Oliver Hansen', 'Van Henry', 'April Tucker', 'Ralph Hubbard', 'Omar Alexander', 'Carlos Abbott', 'Miriam Wagner', 'Bradley Wilkerson', 'Virginia Andrews', 'Kelly Snyder', ]; function getStyles(name: string, personName: readonly string[], theme: Theme) { return { fontWeight: personName.indexOf(name) === -1 ? theme.typography.fontWeightRegular : theme.typography.fontWeightMedium, }; } export const MultiSelect = ({ width, height, size, label, name, value, defaultValue, options, variant, color,...rest }: SelectProps) => { const theme = useTheme(); const [personName, setPersonName] = React.useState(defaultValue ? defaultValue : []); const handleDelete = (e: React.MouseEvent, value: string) => { e.preventDefault(); setPersonName((current) => _without(current, value)); }; const handleChange = (event: SelectChangeEvent) => { const { target: { value }, } = event; setPersonName( // On autofill we get a stringified value. typeof value === 'string' ? value.split(',') : value, ); console.log('value - ', value); console.log('person name - ', personName); }; return (
{label} } renderValue={(selected) => ( {(selected).map((value) => ( event.stopPropagation()} /> } onDelete={(e) => handleDelete(e, value)} /> ))} )} MenuProps={MenuProps} > {names.map((name) => ( -1} /> ))}
); }