UNPKG

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