-
-
Notifications
You must be signed in to change notification settings - Fork 291
/
types.ts
185 lines (166 loc) · 4.69 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import React from 'react';
export type ToastTypes = 'normal' | 'action' | 'success' | 'info' | 'warning' | 'error' | 'loading' | 'default';
export type PromiseT<Data = any> = Promise<Data> | (() => Promise<Data>);
export type PromiseTResult<Data = any> =
| string
| React.ReactNode
| ((data: Data) => React.ReactNode | string | Promise<React.ReactNode | string>);
export type PromiseExternalToast = Omit<ExternalToast, 'description'>;
export type PromiseData<ToastData = any> = PromiseExternalToast & {
loading?: string | React.ReactNode;
success?: PromiseTResult<ToastData>;
error?: PromiseTResult;
description?: PromiseTResult;
finally?: () => void | Promise<void>;
};
export interface ToastClassnames {
toast?: string;
title?: string;
description?: string;
loader?: string;
closeButton?: string;
cancelButton?: string;
actionButton?: string;
success?: string;
error?: string;
info?: string;
warning?: string;
loading?: string;
default?: string;
content?: string;
icon?: string;
}
export interface ToastIcons {
success?: React.ReactNode;
info?: React.ReactNode;
warning?: React.ReactNode;
error?: React.ReactNode;
loading?: React.ReactNode;
close?: React.ReactNode;
}
export interface Action {
label: React.ReactNode;
onClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
actionButtonStyle?: React.CSSProperties;
}
export interface ToastT {
id: number | string;
title?: (() => React.ReactNode) | React.ReactNode;
type?: ToastTypes;
icon?: React.ReactNode;
jsx?: React.ReactNode;
richColors?: boolean;
invert?: boolean;
closeButton?: boolean;
dismissible?: boolean;
description?: (() => React.ReactNode) | React.ReactNode;
duration?: number;
delete?: boolean;
action?: Action | React.ReactNode;
cancel?: Action | React.ReactNode;
onDismiss?: (toast: ToastT) => void;
onAutoClose?: (toast: ToastT) => void;
promise?: PromiseT;
cancelButtonStyle?: React.CSSProperties;
actionButtonStyle?: React.CSSProperties;
style?: React.CSSProperties;
unstyled?: boolean;
className?: string;
classNames?: ToastClassnames;
descriptionClassName?: string;
position?: Position;
}
export function isAction(action: Action | React.ReactNode): action is Action {
return (action as Action).label !== undefined;
}
export type Position = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'top-center' | 'bottom-center';
export interface HeightT {
height: number;
toastId: number | string;
position: Position;
}
interface ToastOptions {
className?: string;
closeButton?: boolean;
descriptionClassName?: string;
style?: React.CSSProperties;
cancelButtonStyle?: React.CSSProperties;
actionButtonStyle?: React.CSSProperties;
duration?: number;
unstyled?: boolean;
classNames?: ToastClassnames;
}
type CnFunction = (...classes: Array<string | undefined>) => string;
export interface ToasterProps {
invert?: boolean;
theme?: 'light' | 'dark' | 'system';
position?: Position;
hotkey?: string[];
richColors?: boolean;
expand?: boolean;
duration?: number;
gap?: number;
visibleToasts?: number;
closeButton?: boolean;
toastOptions?: ToastOptions;
className?: string;
style?: React.CSSProperties;
offset?: string | number;
dir?: 'rtl' | 'ltr' | 'auto';
/**
* @deprecated Please use the `icons` prop instead:
* ```jsx
* <Toaster
* icons={{ loading: <LoadingIcon /> }}
* />
* ```
*/
loadingIcon?: React.ReactNode;
icons?: ToastIcons;
containerAriaLabel?: string;
pauseWhenPageIsHidden?: boolean;
cn?: CnFunction;
}
export interface ToastProps {
toast: ToastT;
toasts: ToastT[];
index: number;
expanded: boolean;
invert: boolean;
heights: HeightT[];
setHeights: React.Dispatch<React.SetStateAction<HeightT[]>>;
removeToast: (toast: ToastT) => void;
gap?: number;
position: Position;
visibleToasts: number;
expandByDefault: boolean;
closeButton: boolean;
interacting: boolean;
style?: React.CSSProperties;
cancelButtonStyle?: React.CSSProperties;
actionButtonStyle?: React.CSSProperties;
duration?: number;
className?: string;
unstyled?: boolean;
descriptionClassName?: string;
loadingIcon?: React.ReactNode;
classNames?: ToastClassnames;
icons?: ToastIcons;
closeButtonAriaLabel?: string;
pauseWhenPageIsHidden: boolean;
cn: CnFunction;
defaultRichColors?: boolean;
}
export enum SwipeStateTypes {
SwipedOut = 'SwipedOut',
SwipedBack = 'SwipedBack',
NotSwiped = 'NotSwiped',
}
export type Theme = 'light' | 'dark';
export interface ToastToDismiss {
id: number | string;
dismiss: boolean;
}
export type ExternalToast = Omit<ToastT, 'id' | 'type' | 'title' | 'jsx' | 'delete' | 'promise'> & {
id?: number | string;
};