Files
hossein-por-shop/frontend/composables/global/useToast.ts
T
marzban-dev f4e4abc94c Updated
2025-06-01 22:15:54 +03:30

32 lines
651 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,
};
}