import React from
"react"
;
import OutlinedInput from
'@mui/material/OutlinedInput'
;
import InputLabel from
'@mui/material/InputLabel'
;
import { useTheme } from
'@mui/material/styles'
;
import FormControl from
'@mui/material/FormControl'
;
import Select from
'@mui/material/Select'
;
import Chip from
'@mui/material/Chip'
;
import { Box } from
"@mui/system"
;
import { MenuItem } from
"@mui/material"
;
const ITEM_HEIGHT = 45;
const ITEM_PADDING_TOP = 5;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};
const names = [
'Stack'
,
'Queue'
,
'Array'
];
function
getStyles(algo, algorithm, theme) {
return
{
fontWeight:
algorithm.indexOf(algo) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
};
}
function
App() {
const theme = useTheme();
const [algorithm, setAlgorithm] = React.useState([]);
const handleChange = (event) => {
const {
target: { value },
} = event;
setAlgorithm(
typeof
value ===
'string'
? value.split(
','
) : value,
);
};
return
(
<div>
<div style={{ textAlign:
"center"
, color:
"green"
}}>
<h1>GeeksforGeeks</h1>
<h2>React MUI Select Input</h2>
</div>
<div style={{ textAlign:
"center"
}}>
<FormControl sx={{ m: 1, width: 300 }}>
<InputLabel id=
"demo-multiple-chip-label"
>
Algorithm
</InputLabel>
<Select
labelId=
"demo-multiple-chip-label"
multiple
value={algorithm}
onChange={handleChange}
input={<OutlinedInput id=
"select-multiple-chip"
label=
"Algorithm"
/>}
renderValue={(selected) => (
<Box sx={{ display:
'flex'
,
flexWrap:
'wrap'
, gap: 0.5 }}>
{selected.map((value) => (
<Chip key={value}
label={value} />
))}
</Box>
)}
MenuProps={MenuProps}
>
{names.map((algo) => (
<MenuItem
key={algo}
value={algo}
style={getStyles(algo, algorithm, theme)}
>
{algo}
</MenuItem>
))}
</Select>
</FormControl>
</div>
</div>
);
}
export
default
App;