2015-10-11 20:07:09 +03:00
|
|
|
import React from 'react';
|
2015-10-21 13:25:07 +03:00
|
|
|
import autobind from 'autobind-decorator';
|
2015-10-02 23:08:02 +03:00
|
|
|
import style from './style.scss';
|
2015-09-09 23:44:24 +03:00
|
|
|
|
2015-10-21 09:13:24 +03:00
|
|
|
@autobind
|
2015-10-20 08:40:51 +03:00
|
|
|
export default class Drawer extends React.Component {
|
|
|
|
static propTypes = {
|
2015-09-09 23:44:24 +03:00
|
|
|
active: React.PropTypes.bool,
|
|
|
|
className: React.PropTypes.string,
|
|
|
|
hideable: React.PropTypes.bool,
|
|
|
|
type: React.PropTypes.string
|
2015-10-20 08:40:51 +03:00
|
|
|
};
|
2015-09-09 23:44:24 +03:00
|
|
|
|
2015-10-20 08:40:51 +03:00
|
|
|
static defaultProps = {
|
|
|
|
className: '',
|
|
|
|
type: 'left'
|
|
|
|
};
|
2015-09-09 23:44:24 +03:00
|
|
|
|
2015-10-20 08:40:51 +03:00
|
|
|
state = {
|
|
|
|
active: this.props.active
|
|
|
|
};
|
2015-09-09 23:44:24 +03:00
|
|
|
|
2015-09-19 14:58:16 +03:00
|
|
|
handleOverlayClick () {
|
|
|
|
if (this.props.hideable) {
|
2015-09-09 23:44:24 +03:00
|
|
|
this.setState({active: false});
|
|
|
|
}
|
2015-10-20 08:40:51 +03:00
|
|
|
}
|
2015-09-09 23:44:24 +03:00
|
|
|
|
|
|
|
render () {
|
2015-10-04 16:12:53 +03:00
|
|
|
let className = `${style.drawer} ${style[this.props.type]}`;
|
|
|
|
if (this.state.active) className += ` ${style.active}`;
|
|
|
|
if (this.props.className) className += ` ${this.props.className}`;
|
2015-09-09 23:44:24 +03:00
|
|
|
|
|
|
|
return (
|
2015-10-06 05:42:56 +03:00
|
|
|
<div data-react-toolbox='drawer' className={className}>
|
2015-10-04 16:12:53 +03:00
|
|
|
<div className={style.overlay} onClick={this.handleOverlayClick}></div>
|
|
|
|
<aside className={style.content}>
|
2015-09-09 23:44:24 +03:00
|
|
|
{ this.props.children }
|
|
|
|
</aside>
|
|
|
|
</div>
|
|
|
|
);
|
2015-10-20 08:40:51 +03:00
|
|
|
}
|
2015-09-09 23:44:24 +03:00
|
|
|
|
|
|
|
show () {
|
|
|
|
this.setState({active: true});
|
2015-10-20 08:40:51 +03:00
|
|
|
}
|
2015-09-09 23:44:24 +03:00
|
|
|
|
|
|
|
hide () {
|
|
|
|
this.setState({active: false});
|
|
|
|
}
|
2015-10-21 13:25:07 +03:00
|
|
|
}
|