DialogWrap.js
2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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 React = _interopRequireWildcard(require("react"));
var _PortalWrapper = _interopRequireDefault(require("rc-util/lib/PortalWrapper"));
var _Dialog = _interopRequireDefault(require("./Dialog"));
// 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;
var _React$useState = React.useState(visible),
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
animatedVisible = _React$useState2[0],
setAnimatedVisible = _React$useState2[1];
React.useEffect(function () {
if (visible) {
setAnimatedVisible(true);
}
}, [visible]); // 渲染在当前 dom 里;
if (getContainer === false) {
return /*#__PURE__*/React.createElement(_Dialog.default, (0, _extends2.default)({}, props, {
getOpenCount: function getOpenCount() {
return 2;
} // 不对 body 做任何操作。。
}));
} // Destroy on close will remove wrapped div
if (!forceRender && destroyOnClose && !animatedVisible) {
return null;
}
return /*#__PURE__*/React.createElement(_PortalWrapper.default, {
visible: visible,
forceRender: forceRender,
getContainer: getContainer
}, function (childProps) {
return /*#__PURE__*/React.createElement(_Dialog.default, (0, _extends2.default)({}, props, {
destroyOnClose: destroyOnClose,
afterClose: function afterClose() {
_afterClose === null || _afterClose === void 0 ? void 0 : _afterClose();
setAnimatedVisible(false);
}
}, childProps));
});
};
DialogWrap.displayName = 'Dialog';
var _default = DialogWrap;
exports.default = _default;