Files
hossein-por-shop/frontend/composables/api/global/useToast.ts
T
2025-01-14 18:49:23 +03:30

31 lines
644 B
TypeScript

export type ToastOptions = {
description?: string;
duration?: number;
status?: "success" | "error" | "info" | "warning",
}
type Toast = {
id: number;
message: string;
options?: ToastOptions
}
const toasts = ref<Toast[]>([]);
export function useToast() {
const addToast = ({ message, options = {} }: Omit<Toast, "id">) => {
const id = Date.now();
toasts.value.push({ id, message, options });
};
const destroyToast = (id: number) => {
toasts.value = toasts.value.filter(toast => toast.id !== id);
};
return {
toasts,
addToast,
destroyToast
};
}