Skip to content

Commit 0a7159f

Browse files
author
Manu
committed
- added profile dropdown
1 parent 4b07938 commit 0a7159f

File tree

2 files changed

+99
-35
lines changed

2 files changed

+99
-35
lines changed

Diff for: src/assets/jss/material-dashboard-react/dropdownStyle.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const dropdownStyle = theme => ({
112112
color: grayColor[8],
113113
whiteSpace: "nowrap",
114114
height: "unset",
115+
minHeight: "unset",
115116
"&:hover": {
116117
backgroundColor: primaryColor[0],
117118
color: whiteColor,

Diff for: src/components/Navbars/AdminNavbarLinks.jsx

+98-35
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Paper from "@material-ui/core/Paper";
1111
import ClickAwayListener from "@material-ui/core/ClickAwayListener";
1212
import Hidden from "@material-ui/core/Hidden";
1313
import Poppers from "@material-ui/core/Popper";
14+
import Divider from "@material-ui/core/Divider";
1415
// @material-ui/icons
1516
import Person from "@material-ui/icons/Person";
1617
import Notifications from "@material-ui/icons/Notifications";
@@ -24,23 +25,30 @@ import headerLinksStyle from "assets/jss/material-dashboard-react/components/hea
2425

2526
class AdminNavbarLinks extends React.Component {
2627
state = {
27-
open: false
28+
openNotifcation: false,
29+
openProfile: false
2830
};
29-
handleToggle = () => {
30-
this.setState(state => ({ open: !state.open }));
31+
handleToggleNotification = () => {
32+
this.setState(state => ({ openNotifcation: !state.openNotifcation }));
3133
};
32-
33-
handleClose = event => {
34-
if (this.anchorEl.contains(event.target)) {
34+
handleCloseNotification = event => {
35+
if (this.anchorNotification.contains(event.target)) {
3536
return;
3637
}
37-
38-
this.setState({ open: false });
38+
this.setState({ openNotifcation: false });
39+
};
40+
handleToggleProfile = () => {
41+
this.setState(state => ({ openProfile: !state.openProfile }));
42+
};
43+
handleCloseProfile = event => {
44+
if (this.anchorProfile.contains(event.target)) {
45+
return;
46+
}
47+
this.setState({ openProfile: false });
3948
};
40-
4149
render() {
4250
const { classes } = this.props;
43-
const { open } = this.state;
51+
const { openNotifcation, openProfile } = this.state;
4452
return (
4553
<div>
4654
<div className={classes.searchWrapper}>
@@ -74,14 +82,14 @@ class AdminNavbarLinks extends React.Component {
7482
<div className={classes.manager}>
7583
<Button
7684
buttonRef={node => {
77-
this.anchorEl = node;
85+
this.anchorNotification = node;
7886
}}
7987
color={window.innerWidth > 959 ? "transparent" : "white"}
8088
justIcon={window.innerWidth > 959}
8189
simple={!(window.innerWidth > 959)}
82-
aria-owns={open ? "menu-list-grow" : null}
90+
aria-owns={openNotifcation ? "notification-menu-list-grow" : null}
8391
aria-haspopup="true"
84-
onClick={this.handleToggle}
92+
onClick={this.handleToggleNotification}
8593
className={classes.buttonLink}
8694
>
8795
<Notifications className={classes.icons} />
@@ -93,54 +101,54 @@ class AdminNavbarLinks extends React.Component {
93101
</Hidden>
94102
</Button>
95103
<Poppers
96-
open={open}
97-
anchorEl={this.anchorEl}
104+
open={openNotifcation}
105+
anchorEl={this.anchorNotification}
98106
transition
99107
disablePortal
100108
className={
101-
classNames({ [classes.popperClose]: !open }) +
109+
classNames({ [classes.popperClose]: !openNotifcation }) +
102110
" " +
103111
classes.popperNav
104112
}
105113
>
106114
{({ TransitionProps, placement }) => (
107115
<Grow
108116
{...TransitionProps}
109-
id="menu-list-grow"
117+
id="notification-menu-list-grow"
110118
style={{
111119
transformOrigin:
112120
placement === "bottom" ? "center top" : "center bottom"
113121
}}
114122
>
115123
<Paper>
116-
<ClickAwayListener onClickAway={this.handleClose}>
124+
<ClickAwayListener onClickAway={this.handleCloseNotification}>
117125
<MenuList role="menu">
118126
<MenuItem
119-
onClick={this.handleClose}
127+
onClick={this.handleCloseNotification}
120128
className={classes.dropdownItem}
121129
>
122130
Mike John responded to your email
123131
</MenuItem>
124132
<MenuItem
125-
onClick={this.handleClose}
133+
onClick={this.handleCloseNotification}
126134
className={classes.dropdownItem}
127135
>
128136
You have 5 new tasks
129137
</MenuItem>
130138
<MenuItem
131-
onClick={this.handleClose}
139+
onClick={this.handleCloseNotification}
132140
className={classes.dropdownItem}
133141
>
134142
You{"'"}re now friend with Andrew
135143
</MenuItem>
136144
<MenuItem
137-
onClick={this.handleClose}
145+
onClick={this.handleCloseNotification}
138146
className={classes.dropdownItem}
139147
>
140148
Another Notification
141149
</MenuItem>
142150
<MenuItem
143-
onClick={this.handleClose}
151+
onClick={this.handleCloseNotification}
144152
className={classes.dropdownItem}
145153
>
146154
Another One
@@ -152,18 +160,73 @@ class AdminNavbarLinks extends React.Component {
152160
)}
153161
</Poppers>
154162
</div>
155-
<Button
156-
color={window.innerWidth > 959 ? "transparent" : "white"}
157-
justIcon={window.innerWidth > 959}
158-
simple={!(window.innerWidth > 959)}
159-
aria-label="Person"
160-
className={classes.buttonLink}
161-
>
162-
<Person className={classes.icons} />
163-
<Hidden mdUp implementation="css">
164-
<p className={classes.linkText}>Profile</p>
165-
</Hidden>
166-
</Button>
163+
<div className={classes.manager}>
164+
<Button
165+
buttonRef={node => {
166+
this.anchorProfile = node;
167+
}}
168+
color={window.innerWidth > 959 ? "transparent" : "white"}
169+
justIcon={window.innerWidth > 959}
170+
simple={!(window.innerWidth > 959)}
171+
aria-owns={openNotifcation ? "profile-menu-list-grow" : null}
172+
aria-haspopup="true"
173+
onClick={this.handleToggleProfile}
174+
className={classes.buttonLink}
175+
>
176+
<Person className={classes.icons} />
177+
<Hidden mdUp implementation="css">
178+
<p className={classes.linkText}>Profile</p>
179+
</Hidden>
180+
</Button>
181+
<Poppers
182+
open={openProfile}
183+
anchorEl={this.anchorProfile}
184+
transition
185+
disablePortal
186+
className={
187+
classNames({ [classes.popperClose]: !openProfile }) +
188+
" " +
189+
classes.popperNav
190+
}
191+
>
192+
{({ TransitionProps, placement }) => (
193+
<Grow
194+
{...TransitionProps}
195+
id="profile-menu-list-grow"
196+
style={{
197+
transformOrigin:
198+
placement === "bottom" ? "center top" : "center bottom"
199+
}}
200+
>
201+
<Paper>
202+
<ClickAwayListener onClickAway={this.handleCloseProfile}>
203+
<MenuList role="menu">
204+
<MenuItem
205+
onClick={this.handleCloseProfile}
206+
className={classes.dropdownItem}
207+
>
208+
Profile
209+
</MenuItem>
210+
<MenuItem
211+
onClick={this.handleCloseProfile}
212+
className={classes.dropdownItem}
213+
>
214+
Settings
215+
</MenuItem>
216+
<Divider light />
217+
<MenuItem
218+
onClick={this.handleCloseProfile}
219+
className={classes.dropdownItem}
220+
>
221+
Logout
222+
</MenuItem>
223+
</MenuList>
224+
</ClickAwayListener>
225+
</Paper>
226+
</Grow>
227+
)}
228+
</Poppers>
229+
</div>
167230
</div>
168231
);
169232
}

0 commit comments

Comments
 (0)