/
index.js
97 lines (95 loc) · 2.98 KB
/
index.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import React from 'react';
import Notification from 'rc-notification';
import Icon from '../icon';
var defaultDuration = 3;
var defaultTop = void 0;
var messageInstance = void 0;
var key = 1;
var prefixCls = 'ant-message';
var getContainer = void 0;
function getMessageInstance() {
messageInstance = messageInstance || Notification.newInstance({
prefixCls: prefixCls,
transitionName: 'move-up',
style: { top: defaultTop },
getContainer: getContainer
});
return messageInstance;
}
function notice(content) {
var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDuration;
var type = arguments[2];
var onClose = arguments[3];
var iconType = {
info: 'info-circle',
success: 'check-circle',
error: 'cross-circle',
warning: 'exclamation-circle',
loading: 'loading'
}[type];
var instance = getMessageInstance();
instance.notice({
key: key,
duration: duration,
style: {},
content: React.createElement(
'div',
{ className: prefixCls + '-custom-content ' + prefixCls + '-' + type },
React.createElement(Icon, { type: iconType }),
React.createElement(
'span',
null,
content
)
),
onClose: onClose
});
return function () {
var target = key++;
return function () {
instance.removeNotice(target);
};
}();
}
export default {
info: function info(content, duration, onClose) {
return notice(content, duration, 'info', onClose);
},
success: function success(content, duration, onClose) {
return notice(content, duration, 'success', onClose);
},
error: function error(content, duration, onClose) {
return notice(content, duration, 'error', onClose);
},
// Departed usage, please use warning()
warn: function warn(content, duration, onClose) {
return notice(content, duration, 'warning', onClose);
},
warning: function warning(content, duration, onClose) {
return notice(content, duration, 'warning', onClose);
},
loading: function loading(content, duration, onClose) {
return notice(content, duration, 'loading', onClose);
},
config: function config(options) {
if (options.top !== undefined) {
defaultTop = options.top;
messageInstance = null; // delete messageInstance for new defaultTop
}
if (options.duration !== undefined) {
defaultDuration = options.duration;
}
if (options.prefixCls !== undefined) {
prefixCls = options.prefixCls;
}
if (options.getContainer !== undefined) {
getContainer = options.getContainer;
}
},
destroy: function destroy() {
if (messageInstance) {
messageInstance.destroy();
messageInstance = null;
}
}
};