@nutui/nutui-react
Version:
京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序
55 lines (54 loc) • 1.59 kB
JavaScript
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import * as React from "react";
import Notification from "./Notification";
import { ComponentDefaults } from "../../utils/typings";
var messageInstance = null;
var options = _object_spread_props(_object_spread({}, ComponentDefaults), {
id: '',
position: 'top',
distance: 8,
navHeight: 57,
closeable: false,
leftIcon: null,
rightIcon: null,
duration: 3000,
onClose: function() {},
onClick: function() {}
});
function getInstance(props, callback) {
if (messageInstance) {
messageInstance.destroy();
messageInstance = null;
}
Notification.newInstance(props, function(notification) {
return callback && callback(notification);
});
}
function notice(opts) {
opts = _object_spread({}, options, opts);
getInstance(opts, function(notification) {
messageInstance = notification;
});
}
var errorMsg = function(message) {
if (!message) {
console.warn('[NutUI Notify]: message不能为空');
}
};
export default {
text: function text(message) {
var option = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
errorMsg(message);
return notice(_object_spread({
message: message,
type: 'base'
}, option));
},
hide: function hide() {
if (messageInstance) {
messageInstance.destroy();
messageInstance = null;
}
}
};