react-toast-msg
Version:
Fast, flexible, developer-friendly React toast notifications with a clean black & white design.
70 lines (66 loc) • 3.17 kB
TypeScript
import * as react_jsx_runtime from 'react/jsx-runtime';
/**
* Represents the different types of toast notifications available.
* Each type corresponds to a specific visual style and semantic meaning.
*/
type ToastType = 'success' | 'error' | 'warning' | 'default' | 'loading';
/**
* Configuration options for creating a new toast notification.
* All properties are optional and will use default values if not provided.
*/
type ToastOptions = {
/** Custom ID for the toast. If not provided, a unique ID will be generated */
id?: string | number;
/** The type of toast to display */
type?: ToastType;
/** Duration in milliseconds before the toast auto-closes. Set to 0 or false to disable auto-close */
duration?: number;
/** Whether to show a close button on this specific toast */
closeButton?: boolean;
/** Whether the toast should auto-close. Can be a boolean or a duration in milliseconds */
autoClose?: boolean | number;
/** Whether hovering this toast should pause its auto-close timer */
pauseOnHover?: boolean;
};
/**
* Props for the ToastContainer component that manages multiple toasts.
* Controls global behavior and appearance of all toasts.
*/
interface ToastContainerProps {
/** Global auto-close setting. Can be a boolean to enable/disable or a number for duration in milliseconds */
autoClose?: boolean | number;
/** Global close button setting. Determines if close buttons are shown by default on all toasts */
closeButton?: boolean;
/** Whether hovering a toast should pause its auto-close timer by default */
pauseOnHover?: boolean;
}
/**
* ToastContainer component that manages and displays multiple toast notifications.
* This component should be rendered once in your app, typically at the root level.
* It provides the context for showing toasts via the toast() function.
*
* @param props - Configuration options for the toast container
* @returns JSX element containing the toast container
*/
declare function ToastContainer({ autoClose, closeButton, pauseOnHover }: ToastContainerProps): react_jsx_runtime.JSX.Element;
/**
* Main toast function for displaying notifications.
* Shows a toast message with the specified options.
*
* @param message - The message text to display in the toast
* @param options - Optional configuration for the toast
* @returns The unique ID of the created toast
*/
declare function toast(message: string, options?: ToastOptions): string | number | undefined;
declare namespace toast {
var success: (message: string, options?: ToastOptions) => string | number | undefined;
var error: (message: string, options?: ToastOptions) => string | number | undefined;
var warning: (message: string, options?: ToastOptions) => string | number | undefined;
var loading: (message: string, options?: ToastOptions) => string | number | undefined;
var promise: <T>(promise: Promise<T>, data: {
loading: string;
success: string | ((data: T) => string);
error: string | ((err: unknown) => string);
}, options?: ToastOptions) => Promise<T>;
}
export { ToastContainer, type ToastType, toast };