import { type ReactNode } from 'react'; import { type LinkTarget } from './AppLink.js'; export type ToastTone = 'info' | 'success' | 'warning' | 'error'; /** Runs `onClick`, or with `href` is a link, such as to what the toast reports * on; either way the toast then closes. */ export type ToastAction = { label: ReactNode; onClick: () => void; href?: undefined; } | ({ label: ReactNode; onClick?: undefined; } & LinkTarget & { href: string; }); export interface ToastOptions { /** Shows the toast in place of an open one with this id, rather than stacking another. */ id?: string | undefined; /** A bold first line, with the message under it. */ title?: ReactNode; /** A button that acts on what the toast reports, such as Undo. */ action?: ToastAction | undefined; /** Milliseconds it stays; false keeps it until it's dismissed or updated. It * pauses while the pointer or focus is on the toasts. */ timeout?: number | false | undefined; /** False drops the close button, for a toast whose own content closes or settles it. */ dismissible?: boolean | undefined; /** False drops the tone's icon, for content that draws its own. */ icon?: boolean | undefined; } export interface ToastUpdate extends Omit { message?: ReactNode; /** Settles the toast into this tone, such as a loading toast into success. The * update then replaces the toast's options rather than adding to them, so it * takes that tone's timeout, close button and icon unless it names its own. */ tone?: ToastTone | undefined; } export interface Toaster { info: (message: ReactNode, options?: ToastOptions) => string; success: (message: ReactNode, options?: ToastOptions) => string; warning: (message: ReactNode, options?: ToastOptions) => string; /** Announced at once, where the others wait for a pause. */ error: (message: ReactNode, options?: ToastOptions) => string; /** A spinner that stays until an update settles it into a tone, or it's dismissed. */ loading: (message: ReactNode, options?: ToastOptions) => string; update: (id: string, update: ToastUpdate) => void; /** Without an id, dismisses every toast. */ dismiss: (id?: string) => void; /** A loading toast that settles into success or error with the promise, which it returns. */ promise: (promise: Promise, messages: { loading: ReactNode; success: ReactNode | ((value: T) => ReactNode); error: ReactNode | ((error: unknown) => ReactNode); }) => Promise; } /** Shows toasts from anywhere, a component or not. They render in the * `UIProvider`'s viewport, over dialogs and under an open popup such as a menu, * and stay usable while a modal is open. */ export declare const toast: Toaster; /** Whether a dialog's close request came from a press on a toast, which the * dialog ignores: a toast floats over it, so pressing one isn't leaving it. */ export declare function pressedToast(event: Event | undefined): boolean; /** The viewport toasts render in, at the top of the window, where it clears a * modal's panel (which opens lower) and the controls along a dialog's foot. */ export declare function Toaster(): import("react").JSX.Element | null;