UNPKG

react-next-toast

Version:

A premium, modern toast notification system for React applications

172 lines (162 loc) 5.81 kB
import React, { ReactNode } from 'react'; import * as react_jsx_runtime from 'react/jsx-runtime'; type ToastVariant = 'success' | 'error' | 'warning' | 'info' | 'loading' | 'default'; type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right'; interface ToastAction { label: string; onClick: () => void; } interface ToastOptions { /** optional description text below the title */ description?: string; /** duration in ms before auto-dismiss. 0 = persistent. Default: 5000 */ duration?: number; /** show close button. Default: true */ dismissible?: boolean; /** action button configuration */ action?: ToastAction; /** custom icon to override default variant icon */ icon?: React.ReactNode; /** unique ID for programmatic control */ id?: string; /** toast position. Default: 'bottom-right' */ position?: ToastPosition; } interface Toast$1 { id: string; variant: ToastVariant; title: string; description?: string; duration: number; dismissible: boolean; action?: ToastAction; icon?: React.ReactNode; position: ToastPosition; createdAt: number; } interface ToastState { toasts: Toast$1[]; } /** @deprecated Use ToastVariant instead */ declare enum ToastType { SUCCESS = "success", ERROR = "error", WARNING = "warning", INFO = "info" } /** @deprecated Use toast() with options instead */ interface ToastDetail { type: 'success' | 'error' | 'info' | 'warning'; message: string; backgroundColor?: string; textColor?: string; position?: 'right' | 'top-right' | 'bottom-right' | 'left' | 'top-left' | 'bottom-left'; duration?: number; } interface ToastTheme { mode: 'light' | 'dark'; } interface ToastContainerProps { /** Default position for all toasts. Default: 'bottom-right' */ position?: ToastPosition; /** Theme mode. Default: 'dark' */ theme?: 'light' | 'dark'; /** Maximum number of visible toasts. Default: 5 */ maxVisible?: number; /** Gap between stacked toasts in px. Default: 12 */ gap?: number; } interface ToastContextValue { toasts: Toast$1[]; addToast: (variant: ToastVariant, title: string, options?: ToastOptions) => string; dismissToast: (id: string) => void; dismissAll: () => void; } declare const useToast: () => ToastContextValue; interface ToastProviderProps extends ToastContainerProps { children: ReactNode; } declare const ToastProvider: React.FC<ToastProviderProps>; interface ToastAPI { (title: string, options?: ToastOptions): string; success: (title: string, options?: ToastOptions) => string; error: (title: string, options?: ToastOptions) => string; warning: (title: string, options?: ToastOptions) => string; info: (title: string, options?: ToastOptions) => string; loading: (title: string, options?: ToastOptions) => string; dismiss: (id: string) => void; dismissAll: () => void; promise: <T>(promise: Promise<T>, messages: { loading: string; success: string | ((data: T) => string); error: string | ((err: any) => string); }, options?: ToastOptions) => Promise<T>; configure: (config: Partial<ToastContainerProps>) => void; } declare const toast: ToastAPI; interface ToastProps { toast: Toast$1; theme: 'light' | 'dark'; onDismiss: (id: string) => void; } declare const Toast: React.FC<ToastProps>; interface InternalToastContainerProps extends ToastContainerProps { toasts: Toast$1[]; onDismiss: (id: string) => void; } declare const ToastContainer: React.FC<InternalToastContainerProps>; interface IconProps { size?: number; color?: string; } declare const SuccessIcon: React.FC<IconProps>; declare const ErrorIcon: React.FC<IconProps>; declare const WarningIcon: React.FC<IconProps>; declare const InfoIcon: React.FC<IconProps>; declare const LoadingIcon: React.FC<IconProps>; declare const CloseIcon: React.FC<IconProps>; declare const TrashIcon: React.FC<IconProps>; declare function getVariantIcon(variant: ToastVariant): React.ReactElement; /** @deprecated Use individual icon exports instead */ declare const Icon: { Success: () => react_jsx_runtime.JSX.Element; Error: () => react_jsx_runtime.JSX.Element; Warning: () => react_jsx_runtime.JSX.Element; Info: () => react_jsx_runtime.JSX.Element; }; declare const colors: { success: string; error: string; warning: string; info: string; loading: string; default: string; }; declare const theme: { dark: { surface: string; surfaceSolid: string; border: string; textPrimary: string; textSecondary: string; backdrop: string; }; light: { surface: string; surfaceSolid: string; border: string; textPrimary: string; textSecondary: string; backdrop: string; }; }; declare function injectStyles(): void; declare const ToastNotification: React.FC<ToastDetail>; /** @deprecated Use `toast` instead */ declare const showToast: { success: (message: string, duration?: number) => string; error: (message: string, duration?: number) => string; warning: (message: string, duration?: number) => string; info: (message: string, duration?: number) => string; }; export { CloseIcon, ErrorIcon, Icon, InfoIcon, LoadingIcon, SuccessIcon, Toast, type ToastAPI, type ToastAction, ToastContainer, type ToastContainerProps, type ToastDetail, ToastNotification, type ToastOptions, type ToastPosition, ToastProvider, type ToastState, type ToastTheme, type Toast$1 as ToastType, ToastType as ToastTypeEnum, type ToastVariant, TrashIcon, WarningIcon, colors, getVariantIcon, injectStyles, showToast, theme, toast, useToast };