ant-design/components/message/index.jsx

52 lines
1.2 KiB
React
Raw Normal View History

2015-07-13 21:40:04 +08:00
import React from 'react';
import Notification from 'rc-notification';
2015-07-23 11:59:56 +08:00
let defaultDuration = 1.5;
2015-07-30 11:47:46 +08:00
let top;
2015-07-30 21:32:12 +08:00
var messageInstance;
2015-07-23 11:59:56 +08:00
function getMessageInstance() {
2015-07-30 21:32:12 +08:00
messageInstance = messageInstance || Notification.newInstance({
prefixCls: 'ant-message',
transitionName: 'move-up',
2015-07-30 11:47:46 +08:00
style: {
top: top
} // 覆盖原来的样式
});
2015-07-30 21:32:12 +08:00
return messageInstance;
2015-07-23 11:59:56 +08:00
}
function notice(content, duration = defaultDuration, type) {
let iconClass = ({
'info': 'anticon-info-circle ant-message-info',
'success': 'anticon-check-circle ant-message-success',
'error': 'anticon-exclamation-circle ant-message-error'
})[type];
getMessageInstance().notice({
duration: duration,
style: {},
content: <div className="ant-message-custom-content">
<i className={'anticon ' + iconClass}></i>
<span>{content}</span>
</div>
});
}
2015-07-11 18:00:58 +08:00
export default {
2015-07-23 11:59:56 +08:00
info(content, duration) {
notice(content, duration, 'info');
},
2015-07-23 11:59:56 +08:00
success(content, duration) {
notice(content, duration, 'success');
},
2015-07-23 11:59:56 +08:00
error(content, duration) {
notice(content, duration, 'error');
2015-07-30 11:47:46 +08:00
},
config(options) {
if (options.top) {
top = options.top;
}
}
};