UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

49 lines 1.85 kB
import * as tslib_1 from "tslib"; import * as ReactDOM from 'react-dom'; import * as React from 'react'; import { PureComponent } from 'react'; var Portal = (function (_super) { tslib_1.__extends(Portal, _super); function Portal() { return _super !== null && _super.apply(this, arguments) || this; } Portal.prototype.renderPortalContent = function (children) { return (React.createElement("div", null, children)); }; Portal.prototype.renderPortal = function (props) { if (!props.mountTo) { return; } if (!this.target) { this.target = document.createElement('div'); props.mountTo.appendChild(this.target); } ReactDOM.unstable_renderSubtreeIntoContainer(this, this.renderPortalContent(props.children), this.target); }; Portal.prototype.componentWillUnmount = function () { var _this = this; // Asynchronously unmounts subtree, otherwise there might be errors when child component calls setState, // but it has already been unmounted by Portal. setTimeout(function () { if (_this.target && _this.target.parentElement) { ReactDOM.unmountComponentAtNode(_this.target); _this.target.parentElement.removeChild(_this.target); } }, 0); }; Portal.prototype.componentWillReceiveProps = function (nextProps) { this.renderPortal(nextProps); }; Portal.prototype.componentDidMount = function () { this.renderPortal(this.props); }; Portal.prototype.render = function () { if (!this.props.mountTo) { return this.renderPortalContent(this.props.children); } return null; }; return Portal; }(PureComponent)); export default Portal; //# sourceMappingURL=index.js.map