|
1 | 1 | import React, { Component } from 'react';
|
2 | 2 | import PropTypes from 'prop-types';
|
3 | 3 | import classNames from 'classnames';
|
4 |
| -import { asideMenuCssClasses } from './Shared'; |
| 4 | +import { asideMenuCssClasses, checkBreakpoint, validBreakpoints } from './Shared'; |
| 5 | +import toggleClasses from './Shared/toggle-classes'; |
5 | 6 |
|
6 | 7 | const propTypes = {
|
7 | 8 | children: PropTypes.node,
|
8 | 9 | className: PropTypes.string,
|
9 | 10 | display: PropTypes.string,
|
10 | 11 | fixed: PropTypes.bool,
|
11 |
| -hidden: PropTypes.bool, |
12 | 12 | isOpen: PropTypes.bool,
|
13 | 13 | offCanvas: PropTypes.bool,
|
14 | 14 | tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
|
@@ -18,7 +18,6 @@ const defaultProps = {
|
18 | 18 | tag: 'aside',
|
19 | 19 | display: '',
|
20 | 20 | fixed: false,
|
21 |
| -hidden: false, |
22 | 21 | isOpen: false,
|
23 | 22 | offCanvas: true
|
24 | 23 | };
|
@@ -28,22 +27,16 @@ class AppAside extends Component {
|
28 | 27 | super(props);
|
29 | 28 |
|
30 | 29 | this.isFixed = this.isFixed.bind(this);
|
31 |
| -this.isHidden = this.isHidden.bind(this); |
32 | 30 | this.isOffCanvas = this.isOffCanvas.bind(this);
|
33 | 31 | this.displayBreakpoint = this.displayBreakpoint.bind(this);
|
34 | 32 | }
|
35 | 33 |
|
36 | 34 | componentDidMount() {
|
37 | 35 | this.isFixed(this.props.fixed);
|
38 |
| -this.isHidden(this.props.hidden); |
39 | 36 | this.isOffCanvas(this.props.offCanvas);
|
40 | 37 | this.displayBreakpoint(this.props.display);
|
41 | 38 | }
|
42 | 39 |
|
43 |
| -isHidden(hidden) { |
44 |
| -if (hidden) { document.body.classList.add('aside-menu-hidden'); } |
45 |
| -} |
46 |
| - |
47 | 40 | isFixed(fixed) {
|
48 | 41 | if (fixed) { document.body.classList.add('aside-menu-fixed'); }
|
49 | 42 | }
|
@@ -53,20 +46,17 @@ class AppAside extends Component {
|
53 | 46 | }
|
54 | 47 |
|
55 | 48 | displayBreakpoint(display) {
|
56 |
| -const cssTemplate = `aside-menu-${display}-show`; |
57 |
| -let [cssClass] = asideMenuCssClasses[0]; |
58 |
| -if (display && asideMenuCssClasses.indexOf(cssTemplate) > -1) { |
59 |
| -cssClass = cssTemplate; |
| 49 | +if (display && checkBreakpoint(display, validBreakpoints)) { |
| 50 | +const cssClass = `aside-menu-${display}-show` |
| 51 | +toggleClasses(cssClass, asideMenuCssClasses, true) |
60 | 52 | }
|
61 |
| -document.body.classList.add(cssClass); |
62 | 53 | }
|
63 | 54 |
|
64 | 55 | render() {
|
65 | 56 | const { className, children, tag: Tag, ...attributes } = this.props;
|
66 | 57 |
|
67 | 58 | delete attributes.display
|
68 | 59 | delete attributes.fixed
|
69 |
| -delete attributes.hidden |
70 | 60 | delete attributes.offCanvas
|
71 | 61 | delete attributes.isOpen
|
72 | 62 |
|
|
0 commit comments