tobogganSe connecter

starfleet-ui

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

BATMAN!868a50c · il y a 2 sem.
20 lignes · 467 octetsBrut · Historique
1export interface Toast {
2 id: number;
3 kind: 'info' | 'success' | 'error' | 'event';
4 text: string;
5}
6
7let nextId = 1;
8
9export const toasts = $state<Toast[]>([]);
10
11export function toast(text: string, kind: Toast['kind'] = 'info', ttlMs = 6000) {
12 const id = nextId++;
13 toasts.push({ id, kind, text });
14 setTimeout(() => dismiss(id), ttlMs);
15}
16
17export function dismiss(id: number) {
18 const i = toasts.findIndex((t) => t.id === id);
19 if (i >= 0) toasts.splice(i, 1);
20}