GoScrobble/web/node_modules/reactstrap/es/Portal.js

45 lines
1.1 KiB
JavaScript

import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import { canUseDOM } from './utils';
var propTypes = {
children: PropTypes.node.isRequired,
node: PropTypes.any
};
var Portal = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(Portal, _React$Component);
function Portal() {
return _React$Component.apply(this, arguments) || this;
}
var _proto = Portal.prototype;
_proto.componentWillUnmount = function componentWillUnmount() {
if (this.defaultNode) {
document.body.removeChild(this.defaultNode);
}
this.defaultNode = null;
};
_proto.render = function render() {
if (!canUseDOM) {
return null;
}
if (!this.props.node && !this.defaultNode) {
this.defaultNode = document.createElement('div');
document.body.appendChild(this.defaultNode);
}
return /*#__PURE__*/ReactDOM.createPortal(this.props.children, this.props.node || this.defaultNode);
};
return Portal;
}(React.Component);
Portal.propTypes = propTypes;
export default Portal;