diff --git a/resources/js/components/SMToast.vue b/resources/js/components/SMToast.vue new file mode 100644 index 0000000..f452011 --- /dev/null +++ b/resources/js/components/SMToast.vue @@ -0,0 +1,135 @@ + + + + + diff --git a/resources/js/components/SMToastList.vue b/resources/js/components/SMToastList.vue new file mode 100644 index 0000000..c807e84 --- /dev/null +++ b/resources/js/components/SMToastList.vue @@ -0,0 +1,30 @@ + + + + + diff --git a/resources/js/store/ToastStore.ts b/resources/js/store/ToastStore.ts new file mode 100644 index 0000000..fe247b7 --- /dev/null +++ b/resources/js/store/ToastStore.ts @@ -0,0 +1,54 @@ +import { defineStore } from "pinia"; + +export interface ToastOptions { + id?: number; + title?: string; + content: string; + type?: string; +} + +export interface ToastItem { + id: number; + title: string; + content: string; + type: string; +} + +export interface ToastStore { + toasts: ToastItem[]; +} + +export const defaultToastItem: ToastItem = { + id: 0, + title: "", + content: "", + type: "primary", +}; + +export const useToastStore = defineStore({ + id: "toasts", + state: (): ToastStore => ({ + toasts: [], + }), + + actions: { + addToast(toast: ToastOptions) { + if (!toast.id || toast.id == 0) { + toast.id = + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1; + } + + toast.title = toast.title || defaultToastItem.title; + toast.type = toast.type || defaultToastItem.type; + + this.toasts.push(toast); + console.log(this.toasts[0].title); + }, + + clearToast(id: number) { + this.toasts = this.toasts.filter( + (item: ToastItem) => item.id !== id + ); + }, + }, +}); diff --git a/resources/js/views/App.vue b/resources/js/views/App.vue index d3d6e25..417c116 100644 --- a/resources/js/views/App.vue +++ b/resources/js/views/App.vue @@ -9,6 +9,7 @@ + @@ -16,6 +17,7 @@ import SMNavbar from "../components/SMNavbar.vue"; import SMFooter from "../components/SMFooter.vue"; import SMProgress from "../components/SMProgress.vue"; +import SMToastList from "../components/SMToastList.vue"; import { DialogWrapper } from "vue3-promise-dialog";