(
Vue: VueConstructor,
globalOptions: PluginOptions = {},
mountContainer = true
)
| 13 | import { getId, isUndefined } from "./utils"; |
| 14 | |
| 15 | const ToastInterface = ( |
| 16 | Vue: VueConstructor, |
| 17 | globalOptions: PluginOptions = {}, |
| 18 | mountContainer = true |
| 19 | ) => { |
| 20 | const events = (globalOptions.eventBus = globalOptions.eventBus || new Vue()); |
| 21 | if (mountContainer) { |
| 22 | const containerComponent = new (Vue.extend(ToastContainer))({ |
| 23 | el: document.createElement("div"), |
| 24 | propsData: globalOptions, |
| 25 | }); |
| 26 | const onMounted = globalOptions.onMounted; |
| 27 | if (!isUndefined(onMounted)) { |
| 28 | onMounted(containerComponent); |
| 29 | } |
| 30 | } |
| 31 | /** |
| 32 | * Display a toast |
| 33 | */ |
| 34 | const toast = (content: ToastContent, options?: ToastOptions): ToastID => { |
| 35 | const props: ToastOptionsAndRequiredContent & { |
| 36 | id: ToastID; |
| 37 | } = Object.assign({}, { id: getId(), type: TYPE.DEFAULT }, options, { |
| 38 | content, |
| 39 | }); |
| 40 | events.$emit(EVENTS.ADD, props); |
| 41 | return props.id; |
| 42 | }; |
| 43 | /** |
| 44 | * Clear all toasts |
| 45 | */ |
| 46 | toast.clear = () => events.$emit(EVENTS.CLEAR); |
| 47 | /** |
| 48 | * Update Plugin Defaults |
| 49 | */ |
| 50 | toast.updateDefaults = (update: PluginOptions) => { |
| 51 | events.$emit(EVENTS.UPDATE_DEFAULTS, update); |
| 52 | }; |
| 53 | /** |
| 54 | * Dismiss toast specified by an id |
| 55 | */ |
| 56 | toast.dismiss = (id: ToastID) => { |
| 57 | events.$emit(EVENTS.DISMISS, id); |
| 58 | }; |
| 59 | /** |
| 60 | * Update Toast |
| 61 | */ |
| 62 | function updateToast( |
| 63 | id: ToastID, |
| 64 | { content, options }: { content?: ToastContent; options?: ToastOptions }, |
| 65 | create?: false |
| 66 | ): void; |
| 67 | function updateToast( |
| 68 | id: ToastID, |
| 69 | { content, options }: { content: ToastContent; options?: ToastOptions }, |
| 70 | create?: true |
| 71 | ): void; |
| 72 | function updateToast( |
no test coverage detected
searching dependent graphs…