@alifd/meet-react
Version:
Fusion Mobile React UI System Component
69 lines • 2.5 kB
JavaScript
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
import { __rest } from "tslib";
import React, { createElement } from "react";
import { renderToRoot } from '../utils/render';
import Message from './message';
import View from '../view';
import { isString } from '../utils';
var hideCurrent = null;
export var hide = function hide() {
if (hideCurrent) {
hideCurrent();
}
hideCurrent = null;
};
export var show = function show(options) {
var _options$shape = options.shape,
shape = _options$shape === void 0 ? 'toast' : _options$shape,
_options$prefix = options.prefix,
prefix = _options$prefix === void 0 ? 'mt-' : _options$prefix,
_options$duration = options.duration,
duration = _options$duration === void 0 ? 1500 : _options$duration,
content = options.content,
type = options.type,
onClose = options.onClose,
other = __rest(options, ["shape", "prefix", "duration", "content", "type", "onClose"]);
var clsPrefix = "".concat(prefix, "message");
hide();
var hideThis = renderToRoot( /*#__PURE__*/React.createElement(View, {
"disable-scroll": true
}, /*#__PURE__*/React.createElement(Message, _extends({
visible: true,
shape: shape,
type: type
}, other), content), /*#__PURE__*/React.createElement(View, {
"disable-scroll": true,
className: "".concat(clsPrefix, "-mask")
})), onClose);
hideCurrent = hideThis;
if (duration > 0) {
if (type === 'loading' && !('duration' in options)) {
return hideThis;
}
setTimeout(function () {
hideThis();
if (hideCurrent === hideThis) {
hideCurrent = null;
}
}, duration);
}
return hideThis;
};
var handleFastCall = function handleFastCall(type, options) {
var opts;
if (isString(options)) {
opts = {
title: options
};
} else {
opts = options;
}
return show(Object.assign(Object.assign({}, opts), {
type: type
}));
};
export var success = handleFastCall.bind(null, 'success');
export var error = handleFastCall.bind(null, 'error');
export var notice = handleFastCall.bind(null, 'notice');
export var help = handleFastCall.bind(null, 'help');
export var loading = handleFastCall.bind(null, 'loading');