@gitlab/ui
Version:
GitLab UI Components
88 lines (77 loc) • 2.66 kB
JavaScript
import { MountingPortal } from 'portal-vue';
import GlToast from './toast';
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
const hasViewTransitions = typeof document !== 'undefined' && typeof document.startViewTransition === 'function';
var script = {
name: 'GlToaster',
components: {
MountingPortal,
GlToast
},
expose: ['addToast', 'hideToast', 'removeToast'],
data() {
return {
toasts: []
};
},
methods: {
addToast(config) {
const add = () => this.toasts.push(config);
if (hasViewTransitions && this.toasts.length > 0) {
document.startViewTransition(add);
} else {
add();
}
},
hideToast(id) {
const refs = this.$refs.toastRefs;
if (!refs) return;
const toastComponents = Array.isArray(refs) ? refs : [refs];
const component = toastComponents.find(c => c.toastId === id);
if (component) {
component.hide();
}
},
removeToast(id) {
const idx = this.toasts.findIndex(t => t.id === id);
if (idx !== -1) {
const toast = this.toasts[idx];
this.toasts.splice(idx, 1);
if (toast.onComplete) {
toast.onComplete({
componentId: id
});
}
}
}
}
};
/* script */
const __vue_script__ = script;
/* template */
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('mounting-portal',{attrs:{"mount-to":"body","append":""}},[_c('div',{staticClass:"b-toaster b-toaster-bottom-left",attrs:{"id":"gl-toaster"}},[_c('div',{staticClass:"b-toaster-slot"},_vm._l((_vm.toasts),function(toast){return _c('gl-toast',{key:toast.id,ref:"toastRefs",refInFor:true,attrs:{"toast-id":toast.id,"message":toast.message,"action":toast.action,"auto-hide-delay":toast.autoHideDelay},on:{"hidden":_vm.removeToast}})}),1)])])};
var __vue_staticRenderFns__ = [];
/* style */
const __vue_inject_styles__ = undefined;
/* scoped */
const __vue_scope_id__ = undefined;
/* module identifier */
const __vue_module_identifier__ = undefined;
/* functional template */
const __vue_is_functional_template__ = false;
/* style inject */
/* style inject SSR */
/* style inject shadow dom */
const __vue_component__ = /*#__PURE__*/__vue_normalize__(
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
__vue_inject_styles__,
__vue_script__,
__vue_scope_id__,
__vue_is_functional_template__,
__vue_module_identifier__,
false,
undefined,
undefined,
undefined
);
export { __vue_component__ as default };