toast
Every export of @kitr/toast, @kitr/toast/provider, read from the published type definitions. The guide shows them in use.
@kitr/toast
setToastImplementation
function setToastImplementation(fn: ToastFn | null): void;
Replace what toast calls: a function with success, error, info, warning and promise methods.
The toast provider sets sonner's toast when the app boots; null goes back to the console fallback.
toastError
function toastError(error: unknown, fallbackMessage?: string): void;
Show a KitrError (or anything) as an error toast with its message.
defineConfig
const defineConfig: <const C extends ToastConfig>(config: C) => C;
Type-check config/toast.ts: returns the object unchanged, with autocomplete for every ToastConfig option.
toast
const toast: ToastFn;
Show a toast: toast('Saved'), toast.success(), .error(), .info(), .warning() and .promise().
Goes to sonner once the toast provider has booted, and to the console before that or without it.
ToastConfig
interface ToastConfig {
/** Where toasts appear. Default `'bottom-right'`. */
position?: 'top-left' | 'top-right' | 'top-center' | 'bottom-left' | 'bottom-right' | 'bottom-center';
/** Coloured success, error, info and warning toasts. Default `true`. */
richColors?: boolean;
/** How long a toast stays, in milliseconds. Default `4000`. */
duration?: number;
/** Show a close button on every toast. Default `false`. */
closeButton?: boolean;
}
The options of config/toast.ts: where toasts appear and how they look.
ToastFn
/** What `toast` calls: a function with `success`, `error`, `info`, `warning` and `promise` methods. */
type ToastFn = ((message: string, options?: Record<string, unknown>) => unknown) & {
success: (message: string, options?: Record<string, unknown>) => unknown;
error: (message: string, options?: Record<string, unknown>) => unknown;
info: (message: string, options?: Record<string, unknown>) => unknown;
warning: (message: string, options?: Record<string, unknown>) => unknown;
promise: <T>(promise: Promise<T>, messages: {
loading: string;
success: string;
error: string;
}) => Promise<T>;
};
What toast calls: a function with success, error, info, warning and promise methods.
@kitr/toast/provider
toastProvider
const toastProvider: import("@kitr/core").KitrProvider;
Sends toast to sonner and mounts its toaster with config/toast.ts.
Listed in kitrrc.ts as () => import('@kitr/toast/provider').