ant-design/components/message/index.jsx

42 lines
1.0 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-23 11:59:56 +08:00
function getMessageInstance() {
2015-07-11 18:00:58 +08:00
return Notification.newInstance({
prefixCls: 'ant-message',
transitionName: 'move-up',
2015-07-11 18:19:48 +08:00
style: {} // 覆盖原来的样式
});
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({
key: 'simpleMessage',
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');
}
};