mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 19:49:59 +08:00
3ce6139169
修复高度设置的 key 错误
90 lines
2.2 KiB
JavaScript
90 lines
2.2 KiB
JavaScript
import React from 'react';
|
|
import Notification from 'rc-notification';
|
|
import Icon from '../icon';
|
|
import warning from 'warning';
|
|
|
|
let defaultDuration = 1.5;
|
|
let defaultTop;
|
|
let messageInstance;
|
|
let key = 1;
|
|
let prefixCls = 'ant-message';
|
|
|
|
function getMessageInstance() {
|
|
messageInstance = messageInstance || Notification.newInstance({
|
|
prefixCls,
|
|
transitionName: 'move-up',
|
|
style: { top: defaultTop }, // 覆盖原来的样式
|
|
});
|
|
return messageInstance;
|
|
}
|
|
|
|
function notice(content, duration = defaultDuration, type, onClose) {
|
|
let iconType = ({
|
|
info: 'info-circle',
|
|
success: 'check-circle',
|
|
error: 'cross-circle',
|
|
warning: 'exclamation-circle',
|
|
loading: 'loading',
|
|
})[type];
|
|
|
|
let instance = getMessageInstance();
|
|
instance.notice({
|
|
key,
|
|
duration,
|
|
style: {},
|
|
content: (
|
|
<div className={`${prefixCls}-custom-content ${prefixCls}-${type}`}>
|
|
<Icon type={iconType} />
|
|
<span>{content}</span>
|
|
</div>
|
|
),
|
|
onClose,
|
|
});
|
|
return (function () {
|
|
let target = key++;
|
|
return function () {
|
|
instance.removeNotice(target);
|
|
};
|
|
}());
|
|
}
|
|
|
|
export default {
|
|
info(content, duration, onClose) {
|
|
return notice(content, duration, 'info', onClose);
|
|
},
|
|
success(content, duration, onClose) {
|
|
return notice(content, duration, 'success', onClose);
|
|
},
|
|
error(content, duration, onClose) {
|
|
return notice(content, duration, 'error', onClose);
|
|
},
|
|
// Departed usage, please use warning()
|
|
warn(content, duration, onClose) {
|
|
warning(false, 'message.warn() is departed, please use message.warning()');
|
|
return notice(content, duration, 'warning', onClose);
|
|
},
|
|
warning(content, duration, onClose) {
|
|
return notice(content, duration, 'warning', onClose);
|
|
},
|
|
loading(content, duration, onClose) {
|
|
return notice(content, duration, 'loading', onClose);
|
|
},
|
|
config(options) {
|
|
if ('top' in options) {
|
|
defaultTop = options.top;
|
|
}
|
|
if ('duration' in options) {
|
|
defaultDuration = options.duration;
|
|
}
|
|
if ('prefixCls' in options) {
|
|
prefixCls = options.prefixCls;
|
|
}
|
|
},
|
|
destroy() {
|
|
if (messageInstance) {
|
|
messageInstance.destroy();
|
|
messageInstance = null;
|
|
}
|
|
},
|
|
};
|