import Vue from 'vue'; import { MToast, MToastPosition, MToastState, MToastTimeout } from '../../components/toast/toast'; export interface ToastParams { text: string; // Can be html, but must start with a root tag:
text of toast
actionLabel?: string; action?: (event: Event) => any; state?: MToastState; position?: MToastPosition; timeout?: MToastTimeout; icon?: boolean; closeButton?: boolean; } const TIME_BEFORE_ANIMATION_IS_OVER: number = 300; export default class ToastService { public activeToast?: MToast; public toasts: MToast[] = []; public baseTopPosition: string = '0'; public show(params: ToastParams): void { const toast: MToast = this.createToast(params); this.toasts.push(toast); if (this.activeToast) { this.activeToast.open = false; this.activeToast = this.toasts[1]; this.toasts.splice(0, 1); } else { this.activeToast = this.toasts[0]; } } public async clear(): Promise${params.text}
`; if (Vue.compile !== undefined) { toast.$slots.default = [toast.$createElement(Vue.compile(params.text))]; } else { toast.$slots.default = [toast.$createElement('div', { domProps: { innerHTML: params.text } })]; } return toast; } }