-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathindex.ts
277 lines (261 loc) · 7.31 KB
/
index.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
272
273
274
275
276
277
import Vue, { Component } from "vue";
import { CombinedVueInstance, VueConstructor } from "vue/types/vue";
import ToastInterface from "../ts/interface";
import { TYPE, POSITION } from "../ts/constants";
export type ToastID = string | number;
export interface CommonOptions {
/**
* Position of the toast on the screen.
*
* Can be any of top-right, top-center, top-left, bottom-right, bottom-center, bottom-left.
*/
position?: POSITION;
/**
* Position of the toast on the screen.
*
* Can be any of top-right, top-center, top-left, bottom-right, bottom-center, bottom-left.
*/
draggable?: boolean;
/**
* By how much of the toast width in percent (0 to 1) it must be dragged before being dismissed.
*/
draggablePercent?: number;
/**
* Whether or not the toast is paused when the window loses focus.
*/
pauseOnFocusLoss?: boolean;
/**
* Whether or not the toast is paused when it is hovered by the mouse.
*/
pauseOnHover?: boolean;
/**
* Whether or not the toast is closed when clicked.
*/
closeOnClick?: boolean;
/**
* How many milliseconds for the toast to be auto dismissed, or false to disable.
*/
timeout?: number | false;
/**
* Custom classes applied to the toast.
*/
toastClassName?: string | string[];
/**
* Custom classes applied to the body of the toast.
*/
bodyClassName?: string | string[];
/**
* Whether or not the progress bar is hidden.
*/
hideProgressBar?: boolean;
/**
* Only shows the close button when hovering the toast
*/
showCloseButtonOnHover?: boolean;
/**
* Custom icon class to be used.
*
* When set to `true`, the icon is set automatically depending on the toast type and `false` disables the icon.
*/
icon?:
| boolean
| string
| {
iconTag?: keyof HTMLElementTagNameMap;
iconChildren?: string;
iconClass?: string;
}
| Component
| JSX.Element;
/**
* Custom close button component
*
* Alternative close button component to be displayed in toasts
*/
closeButton?: false | keyof HTMLElementTagNameMap | Component | JSX.Element;
/**
* Custom classes applied to the close button of the toast.
*/
closeButtonClassName?: string | string[];
/**
* Accessibility options
*/
accessibility?: {
/**
* Toast accessibility role
*
* Accessibility option "role" for screen readers. Defaults to "alert".
*/
toastRole?: string;
/**
* Close button label
*
* Accessibility option of the closeButton's "label" for screen readers. Defaults to "close".
*/
closeButtonLabel?: string;
};
/**
* Right-to-Left support.
*
* If true, switches the toast contents from right to left. Defaults to false.
*/
rtl?: boolean;
/**
* Vue instance used to pass events across the interface
*
* Created by default, but you can use your own if you want
*/
eventBus?: InstanceType<VueConstructor>;
}
type ContainerCallback = () => HTMLElement | Promise<HTMLElement>;
export interface PluginOptions extends CommonOptions {
/**
* Container where the toasts are mounted.
*/
container?: HTMLElement | ContainerCallback;
/**
* Whether or not the newest toasts are placed on the top of the stack.
*/
newestOnTop?: boolean;
/**
* Maximum number of toasts on each stack at a time. Overflows wait until older toasts are dismissed to appear.
*/
maxToasts?: number;
/**
* Name of the Vue Transition or object with classes to use.
*
* Only `enter-active`, `leave-active` and `move` are applied.
*/
transition?: string | Record<"enter" | "leave" | "move", string>;
/**
* Duration of the transition.
*
* Can either be a positive integer for both enter and leave, or an object of shape `{enter: number, leave: number}`.
*/
transitionDuration?: number | Record<"enter" | "leave", number>;
/**
* Toast's defaults object for configuring default toast options for each toast type.
*
* Possible object properties can be any of `success error default info warning`
*/
toastDefaults?: Partial<Record<TYPE, ToastOptions>>;
/**
* Callback to filter toasts during creation
*
* Takes the new toast and a list of the current toasts and returns a modified toast or false.
*/
filterBeforeCreate?: (
toast: ToastOptionsAndRequiredContent,
toasts: ToastOptionsAndRequiredContent[]
) => ToastOptionsAndRequiredContent | false;
/**
* Callback to filter toasts during render
*
* Filter toasts during render and queues filtered toasts.
*/
filterToasts?: (
toasts: ToastOptionsAndRequiredContent[]
) => ToastOptionsAndRequiredContent[];
/**
* Extra CSS class or classes added to each of the Toast containers.
*
* Keep in mind that there is one container for each possible toast position.
*/
containerClassName?: string | string[];
/**
* Callback executed when the toast container is mounted.
*
* Receives the Container vue instance as a parameter.
*/
onMounted?: (
containerComponent: CombinedVueInstance<
Record<never, unknown> & Vue,
unknown,
unknown,
unknown,
Record<never, unknown>
>
) => void;
}
export interface ToastOptions extends CommonOptions {
/**
* ID of the toast.
*/
id?: ToastID;
/**
* Type of the toast.
*
* Can be any of `success error default info warning`
*/
type?: TYPE;
/**
* Callback executed when the toast is clicked.
*
* A closeToast callback is passed as argument to onClick when it is called.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
onClick?: (closeToast: Function) => void;
/**
* Callback executed when the toast is closed.
*/
onClose?: () => void;
}
export type RenderableToastContent = string | Component;
export interface ToastComponent {
/**
* Component that will be rendered.
*/
component: ToastContent;
/**
* `propName: propValue` pairs of props that will be passed to the component.
*
* __These are not reactive__
*/
props?: { [propName: string]: unknown };
/**
* `eventName: eventHandler` pairs of events that the component can emit.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
listeners?: { [listenerEvent: string]: Function };
}
export type ToastContent =
| RenderableToastContent
| JSX.Element
| ToastComponent;
export type ToastOptionsAndContent = ToastOptions & { content?: ToastContent };
export type ToastOptionsAndRequiredContent = ToastOptions & {
content: ToastContent;
};
export interface NuxtModuleOptions extends PluginOptions {
/**
* Path to the CSS file containing styles for the toasts.
* By default it is original Vue Toastification CSS file.
*
* If set to false, no CSS file is injected.
*/
cssFile?: string | false;
}
declare module "vue/types/vue" {
interface Vue {
$toast: ReturnType<typeof ToastInterface>;
}
interface VueConstructor {
$toast: ReturnType<typeof ToastInterface>;
}
}
declare module "@nuxt/types" {
interface NuxtAppOptions {
$toast: ReturnType<typeof ToastInterface>;
}
interface Context {
$toast: ReturnType<typeof ToastInterface>;
}
interface NuxtOptions {
toast?: NuxtModuleOptions;
}
}
declare module "vuex/types/index" {
interface Store<S> {
$toast: ReturnType<typeof ToastInterface>;
}
}