1 | import * as React from 'react';
|
---|
2 | import OutlinedInput from '@mui/material/OutlinedInput';
|
---|
3 | import InputLabel from '@mui/material/InputLabel';
|
---|
4 | import MenuItem from '@mui/material/MenuItem';
|
---|
5 | import FormControl from '@mui/material/FormControl';
|
---|
6 | import ListItemText from '@mui/material/ListItemText';
|
---|
7 | import Select from '@mui/material/Select';
|
---|
8 | import Checkbox from '@mui/material/Checkbox';
|
---|
9 | import "./FilterSelectComponent.css"
|
---|
10 |
|
---|
11 | const ITEM_HEIGHT = 48;
|
---|
12 | const ITEM_PADDING_TOP = 8;
|
---|
13 | const MenuProps = {
|
---|
14 | PaperProps: {
|
---|
15 | style: {
|
---|
16 | maxHeight: ITEM_HEIGHT * 5.5 + ITEM_PADDING_TOP,
|
---|
17 | width: 250,
|
---|
18 | },
|
---|
19 | },
|
---|
20 | };
|
---|
21 |
|
---|
22 | const categories = [
|
---|
23 | 'Category1',
|
---|
24 | 'Category2',
|
---|
25 | 'Category3',
|
---|
26 | 'Category4',
|
---|
27 | 'Category5',
|
---|
28 | 'Category6',
|
---|
29 | 'Category7',
|
---|
30 | 'Category8',
|
---|
31 | 'Category9',
|
---|
32 | 'Category10',
|
---|
33 | ];
|
---|
34 |
|
---|
35 | export default function MultipleSelectCheckmarks() {
|
---|
36 | const [category, setCategory] = React.useState([]);
|
---|
37 |
|
---|
38 | const handleChange = (event) => {
|
---|
39 | const {
|
---|
40 | target: { value },
|
---|
41 | } = event;
|
---|
42 | setCategory(
|
---|
43 | // On autofill we get a stringified value.
|
---|
44 | typeof value === 'string' ? value.split(',') : value,
|
---|
45 | );
|
---|
46 | };
|
---|
47 |
|
---|
48 | return (
|
---|
49 | <div>
|
---|
50 | <FormControl id="form" sx={{ m: 1, width: 200 }}>
|
---|
51 | <InputLabel id="demo-multiple-checkbox-label">Category</InputLabel>
|
---|
52 | <Select
|
---|
53 | size={"small"}
|
---|
54 | labelId="demo-multiple-checkbox-label"
|
---|
55 | id="demo-multiple-checkbox"
|
---|
56 | multiple
|
---|
57 | value={category}
|
---|
58 | onChange={handleChange}
|
---|
59 | input={<OutlinedInput label="Category" />} // tuka odi soodvetno imeto na filter
|
---|
60 | renderValue={(selected) => selected.join(', ')}
|
---|
61 | MenuProps={MenuProps}
|
---|
62 | >
|
---|
63 | {categories.map((cat) => (
|
---|
64 | <MenuItem key={cat} value={cat}>
|
---|
65 | <Checkbox checked={category.indexOf(cat) > -1} />
|
---|
66 | <ListItemText primary={cat} />
|
---|
67 | </MenuItem>
|
---|
68 | ))}
|
---|
69 | </Select>
|
---|
70 | </FormControl>
|
---|
71 | </div>
|
---|
72 | );
|
---|
73 | }
|
---|