starfleet-ui
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#6 · main · 2 min 01 s
0Étoiles
0Forks
0Issues
| 1 | export interface Toast { |
| 2 | id: number; |
| 3 | kind: 'info' | 'success' | 'error' | 'event'; |
| 4 | text: string; |
| 5 | } |
| 6 | |
| 7 | let nextId = 1; |
| 8 | |
| 9 | export const toasts = $state<Toast[]>([]); |
| 10 | |
| 11 | export 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 | |
| 17 | export function dismiss(id: number) { |
| 18 | const i = toasts.findIndex((t) => t.id === id); |
| 19 | if (i >= 0) toasts.splice(i, 1); |
| 20 | } |