stremio-web/src/common/Modal/Modal.js
NikolaBorislavovHristov 90fd16edcd nested modals issue fixed
2018-11-15 16:13:13 +02:00

33 lines
845 B
JavaScript

import { PureComponent } from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import classnames from 'classnames';
class Modal extends PureComponent {
constructor(props) {
super(props);
this.modalElement = document.createElement('div');
}
componentWillMount() {
document.body.appendChild(this.modalElement);
}
componentWillUnmount() {
document.body.removeChild(this.modalElement);
}
render() {
this.modalElement.className = classnames('modal-container', this.props.className);
this.modalElement.onclick = this.props.onRequestClose;
return ReactDOM.createPortal(this.props.children, this.modalElement);
}
}
Modal.propTypes = {
onRequestClose: PropTypes.func,
className: PropTypes.string
};
export default Modal;