choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
158 lines (129 loc) • 4.19 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
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 React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Dialog from './Dialog';
import ContainerRender from '../util/ContainerRender';
import Portal from '../util/Portal';
var IS_REACT_16 = 'createPortal' in ReactDOM;
var DialogWrap =
/*#__PURE__*/
function (_Component) {
_inherits(DialogWrap, _Component);
var _super = _createSuper(DialogWrap);
function DialogWrap() {
var _this;
_classCallCheck(this, DialogWrap);
_this = _super.apply(this, arguments);
_this.saveDialog = function (node) {
_this._component = node;
};
_this.getComponent = function () {
var extra = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return React.createElement(Dialog, _extends({
ref: _this.saveDialog
}, _this.props, extra, {
key: "dialog"
}));
};
_this.getContainer = function () {
var getContainer = _this.props.getContainer;
if (getContainer) {
return getContainer(_assertThisInitialized(_this));
}
var container = document.createElement('div');
document.body.appendChild(container);
return container;
};
return _this;
}
_createClass(DialogWrap, [{
key: "shouldComponentUpdate",
value: function shouldComponentUpdate(_ref) {
var visible = _ref.visible;
var props = this.props;
return !!(props.visible || visible);
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
if (IS_REACT_16) {
return;
}
var visible = this.props.visible;
if (visible) {
this.renderComponent({
afterClose: this.removeContainer,
onClose: function onClose() {},
visible: false
});
} else {
this.removeContainer();
}
}
}, {
key: "render",
value: function render() {
var _this2 = this;
var visible = this.props.visible;
var portal = null;
if (!IS_REACT_16) {
var container = function container(_ref2) {
var renderComponent = _ref2.renderComponent,
removeContainer = _ref2.removeContainer;
_this2.renderComponent = renderComponent;
_this2.removeContainer = removeContainer;
return null;
};
return React.createElement(ContainerRender, {
parent: this,
visible: visible,
autoDestroy: false,
getComponent: this.getComponent,
getContainer: this.getContainer
}, container);
}
if (visible || this._component) {
portal = React.createElement(Portal, {
getContainer: this.getContainer
}, this.getComponent());
}
return portal;
}
}]);
return DialogWrap;
}(Component);
DialogWrap.defaultProps = {
visible: false
};
export default DialogWrap;
//# sourceMappingURL=DialogWrap.js.map