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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import MoreVertIcon from '@material-ui/icons/MoreVert';
import { IconButton, List, ListItem, ListItemText, Menu, MenuItem, Grid } from '@material-ui/core';
const styles = {
root: {
width: '100%',
},
};
const options = [
'Show some love to Material-UI',
'Show all notification content',
'Hide sensitive notification content',
'Hide all notification content',
];
const optionsOpt = [
'None',
'Atria',
'Callisto',
'Dione',
'Ganymede',
'Hangouts Call',
'Luna',
'Oberon',
'Phobos',
'Pyxis',
'Sedna',
'Titania',
'Triton',
'Umbriel',
];
const ITEM_HEIGHT = 48;
class DropdownMenu extends React.Component {
state = {
anchorEl: null,
anchorElOpt: null,
selectedIndex: 1,
};
button = undefined;
handleClickListItem = event => {
this.setState({ anchorEl: event.currentTarget });
};
handleMenuItemClick = (event, index) => {
this.setState({ selectedIndex: index, anchorEl: null });
};
handleClose = () => {
this.setState({ anchorEl: null });
};
handleClickOpt = event => {
this.setState({ anchorElOpt: event.currentTarget });
};
handleCloseOpt = () => {
this.setState({ anchorElOpt: null });
};
render() {
const { classes } = this.props;
const { anchorEl, anchorElOpt } = this.state;
return (
<div className={classes.root}>
<Grid container spacing={2}>
<Grid item md={8}>
<List component="nav">
<ListItem
button
aria-haspopup="true"
aria-controls="lock-menu"
aria-label="When device is locked"
onClick={this.handleClickListItem}
>
<ListItemText
primary="When device is locked"
secondary={options[this.state.selectedIndex]}
/>
</ListItem>
</List>
<Menu
id="lock-menu"
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={this.handleClose}
>
{options.map((option, index) => (
<MenuItem
key={option}
disabled={index === 0}
selected={index === this.state.selectedIndex}
onClick={event => this.handleMenuItemClick(event, index)}
>
{option}
</MenuItem>
))}
</Menu>
</Grid>
<Grid item md={4}>
<IconButton
aria-label="More"
aria-owns={anchorEl ? 'long-menu' : null}
aria-haspopup="true"
onClick={this.handleClickOpt}
>
<MoreVertIcon />
</IconButton>
<Menu
id="long-menu"
anchorEl={anchorElOpt}
open={Boolean(anchorElOpt)}
onClose={this.handleCloseOpt}
PaperProps={{
style: {
maxHeight: ITEM_HEIGHT * 4.5,
width: 200,
},
}}
>
{optionsOpt.map(option => (
<MenuItem key={option} selected={option === 'Pyxis'} onClick={this.handleCloseOpt}>
{option}
</MenuItem>
))}
</Menu>
</Grid>
</Grid>
</div>
);
}
}
DropdownMenu.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(DropdownMenu);
|