@jdcfe/yep-react
Version:
一套移动端的React组件库
107 lines (88 loc) • 4.09 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _CheckCircleOutlined = _interopRequireDefault(require("@jdcfe/icons-react/CheckCircleOutlined"));
var _TipOutlined = _interopRequireDefault(require("@jdcfe/icons-react/TipOutlined"));
var _icon = _interopRequireDefault(require("../icon"));
var _Notification = _interopRequireDefault(require("./Notification"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var JiaZai = _icon.default.JiaZai;
var messageInstance = null;
var SHORT = 3;
var options = {
duration: SHORT,
mask: false
};
function getInstance(props, callback) {
if (messageInstance) {
messageInstance.destroy();
messageInstance = null;
}
_Notification.default.newInstance(props, function (notification) {
return callback && callback(notification);
});
}
function notice(message, icon) {
var duration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : options.duration;
var onClose = arguments.length > 3 ? arguments[3] : undefined;
var mask = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : options.mask;
function close() {
if (messageInstance) {
messageInstance.destroy();
messageInstance = null;
}
if (onClose) {
onClose();
}
}
getInstance({
message: message,
icon: icon,
duration: duration,
onClose: close,
mask: mask
}, function (notification) {
messageInstance = notification;
});
}
var _default = {
SHORT: SHORT,
LONG: 8,
show: function show(message, duration, onClose, mask) {
return notice(message, null, duration, onClose, mask);
},
success: function success(message, duration, onClose, mask) {
return notice(message, /*#__PURE__*/React.createElement(_CheckCircleOutlined.default, null), duration, onClose, mask);
},
fail: function fail(message, duration, onClose, mask) {
return notice(message, /*#__PURE__*/React.createElement(_TipOutlined.default, null), duration, onClose, mask);
},
loading: function loading(message, duration, onClose, mask) {
return notice(message, /*#__PURE__*/React.createElement(JiaZai, {
className: 'Yep-toast-notice-icon Yep-icon-jiazai'
}), duration, onClose, mask);
},
hide: function hide() {
if (messageInstance) {
messageInstance.destroy();
messageInstance = null;
}
},
config: function config() {
var option = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _option$duration = option.duration,
duration = _option$duration === void 0 ? SHORT : _option$duration,
mask = option.mask;
options.duration = duration;
if (mask === true) {
options.mask = true;
}
}
};
exports.default = _default;
;