-
Notifications
You must be signed in to change notification settings - Fork 183
/
DialogWrap.tsx
61 lines (53 loc) · 1.68 KB
/
DialogWrap.tsx
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
import * as React from 'react';
import Portal from '@rc-component/portal';
import Dialog from './Dialog';
import type { IDialogPropTypes } from './IDialogPropTypes';
// 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.
* */
const DialogWrap: React.FC<IDialogPropTypes> = (props: IDialogPropTypes) => {
const { visible, getContainer, forceRender, destroyOnClose = false, afterClose } = props;
const [animatedVisible, setAnimatedVisible] = React.useState<boolean>(visible);
React.useEffect(() => {
if (visible) {
setAnimatedVisible(true);
}
}, [visible]);
// // 渲染在当前 dom 里;
// if (getContainer === false) {
// return (
// <Dialog
// {...props}
// getOpenCount={() => 2} // 不对 body 做任何操作。。
// />
// );
// }
// Destroy on close will remove wrapped div
if (!forceRender && destroyOnClose && !animatedVisible) {
return null;
}
return (
<Portal
open={visible || forceRender || animatedVisible}
autoDestroy={false}
getContainer={getContainer}
autoLock={visible || animatedVisible}
>
<Dialog
{...props}
destroyOnClose={destroyOnClose}
afterClose={() => {
afterClose?.();
setAnimatedVisible(false);
}}
/>
</Portal>
);
};
DialogWrap.displayName = 'Dialog';
export default DialogWrap;