converted to proper npm sveltekit project
This commit is contained in:
15
src/lib/toast.svelte.ts
Normal file
15
src/lib/toast.svelte.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
// 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();
|
||||
Reference in New Issue
Block a user