diff --git a/frontend/plugins/Toast/Toast.vue b/frontend/plugins/Toast/Toast.vue new file mode 100644 index 0000000..1340526 --- /dev/null +++ b/frontend/plugins/Toast/Toast.vue @@ -0,0 +1,188 @@ + + + + + diff --git a/frontend/plugins/Toast/index.js b/frontend/plugins/Toast/index.js new file mode 100644 index 0000000..5528311 --- /dev/null +++ b/frontend/plugins/Toast/index.js @@ -0,0 +1,51 @@ +import Vue from "vue"; +import ToastComponent from "./Toast"; + +const optionsDefaults = { + data: { + type: "info", + show: true, + timeout: 4500, + + onCreate(created = null) {}, + onEdit(editted = null) {}, + onRemove(removed = null) {} + } +}; + +function toast(options) { + // merge the default options with the passed options. + const root = new Vue({ + data: { + ...optionsDefaults.data, + ...options + }, + render: createElement => createElement(ToastComponent) + }); + + root.$mount(document.body.appendChild(document.createElement("div"))); +} + +export default { + install(vue) { + console.log("Installing toast plugin!"); + + Vue.prototype.$toast = { + 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 }); + } + }; + } +}; diff --git a/frontend/ui/TextToast.vue b/frontend/ui/TextToast.vue deleted file mode 100644 index 43ad634..0000000 --- a/frontend/ui/TextToast.vue +++ /dev/null @@ -1,99 +0,0 @@ - - - - - \ No newline at end of file diff --git a/frontend/vinlottis-init.js b/frontend/vinlottis-init.js index e1c6edb..c693761 100644 --- a/frontend/vinlottis-init.js +++ b/frontend/vinlottis-init.js @@ -3,11 +3,16 @@ import VueRouter from "vue-router"; import { routes } from "@/router.js"; import Vinlottis from "@/Vinlottis"; +import Toast from "@/plugins/Toast"; + import * as Sentry from "@sentry/browser"; import { Vue as VueIntegration } from "@sentry/integrations"; Vue.use(VueRouter); +// Plugins +Vue.use(Toast); + const ENV = window.location.href.includes("localhost") ? "development" : "production"; if (ENV !== "development") { Sentry.init({