forked from coreui/coreui-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAside.js
76 lines (62 loc) · 1.86 KB
/
Aside.js
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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { asideMenuCssClasses, checkBreakpoint, validBreakpoints } from './Shared';
import toggleClasses from './Shared/toggle-classes';
const propTypes = {
children: PropTypes.node,
className: PropTypes.string,
display: PropTypes.string,
fixed: PropTypes.bool,
isOpen: PropTypes.bool,
offCanvas: PropTypes.bool,
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
};
const defaultProps = {
tag: 'aside',
display: '',
fixed: false,
isOpen: false,
offCanvas: true
};
class AppAside extends Component {
constructor(props) {
super(props);
this.isFixed = this.isFixed.bind(this);
this.isOffCanvas = this.isOffCanvas.bind(this);
this.displayBreakpoint = this.displayBreakpoint.bind(this);
}
componentDidMount() {
this.isFixed(this.props.fixed);
this.isOffCanvas(this.props.offCanvas);
this.displayBreakpoint(this.props.display);
}
isFixed(fixed) {
if (fixed) { document.body.classList.add('aside-menu-fixed'); }
}
isOffCanvas(offCanvas) {
if (offCanvas) { document.body.classList.add('aside-menu-off-canvas'); }
}
displayBreakpoint(display) {
if (display && checkBreakpoint(display, validBreakpoints)) {
const cssClass = `aside-menu-${display}-show`
toggleClasses(cssClass, asideMenuCssClasses, true)
}
}
render() {
const { className, children, tag: Tag, ...attributes } = this.props;
delete attributes.display
delete attributes.fixed
delete attributes.offCanvas
delete attributes.isOpen
const classes = classNames(className, 'aside-menu');
return (
<Tag {...attributes} className={classes}>
{children}
</Tag>
);
}
}
AppAside.propTypes = propTypes;
AppAside.defaultProps = defaultProps;
export default AppAside;