feat: polish

This commit is contained in:
Anatoly Antonov 2026-04-22 01:27:38 +09:00
parent 2e6177fe74
commit 4bd927bb4e
137 changed files with 6357 additions and 137560 deletions

54
src/lib/ui/toasts.ts Normal file
View file

@ -0,0 +1,54 @@
import { writable } from 'svelte/store';
export type ToastColor =
| 'primary'
| 'secondary'
| 'success'
| 'danger'
| 'warning'
| 'info'
| 'light'
| 'dark';
export interface Toast {
id: string;
header: string;
body: string;
color: ToastColor;
persistent: boolean;
onRemove?: (id: string) => void;
}
export interface ToastInit {
header: string;
body: string;
color?: ToastColor;
persistent?: boolean;
onRemove?: (id: string) => void;
}
export const toasts = writable<Toast[]>([]);
export function addToast(init: ToastInit): string {
const id = crypto.randomUUID();
toasts.update((all) => [
...all,
{
id,
header: init.header,
body: init.body,
color: init.color ?? 'info',
persistent: init.persistent ?? false,
onRemove: init.onRemove,
},
]);
return id;
}
export function removeToast(id: string): void {
toasts.update((all) => {
const t = all.find((x) => x.id === id);
t?.onRemove?.(id);
return all.filter((x) => x.id !== id);
});
}