/** * toast-store - the headless model behind : a singleton reactive * queue of transient notifications with auto-dismiss timers, plus the `toast()` * API you call from anywhere. Every toast is also pushed to the shared ARIA * live region via `announce()`, so screen-reader users hear it even though the * visual toast is off to the side. * * ```ts * import { toast } from '@svgrid/grid' * toast.success('Saved') * toast.error('Could not save', { duration: 0 }) // sticky * ``` * * Mount a single once near the app root to render the queue. */ import type { Snippet } from 'svelte'; export type ToastVariant = 'info' | 'success' | 'warning' | 'error'; /** A button rendered inside a toast (a primary `action` or a secondary `cancel`). */ export type ToastAction = { label: string; /** Invoked with the toast id when pressed. */ onClick?: (id: number) => void; /** Keep the toast open after the click (default: dismiss it). */ keepOpen?: boolean; }; export type ToastOptions = { variant?: ToastVariant; /** Auto-dismiss after N ms. `0` = sticky (dismiss manually). Default 4000. */ duration?: number; /** Show the dismiss (x) button. Default true. */ dismissible?: boolean; /** Optional bold title above the message. */ title?: string; /** Primary action button. */ action?: ToastAction; /** Secondary (cancel) action button. */ cancel?: ToastAction; /** Render a fully custom toast body instead of the icon + title + message. */ render?: Snippet<[Toast]>; }; export type Toast = { id: number; message: string; variant: ToastVariant; duration: number; dismissible: boolean; title?: string; action?: ToastAction; cancel?: ToastAction; render?: Snippet<[Toast]>; }; /** Patch applied by `toast.update(id, patch)`; every field is optional. */ export type UpdateToast = Partial>; /** Messages for `toast.promise`; success/error may derive from the value/error. */ export type PromiseMessages = { loading: string; success: string | ((value: T) => string); error: string | ((error: unknown) => string); }; type VariantOptions = Omit; export type ToastFn = { (message: string, options?: ToastOptions): number; info: (message: string, options?: VariantOptions) => number; success: (message: string, options?: VariantOptions) => number; warning: (message: string, options?: VariantOptions) => number; error: (message: string, options?: VariantOptions) => number; /** * Show a sticky loading toast, then update it IN PLACE to success/error when * the promise settles. Returns the original promise so callers can await it. */ promise: (promise: Promise, messages: PromiseMessages, options?: ToastOptions) => Promise; /** Patch an existing toast (message/variant/title/action/duration/render). */ update: (id: number, patch: UpdateToast) => void; /** Push a toast with a fully custom body snippet. Returns its id. */ custom: (render: Snippet<[Toast]>, options?: ToastOptions) => number; /** Dismiss a toast by id. */ dismiss: (id: number) => void; }; /** Live reactive list of active toasts (read inside a component/effect). */ export declare const toastStore: { readonly toasts: Toast[]; }; /** Show a toast. Returns its id. Has `.info/.success/.warning/.error` helpers. */ export declare const toast: ToastFn; /** Dismiss a toast by id. */ export declare const dismissToast: (id: number) => void; /** Patch an existing toast in place (message/variant/title/action/duration/render). */ export declare const updateToast: (id: number, patch: UpdateToast) => void; /** Remove every toast (and cancel their timers). */ export declare const clearToasts: () => void; /** Pause a toast's auto-dismiss countdown (e.g. while hovered). */ export declare const pauseToast: (id: number) => void; /** Resume a paused toast's countdown with the time it had left. */ export declare const resumeToast: (id: number) => void; export {};