-
Notifications
You must be signed in to change notification settings - Fork 549
Expand file tree
/
Copy pathMainLayout.js
More file actions
135 lines (118 loc) · 3.4 KB
/
MainLayout.js
File metadata and controls
135 lines (118 loc) · 3.4 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
import { Content, Footer, Header, Sidebar } from 'components/Layout';
import React from 'react';
import {
MdImportantDevices,
// MdCardGiftcard,
MdLoyalty,
} from 'react-icons/md';
import NotificationSystem from 'react-notification-system';
import { NOTIFICATION_SYSTEM_STYLE } from 'utils/constants';
class MainLayout extends React.Component {
constructor(props) {
super(props);
this.state = {
isContentClicked: false, // state to control if Content tag is clicked
};
// bind handleContentClickStateChange to the current component
// so that it can be use as props in Header component
this.handleContentClickStateChange =
this.handleContentClickStateChange.bind(this);
}
static isSidebarOpen() {
return document
.querySelector('.cr-sidebar')
.classList.contains('cr-sidebar--open');
}
componentWillReceiveProps({ breakpoint }) {
if (breakpoint !== this.props.breakpoint) {
this.checkBreakpoint(breakpoint);
}
}
componentDidMount() {
this.checkBreakpoint(this.props.breakpoint);
setTimeout(() => {
if (!this.notificationSystem) {
return;
}
this.notificationSystem.addNotification({
title: <MdImportantDevices />,
message: 'Welome to Reduction Admin!',
level: 'info',
});
}, 1500);
setTimeout(() => {
if (!this.notificationSystem) {
return;
}
this.notificationSystem.addNotification({
title: <MdLoyalty />,
message:
'Reduction is carefully designed template powered by React and Bootstrap4!',
level: 'info',
});
}, 2500);
}
// close sidebar when
handleContentClick = event => {
// close sidebar if sidebar is open and screen size is less than `md`
if (
MainLayout.isSidebarOpen() &&
(this.props.breakpoint === 'xs' ||
this.props.breakpoint === 'sm' ||
this.props.breakpoint === 'md')
) {
this.openSidebar('close');
}
// this.handleContentClickStateChange(false);
};
handleContentClickStateChange(open) {
this.setState({ isContentClicked: open });
}
handleMainContentClick = () => {
this.handleContentClickStateChange(false);
};
checkBreakpoint(breakpoint) {
switch (breakpoint) {
case 'xs':
case 'sm':
case 'md':
return this.openSidebar('close');
case 'lg':
case 'xl':
default:
return this.openSidebar('open');
}
}
openSidebar(openOrClose) {
if (openOrClose === 'open') {
return document
.querySelector('.cr-sidebar')
.classList.add('cr-sidebar--open');
}
document.querySelector('.cr-sidebar').classList.remove('cr-sidebar--open');
}
render() {
const { children } = this.props;
return (
<main className="cr-app bg-light" onClick={this.handleMainContentClick}>
<Sidebar />
<Content fluid onClick={this.handleContentClick}>
<Header
isContentClicked={this.state.isContentClicked}
handleContentClickStateChange={this.handleContentClickStateChange}
/>
{children}
<Footer />
</Content>
<NotificationSystem
dismissible={false}
ref={notificationSystem =>
(this.notificationSystem = notificationSystem)
}
style={NOTIFICATION_SYSTEM_STYLE}
/>
</main>
);
}
}
export default MainLayout;