11import React , { Component } from 'react' ;
22import PropTypes from 'prop-types' ;
33import classNames from 'classnames' ;
4- import { asideMenuCssClasses } from './Shared' ;
4+ import { asideMenuCssClasses , checkBreakpoint , validBreakpoints } from './Shared' ;
5+ import toggleClasses from './Shared/toggle-classes' ;
56
67const propTypes = {
78 children : PropTypes . node ,
89 className : PropTypes . string ,
910 display : PropTypes . string ,
1011 fixed : PropTypes . bool ,
11- hidden : PropTypes . bool ,
1212 isOpen : PropTypes . bool ,
1313 offCanvas : PropTypes . bool ,
1414 tag : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . string ] )
@@ -18,7 +18,6 @@ const defaultProps = {
1818 tag : 'aside' ,
1919 display : '' ,
2020 fixed : false ,
21- hidden : false ,
2221 isOpen : false ,
2322 offCanvas : true
2423} ;
@@ -28,22 +27,16 @@ class AppAside extends Component {
2827 super ( props ) ;
2928
3029 this . isFixed = this . isFixed . bind ( this ) ;
31- this . isHidden = this . isHidden . bind ( this ) ;
3230 this . isOffCanvas = this . isOffCanvas . bind ( this ) ;
3331 this . displayBreakpoint = this . displayBreakpoint . bind ( this ) ;
3432 }
3533
3634 componentDidMount ( ) {
3735 this . isFixed ( this . props . fixed ) ;
38- this . isHidden ( this . props . hidden ) ;
3936 this . isOffCanvas ( this . props . offCanvas ) ;
4037 this . displayBreakpoint ( this . props . display ) ;
4138 }
4239
43- isHidden ( hidden ) {
44- if ( hidden ) { document . body . classList . add ( 'aside-menu-hidden' ) ; }
45- }
46-
4740 isFixed ( fixed ) {
4841 if ( fixed ) { document . body . classList . add ( 'aside-menu-fixed' ) ; }
4942 }
@@ -53,20 +46,17 @@ class AppAside extends Component {
5346 }
5447
5548 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 )
6052 }
61- document . body . classList . add ( cssClass ) ;
6253 }
6354
6455 render ( ) {
6556 const { className, children, tag : Tag , ...attributes } = this . props ;
6657
6758 delete attributes . display
6859 delete attributes . fixed
69- delete attributes . hidden
7060 delete attributes . offCanvas
7161 delete attributes . isOpen
7262
0 commit comments