File size: 1,235 Bytes
420b22a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as React from 'react';
import Box from '@mui/material/Box';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';

export default function BasicSelect({label, content, styling, onChange}) {
  const [selectedValue, setSelectedValue] = React.useState('');

  const handleChange = (event) => {
    const selectedValue = event.target.value;
    setSelectedValue(selectedValue);
    
    // Call the provided onChange callback with the selected value
    if (onChange) {
      onChange(event.target.value);
    }
  };

  return (
    <div className={styling}>
    <Box sx={{ minWidth: 120 }}>
      <FormControl fullWidth>
        <InputLabel id="demo-simple-select-label">{label}</InputLabel>
        <Select
          labelId="demo-simple-select-label"
          id="demo-simple-select"
          value={selectedValue}
          label="Value"
          onChange={handleChange}
        >
          {content.map((item) => {
            return <MenuItem value={item.id}>{`[${item.id}] ${item.name}`}</MenuItem>
          })}
        </Select>
      </FormControl>
    </Box>
    </div>
  );
}