|
@@ -1,126 +1,85 @@
|
1
|
1
|
import * as React from 'react';
|
2
|
|
-import TextField from '@mui/material/TextField';
|
3
|
|
-import Autocomplete from '@mui/material/Autocomplete';
|
4
|
|
-import CircularProgress from '@mui/material/CircularProgress';
|
|
2
|
+import Box from '@mui/material/Box';
|
|
3
|
+import FormLabel from '@mui/material/FormLabel';
|
|
4
|
+import FormControl from '@mui/material/FormControl';
|
|
5
|
+import FormGroup from '@mui/material/FormGroup';
|
|
6
|
+import FormControlLabel from '@mui/material/FormControlLabel';
|
|
7
|
+import FormHelperText from '@mui/material/FormHelperText';
|
|
8
|
+import Checkbox from '@mui/material/Checkbox';
|
5
|
9
|
|
6
|
|
-function sleep(delay = 0) {
|
7
|
|
- return new Promise((resolve) => {
|
8
|
|
- setTimeout(resolve, delay);
|
|
10
|
+export default function CheckboxesGroup() {
|
|
11
|
+ const [state, setState] = React.useState({
|
|
12
|
+ gilad: true,
|
|
13
|
+ jason: false,
|
|
14
|
+ antoine: false,
|
9
|
15
|
});
|
10
|
|
-}
|
11
|
|
-
|
12
|
|
-export default function Asynchronous() {
|
13
|
|
- const [open, setOpen] = React.useState(false);
|
14
|
|
- const [options, setOptions] = React.useState([]);
|
15
|
|
- const loading = open && options.length === 0;
|
16
|
|
-
|
17
|
|
- React.useEffect(() => {
|
18
|
|
- let active = true;
|
19
|
|
-
|
20
|
|
- if (!loading) {
|
21
|
|
- return undefined;
|
22
|
|
- }
|
23
|
16
|
|
24
|
|
- (async () => {
|
25
|
|
- await sleep(1e3); // For demo purposes.
|
|
17
|
+ const handleChange = (event) => {
|
|
18
|
+ setState({
|
|
19
|
+ ...state,
|
|
20
|
+ [event.target.name]: event.target.checked,
|
|
21
|
+ });
|
|
22
|
+ };
|
26
|
23
|
|
27
|
|
- if (active) {
|
28
|
|
- setOptions([...topFilms]);
|
29
|
|
- }
|
30
|
|
- })();
|
31
|
|
-
|
32
|
|
- return () => {
|
33
|
|
- active = false;
|
34
|
|
- };
|
35
|
|
- }, [loading]);
|
36
|
|
-
|
37
|
|
- React.useEffect(() => {
|
38
|
|
- if (!open) {
|
39
|
|
- setOptions([]);
|
40
|
|
- }
|
41
|
|
- }, [open]);
|
|
24
|
+ const { gilad, jason, antoine } = state;
|
|
25
|
+ const error = [gilad, jason, antoine].filter((v) => v).length !== 2;
|
42
|
26
|
|
43
|
27
|
return (
|
44
|
|
- <Autocomplete
|
45
|
|
- id="asynchronous-demo"
|
46
|
|
- sx={{ width: 300 }}
|
47
|
|
- open={open}
|
48
|
|
- onOpen={() => {
|
49
|
|
- setOpen(true);
|
50
|
|
- }}
|
51
|
|
- onClose={() => {
|
52
|
|
- setOpen(false);
|
53
|
|
- }}
|
54
|
|
- isOptionEqualToValue={(option, value) => option.title === value.title}
|
55
|
|
- getOptionLabel={(option) => option.title}
|
56
|
|
- options={options}
|
57
|
|
- loading={loading}
|
58
|
|
- renderInput={(params) => (
|
59
|
|
- <TextField
|
60
|
|
- {...params}
|
61
|
|
- label="Asynchronous"
|
62
|
|
- InputProps={{
|
63
|
|
- ...params.InputProps,
|
64
|
|
- endAdornment: (
|
65
|
|
- <React.Fragment>
|
66
|
|
- {loading ? <CircularProgress color="inherit" size={20} /> : null}
|
67
|
|
- {params.InputProps.endAdornment}
|
68
|
|
- </React.Fragment>
|
69
|
|
- ),
|
70
|
|
- }}
|
71
|
|
- />
|
72
|
|
- )}
|
73
|
|
- />
|
|
28
|
+ <Box sx={{ display: 'flex' }}>
|
|
29
|
+ <FormControl sx={{ m: 3 }} component="fieldset" variant="standard">
|
|
30
|
+ <FormLabel component="legend">Assign responsibility</FormLabel>
|
|
31
|
+ <FormGroup>
|
|
32
|
+ <FormControlLabel
|
|
33
|
+ control={
|
|
34
|
+ <Checkbox checked={gilad} onChange={handleChange} name="gilad" />
|
|
35
|
+ }
|
|
36
|
+ label="Gilad Gray"
|
|
37
|
+ />
|
|
38
|
+ <FormControlLabel
|
|
39
|
+ control={
|
|
40
|
+ <Checkbox checked={jason} onChange={handleChange} name="jason" />
|
|
41
|
+ }
|
|
42
|
+ label="Jason Killian"
|
|
43
|
+ />
|
|
44
|
+ <FormControlLabel
|
|
45
|
+ control={
|
|
46
|
+ <Checkbox checked={antoine} onChange={handleChange} name="antoine" />
|
|
47
|
+ }
|
|
48
|
+ label="Antoine Llorca"
|
|
49
|
+ />
|
|
50
|
+ </FormGroup>
|
|
51
|
+ <FormHelperText>Be careful</FormHelperText>
|
|
52
|
+ </FormControl>
|
|
53
|
+ <FormControl
|
|
54
|
+ required
|
|
55
|
+ error={error}
|
|
56
|
+ component="fieldset"
|
|
57
|
+ sx={{ m: 3 }}
|
|
58
|
+ variant="standard"
|
|
59
|
+ >
|
|
60
|
+ <FormLabel component="legend">Pick two</FormLabel>
|
|
61
|
+ <FormGroup>
|
|
62
|
+ <FormControlLabel
|
|
63
|
+ control={
|
|
64
|
+ <Checkbox checked={gilad} onChange={handleChange} name="gilad" />
|
|
65
|
+ }
|
|
66
|
+ label="Gilad Gray"
|
|
67
|
+ />
|
|
68
|
+ <FormControlLabel
|
|
69
|
+ control={
|
|
70
|
+ <Checkbox checked={jason} onChange={handleChange} name="jason" />
|
|
71
|
+ }
|
|
72
|
+ label="Jason Killian"
|
|
73
|
+ />
|
|
74
|
+ <FormControlLabel
|
|
75
|
+ control={
|
|
76
|
+ <Checkbox checked={antoine} onChange={handleChange} name="antoine" />
|
|
77
|
+ }
|
|
78
|
+ label="Antoine Llorca"
|
|
79
|
+ />
|
|
80
|
+ </FormGroup>
|
|
81
|
+ <FormHelperText>You can display an error</FormHelperText>
|
|
82
|
+ </FormControl>
|
|
83
|
+ </Box>
|
74
|
84
|
);
|
75
|
85
|
}
|
76
|
|
-
|
77
|
|
-// Top films as rated by IMDb users. http://www.imdb.com/chart/top
|
78
|
|
-const topFilms = [
|
79
|
|
- { title: 'The Shawshank Redemption', year: 1994 },
|
80
|
|
- { title: 'The Godfather', year: 1972 },
|
81
|
|
- { title: 'The Godfather: Part II', year: 1974 },
|
82
|
|
- { title: 'The Dark Knight', year: 2008 },
|
83
|
|
- { title: '12 Angry Men', year: 1957 },
|
84
|
|
- { title: "Schindler's List", year: 1993 },
|
85
|
|
- { title: 'Pulp Fiction', year: 1994 },
|
86
|
|
- {
|
87
|
|
- title: 'The Lord of the Rings: The Return of the King',
|
88
|
|
- year: 2003,
|
89
|
|
- },
|
90
|
|
- { title: 'The Good, the Bad and the Ugly', year: 1966 },
|
91
|
|
- { title: 'Fight Club', year: 1999 },
|
92
|
|
- {
|
93
|
|
- title: 'The Lord of the Rings: The Fellowship of the Ring',
|
94
|
|
- year: 2001,
|
95
|
|
- },
|
96
|
|
- {
|
97
|
|
- title: 'Star Wars: Episode V - The Empire Strikes Back',
|
98
|
|
- year: 1980,
|
99
|
|
- },
|
100
|
|
- { title: 'Forrest Gump', year: 1994 },
|
101
|
|
- { title: 'Inception', year: 2010 },
|
102
|
|
- {
|
103
|
|
- title: 'The Lord of the Rings: The Two Towers',
|
104
|
|
- year: 2002,
|
105
|
|
- },
|
106
|
|
- { title: "One Flew Over the Cuckoo's Nest", year: 1975 },
|
107
|
|
- { title: 'Goodfellas', year: 1990 },
|
108
|
|
- { title: 'The Matrix', year: 1999 },
|
109
|
|
- { title: 'Seven Samurai', year: 1954 },
|
110
|
|
- {
|
111
|
|
- title: 'Star Wars: Episode IV - A New Hope',
|
112
|
|
- year: 1977,
|
113
|
|
- },
|
114
|
|
- { title: 'City of God', year: 2002 },
|
115
|
|
- { title: 'Se7en', year: 1995 },
|
116
|
|
- { title: 'The Silence of the Lambs', year: 1991 },
|
117
|
|
- { title: "It's a Wonderful Life", year: 1946 },
|
118
|
|
- { title: 'Life Is Beautiful', year: 1997 },
|
119
|
|
- { title: 'The Usual Suspects', year: 1995 },
|
120
|
|
- { title: 'Léon: The Professional', year: 1994 },
|
121
|
|
- { title: 'Spirited Away', year: 2001 },
|
122
|
|
- { title: 'Saving Private Ryan', year: 1998 },
|
123
|
|
- { title: 'Once Upon a Time in the West', year: 1968 },
|
124
|
|
- { title: 'American History X', year: 1998 },
|
125
|
|
- { title: 'Interstellar', year: 2014 },
|
126
|
|
-];
|