You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design/components/notification/index.jsx

93 lines
2.3 KiB
React

10 years ago
import Notification from 'rc-notification';
10 years ago
let top = 24;
var notificationInstance;
function getNotificationInstance() {
notificationInstance = notificationInstance || Notification.newInstance({
prefixCls: 'ant-notification',
style: {
top: top,
right: 0
}
});
return notificationInstance;
}
10 years ago
function notice(args) {
10 years ago
if (args.icon) {
let prefixCls = ' ant-notification-notice-content-icon-';
let iconClass = 'anticon anticon-';
switch (args.icon) {
case 'success':
iconClass += 'check-circle-o';
break;
case 'info':
iconClass += 'info-circle-o';
break;
case 'error':
iconClass += 'exclamation-circle-o';
break;
case 'warn':
iconClass += 'question-circle-o';
break;
default:
iconClass += 'info-circle';
}
10 years ago
getNotificationInstance().notice({
10 years ago
content: <div>
<i className={iconClass + prefixCls + 'icon-' + args.icon + prefixCls + 'icon'}></i>
10 years ago
<p className={prefixCls + 'message'}>{args.message}</p>
10 years ago
<p className={prefixCls + 'description'}>{args.description}</p>
10 years ago
</div>,
duration: null,
closable: true,
onClose: args.defaultClose,
10 years ago
style: {}
});
} else {
let prefixCls = 'ant-notification-notice-content-';
10 years ago
if (!args.btn) {
10 years ago
getNotificationInstance().notice({
10 years ago
content: <div>
<p className={prefixCls + 'message'}>{args.message}</p>
<p className={prefixCls + 'description'}>{args.description}</p>
</div>,
10 years ago
duration: null,
closable: true,
onClose: args.defaultClose,
10 years ago
style: {}
});
} else {
10 years ago
getNotificationInstance().notice({
10 years ago
content: <div>
<p className={prefixCls + 'message'}>{args.message}</p>
10 years ago
<p className={prefixCls + 'description'}>{args.description}</p>
<span className={prefixCls + 'btn'}>
10 years ago
{args.btn}
</span>
10 years ago
</div>,
duration: null,
closable: true,
onClose: args.onClose,
key: args.key,
10 years ago
style: {}
});
}
}
}
10 years ago
export default {
open(args){
notice(args);
},
close(key){
Notification.notification.removeNotice(key);
10 years ago
},
config(options) {
top = isNaN(options.top) ? 24 : options.top;
}
};