dtd
Version:
根据数梦工场视觉规范打造的组件库,感谢react-components和ant design
1 lines • 2.67 kB
JavaScript
import _extends from"babel-runtime/helpers/extends";import*as React from"react";import Notification from"rc-notification";import Icon from"../icon";var notificationInstance={},defaultDuration=4.5,defaultTop=24,defaultBottom=24,defaultPlacement="topRight",defaultGetContainer=void 0;function setNotificationConfig(t){var e=t.duration,n=t.placement,o=t.bottom,a=t.top,i=t.getContainer;void 0!==e&&(defaultDuration=e),void 0!==n&&(defaultPlacement=n),void 0!==o&&(defaultBottom=o),void 0!==a&&(defaultTop=a),void 0!==i&&(defaultGetContainer=i)}function getPlacementStyle(t){var e=void 0;switch(t){case"topLeft":e={left:0,top:defaultTop,bottom:"auto"};break;case"topRight":e={right:0,top:defaultTop,bottom:"auto"};break;case"bottomLeft":e={left:0,top:"auto",bottom:defaultBottom};break;default:e={right:0,top:"auto",bottom:defaultBottom}}return e}function getNotificationInstance(t,e,n){var o=t+"-"+e;notificationInstance[o]?n(notificationInstance[o]):Notification.newInstance({prefixCls:t,className:t+"-"+e,style:getPlacementStyle(e),getContainer:defaultGetContainer},function(t){notificationInstance[o]=t,n(t)})}var typeToIcon={success:"check-circle",info:"info-circle",error:"close-circle",warning:"exclamation-circle"};function notice(t){var e=t.prefixCls||"dt-notification",n=e+"-notice",o=void 0===t.duration?defaultDuration:t.duration,a=null;if(t.icon)a=React.createElement("span",{className:n+"-icon"},t.icon);else if(t.type){var i=typeToIcon[t.type];a=React.createElement(Icon,{className:n+"-icon "+n+"-icon-"+t.type,type:i})}var c=!t.description&&a?React.createElement("span",{className:n+"-message-single-line-auto-margin"}):null;getNotificationInstance(e,t.placement||defaultPlacement,function(e){e.notice({content:React.createElement("div",null,React.createElement("div",{className:a?n+"-with-icon":""},a,React.createElement("div",{className:n+"-message"},c,t.message),React.createElement("div",{className:n+"-description"},t.description),t.btn&&!t.footer?React.createElement("span",{className:n+"-btn"},t.btn):null),t.footer?React.createElement("div",{className:n+"-footer"},t.footer):null),duration:o,closable:!0,onClose:t.onClose,key:t.key,style:t.style||{},className:t.className})})}var api={open:notice,close:function(t){Object.keys(notificationInstance).forEach(function(e){return notificationInstance[e].removeNotice(t)})},config:setNotificationConfig,destroy:function(){Object.keys(notificationInstance).forEach(function(t){notificationInstance[t].destroy(),delete notificationInstance[t]})}};["success","info","warning","error"].forEach(function(t){api[t]=function(e){return api.open(_extends({},e,{type:t}))}}),api.warn=api.warning;export default api;