UNPKG

@jdcfe/yep-react

Version:

一套移动端的React组件库

86 lines (78 loc) 2.49 kB
import * as React from 'react'; import CheckCircleOutlined from '@jdcfe/icons-react/CheckCircleOutlined'; import TipOutlined from '@jdcfe/icons-react/TipOutlined'; import Icon from '../icon'; import Notification from './Notification'; var JiaZai = Icon.JiaZai; var messageInstance = null; var SHORT = 3; var options = { duration: SHORT, mask: false }; function getInstance(props, callback) { if (messageInstance) { messageInstance.destroy(); messageInstance = null; } Notification.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; }); } export 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, null), duration, onClose, mask); }, fail: function fail(message, duration, onClose, mask) { return notice(message, /*#__PURE__*/React.createElement(TipOutlined, 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; } } };