@aimake/nanod
Version:
## 设计模式 NANO DESIGN 是面向于企业级中台化应用的解决方案。服务于 ToB 和 ToE 类型的单页应用,应用于各产品中从而产出了一套设计及前端规范。
220 lines (192 loc) • 5.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var React = _interopRequireWildcard(require("react"));
var _rcNotification = _interopRequireDefault(require("rc-notification"));
var _icon = _interopRequireDefault(require("../icon"));
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { "default": obj };
}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
} else {
var newObj = {};if (obj != null) {
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};if (desc.get || desc.set) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
}newObj["default"] = obj;return newObj;
}
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}return target;
};return _extends.apply(this, arguments);
}
var notificationInstance = {};
var defaultDuration = 4.5;
var defaultTop = 24;
var defaultBottom = 24;
var defaultPlacement = 'topRight';
var defaultGetContainer;
function setNotificationConfig(options) {
var duration = options.duration,
placement = options.placement,
bottom = options.bottom,
top = options.top,
getContainer = options.getContainer;
if (duration !== undefined) {
defaultDuration = duration;
}
if (placement !== undefined) {
defaultPlacement = placement;
}
if (bottom !== undefined) {
defaultBottom = bottom;
}
if (top !== undefined) {
defaultTop = top;
}
if (getContainer !== undefined) {
defaultGetContainer = getContainer;
}
}
function getPlacementStyle(placement) {
var style;
switch (placement) {
case 'topLeft':
style = {
left: 0,
top: defaultTop,
bottom: 'auto'
};
break;
case 'topRight':
style = {
right: 0,
top: defaultTop,
bottom: 'auto'
};
break;
case 'bottomLeft':
style = {
left: 0,
top: 'auto',
bottom: defaultBottom
};
break;
default:
style = {
right: 0,
top: 'auto',
bottom: defaultBottom
};
break;
}
return style;
}
function getNotificationInstance(prefixCls, placement, callback) {
var cacheKey = "".concat(prefixCls, "-").concat(placement);
if (notificationInstance[cacheKey]) {
callback(notificationInstance[cacheKey]);
return;
}
_rcNotification["default"].newInstance({
prefixCls: prefixCls,
className: "".concat(prefixCls, "-").concat(placement),
style: getPlacementStyle(placement),
getContainer: defaultGetContainer,
closeIcon: React.createElement(_icon["default"], {
className: "".concat(prefixCls, "-close-icon"),
type: 'close'
})
}, function (notification) {
notificationInstance[cacheKey] = notification;
callback(notification);
});
}
var typeToIcon = {
success: 'check-circle-o',
info: 'info-circle-o',
error: 'close-circle-o',
warning: 'exclamation-circle-o'
};
function notice(args) {
var outerPrefixCls = args.prefixCls || 'ant-notification';
var prefixCls = "".concat(outerPrefixCls, "-notice");
var duration = args.duration === undefined ? defaultDuration : args.duration;
var iconNode = null;
if (args.icon) {
iconNode = React.createElement("span", {
className: "".concat(prefixCls, "-icon")
}, args.icon);
} else if (args.type) {
var iconType = typeToIcon[args.type];
iconNode = React.createElement(_icon["default"], {
className: "".concat(prefixCls, "-icon ").concat(prefixCls, "-icon-").concat(args.type),
type: iconType
});
}
var autoMarginTag = !args.description && iconNode ? React.createElement("span", {
className: "".concat(prefixCls, "-message-single-line-auto-margin")
}) : null;
getNotificationInstance(outerPrefixCls, args.placement || defaultPlacement, function (notification) {
notification.notice({
content: React.createElement("div", {
className: iconNode ? "".concat(prefixCls, "-with-icon") : ''
}, iconNode, React.createElement("div", {
className: "".concat(prefixCls, "-message")
}, autoMarginTag, args.message), React.createElement("div", {
className: "".concat(prefixCls, "-description")
}, args.description), args.btn ? React.createElement("span", {
className: "".concat(prefixCls, "-btn")
}, args.btn) : null),
duration: duration,
closable: true,
onClose: args.onClose,
onClick: args.onClick,
key: args.key,
style: args.style || {},
className: args.className
});
});
}
var api = {
open: notice,
close: function close(key) {
Object.keys(notificationInstance).forEach(function (cacheKey) {
return notificationInstance[cacheKey].removeNotice(key);
});
},
config: setNotificationConfig,
destroy: function destroy() {
Object.keys(notificationInstance).forEach(function (cacheKey) {
notificationInstance[cacheKey].destroy();
delete notificationInstance[cacheKey];
});
}
};
['success', 'info', 'warning', 'error'].forEach(function (type) {
api[type] = function (args) {
return api.open(_extends({}, args, {
type: type
}));
};
});
api.warn = api.warning;
var _default = api;
exports["default"] = _default;