UNPKG

@shopware-ag/meteor-component-library

Version:

The meteor component library is a Vue component library developed by Shopware. It is based on the [Meteor Design System](https://shopware.design/).

111 lines (110 loc) 4.11 kB
import '../mt-toast.css'; import { defineComponent, ref, toRef, computed, watch, openBlock, createElementBlock, normalizeClass, createElementVNode, createVNode, Transition, withCtx, createBlock, createCommentVNode, TransitionGroup, Fragment, renderList, normalizeStyle } from "vue"; import MtToastNotification from "./MtToastNotification.js"; import { _ as _export_sfc } from "../_plugin-vue_export-helper-cc2b3d55.mjs"; import "../mt-icon.vue_vue_type_style_index_0_lang-2cc5f73e.mjs"; import "./MtButton.js"; import "../useIsInsideTooltip-0c3bd290.mjs"; import "./MtLoader.js"; import "./MtText.js"; const _hoisted_1 = { class: "mt-toast--bottom-center" }; const _hoisted_2 = { class: "mt-toast--bottom-right" }; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "mt-toast", props: { /** * A collection of toasts. The most current one needs to be prepended. */ toasts: { type: Array, required: true } }, emits: ["remove-toast"], setup(__props, { emit: __emit }) { const emit = __emit; const props = __props; const isHovered = ref(false); const toasts = toRef(() => props.toasts); const hoverTimeoutId = ref(void 0); const quickToast = computed(() => { const ct = toasts.value.filter((t) => { return !t.action && t.type !== "critical" && !t.dismissible; }); return ct[0]; }); const rightToasts = computed(() => { return toasts.value.filter((t) => { return t.action || t.type === "critical" || t.dismissible; }); }); const classes = computed(() => { return { "mt-toast--collapsed": !isHovered.value, "mt-toast--expanded": isHovered.value }; }); watch(quickToast, (_, oldToast) => { if (!oldToast) { return; } emit("remove-toast", oldToast.id); }); function onMouseEnter() { if (hoverTimeoutId.value) { window.clearTimeout(hoverTimeoutId.value); } isHovered.value = true; } function onMouseLeave() { hoverTimeoutId.value = window.setTimeout(() => { isHovered.value = false; }, 500); } return (_ctx, _cache) => { return openBlock(), createElementBlock("div", { class: normalizeClass(["mt-toast", classes.value]), onMouseenter: onMouseEnter, onMouseleave: onMouseLeave }, [ _cache[1] || (_cache[1] = createElementVNode("div", { class: "mt-toast--bottom-left" }, null, -1)), createElementVNode("div", _hoisted_1, [ createVNode(Transition, { name: "quick-toasts" }, { default: withCtx(() => [ quickToast.value ? (openBlock(), createBlock(MtToastNotification, { toast: quickToast.value, onRemoveToast: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("remove-toast", quickToast.value.id)), "quick-display": true, key: quickToast.value.id }, null, 8, ["toast"])) : createCommentVNode("", true) ]), _: 1 }) ]), createElementVNode("div", _hoisted_2, [ createVNode(TransitionGroup, { name: "toasts" }, { default: withCtx(() => [ (openBlock(true), createElementBlock(Fragment, null, renderList(rightToasts.value, (toast, index) => { return openBlock(), createBlock(MtToastNotification, { key: toast.id, toast, onRemoveToast: ($event) => _ctx.$emit("remove-toast", toast.id), style: normalizeStyle({ "--num": index }), index }, null, 8, ["toast", "onRemoveToast", "style", "index"]); }), 128)) ]), _: 1 }) ]) ], 34); }; } }); const mtToast_vue_vue_type_style_index_0_scoped_49c93b73_lang = ""; const mtToast_vue_vue_type_style_index_1_lang = ""; const mtToast = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-49c93b73"]]); export { mtToast as default }; //# sourceMappingURL=MtToast.js.map