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