UNPKG

react-quick-notify

Version:

react-quick-notify: A beautiful, customizable toast notification system for React applications with zero CSS dependencies

69 lines (62 loc) 2.12 kB
import React, { ReactNode } from 'react'; type ToastType = 'success' | 'error' | 'warning' | 'info' | 'loading'; interface ToastConfig { position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center'; duration?: number; maxToasts?: number; reverseOrder?: boolean; } interface Toast { id: string; type: ToastType; title?: string; message: string; duration?: number; action?: { label: string; onClick: () => void; }; isPromise?: boolean; promiseId?: string; } interface PromiseToastMessages { loading: string; success: string; error: string; } interface ToastContextType { toasts: Toast[]; config: ToastConfig; addToast: (toast: Omit<Toast, 'id'>) => void; removeToast: (id: string) => void; clearAllToasts: () => void; updatePromiseToast: (promiseId: string, type: ToastType, message: string) => void; } interface ToastProviderProps { children: ReactNode; config?: ToastConfig; } declare const ToastProvider: React.FC<ToastProviderProps>; declare const useToast: () => { toast: { success: (message: string, duration?: number) => void; error: (message: string, duration?: number) => void; warning: (message: string, duration?: number) => void; info: (message: string, duration?: number) => void; custom: (type: ToastType, message: string, duration?: number) => void; promise: <T>(promise: Promise<T>, messages: PromiseToastMessages, duration?: number) => Promise<T>; dismiss: (id: string) => void; clear: () => void; }; toasts: Toast[]; }; interface ToastContainerProps { position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center'; } declare const ToastContainer: React.FC<ToastContainerProps>; interface ToastItemProps { toast: Toast; } declare const ToastItem: React.FC<ToastItemProps>; export { ToastContainer, ToastItem, ToastProvider, useToast }; export type { PromiseToastMessages, Toast, ToastConfig, ToastContextType, ToastType };