First version running with npm run dev
This commit is contained in:
commit
f90ec06a4f
28 files changed
+12042
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { ref } from "vue";
|
||||
|
||||
interface Toast {
|
||||
id: number;
|
||||
message: string;
|
||||
type: "success" | "error" | "info";
|
||||
}
|
||||
|
||||
const toasts = ref<Toast[]>([]);
|
||||
let nextId = 0;
|
||||
|
||||
export function useToast() {
|
||||
function show(
|
||||
message: string,
|
||||
type: Toast["type"] = "success",
|
||||
duration = 2500,
|
||||
): void {
|
||||
const id = nextId++;
|
||||
toasts.value.push({ id, message, type });
|
||||
setTimeout(() => {
|
||||
dismiss(id);
|
||||
}, duration);
|
||||
}
|
||||
|
||||
function dismiss(id: number): void {
|
||||
const index = toasts.value.findIndex((t) => t.id === id);
|
||||
if (index !== -1) {
|
||||
toasts.value.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
toasts,
|
||||
show,
|
||||
dismiss,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user