forked from ant-design/ant-design-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert.tsx
43 lines (37 loc) · 1.02 KB
/
alert.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
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import Modal from './Modal';
export default function (...args) {
const title = args[0];
const content = args[1];
const actions = args[2] || [{ text: '确定' }];
if (!title && !content) {
// console.log('Must specify either an alert title, or message, or both');
return;
}
const prefixCls = 'am-modal';
let div = document.createElement('div');
document.body.appendChild(div);
function close() {
ReactDOM.unmountComponentAtNode(div);
div.parentNode.removeChild(div);
}
const footer = actions.map((button) => {
const orginPress = button.onPress || function() {};
button.onPress = () => {
orginPress();
close();
};
return button;
});
ReactDOM.render(<Modal
visible
transparent
prefixCls={prefixCls}
title={title}
transitionName="am-zoom"
footer={footer}
maskTransitionName="am-fade">
<div style={{ zoom: 1, overflow: 'hidden' }}>{content}</div>
</Modal>, div);
}