UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

109 lines (91 loc) 2.78 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } import { Component } from 'react'; import ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; 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 ReactDOM.createPortal(this.props.children, this._container); } return null; } }]); return Portal; }(Component); _defineProperty(Portal, "propTypes", { getContainer: PropTypes.func.isRequired, children: PropTypes.node.isRequired, didUpdate: PropTypes.func }); export { Portal as default }; //# sourceMappingURL=Portal.js.map