-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathtypes.ts
271 lines (235 loc) · 5.11 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import type { ComponentProps, ComponentType } from 'svelte';
import type { Expand } from '$lib/internal/types.js';
import type { HTMLOlAttributes } from 'svelte/elements';
export type FixMe = unknown;
export type ToastTypes =
| 'action'
| 'success'
| 'info'
| 'warning'
| 'error'
| 'loading'
| 'default';
export type PromiseT<Data = unknown> = Promise<Data> | (() => Promise<Data>);
export type PromiseData<ToastData = unknown> = ExternalToast & {
loading?: string | ComponentType;
success?: string | ComponentType | ((data: ToastData) => ComponentType | string);
error?: string | ComponentType | ((error: unknown) => ComponentType | string);
finally?: () => void | Promise<void>;
};
export type ToastT<T extends ComponentType = ComponentType> = {
id: number | string;
title?: string | ComponentType;
type: ToastTypes;
icon?: ComponentType;
component?: T;
componentProps?: ComponentProps<InstanceType<T>>;
invert?: boolean;
description?: string | ComponentType;
cancelButtonStyle?: string;
actionButtonStyle?: string;
duration?: number;
delete?: boolean;
important?: boolean;
action?: {
label: string;
onClick: (event: MouseEvent) => void;
};
cancel?: {
label: string;
onClick?: () => void;
};
onDismiss?: (toast: ToastT) => void;
onAutoClose?: (toast: ToastT) => void;
dismissable?: boolean;
promise?: PromiseT;
style?: string;
class?: string;
classes?: ToastClassnames;
descriptionClass?: string;
position?: Position;
unstyled?: boolean;
/**
* @internal This is used to determine if the toast has been updated to determine when to reset timer. Hacky but works.
*/
updated?: boolean;
};
export type Position =
| 'top-left'
| 'top-right'
| 'bottom-left'
| 'bottom-right'
| 'top-center'
| 'bottom-center';
export type HeightT = {
height: number;
toastId: number | string;
};
export enum SwipeStateTypes {
SwipedOut = 'SwipedOut',
SwipedBack = 'SwipedBack',
NotSwiped = 'NotSwiped'
}
export type Theme = 'light' | 'dark';
export type ToastToDismiss = {
id: number | string;
dismiss: boolean;
};
export type ExternalToast<T extends ComponentType = ComponentType> = Omit<
ToastT<T>,
'id' | 'type' | 'title' | 'promise' | 'updated'
> & {
id?: number | string;
};
export type ToasterProps = Partial<{
/**
* Dark toasts in light mode and vice versa.
*
* @default false
*/
invert: boolean;
/**
* Toast's theme, either light, dark, or system
*
* @default 'light'
*/
theme: 'light' | 'dark' | 'system';
/**
* Place where the toasts will be rendered
*
* @default 'bottom-right'
*/
position: Position;
/**
* Keyboard shortcut that will move focus to the toaster area.
*
* @default '⌥/alt + T'
*/
hotkey: string[];
/**
* Makes error and success state more colorful
*
* @default false
*/
richColors: boolean;
/**
* Toasts will be expanded by default
*
* @default false
*/
expand: boolean;
/**
* The duration of the toast in milliseconds.
*
* @default 4000
*/
duration: number;
/**
* Amount of visible toasts
*
* @default 3
*/
visibleToasts: number;
/**
* Adds a close button to all toasts, shows on hover
*
* @default false
*/
closeButton: boolean;
/**
* These will act as default options for all toasts.
*
* @default {}
*/
toastOptions: ToastOptions;
/**
* Offset from the edges of the screen.
*
* @default '32px'
*/
offset: string | number | null;
/**
* Directionality of toast's text
*
* @default 'auto'
*/
dir: 'ltr' | 'rtl' | 'auto';
/**
* Gap between toasts when expanded, in pixels.
*
* @default '14px'
*/
gap: number;
/**
* Aria label to announce the notifications
* @default 'Notifications'
*
*/
containerAriaLabel?: string
}> &
HTMLOlAttributes;
export type ToastOptions = {
/**
* The classes applied to the toast element.
*/
class?: string;
/**
* The classes applied to the toast description element.
*/
descriptionClass?: string;
/**
* The CSS styles applied to the toast element.
*/
style?: string;
/**
* The CSS styles applied to the cancel button element.
*/
cancelButtonStyle?: string;
/**
* The CSS styles applied to the action button element.
*/
actionButtonStyle?: string;
/**
* The duration of the toast in milliseconds.
*/
duration?: number;
/**
* Whether the toast should be unstyled or not.
*/
unstyled?: boolean;
/**
* Classes to apply to the various elements of the toast.
*/
classes?: Expand<ToastClassnames>;
};
/**
* The classes applied to the various elements of the toast.
*/
export type ToastClassnames = {
toast?: string;
title?: string;
description?: string;
loader?: string;
closeButton?: string;
cancelButton?: string;
actionButton?: string;
} & ToastTypeClasses;
type ToastTypeClasses = Partial<Record<ToastTypes, string>>;
export type ToastProps = {
toast: ToastT;
index: number;
expanded: boolean;
invert: boolean;
position: Position;
visibleToasts: number;
expandByDefault: boolean;
closeButton: boolean;
interacting: boolean;
cancelButtonStyle: string;
actionButtonStyle: string;
duration: number;
class: string;
descriptionClass: string;
classes: ToastClassnames;
unstyled: boolean;
};