ant-design/components/notification/index.jsx

72 lines
1.9 KiB
React
Raw Normal View History

2015-07-28 15:40:28 +08:00
import Notification from 'rc-notification';
2015-07-31 18:13:32 +08:00
function getNotificationInstance() {
2015-07-30 21:04:52 +08:00
if (!Notification.notification) {
Notification.notification = Notification.newInstance({
prefixCls: 'ant-notification',
style: {
top: 0,
right: 0
}
});
2015-07-28 15:40:28 +08:00
}
2015-07-31 18:13:32 +08:00
return Notification.notification;
}
2015-07-28 15:40:28 +08:00
2015-07-31 18:13:32 +08:00
function notice(args) {
getNotificationInstance();
2015-07-28 15:40:28 +08:00
if (args.icon) {
let prefixCls = 'ant-notification-notice-content-icon-';
Notification.notification.notice({
content: <div>
<i className={'anticon anticon-question-circle-o ' + prefixCls + 'icon'}></i>
<p className={prefixCls + 'message'}>{args.message}</p>
2015-07-29 20:08:16 +08:00
<p className={prefixCls + 'description'}>{args.description}</p>
2015-07-28 15:40:28 +08:00
</div>,
duration: null,
closable: true,
2015-07-30 21:04:52 +08:00
onClose: args.onClose,
2015-07-28 15:40:28 +08:00
style: {}
});
} else {
if (!args.btn) {
let prefixCls = 'ant-notification-notice-content-';
Notification.notification.notice({
content: <div>
2015-07-30 21:04:52 +08:00
<p className={prefixCls + 'message'}>{args.message}</p>
<p className={prefixCls + 'description'}>{args.description}</p>
</div>,
2015-07-28 15:40:28 +08:00
duration: null,
closable: true,
2015-07-30 21:04:52 +08:00
onClose: args.onClose,
2015-07-28 15:40:28 +08:00
style: {}
});
} else {
let prefixCls = 'ant-notification-notice-content-';
Notification.notification.notice({
content: <div>
<p className={prefixCls + 'message'}>{args.message}</p>
2015-07-29 20:08:16 +08:00
<p className={prefixCls + 'description'}>{args.description}</p>
2015-07-31 18:13:32 +08:00
<span className={prefixCls + 'btn'}>
2015-07-29 20:08:16 +08:00
{args.btn}
</span>
2015-07-28 15:40:28 +08:00
</div>,
duration: null,
closable: true,
2015-07-30 21:04:52 +08:00
onClose: args.onClose,
2015-07-31 18:13:32 +08:00
key: args.key,
2015-07-28 15:40:28 +08:00
style: {}
});
}
}
2015-07-31 18:13:32 +08:00
}
2015-07-28 15:40:28 +08:00
2015-07-31 18:13:32 +08:00
export default {
open(args){
notice(args);
},
close(key){
Notification.notification.removeNotice(key);
}
};