Files
nick-sde-value-driver-website/src/lib/toast.svelte.ts
2026-07-22 14:52:35 -05:00

16 lines
454 B
TypeScript

// Tiny shared toast controller. Import `toast` anywhere and call toast.show('...').
class ToastController {
message = $state('');
visible = $state(false);
#timer: ReturnType<typeof setTimeout> | null = null;
show(msg: string, ms = 2200): void {
this.message = msg;
this.visible = true;
if (this.#timer) clearTimeout(this.#timer);
this.#timer = setTimeout(() => (this.visible = false), ms);
}
}
export const toast = new ToastController();