choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
67 lines (57 loc) • 1.66 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import { Component } from 'react';
import ReactDOM from 'react-dom';
var Portal = /*#__PURE__*/function (_Component) {
_inherits(Portal, _Component);
var _super = _createSuper(Portal);
function Portal() {
_classCallCheck(this, Portal);
return _super.apply(this, arguments);
}
_createClass(Portal, [{
key: "componentDidMount",
value: function componentDidMount() {
this.createContainer();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
var didUpdate = this.props.didUpdate;
if (didUpdate) {
didUpdate(prevProps);
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.removeContainer();
}
}, {
key: "createContainer",
value: function createContainer() {
this._container = this.props.getContainer();
this.forceUpdate();
}
}, {
key: "removeContainer",
value: function removeContainer() {
if (this._container) {
this._container.parentNode.removeChild(this._container);
}
}
}, {
key: "render",
value: function render() {
if (this._container) {
return /*#__PURE__*/ReactDOM.createPortal(this.props.children, this._container);
}
return null;
}
}]);
return Portal;
}(Component);
export { Portal as default };
//# sourceMappingURL=Portal.js.map