UNPKG

@nutui/nutui-react

Version:

京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序

74 lines (73 loc) 1.99 kB
import { _ as _object_spread } from "@swc/helpers/_/_object_spread"; import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props"; import Notification from "./Notification"; import { defaultOverlayProps } from "../overlay/overlay"; var messageInstance = null; var defaultProps = _object_spread_props(_object_spread({}, defaultOverlayProps), { id: '', position: 'middle', title: '', size: 'base', icon: null, content: '', contentClassName: '', contentStyle: {}, wordBreak: 'break-all', duration: 2, closeOnOverlayClick: false, lockScroll: false, zIndex: 1300, onClose: function() {} }); function getInstance(props, callback) { if (messageInstance) { messageInstance.destroy(); messageInstance = null; } Notification.newInstance(props, function(notification) { return callback && callback(notification); }); } function notice(opts) { function close() { if (messageInstance) { messageInstance.destroy(); messageInstance = null; opts.onClose && opts.onClose(); } } var opts2 = _object_spread_props(_object_spread({}, defaultProps, opts), { onClose: close }); getInstance(opts2, function(notification) { messageInstance = notification; }); } var errorMsg = function(msg) { if (!msg) { console.warn('[NutUI Toast]: msg cannot be null'); } }; function show(option) { if (typeof option === 'string') { errorMsg(option); return notice({ content: option }); } errorMsg(option.content); return notice(_object_spread({}, option)); } function config(config) { defaultProps = _object_spread({}, defaultProps, config); } export default { show: show, config: config, clear: function clear() { if (messageInstance) { messageInstance.destroy(); messageInstance = null; } } };