UNPKG

2.41 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = void 0;
11
12var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
14var React = _interopRequireWildcard(require("react"));
15
16var _PortalWrapper = _interopRequireDefault(require("rc-util/lib/PortalWrapper"));
17
18var _Dialog = _interopRequireDefault(require("./Dialog"));
19
20// fix issue #10656
21
22/*
23 * getContainer remarks
24 * Custom container should not be return, because in the Portal component, it will remove the
25 * return container element here, if the custom container is the only child of it's component,
26 * like issue #10656, It will has a conflict with removeChild method in react-dom.
27 * So here should add a child (div element) to custom container.
28 * */
29var DialogWrap = function DialogWrap(props) {
30 var visible = props.visible,
31 getContainer = props.getContainer,
32 forceRender = props.forceRender,
33 destroyOnClose = props.destroyOnClose,
34 _afterClose = props.afterClose;
35
36 var _React$useState = React.useState(visible),
37 _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
38 animatedVisible = _React$useState2[0],
39 setAnimatedVisible = _React$useState2[1];
40
41 React.useEffect(function () {
42 if (visible) {
43 setAnimatedVisible(true);
44 }
45 }, [visible]); // 渲染在当前 dom 里;
46
47 if (getContainer === false) {
48 return React.createElement(_Dialog.default, Object.assign({}, props, {
49 getOpenCount: function getOpenCount() {
50 return 2;
51 }
52 }));
53 } // Destroy on close will remove wrapped div
54
55
56 if (!forceRender && destroyOnClose && !animatedVisible) {
57 return null;
58 }
59
60 return React.createElement(_PortalWrapper.default, {
61 visible: visible,
62 forceRender: forceRender,
63 getContainer: getContainer
64 }, function (childProps) {
65 return React.createElement(_Dialog.default, Object.assign({}, props, {
66 afterClose: function afterClose() {
67 _afterClose === null || _afterClose === void 0 ? void 0 : _afterClose();
68 setAnimatedVisible(false);
69 }
70 }, childProps));
71 });
72};
73
74DialogWrap.displayName = 'Dialog';
75var _default = DialogWrap;
76exports.default = _default;
\No newline at end of file