UNPKG

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