1 | import React from 'react';
|
2 | import { CloseButtonProps, IconProps } from './components';
|
3 | type Nullable<T> = {
|
4 | [P in keyof T]: T[P] | null;
|
5 | };
|
6 | export type TypeOptions = 'info' | 'success' | 'warning' | 'error' | 'default';
|
7 | export type Theme = 'light' | 'dark' | 'colored' | (string & {});
|
8 | export type ToastPosition = 'top-right' | 'top-center' | 'top-left' | 'bottom-right' | 'bottom-center' | 'bottom-left';
|
9 | export interface ToastContentProps<Data = unknown> {
|
10 | closeToast: () => void;
|
11 | toastProps: ToastProps;
|
12 | data: Data;
|
13 | }
|
14 | export type ToastContent<T = unknown> = React.ReactNode | ((props: ToastContentProps<T>) => React.ReactNode);
|
15 | export type ToastIcon = false | ((props: IconProps) => React.ReactNode) | React.ReactElement<IconProps>;
|
16 | export type Id = number | string;
|
17 | export type ToastTransition = React.FC<ToastTransitionProps> | React.ComponentClass<ToastTransitionProps>;
|
18 | /**
|
19 | * ClassName for the elements - can take a function to build a classname or a raw string that is cx'ed to defaults
|
20 | */
|
21 | export type ToastClassName = ((context?: {
|
22 | type?: TypeOptions;
|
23 | defaultClassName?: string;
|
24 | position?: ToastPosition;
|
25 | rtl?: boolean;
|
26 | }) => string) | string;
|
27 | export interface ClearWaitingQueueParams {
|
28 | containerId?: Id;
|
29 | }
|
30 | export type DraggableDirection = 'x' | 'y';
|
31 | interface CommonOptions {
|
32 | /**
|
33 | * Pause the timer when the mouse hover the toast.
|
34 | * `Default: true`
|
35 | */
|
36 | pauseOnHover?: boolean;
|
37 | /**
|
38 | * Pause the toast when the window loses focus.
|
39 | * `Default: true`
|
40 | */
|
41 | pauseOnFocusLoss?: boolean;
|
42 | /**
|
43 | * Remove the toast when clicked.
|
44 | * `Default: false`
|
45 | */
|
46 | closeOnClick?: boolean;
|
47 | /**
|
48 | * Set the delay in ms to close the toast automatically.
|
49 | * Use `false` to prevent the toast from closing.
|
50 | * `Default: 5000`
|
51 | */
|
52 | autoClose?: number | false;
|
53 | /**
|
54 | * Set the default position to use.
|
55 | * `One of: 'top-right', 'top-center', 'top-left', 'bottom-right', 'bottom-center', 'bottom-left'`
|
56 | * `Default: 'top-right'`
|
57 | */
|
58 | position?: ToastPosition;
|
59 | /**
|
60 | * Pass a custom close button.
|
61 | * To remove the close button pass `false`
|
62 | */
|
63 | closeButton?: boolean | ((props: CloseButtonProps) => React.ReactNode) | React.ReactElement<CloseButtonProps>;
|
64 | /**
|
65 | * An optional css class to set for the progress bar.
|
66 | */
|
67 | progressClassName?: ToastClassName;
|
68 | /**
|
69 | * An optional style to set for the progress bar.
|
70 | */
|
71 | progressStyle?: React.CSSProperties;
|
72 | /**
|
73 | * An optional css class to set for the toast content.
|
74 | */
|
75 | bodyClassName?: ToastClassName;
|
76 | /**
|
77 | * An optional inline style to apply for the toast content.
|
78 | */
|
79 | bodyStyle?: React.CSSProperties;
|
80 | /**
|
81 | * Hide or show the progress bar.
|
82 | * `Default: false`
|
83 | */
|
84 | hideProgressBar?: boolean;
|
85 | /**
|
86 | * Pass a custom transition see https://fkhadra.github.io/react-toastify/custom-animation/
|
87 | */
|
88 | transition?: ToastTransition;
|
89 | /**
|
90 | * Allow toast to be draggable
|
91 | * `Default: 'touch'`
|
92 | */
|
93 | draggable?: boolean | 'mouse' | 'touch';
|
94 | /**
|
95 | * The percentage of the toast's width it takes for a drag to dismiss a toast
|
96 | * `Default: 80`
|
97 | */
|
98 | draggablePercent?: number;
|
99 | /**
|
100 | * Specify in which direction should you swipe to dismiss the toast
|
101 | * `Default: "x"`
|
102 | */
|
103 | draggableDirection?: DraggableDirection;
|
104 | /**
|
105 | * Define the ARIA role for the toast
|
106 | * `Default: alert`
|
107 | * https://www.w3.org/WAI/PF/aria/roles
|
108 | */
|
109 | role?: string;
|
110 | /**
|
111 | * Set id to handle multiple container
|
112 | */
|
113 | containerId?: Id;
|
114 | /**
|
115 | * Fired when clicking inside toaster
|
116 | */
|
117 | onClick?: (event: React.MouseEvent) => void;
|
118 | |
119 |
|
120 |
|
121 |
|
122 | rtl?: boolean;
|
123 | |
124 |
|
125 |
|
126 |
|
127 | icon?: ToastIcon;
|
128 | |
129 |
|
130 |
|
131 |
|
132 |
|
133 | theme?: Theme;
|
134 | }
|
135 | export interface ToastOptions<Data = unknown> extends CommonOptions {
|
136 | |
137 |
|
138 |
|
139 | className?: ToastClassName;
|
140 | |
141 |
|
142 |
|
143 | onOpen?: <T = {}>(props: T) => void;
|
144 | |
145 |
|
146 |
|
147 | onClose?: <T = {}>(props: T) => void;
|
148 | |
149 |
|
150 |
|
151 | style?: React.CSSProperties;
|
152 | |
153 |
|
154 |
|
155 |
|
156 | type?: TypeOptions;
|
157 | |
158 |
|
159 |
|
160 | toastId?: Id;
|
161 | |
162 |
|
163 |
|
164 | updateId?: Id;
|
165 | |
166 |
|
167 |
|
168 | progress?: number | string;
|
169 | |
170 |
|
171 |
|
172 | delay?: number;
|
173 | isLoading?: boolean;
|
174 | data?: Data;
|
175 | }
|
176 | export interface UpdateOptions<T = unknown> extends Nullable<ToastOptions<T>> {
|
177 | |
178 |
|
179 |
|
180 |
|
181 | render?: ToastContent<T>;
|
182 | }
|
183 | export interface ToastContainerProps extends CommonOptions {
|
184 | |
185 |
|
186 |
|
187 | className?: ToastClassName;
|
188 | |
189 |
|
190 |
|
191 | stacked?: boolean;
|
192 | |
193 |
|
194 |
|
195 |
|
196 | newestOnTop?: boolean;
|
197 | |
198 |
|
199 |
|
200 | style?: React.CSSProperties;
|
201 | |
202 |
|
203 |
|
204 | toastStyle?: React.CSSProperties;
|
205 | |
206 |
|
207 |
|
208 | toastClassName?: ToastClassName;
|
209 | |
210 |
|
211 |
|
212 | limit?: number;
|
213 | }
|
214 | export interface ToastTransitionProps {
|
215 | isIn: boolean;
|
216 | done: () => void;
|
217 | position: ToastPosition | string;
|
218 | preventExitTransition: boolean;
|
219 | nodeRef: React.RefObject<HTMLElement>;
|
220 | children?: React.ReactNode;
|
221 | playToast(): void;
|
222 | }
|
223 |
|
224 |
|
225 |
|
226 | export interface ToastProps extends ToastOptions {
|
227 | isIn: boolean;
|
228 | staleId?: Id;
|
229 | toastId: Id;
|
230 | key: Id;
|
231 | transition: ToastTransition;
|
232 | closeToast: () => void;
|
233 | position: ToastPosition;
|
234 | children?: ToastContent;
|
235 | draggablePercent: number;
|
236 | draggableDirection?: DraggableDirection;
|
237 | progressClassName?: ToastClassName;
|
238 | className?: ToastClassName;
|
239 | bodyClassName?: ToastClassName;
|
240 | deleteToast: () => void;
|
241 | theme: Theme;
|
242 | type: TypeOptions;
|
243 | collapseAll: () => void;
|
244 | stacked?: boolean;
|
245 | }
|
246 |
|
247 |
|
248 |
|
249 | export interface NotValidatedToastProps extends Partial<ToastProps> {
|
250 | toastId: Id;
|
251 | }
|
252 |
|
253 |
|
254 |
|
255 | export interface Toast {
|
256 | content: ToastContent;
|
257 | props: ToastProps;
|
258 | toggle?: (v: boolean) => void;
|
259 | }
|
260 | export type ToastItemStatus = 'added' | 'removed' | 'updated';
|
261 | export interface ToastItem<Data = {}> {
|
262 | content: ToastContent<Data>;
|
263 | id: Id;
|
264 | theme?: Theme;
|
265 | type?: TypeOptions;
|
266 | isLoading?: boolean;
|
267 | containerId?: Id;
|
268 | data: Data;
|
269 | icon?: ToastIcon;
|
270 | status: ToastItemStatus;
|
271 | }
|
272 | export type OnChangeCallback = (toast: ToastItem) => void;
|
273 | export type IdOpts = {
|
274 | id?: Id;
|
275 | containerId?: Id;
|
276 | };
|
277 | export {};
|