-
-
Notifications
You must be signed in to change notification settings - Fork 268
/
Copy pathSidebarToggler.js
64 lines (53 loc) · 1.64 KB
/
SidebarToggler.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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { sidebarCssClasses } from './Shared/index';
import toggleClasses from './Shared/toggle-classes';
const propTypes = {
children: PropTypes.node,
className: PropTypes.string,
display: PropTypes.any,
mobile: PropTypes.bool,
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
type: PropTypes.string
};
const defaultProps = {
display: 'lg',
mobile: false,
tag: 'button',
type: 'button'
};
class AppSidebarToggler extends Component {
constructor(props) {
super(props);
this.sidebarToggle = this.sidebarToggle.bind(this);
}
sidebarToggle(e) {
e.preventDefault();
if (this.props.mobile) {
document.body.classList.toggle('sidebar-show');
} else {
const display = this.props.display;
const cssTemplate = `sidebar-${display}-show`;
let [cssClass] = sidebarCssClasses[0];
if (display && sidebarCssClasses.indexOf(cssTemplate) > -1) {
cssClass = cssTemplate;
}
toggleClasses(cssClass, sidebarCssClasses);
}
}
render() {
const { className, children, tag: Tag, ...attributes } = this.props;
delete attributes.mobile
delete attributes.display
const classes = classNames(className, 'navbar-toggler');
return (
<Tag type="button" className={classes} {...attributes} onClick={(event)=>this.sidebarToggle(event)}>
{children || <span className="navbar-toggler-icon" />}
</Tag>
);
}
}
AppSidebarToggler.propTypes = propTypes;
AppSidebarToggler.defaultProps = defaultProps;
export default AppSidebarToggler;