UNPKG

miniapp-web-jsapi

Version:

JSAPI/View adapter for miniprogram running on the web

35 lines 1.13 kB
import Toast from "../../components/toast"; import AdapterEvents from "../../events/events"; import { defaultEventManager } from "../../events"; export function showToast(options) { var _ref = options || {}, content = _ref.content, type = _ref.type, _ref$duration = _ref.duration, duration = _ref$duration === void 0 ? 2000 : _ref$duration, success = _ref.success, complete = _ref.complete; if (!content) { return; } var div = document.createElement('div'); document.body.appendChild(div); var toast = new Toast({ target: div, props: { content: content, type: type, duration: duration, onClose: function onClose() { var _div$parentNode; success === null || success === void 0 ? void 0 : success(); complete === null || complete === void 0 ? void 0 : complete(); toast.$destroy(); (_div$parentNode = div.parentNode) === null || _div$parentNode === void 0 ? void 0 : _div$parentNode.removeChild(div); } } }); } export function hideToast(options) { defaultEventManager.notifyEvent(AdapterEvents.ToastHide); }