-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
type.ts
266 lines (230 loc) · 6.3 KB
/
type.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
export type XPosition = 'left' | 'center' | 'right';
export type YPosition = 'top' | 'center' | 'bottom';
export type Position = `${YPosition}-${XPosition}`;
export type MaybeArray<T> = T | T[];
export interface Icon {
/**
* The html element name to use.
*/
tag?: keyof HTMLElementTagNameMap;
/**
* The html to use.
*/
ligature?: string;
icon?: string;
}
/**
* Settings that can be applied to both toasts and global settings.
*/
export interface BaseSettings {
/**
* Whether the toast disappears after a time.
*
* @default true
*/
canTimeout?: boolean;
/**
* Whether the toast can be paused by hovering over the toast.
*
* @default true
*/
pauseOnHover?: boolean;
/**
* Whether a default title should be shown if no title is supplied.
*
* @default true
*/
defaultTitle?: boolean;
/**
* Whether the progressbar should be shown on the notification or not.
*
* @default false
*/
hideProgressbar?: boolean;
/**
* The theme that should be displaying.
* By default, there's `light` and `dark` theme.
*
* @default 'dark'
*/
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
theme?: 'light' | 'dark' | string;
/**
* If string supplied this will apply the usual transition classes (eg.: .name-enter-active).
* If an object is supplied, it expects a `name` and optionally a `moveClass`
* (this class has to use `!important` for its rules) attribute.
* The name will be applied as above. The move class is applied when the notifications adjust their position.
*/
transition?: string | { name: string; moveClass?: string };
/**
* If set to false, no icon will be shown on the notification.
*
* @default true
*/
iconEnabled?: boolean;
/**
* Whether to enable dismissing the notification by dragging or not.
*
* @default true
*/
draggable?: boolean;
/**
* A number between 0-5 representing how far the notification should be dragged to dismiss.
*
* @default 0.75
*/
// todo - 5 is probably an option for too high value
dragThreshold?: number;
/**
* Whether the toast should pause when the window loses focus.
*
* @default true
*/
pauseOnFocusLoss?: boolean;
}
export interface Settings extends BaseSettings {
/**
* Only display one toast at a time.
*/
singular?: boolean;
/**
* Whether new notifications should display on top of the stack or not.
*
* @default true
*/
orderLatest?: boolean;
/**
* Show a backdrop that blocks the rest of the page.
*
* @default false
*/
withBackdrop?: boolean;
/**
* The color of the backdrop.
*
* @default rgba(0, 0, 0, 0.2)
*/
backdrop?: string;
/**
* The position of the toast.
*
* @default bottom-right
*/
position?: Position;
/**
* The duration in milliseconds the error notification should be visible for.
*
* @default 8000
*/
errorDuration?: number;
/**
* The duration in milliseconds the success notification should be visible for.
*
* @default 4000
*/
successDuration?: number;
/**
* The duration in milliseconds the warning and info notification should be visible for.
*
* @default 6000
*/
warningInfoDuration?: number;
/**
* If string is set, this will be appended to every user-supplied icon's class.
*/
baseIconClass?: string;
/**
* Defines how many toasts should be visible at a time. Others are queued.
*
* @default 6
*/
maxToasts?: number;
/**
* If turned on, only toasts with unique mode/type will be shown.
* Others are queued.
*
* @default false
*/
oneType?: boolean;
customNotifications?: Record<string, ToastOptions>;
}
export interface ToastOptions extends BaseSettings {
/**
* The time the notification is displayed for in milliseconds regardless of its type. (this cannot be updated later)
*/
duration?: number;
/**
* String to display or alternatively a html string.
*/
body: string;
/**
* Title to display for the toast.
*/
title?: string;
/**
* Defines what notification type should be showing available types:
* "success", "warning", "info", "error".
*
* @default 'success'
*/
type?: 'info' | 'warning' | 'error' | 'success';
/**
* If set the notification will be shown in the given mode: loader, prompt.
* Alternatively you may use the methods: `this.$vToastify.loader("more readable")`
*/
mode?: 'loader' | 'prompt';
/**
* If the type is prompt the object keys will display to the user and the value will be returned to the promise.
*
* @default {{ Yes: true, No: false }}
*/
answers?: Record<string, any>;
/**
* This will be displayed instead of the default icons.
* If is a string the string will be assigned to the class unless it is a svg.
*/
icon?: string | Icon;
/**
* This function will be called when the notification has been dismissed or the timeout has finished.
*/
callback?: CallableFunction;
/**
* Delay the notification by the given number of milliseconds.
*/
delay?: number;
}
export type Status = string | ToastOptions;
export interface Toast extends ToastOptions {
/**
* v4 uuid.
*/
id: string;
}
export type ContainerMethods = {
/**
* Add new toast.
* @param status
*/
add: (status: ToastOptions) => Toast['id'];
/**
* Remove toast by id or all toasts (queued included) if no id given.
* @param id
*/
remove: (id?: Toast['id']) => number;
/**
* Get toast by id or all toasts (queued included) if no id given.
* @param id
*/
get: <T extends Toast['id']>(id?: T) => T extends undefined ? Toast[] : Toast | undefined;
/**
* Update toast by id.
* @param id
* @param toast
*/
set: (id: string, toast: ToastOptions) => boolean;
/**
* Stop the loader toast by id or all loaders if no id given.
* @param id
*/
stopLoader: (id?: Toast['id']) => number;
};