From bc884eaa049bfdb9f3fa313d1b9d6b671e954d48 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 2 Jun 2019 00:28:08 +0200 Subject: [PATCH] =?UTF-8?q?Toast=20plugin=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/Toast/ToastComponent.vue | 191 +++++++++++++++++++++++++++ src/plugins/Toast/index.js | 57 ++++++++ 2 files changed, 248 insertions(+) create mode 100644 src/plugins/Toast/ToastComponent.vue create mode 100644 src/plugins/Toast/index.js diff --git a/src/plugins/Toast/ToastComponent.vue b/src/plugins/Toast/ToastComponent.vue new file mode 100644 index 0000000..e35062b --- /dev/null +++ b/src/plugins/Toast/ToastComponent.vue @@ -0,0 +1,191 @@ + + + + + \ No newline at end of file diff --git a/src/plugins/Toast/index.js b/src/plugins/Toast/index.js new file mode 100644 index 0000000..6bf8f19 --- /dev/null +++ b/src/plugins/Toast/index.js @@ -0,0 +1,57 @@ +import Vue from 'vue' +import ToastComponent from './ToastComponent.vue' + +const optionsDefaults = { + data: { + type: 'info', + show: true, + timeout: 3000, + + onCreate(created = null) { + }, + onEdit(editted = null) { + }, + onRemove(removed = null) { + } + } +} + +function toast(options, router) { + // merge the default options with the passed options. + const root = new Vue({ + data: { + ...optionsDefaults.data, + ...options, + router + }, + render: createElement => createElement(ToastComponent) + }) + + root.$mount(document.body.appendChild(document.createElement('div'))) +} + + +export default { + install(vue, opts) { + console.log('installing toast plugin!') + console.log('plugin options', opts) + + Vue.prototype.$notifications = { + info(options) { + toast({ type: 'info', ...options }) + }, + success(options) { + toast({ type: 'success', ...options }) + }, + warning(options) { + toast({ type: 'warning', ...options }) + }, + error(options) { + toast({ type: 'error', ...options }) + }, + simple(options) { + toast({ type: 'simple', ...options}) + } + } + } +} \ No newline at end of file