forked from alibaba/ice
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreateFuncDialog.jsx
More file actions
44 lines (40 loc) · 1.1 KB
/
CreateFuncDialog.jsx
File metadata and controls
44 lines (40 loc) · 1.1 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
import React from 'react';
import ReactDOM from 'react-dom';
// 包装 Dialog 类组件,使其支持 show、hide 这种命令式调用
const CreateFuncDialog = (WrapperElement) => {
let instance = null;
let container = null;
return {
// 创建并打开一个弹窗,并传入初始化的 props
show: (props) => {
// 如果已经有实例打开了,则不会继续打开
if (instance) {
return;
}
container = document.createElement('div'); /* eslint no-undef: "off" */
document.body.appendChild(container);
instance = ReactDOM.render(
<WrapperElement {...props} visible />,
container,
);
},
// 隐藏并销毁弹窗
hide: () => {
if (instance) {
instance.setState(
{
visible: false,
},
() => {
setTimeout(() => {
ReactDOM.unmountComponentAtNode(container);
instance = null;
container.parentNode.removeChild(container);
}, 1000);
},
);
}
},
};
};
export default CreateFuncDialog;