69 lines
3.4 KiB
JavaScript
69 lines
3.4 KiB
JavaScript
"use strict";
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
var _portal = _interopRequireDefault(require("@rc-component/portal"));
|
|
var React = _interopRequireWildcard(require("react"));
|
|
var _context = require("./context");
|
|
var _Dialog = _interopRequireDefault(require("./Dialog"));
|
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
// fix issue #10656
|
|
/*
|
|
* getContainer remarks
|
|
* Custom container should not be return, because in the Portal component, it will remove the
|
|
* return container element here, if the custom container is the only child of it's component,
|
|
* like issue #10656, It will has a conflict with removeChild method in react-dom.
|
|
* So here should add a child (div element) to custom container.
|
|
* */
|
|
|
|
var DialogWrap = function DialogWrap(props) {
|
|
var visible = props.visible,
|
|
getContainer = props.getContainer,
|
|
forceRender = props.forceRender,
|
|
_props$destroyOnClose = props.destroyOnClose,
|
|
destroyOnClose = _props$destroyOnClose === void 0 ? false : _props$destroyOnClose,
|
|
_afterClose = props.afterClose,
|
|
panelRef = props.panelRef;
|
|
var _React$useState = React.useState(visible),
|
|
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
|
|
animatedVisible = _React$useState2[0],
|
|
setAnimatedVisible = _React$useState2[1];
|
|
var refContext = React.useMemo(function () {
|
|
return {
|
|
panel: panelRef
|
|
};
|
|
}, [panelRef]);
|
|
React.useEffect(function () {
|
|
if (visible) {
|
|
setAnimatedVisible(true);
|
|
}
|
|
}, [visible]);
|
|
|
|
// Destroy on close will remove wrapped div
|
|
if (!forceRender && destroyOnClose && !animatedVisible) {
|
|
return null;
|
|
}
|
|
return /*#__PURE__*/React.createElement(_context.RefContext.Provider, {
|
|
value: refContext
|
|
}, /*#__PURE__*/React.createElement(_portal.default, {
|
|
open: visible || forceRender || animatedVisible,
|
|
autoDestroy: false,
|
|
getContainer: getContainer,
|
|
autoLock: visible || animatedVisible
|
|
}, /*#__PURE__*/React.createElement(_Dialog.default, (0, _extends2.default)({}, props, {
|
|
destroyOnClose: destroyOnClose,
|
|
afterClose: function afterClose() {
|
|
_afterClose === null || _afterClose === void 0 || _afterClose();
|
|
setAnimatedVisible(false);
|
|
}
|
|
}))));
|
|
};
|
|
DialogWrap.displayName = 'Dialog';
|
|
var _default = exports.default = DialogWrap; |