1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-05 19:26:30 +00:00
seahub/frontend/src/components/modal-portal.js

36 lines
655 B
JavaScript
Raw Normal View History

import React from 'react';
import { createPortal } from 'react-dom';
import PropTypes from 'prop-types';
const propTypes = {
children: PropTypes.any.isRequired,
};
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() {
return createPortal(
this.props.children,
this.el,
);
}
}
ModalPortal.propTypes = propTypes;
export default ModalPortal;