2018-11-27 06:47:19 +00:00
|
|
|
import React from 'react';
|
2025-02-14 06:04:25 +00:00
|
|
|
import { createPortal } from 'react-dom';
|
2018-11-27 06:47:19 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
const propTypes = {
|
2024-11-05 10:03:53 +00:00
|
|
|
children: PropTypes.any.isRequired,
|
2018-11-27 06:47:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const modalRoot = document.getElementById('modal-wrapper');
|
|
|
|
class ModalPortal extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.el = document.createElement('div');
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
modalRoot.appendChild(this.el);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
modalRoot.removeChild(this.el);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2025-02-14 06:04:25 +00:00
|
|
|
return createPortal(
|
2018-11-27 06:47:19 +00:00
|
|
|
this.props.children,
|
|
|
|
this.el,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ModalPortal.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default ModalPortal;
|