react-toolbox/components/drawer/index.jsx

52 lines
1.1 KiB
React
Raw Normal View History

import React from 'react';
2015-10-21 13:25:07 +03:00
import autobind from 'autobind-decorator';
import style from './style.scss';
2015-09-09 23:44:24 +03:00
2015-10-21 09:13:24 +03:00
@autobind
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-09-09 23:44:24 +03:00
static defaultProps = {
className: '',
type: 'left'
};
2015-09-09 23:44:24 +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-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-09-09 23:44:24 +03:00
show () {
this.setState({active: true});
}
2015-09-09 23:44:24 +03:00
hide () {
this.setState({active: false});
}
2015-10-21 13:25:07 +03:00
}