forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sweetalert.d.ts
215 lines (180 loc) · 7.8 KB
/
sweetalert.d.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
// Type definitions for SweetAlert 1.1.0
// Project: https://github.com/t4t5/sweetalert/
// Definitions by: Markus Peloso <https://github.com/ToastHawaii/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare var sweetAlert: SweetAlert.SweetAlertStatic;
declare var swal: SweetAlert.SweetAlertStatic;
declare module "sweetalert" {
export = swal;
}
declare module SweetAlert {
interface SettingsBase {
/**
* A description for the modal.
* Default: null
*/
text?: string;
/**
* The type of the modal. SweetAlert comes with 4 built-in types which will show a corresponding icon animation: "warning", "error", "success" and "info". You can also set it as "input" to get a prompt modal.
* Default: null
*/
type?: string;
/**
* If set to true, the user can dismiss the modal by pressing the Escape key.
* Default: true
*/
allowEscapeKey?: boolean;
/**
* A custom CSS class for the modal.
* Default: null
*/
customClass?: string;
/**
* If set to true, the user can dismiss the modal by clicking outside it.
* Default: false
*/
allowOutsideClick?: boolean;
/**
* If set to true, a "Cancel"-button will be shown, which the user can click on to dismiss the modal.
* Default: false
*/
showCancelButton?: boolean;
/**
* If set to false, the "OK/Confirm"-button will be hidden. Make sure you set a timer or set allowOutsideClick to true when using this, in order not to annoy the user.
* Default: true
*/
showConfirmButton?: boolean;
/**
* Use this to change the text on the "Confirm"-button. If showCancelButton is set as true, the confirm button will automatically show "Confirm" instead of "OK".
* Default: "OK"
*/
confirmButtonText?: string;
/**
* Use this to change the background color of the "Confirm"-button (must be a HEX value).
* Default: "#8CD4F5"
*/
confirmButtonColor?: string;
/**
* Use this to change the text on the "Cancel"-button.
* Default: "Cancel"
*/
cancelButtonText?: string;
/**
* Set to false if you want the modal to stay open even if the user presses the "Confirm"-button. This is especially useful if the function attached to the "Confirm"-button is another SweetAlert.
* Default: true
*/
closeOnConfirm?: boolean;
/**
* Set to false if you want the modal to stay open even if the user presses the "Cancel"-button. This is especially useful if the function attached to the "Cancel"-button is another SweetAlert.
* Default: true
*/
closeOnCancel?: boolean;
/**
* Add a customized icon for the modal.Should contain a string with the path to the image.
* Default: null
*/
imageUrl?: string;
/**
* If imageUrl is set, you can specify imageSize to describes how big you want the icon to be in px. Pass in a string with two values separated by an "x". The first value is the width, the second is the height.
* Default: "80x80"
*/
imageSize?: string;
/**
* Auto close timer of the modal. Set in ms (milliseconds).
* Default: null
*/
timer?: number;
/**
* If set to true, will not escape title and text parameters. (Set to false if you're worried about XSS attacks.)
* Default: false
*/
html?: boolean;
/**
* If set to false, the modal's animation will be disabled. Possible animations: "slide-from-top", "slide-from-bottom", "pop" (use true instead) and "none" (use false instead).
* Default: true
*/
animation?: boolean | string;
/**
* Change the type of the input field when using type: "input" (this can be useful if you want users to type in their password for example).
* Default: "text"
*/
inputType?: string;
/**
* When using the input-type, you can specify a placeholder to help the user.
* Default: null
*/
inputPlaceholder?: string;
/**
* Specify a default text value that you want your input to show when using type: "input"
* Default: null
*/
inputValue?: string;
/**
* Set to true to disable the buttons and show that something is loading.
* Default: false
*/
showLoaderOnConfirm?: boolean;
}
interface Settings extends SettingsBase {
/**
* The title of the modal.
*/
title: string;
}
interface SetDefaultsSettings extends SettingsBase {
/**
* The title of the modal.
* Default: null
*/
title?: string;
}
/**
* Is true or false if the user confirms or cancels the alert. Except for the type "input", then when the user confirms the alert, this variable contains the value of the input element.
*/
type CallbackArgument = boolean | string;
interface SweetAlertStatic {
/**
* SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. An awesome replacement for JavaScript's alert.
* @param title The title of the modal.
*/
(title: string): void;
/**
* SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. An awesome replacement for JavaScript's alert.
* @param title The title of the modal.
* @param text A description for the modal.
*/
(title: string, text: string): void;
/**
* SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. An awesome replacement for JavaScript's alert.
* @param title The title of the modal.
* @param text A description for the modal.
* @param type The type of the modal. SweetAlert comes with 4 built-in types which will show a corresponding icon animation: "warning", "error", "success" and "info". You can also set it as "input" to get a prompt modal.
*/
(title: string, text: string, type: string): void;
/**
* SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. An awesome replacement for JavaScript's alert.
* @param callback The callback from the users action. The value is true or false if the user confirms or cancels the alert. Except for the type "input", then when the user confirms the alert, the argument contains the value of the input element.
*/
(settings: Settings, callback?: (isConfirmOrInputValue: CallbackArgument) => any): void;
/**
* If you end up using a lot of the same settings when calling SweetAlert, you can use setDefaults at the start of your program to set them once and for all!
*/
setDefaults(settings: SetDefaultsSettings): void;
/**
* Close the currently open SweetAlert programmatically.
*/
close(): void;
/**
* Show an error message after validating the input field, if the user's data is bad.
*/
showInputError(errorMessage: string): void;
/**
* Enable the user to click on the cancel and confirm buttons.
*/
enableButtons(): void;
/**
* Disable the user to click on the cancel and confirm buttons.
*/
disableButtons(): void;
}
}