UNPKG

react-toast-plus

Version:

React Toast Plus: A flexible, customizable, and modern toast notification library for React.

253 lines (214 loc) 8.54 kB
import { ButtonHTMLAttributes } from 'react'; import { ClassAttributes } from 'react'; import { Context } from 'react'; import { default as default_2 } from 'react'; import { DefaultTheme } from 'goober'; import { Dispatch as Dispatch_2 } from '../../index.ts'; import { FunctionComponent } from 'react'; import { HTMLAttributes } from 'react'; import { ReactNode } from 'react'; import { StyledVNode } from 'goober'; import { ToastContextProps as ToastContextProps_2 } from '../../index.ts'; export declare type Action = { type: ActionTypes.ADD_TOAST; toast: ToastContextProps; } | { type: ActionTypes.REMOVE_TOAST; id: ToastContextProps["id"]; } | { type: ActionTypes.UPDATE_TOAST; toast: Partial<ToastContextProps> & Pick<ToastContextProps, "id">; } | { type: ActionTypes.REMOVE_ALL_TOASTS; }; export declare enum ActionTypes { ADD_TOAST = "ADD_TOAST", REMOVE_TOAST = "REMOVE_TOAST", UPDATE_TOAST = "UPDATE_TOAST", REMOVE_ALL_TOASTS = "REMOVE_ALL_TOASTS" } export declare interface AutoCloseHandler { start: (duration: number) => void; pause: () => void; resume: () => void; clear: () => void; remainingTime: () => number; isRunning: boolean; isPaused: boolean; } export declare const CloseIcon: FunctionComponent; export declare interface containerOptions extends Omit<ToastContainerProps, "children"> { component?: default_2.ElementType<ToastContainerProps>; portalSelector?: Element | DocumentFragment; } export declare type DefaultTransitionsMap = { [key in ToastTransitionType]: default_2.CSSProperties; }; export declare type Dispatch = default_2.Dispatch<Action>; export declare const ErrorIcon: FunctionComponent; export declare const InfoIcon: FunctionComponent; declare interface MainToastOptions extends ToastOptions { component?: default_2.ElementType<ToastProps>; successOptions?: ToastOptions; errorOptions?: ToastOptions; warningOptions?: ToastOptions; infoOptions?: ToastOptions; emptyOptions?: ToastOptions; loadingOptions?: ToastOptions; } export declare type Placement = 'bottom-left' | 'bottom-center' | 'bottom-right' | 'top-left' | 'top-center' | 'top-right'; export declare interface State { toasts: ToastContextProps[]; } export declare const StyledCloseButton: StyledVNode<Omit<ClassAttributes<HTMLButtonElement> & ButtonHTMLAttributes<HTMLButtonElement> & DefaultTheme & { as?: any; }, never>>; export declare const StyledLoadingIcon: StyledVNode<Omit<ClassAttributes<HTMLSpanElement> & HTMLAttributes<HTMLSpanElement> & DefaultTheme & { as?: any; }, never>>; export declare const StyledProgressBar: StyledVNode<Omit<ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & DefaultTheme & { type: ToastType; duration: number; state: "running" | "paused"; }, never>>; export declare const StyledToastContainer: StyledVNode<Omit<ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & DefaultTheme & { as?: any; }, never>>; export declare const StyledToaster: StyledVNode<Omit<ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & DefaultTheme & { as?: any; }, never>>; export declare const StyledToasterContent: StyledVNode<Omit<ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & DefaultTheme & { as?: any; }, never>>; export declare const SuccessIcon: FunctionComponent; export declare interface ToastContainerProps { className?: string; children: default_2.ReactNode; style?: default_2.CSSProperties; } export declare const ToastContext: Context<ToastContextType | undefined>; export declare interface ToastContextProps { id: string; content: string | ReactNode | ((props: ToastProps) => ReactNode); onClose: (id: string) => void; type?: ToastType; options?: ToastOptions; element?: { height?: number; }; renderCustomToast?: ((props: ToastProps) => ReactNode); } export declare interface ToastContextType { state: State; dispatch: Dispatch; } export declare interface ToastControllerProps { children: default_2.ElementType<ToastProps>; toastContextProps: ToastContextProps; gutter: number; newestFirst?: boolean; } export declare interface ToastOptions { className?: string; style?: default_2.CSSProperties; lifetime?: number; autoClose?: boolean; pauseOnHover?: boolean; pauseOnFocusLoss?: boolean; draggableClose?: boolean; closeOnClick?: boolean; closeButton?: { visible?: boolean; className?: string; style?: default_2.CSSProperties; }; progressBar?: { visible?: boolean; className?: string; style?: default_2.CSSProperties; }; transition?: ToastTransitionType; transitionDuration?: number; placement?: Placement; icon?: ReactNode; iconProps?: { visible?: boolean; className?: string; style?: default_2.CSSProperties; }; } export declare interface ToastProps extends Omit<ToastContextProps, "renderCustomToast">, Partial<AutoCloseHandler> { } export declare const ToastProvider: FunctionComponent<ToastProviderProps>; export declare interface ToastProviderProps { children: ReactNode; newestFirst?: boolean; containerOptions?: containerOptions; toastOptions?: MainToastOptions; gutter?: number; toastStyles?: Partial<ToastStylesProps>; portalActive?: boolean; } export declare interface ToastStylesProps { toastMaxWidth: string; toastMinWidth: string; toastMinHeight: string; toastFontFamily: string; toastBgColor: string; toastTextColor: string; toastEmptyColor: string; toastSuccessColor: string; toastInfoColor: string; toastWarningColor: string; toastErrorColor: string; toastLoaderColor: string; toastLoaderAreaColor: string; toastRadius: string; toastPadding: string; toastBoxShadow: string; } export declare type ToastTransitionType = 'fade' | 'zoom' | 'slide' | 'bounce'; export declare type ToastType = 'success' | 'error' | 'warning' | 'info' | 'empty' | 'loading'; export declare type TransitionsMap = { [key in ToastTransitionType]: TransitionStyles; }; export declare type TransitionState = 'unmounted' | 'entering' | 'entered' | 'exiting' | 'exited'; export declare type TransitionStyles = { [key in TransitionState]: default_2.CSSProperties; }; export declare const useToast: () => { addToast: { (content: ToastContextProps["content"], type?: ToastType, options?: ToastOptions): Pick<ToastContextProps, "id">; success: (message: ToastContextProps["content"], options?: ToastOptions) => Pick<ToastContextProps, "id">; error: (message: ToastContextProps["content"], options?: ToastOptions) => Pick<ToastContextProps, "id">; warning: (message: ToastContextProps["content"], options?: ToastOptions) => Pick<ToastContextProps, "id">; info: (message: ToastContextProps["content"], options?: ToastOptions) => Pick<ToastContextProps, "id">; empty: (message: ToastContextProps["content"], options?: ToastOptions) => Pick<ToastContextProps, "id">; loading: (message: ToastContextProps["content"], options?: ToastOptions) => Pick<ToastContextProps, "id">; promise<T>(promiseOrFunction: Promise<T> | (() => Promise<T>), messages: { pending: string; success: string | ((data: T) => string); error: string | ((err: T) => string); }, options?: Omit<ToastOptions, "autoClose" | "closeButton" | "draggableClose"> & { success?: ToastOptions; error?: ToastOptions; }): { id: string; }; custom(renderFunction: ToastContextProps["renderCustomToast"], options?: ToastOptions): { id: string; }; }; removeToast: { (id: ToastContextProps["id"]): void; byIndex(index: number): void; }; removeAllToasts: () => void; updateToast: (toast: Omit<Partial<ToastContextProps>, "onClose" | "element" | "id"> & Pick<ToastContextProps, "id">) => void; }; export declare const useToastStore: () => { toasts: ToastContextProps_2[]; dispatch: Dispatch_2; }; export declare const WarningIcon: FunctionComponent; export { }