-
Notifications
You must be signed in to change notification settings - Fork 549
Expand file tree
/
Copy pathHeader.js
More file actions
195 lines (179 loc) · 5.91 KB
/
Header.js
File metadata and controls
195 lines (179 loc) · 5.91 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import Avatar from 'components/Avatar';
import { UserCard } from 'components/Card';
import Notifications from 'components/Notifications';
import SearchInput from 'components/SearchInput';
import { notificationsData } from 'demos/header';
import withBadge from 'hocs/withBadge';
import React from 'react';
import {
MdClearAll,
MdExitToApp,
MdHelp,
MdInsertChart,
MdMessage,
MdNotificationsActive,
MdNotificationsNone,
MdPersonPin,
MdSettingsApplications,
} from 'react-icons/md';
import {
Button,
ListGroup,
ListGroupItem,
// NavbarToggler,
Nav,
Navbar,
NavItem,
NavLink,
Popover,
PopoverBody,
} from 'reactstrap';
import bn from 'utils/bemnames';
const bem = bn.create('header');
const MdNotificationsActiveWithBadge = withBadge({
size: 'md',
color: 'primary',
style: {
top: -10,
right: -10,
display: 'inline-flex',
justifyContent: 'center',
alignItems: 'center',
},
children: <small>5</small>,
})(MdNotificationsActive);
class Header extends React.Component {
constructor(props) {
super(props);
this.state = {
isOpenNotificationPopover: false,
isNotificationConfirmed: false,
isOpenUserCardPopover: false,
};
}
toggleNotificationPopover = () => {
this.props.handleContentClickStateChange(true);
this.setState({
isOpenNotificationPopover: !this.state.isOpenNotificationPopover,
});
if (!this.state.isNotificationConfirmed) {
this.setState({ isNotificationConfirmed: true });
}
};
toggleUserCardPopover = () => {
// set isContentClicked state in "MainLyout" component to true
// so that when click is outside of popover, isContentClicked will be set to false
// then the popover will be closed
this.props.handleContentClickStateChange(true);
this.setState({
isOpenUserCardPopover: !this.state.isOpenUserCardPopover,
});
};
handleSidebarControlButton = event => {
event.preventDefault();
event.stopPropagation();
document.querySelector('.cr-sidebar').classList.toggle('cr-sidebar--open');
};
componentDidUpdate() {
// need to close popover if click is outside of popover :
// check if popover is open and isContentClicked is false
// if so, close the popover
if (this.state.isOpenUserCardPopover && !this.props.isContentClicked) {
this.setState({ isOpenUserCardPopover: this.props.isContentClicked });
}
if (this.state.isOpenNotificationPopover && !this.props.isContentClicked) {
this.setState({ isOpenNotificationPopover: this.props.isContentClicked });
}
}
render() {
const { isNotificationConfirmed } = this.state;
return (
<Navbar light expand className={bem.b('bg-white')}>
<Nav navbar className="mr-2">
<Button outline onClick={this.handleSidebarControlButton}>
<MdClearAll size={25} />
</Button>
</Nav>
<Nav navbar>
<SearchInput />
</Nav>
<Nav navbar className={bem.e('nav-right')}>
<NavItem className="d-inline-flex">
<NavLink id="Popover1" className="position-relative">
{isNotificationConfirmed ? (
<MdNotificationsNone
size={25}
className="text-secondary can-click"
onClick={this.toggleNotificationPopover}
/>
) : (
<MdNotificationsActiveWithBadge
size={25}
className="text-secondary can-click animated swing infinite"
onClick={this.toggleNotificationPopover}
/>
)}
</NavLink>
<Popover
placement="bottom"
isOpen={this.state.isOpenNotificationPopover}
toggle={this.toggleNotificationPopover}
target="Popover1"
>
<PopoverBody>
<Notifications notificationsData={notificationsData} />
</PopoverBody>
</Popover>
</NavItem>
<NavItem>
<NavLink id="Popover2">
<Avatar
onClick={this.toggleUserCardPopover}
className="can-click"
/>
</NavLink>
<Popover
placement="bottom-end"
isOpen={this.state.isOpenUserCardPopover}
toggle={this.toggleUserCardPopover}
target="Popover2"
className="p-0 border-0"
style={{ minWidth: 250 }}
>
<PopoverBody className="p-0 border-light">
<UserCard
title="Jane"
subtitle="jane@jane.com"
text="Last updated 3 mins ago"
className="border-light"
>
<ListGroup flush>
<ListGroupItem tag="button" action className="border-light">
<MdPersonPin /> Profile
</ListGroupItem>
<ListGroupItem tag="button" action className="border-light">
<MdInsertChart /> Stats
</ListGroupItem>
<ListGroupItem tag="button" action className="border-light">
<MdMessage /> Messages
</ListGroupItem>
<ListGroupItem tag="button" action className="border-light">
<MdSettingsApplications /> Settings
</ListGroupItem>
<ListGroupItem tag="button" action className="border-light">
<MdHelp /> Help
</ListGroupItem>
<ListGroupItem tag="button" action className="border-light">
<MdExitToApp /> Signout
</ListGroupItem>
</ListGroup>
</UserCard>
</PopoverBody>
</Popover>
</NavItem>
</Nav>
</Navbar>
);
}
}
export default Header;