2020-10-20 21:50:53 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
2020-10-14 08:51:37 +02:00
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
2020-10-20 21:50:53 +02:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-10-14 08:51:37 +02:00
|
|
|
|
|
|
|
type Props = {
|
2020-10-20 21:50:53 +02:00
|
|
|
children: React.ReactNode
|
2020-10-14 08:51:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class RootPortal extends React.PureComponent<Props> {
|
2020-10-20 21:50:53 +02:00
|
|
|
el: HTMLDivElement
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props)
|
|
|
|
this.el = document.createElement('div')
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const rootPortal = document.getElementById('root-portal')
|
|
|
|
if (rootPortal) {
|
|
|
|
rootPortal.appendChild(this.el)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
const rootPortal = document.getElementById('root-portal')
|
|
|
|
if (rootPortal) {
|
|
|
|
rootPortal.removeChild(this.el)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return ReactDOM.createPortal(
|
|
|
|
this.props.children,
|
|
|
|
this.el,
|
|
|
|
)
|
|
|
|
}
|
2020-10-14 08:51:37 +02:00
|
|
|
}
|