-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.tsx
46 lines (40 loc) · 1.15 KB
/
index.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
import React from 'react';
import { showDialog } from '../Dialog';
import { AlertWrapper, AlertWrapperProps } from './Wrapper';
import isPlainObject from 'lodash/isPlainObject';
import omit from 'lodash/omit';
export interface ShowAlertOption extends AlertWrapperProps {
// 是否显示遮罩,主要是提供一个便捷选项
showMask?: boolean;
}
/**
* 显示弹框
* @param option
*/
export function showAlert(option: React.ReactNode | ShowAlertOption) {
let config: ShowAlertOption;
if (React.isValidElement(option) || !isPlainObject(option)) {
config = {
title: option as React.ReactNode,
};
} else {
config = option as ShowAlertOption;
}
// 组件选项
const props: AlertWrapperProps = omit(config, ['showMask']);
props.onCancel = async () => {
await closeDialog();
config.onCancel?.();
};
props.onConfirm = async () => {
await closeDialog();
config.onConfirm?.();
};
// 创建对话框
const closeDialog = showDialog({
showMask: typeof config.showMask === 'undefined' ? true : !!config.showMask,
content: <AlertWrapper {...props} />,
});
// 返回关闭逻辑
return closeDialog;
}