From 6284319afbad33b75fb98bb549aea8a6ecb526c3 Mon Sep 17 00:00:00 2001 From: marzban-dev Date: Mon, 30 Dec 2024 19:55:58 +0330 Subject: [PATCH] Create useToast composable --- frontend/composables/useToast.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 frontend/composables/useToast.ts diff --git a/frontend/composables/useToast.ts b/frontend/composables/useToast.ts new file mode 100644 index 0000000..95bec80 --- /dev/null +++ b/frontend/composables/useToast.ts @@ -0,0 +1,32 @@ +type Toast = { + id: number; + message: string; + description?: string; + duration?: number; +} + +type Props = { + message: string, + description?: string, + options?: Omit +} + +const toasts = ref([]); + +export function useToast() { + const addToast = ({ message, description, options = {} }: Props) => { + const id = Date.now(); + + toasts.value.push({ id, message, description, ...options }); + }; + + const destroyToast = (id: number) => { + toasts.value = toasts.value.filter(toast => toast.id !== id); + }; + + return { + toasts, + addToast, + destroyToast + }; +} \ No newline at end of file