2015-11-14 23:38:17 +03:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import style from './style';
|
|
|
|
|
|
|
|
class Overlay extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
active: React.PropTypes.bool,
|
2015-11-14 23:42:13 +03:00
|
|
|
className: React.PropTypes.string,
|
|
|
|
onClick: React.PropTypes.func
|
2015-11-14 23:38:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
className: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this.app = document.getElementById('react-toolbox-app') || document.body;
|
|
|
|
this.node = document.createElement('div');
|
|
|
|
this.app.appendChild(this.node);
|
|
|
|
this.handleRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate () {
|
|
|
|
this.handleRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
ReactDOM.unmountComponentAtNode(this.node);
|
|
|
|
this.app.removeChild(this.node);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRender () {
|
|
|
|
let className = style.root;
|
|
|
|
if (this.props.active) className += ` ${style.active}`;
|
|
|
|
ReactDOM.render(
|
|
|
|
<div className={className}>
|
2015-11-14 23:42:13 +03:00
|
|
|
<div className={style.overlay} onClick={this.props.onClick}></div>
|
2015-11-14 23:38:17 +03:00
|
|
|
{this.props.children}
|
|
|
|
</div>
|
|
|
|
, this.node);
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return React.DOM.noscript();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Overlay;
|