16 lines
454 B
TypeScript
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();
|