forked from sweetalert2/sweetalert2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
1769 lines (1645 loc) · 63.6 KB
/
index.html
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge;" />
<title>SweetAlert2 - a beautiful, responsive, customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes</title>
<link rel="icon" href="./assets/favicon.png">
<link rel="apple-touch-icon" href="./assets/apple-touch-icon.png">
<link rel="dns-prefetch" href="https://fonts.googleapis.com">
<link rel="dns-prefetch" href="https://cdnjs.cloudflare.com">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Courgette">
<link rel="stylesheet" href="./assets/example.css">
<link rel="stylesheet" href="./assets/bootstrap4-buttons.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="preload" href="https://unsplash.it/400/200/?random" as="image">
<link rel="preload" href="https://bit.ly/1Nqn9HU" as="image">
<!-- Include a polyfill for ES6 Promises (optional) for IE11, UC Browser and Android browser support -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.js"></script>
<!-- This is what you need -->
<script src="./dist/sweetalert2.all.min.js"></script>
<!--.......................-->
</head>
<body>
<header>
<img src="./assets/swal2-logo.png" class="logo" width="498" alt="SweetAlert2 logo">
<h1>A beautiful, responsive, customizable, accessible (WAI-ARIA) replacement for JavaScript's popup boxes</h2>
<h2>Zero dependencies</h2>
<div class="carbonads-wrapper">
<script src="//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=limontegithubiosweetalert2" id="_carbonads_js" async></script>
</div>
<div class="stats mobile-hidden">
Current version: <a href="https://github.com/limonte/sweetalert2/releases" id="current-version" aria-label="Current version "></a> ●
Latest update: <a href="https://github.com/limonte/sweetalert2/commits/master" id="latest-update" aria-label="Latest update "></a> ●
Downloads last month: <a href="https://npm-stat.com/charts.html?package=sweetalert2" id="downloads-last-month" aria-label="Downloads last month "></a>
</div>
<a class="top-right-button download">Download</a>
<a href="https://unpkg.com/sweetalert2" tabindex="-1" class="top-right-button cdn" target="_blank" rel="noopener">CDN</a>
<div class="top-right-button donate">
<img src="./assets/paypal.png" width="32" height="32" alt="">
<span>Donate</span>
</div>
</header>
<div class="showcase normal">
<h4>Normal alert</h4>
<button>Show normal alert</button>
<pre><span class="func">alert</span>(<span class="str">'You clicked the button!'</span>)</pre>
<div class="vs-icon"></div>
</div>
<div class="showcase sweet">
<img src="./assets/swal2-logo.png" height="30" alt="SweetAlert2">
<button aria-label="Show SweetAlert2 success message">Show success message</button>
<pre>
swal(
<span class="str">'Good job!'</span>,
<span class="str">'You clicked the button!'</span>,
<span class="str">'success'</span>
)</pre>
</div>
<p>Pretty cool huh? SweetAlert2 automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. It's even highly customizeable, as you can see below!</p>
<!-- Examples -->
<h3>More examples</h3>
<ul class="examples">
<li class="message">
<div class="ui">
<p>A basic message</p>
<button aria-label="Try me! Example: A basic message">Try me!</button>
</div>
<pre>swal(<span class="str">'Any fool can use a computer'</span>)</pre>
</li>
<li class="title-text">
<div class="ui">
<p>A title with a text under</p>
<button aria-label="Try me! Example: A title with a text under">Try me!</button>
</div>
<pre>
swal(
<span class="str">'The Internet?'</span>,
<span class="str">'That thing is still around?'</span>,
<span class="str">'question'</span>
)</pre>
</li>
<li class="error">
<div class="ui">
<p>An error message</p>
<button aria-label="Try me! Example: An error message!">Try me!</button>
</div>
<pre>
swal(
<span class="str">'Oops...'</span>,
<span class="str">'Something went wrong!'</span>,
<span class="str">'error'</span>
)</pre>
</li>
<li id="long-text">
<div class="ui">
<p>A modal window with a long text inside:</p>
<button aria-label="Try me! Example: A modal window with a long text inside">Try me!</button>
</div>
<pre>
swal({
html: <span class="str">'Less is more.<br>'</span>.repeat(<span class="val">100</span>)
})</pre>
</li>
<li class="html" id="custom-html">
<div class="ui">
<p>Custom HTML description and buttons with ARIA labels</p>
<button aria-label="Try me! Example: Custom HTML description and buttons">Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'<i>HTML</i> <u>example</u>'</span>,
type: <span class="str">'info'</span>,
html:
<span class="str">'You can use <b>bold text</b>, '</span> +
<span class="str">'<a href="//github.com">links</a> '</span> +
<span class="str">'and other HTML tags'</span>,
showCloseButton: <span class="val">true</span>,
showCancelButton: <span class="val">true</span>,
focusConfirm: <span class="val">false</span>,
confirmButtonText:
<span class="str">'<i class="fa fa-thumbs-up"></i> Great!'</span>,
confirmButtonAriaLabel: <span class="str">'Thumbs up, great!'</span>,
cancelButtonText:
<span class="str">'<i class="fa fa-thumbs-down"></i>'</span>,
cancelButtonAriaLabel: <span class="str">'Thumbs down'</span>,
})</pre>
</li>
<li id="position">
<div class="ui">
<p>A custom positioned dialog</p>
<button aria-label="Try me! Example: A custom positioned dialog">Try me!</button>
</div>
<pre>
swal({
position: <span class="str">'top-right'</span>,
type: <span class="str">'success'</span>,
title: <span class="str">'Your work has been saved'</span>,
showConfirmButton: <span class="val">false</span>,
timer: <span class="str">1500</span>
})</pre>
</li>
<li class="html-jquery">
<div class="ui">
<p>jQuery HTML with custom animation (<a href="https://daneden.github.io/animate.css/" target="_blank" rel="noopener">Animate.css <i class="fa fa-external-link"></i></a>)</p>
<button aria-label="Try me! Example: jQuery HTML with custom animation">Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'jQuery HTML example'</span>,
html: $(<span class="str">'<div>'</span>)
.addClass(<span class="str">'some-class'</span>)
.text(<span class="str">'jQuery is everywhere.'</span>),
animation: <span class="val">false</span>,
customClass: <span class="str">'animated tada'</span>
})</pre>
</li>
<li class="warning confirm">
<div class="ui">
<p>A warning message, with a function attached to the "Confirm"-button...</p>
<button aria-label="Try me! Example: A warning message, with a function attached to the 'Confirm'-button">Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'Are you sure?'</span>,
text: <span class="str">"You won't be able to revert this!"</span>,
type: <span class="str">'warning'</span>,
showCancelButton: <span class="val">true</span>,
confirmButtonColor: <span class="str">'#3085d6'</span>,
cancelButtonColor: <span class="str">'#d33'</span>,
confirmButtonText: <span class="str">'Yes, delete it!'</span>
}).<span class="tag">then</span>((result) => {
<span class="tag">if</span> (result.value) {
swal(
<span class="str">'Deleted!'</span>,
<span class="str">'Your file has been deleted.'</span>,
<span class="str">'success'</span>
)
}
})</pre>
</li>
<li class="warning cancel" id="dismiss-handle">
<div class="ui">
<p>... and by passing a parameter, you can execute something else for "Cancel".</p>
<button aria-label="Try me! Example: passing a parameter, you can execute something else for 'Cancel'">Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'Are you sure?'</span>,
text: <span class="str">"You won't be able to revert this!"</span>,
type: <span class="str">'warning'</span>,
showCancelButton: <span class="val">true</span>,
confirmButtonColor: <span class="str">'#3085d6'</span>,
cancelButtonColor: <span class="str">'#d33'</span>,
confirmButtonText: <span class="str">'Yes, delete it!'</span>,
cancelButtonText: <span class="str">'No, cancel!'</span>,
confirmButtonClass: <span class="str">'btn btn-success'</span>,
cancelButtonClass: <span class="str">'btn btn-danger'</span>,
buttonsStyling: <span class="val">false</span>
}).<span class="tag">then</span>((result) => {
<span class="tag">if</span> (result.value) {
swal(
<span class="str">'Deleted!'</span>,
<span class="str">'Your file has been deleted.'</span>,
<span class="str">'success'</span>
)
<span class="comment">// result.dismiss can be 'cancel', 'overlay',</span>
<span class="comment">// 'close', and 'timer'</span>
} <span class="tag">else if</span> (result.dismiss === <span class="str">'cancel'</span>) {
swal(
<span class="str">'Cancelled'</span>,
<span class="str">'Your imaginary file is safe :)'</span>,
<span class="str">'error'</span>
)
}
})</pre>
</li>
<li class="custom-image">
<div class="ui">
<p>A message with a custom image and CSS animation disabled</p>
<button aria-label="Try me! Example: A message with a custom image and CSS animation disabled">Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'Sweet!'</span>,
text: <span class="str">'Modal with a custom image.'</span>,
imageUrl: <span class="str">'https://unsplash.it/400/200'</span>,
imageWidth: <span class="val">400</span>,
imageHeight: <span class="val">200</span>,
imageAlt: <span class="str">'Custom image'</span>,
animation: <span class="val">false</span>
})</pre>
</li>
<li class="custom-width-padding-background">
<div class="ui">
<p>A message with custom width, padding and background</p>
<button aria-label="Try me! Example: A message with custom width, padding and background">Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'Custom width, padding, background.'</span>,
width: <span class="val">600</span>,
padding: <span class="val">100</span>,
background: <span class="str">'#fff url(//bit.ly/1Nqn9HU)'</span>
})</pre>
</li>
<li class="timer">
<div class="ui">
<p>A message with auto close timer</p>
<button aria-label="Try me! Example: A message with auto close timer">Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'Auto close alert!'</span>,
text: <span class="str">'I will close in 5 seconds.'</span>,
timer: <span class="val">5000</span>,
onOpen: () => {
swal.showLoading()
}
}).<span class="tag">then</span>((result) => {
<span class="tag">if</span> (result.dismiss === <span class="str">'timer'</span>) {
console.log(<span class="str">'I was closed by the timer'</span>)
}
})</pre>
</li>
<li class="ajax-request" id="ajax-request">
<div class="ui">
<p>Ajax request example</p>
<button aria-label="Try me! Example: Ajax request">Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'Submit email to run ajax request'</span>,
input: <span class="str">'email'</span>,
showCancelButton: <span class="val">true</span>,
confirmButtonText: <span class="str">'Submit'</span>,
showLoaderOnConfirm: <span class="val">true</span>,
preConfirm: (email) => {
<span class="tag">return new</span> <span class="func">Promise</span>((resolve) => {
<span class="func">setTimeout</span>(() => {
<span class="tag">if</span> (email === <span class="str">'taken@example.com'</span>) {
swal.showValidationError(
<span class="str">'This email is already taken.'</span>
)
}
resolve()
}, <span class="val">2000</span>)
})
},
allowOutsideClick: <span class="val">false</span>
}).<span class="tag">then</span>((result) => {
<span class="tag">if</span> (result.value) {
swal({
type: <span class="str">'success'</span>,
title: <span class="str">'Ajax request finished!'</span>,
html: <span class="str">'Submitted email: '</span> + result.email
})
}
})</pre>
</li>
<li class="chaining-modals" id="chaining-modals">
<div class="ui">
<p>Chaining modals (queue) example</p>
<button aria-label="Try me! Example: Chaining modals (queue)">Try me!</button>
</div>
<pre>
swal.setDefaults({
input: <span class="str">'text'</span>,
confirmButtonText: <span class="str">'Next &rarr;'</span>,
showCancelButton: <span class="val">true</span>,
progressSteps: [<span class="str">'1'</span>, <span class="str">'2'</span>, <span class="str">'3'</span>]
})
<span class="func">var</span> steps = [
{
title: <span class="str">'Question 1'</span>,
text: <span class="str">'Chaining swal2 modals is easy'</span>
},
<span class="str">'Question 2'</span>,
<span class="str">'Question 3'</span>
]
swal.queue(steps).<span class="tag">then</span>((result) => {
swal.resetDefaults()
<span class="tag">if</span> (result.value) {
swal({
title: <span class="str">'All done!'</span>,
html:
<span class="str">'Your answers: <pre>'</span> +
JSON.stringify(result.value) +
<span class="str">'</pre>'</span>,
confirmButtonText: <span class="str">'Lovely!'</span>
})
}
})</pre>
</li>
<li class="dynamic-queue" id="dynamic-queue">
<div class="ui">
<p>Dynamic queue example</p>
<button aria-label="Try me! Example: Dynamic queue">Try me!</button>
</div>
<pre>
const ipAPI = <span class="str">'https://api.ipify.org?format=json'</span>
swal.queue([{
title: <span class="str">'Your public IP'</span>,
confirmButtonText: <span class="str">'Show my public IP'</span>,
text:
<span class="str">'Your public IP will be received '</span> +
<span class="str">'via AJAX request'</span>,
showLoaderOnConfirm: <span class="val">true</span>,
preConfirm: () => {
<span class="tag">return new</span> <span class="func">Promise</span>((resolve) => {
<span class="tag">return</span> $.get(ipAPI).<span class="tag">then</span>((data) => {
swal.insertQueueStep(data.ip)
})
}}
}
}])</pre>
</li>
</ul>
<!-- Download & Install -->
<div class="center-container download-section">
<h3>Download & install</h3>
<pre class="center">$ npm install sweetalert2</pre>
<p>Or</p>
<pre class="center">$ bower install sweetalert2</pre>
<p>
Or download from CDN:
<a href="https://unpkg.com/sweetalert2" target="_blank" rel="noopener">unpkg.com/sweetalert2 <i class="fa fa-external-link"></i></a>
</p>
</div>
<div class="center-container">
<h3>Usage</h3>
<p>1. Initialize the plugin by referencing the necessary files:</p>
<pre><<span class="tag">script</span> <span class="attr">src</span>=<span class="str">"bower_components/sweetalert2/dist/sweetalert2.all.min.js"</span>></<span class="tag">script</span>>
<span class="comment"><!-- Include a polyfill for ES6 Promises (optional) for IE11 and Android browser --></span>
<<span class="tag">script</span> <span class="attr">src</span>=<span class="str">"https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.js"</span>></<span class="tag">script</span>></pre>
<p>You can also include the stylesheet separately if desired:</p>
<pre><<span class="tag">script</span> <span class="attr">src</span>=<span class="str">"bower_components/sweetalert2/dist/sweetalert2.min.js"</span>></<span class="tag">script</span>>
<<span class="tag">link</span> <span class="attr">rel</span>=<span class="str">"stylesheet"</span> <span class="tag">href</span>=<span class="str">"bower_components/sweetalert2/dist/sweetalert2.min.css"</span>></pre>
<p>Or</p>
<pre><span class="comment">// ES6 Modules or TypeScript</span>
<span class="val">import</span> swal <span class="val">from</span> <span class="str">'sweetalert2'</span>
<span class="comment">// CommonJS</span>
<span class="val">const</span> swal = <span class="func">require</span>(<span class="str">'sweetalert2'</span>)</pre>
<p>2. Call the sweetAlert2-function after the page has loaded</p>
<pre>swal({
title: <span class="str">'Error!'</span>,
text: <span class="str">'Do you want to continue'</span>,
type: <span class="str">'error'</span>,
confirmButtonText: <span class="str">'Cool'</span>
})</pre>
</div>
<div class="mobile-hidden">
<!-- Configuration -->
<h3>Configuration</h3>
<p class="center">Here are the keys that you can use if you pass an object into sweetAlert2:</p>
<table>
<tr class="titles">
<th>
Argument
</th>
<th>Default value</th>
<th>
Description
</th>
</tr>
<tr>
<td><b>title</b></td>
<td><i>null</i></td>
<td>The title of the modal, as HTML. It can either be added to the object under the key "title" or passed as the first parameter of the function.</td>
</tr>
<tr>
<td><b>titleText</b></td>
<td><i>null</i></td>
<td>The title of the modal, as text. Useful to avoid HTML injection.</td>
</tr>
<tr>
<td><b>text</b></td>
<td><i>null</i></td>
<td>A description for the modal. It can either be added to the object under the key "text" or passed as the second parameter of the function.</td>
</tr>
<tr>
<td><b>html</b></td>
<td><i>null</i></td>
<td>A HTML description for the modal. If "text" and "html" parameters are provided in the same time, "text" will be used.</td>
</tr>
<tr>
<td><b>type</b></td>
<td><i>null</i></td>
<td>The type of the modal. SweetAlert2 comes with 5 built-in types which will show a corresponding icon animation: <strong>warning</strong>, <strong>error</strong>, <strong>success</strong>, <strong>info</strong> and <strong>question</strong>. It can either be put in the array under the key "type" or passed as the third parameter of the function.</td>
</tr>
<tr>
<td><b>backdrop</b></td>
<td><i>true</i></td>
<td>Whether or not SweetAlert2 should show a full screen click-to-dismiss backdrop</td>
</tr>
<tr>
<td><b>toast</b></td>
<td><i>false</i></td>
<td> Whether or not an alert should be treated as a toast notification. This option is normally coupled with the <strong>position</strong> parameter and a timer. Toasts are NEVER autofocused.</td>
</tr>
<tr>
<td><b>target</b></td>
<td><i>'body'</i></td>
<td>The container element for adding modal into.</td>
</tr>
<tr id="input-parameter">
<td><b>input</b></td>
<td><i>null</i></td>
<td>
Input field type, can be
<strong>text</strong>, <strong>email</strong>, <strong>password</strong>,
<strong>number</strong>, <strong>tel</strong>, <strong>range</strong>,
<strong>textarea</strong>, <strong>select</strong>, <strong>radio</strong>,
<strong>checkbox</strong>, <strong>file</strong> and <strong>url</strong>.
</td>
</tr>
<tr>
<td><b>width</b></td>
<td><i>'500px'</i></td>
<td>Modal window width, including paddings (<i>box-sizing: border-box</i>). Can be in <strong>px</strong> or <strong>%</strong>.</td>
</tr>
<tr>
<td><b>padding</b></td>
<td><i>20</i></td>
<td>Modal window padding.</td>
</tr>
<tr>
<td><b>background</b></td>
<td><i>'#fff'</i></td>
<td>Modal window background (CSS background property).</td>
</tr>
<tr>
<td><b>position</b></td>
<td><i>'center'</i></td>
<td>Modal window position, can be <strong>'top'</strong>, <strong>'top-left'</strong>, <strong>'top-right'</strong>, <strong>'center'</strong>, <strong>'center-left'</strong>, <strong>'center-right'</strong>, <strong>'bottom'</strong>, <strong>'bottom-left'</strong>, or <strong>'bottom-right'</strong>.</td>
</tr>
<tr>
<td><b>grow</b></td>
<td><i>'false'</i></td>
<td>Paired with window position, sets the direction the modal should grow in, can be set to <strong>'row'</strong>, <strong>'column'</strong>, <strong>'fullscreen'</strong>, or <strong>false</strong>.</td>
</tr>
<tr>
<td><b>customClass</b></td>
<td><i>null</i></td>
<td>A custom CSS class for the modal.</td>
</tr>
<tr id="timer">
<td><b>timer</b></td>
<td><i>null</i></td>
<td>Auto close timer of the modal. Set in ms (milliseconds).</td>
</tr>
<tr>
<td><b>animation</b></td>
<td><i>true</i></td>
<td>If set to <strong>false</strong>, modal CSS animation will be disabled.</td>
</tr>
<tr id="allow-outside-click">
<td><b>allowOutsideClick</b></td>
<td><i>true</i></td>
<td>If set to <strong>false</strong>, the user can't dismiss the modal by clicking outside it.</td>
</tr>
<tr id="allow-escape-key">
<td><b>allowEscapeKey</b></td>
<td><i>true</i></td>
<td>If set to <strong>false</strong>, the user can't dismiss the modal by pressing the Escape key.</td>
</tr>
<tr id="allow-enter-key">
<td><b>allowEnterKey</b></td>
<td><i>true</i></td>
<td>If set to <strong>false</strong>, the user can't confirm the modal by pressing the Enter or Space keys, unless they manually focus the confirm button.</td>
</tr>
<tr>
<td><b>showConfirmButton</b></td>
<td><i>true</i></td>
<td>If set to <strong>false</strong>, a "Confirm"-button will not be shown. It can be useful when you're using custom HTML description.</td>
</tr>
<tr id="show-cancel-button">
<td><b>showCancelButton</b></td>
<td><i>false</i></td>
<td>If set to <strong>true</strong>, a "Cancel"-button will be shown, which the user can click on to dismiss the modal.</td>
</tr>
<tr>
<td><b>confirmButtonText</b></td>
<td><i>'OK'</i></td>
<td>Use this to change the text on the "Confirm"-button.</td>
</tr>
<tr>
<td><b>cancelButtonText</b></td>
<td><i>'Cancel'</i></td>
<td>Use this to change the text on the "Cancel"-button.</td>
</tr>
<tr>
<td><b>confirmButtonColor</b></td>
<td><i>'#3085d6'</i></td>
<td>Use this to change the background color of the "Confirm"-button (must be a HEX value).</td>
</tr>
<tr>
<td><b>cancelButtonColor</b></td>
<td><i>'#aaa'</i></td>
<td>Use this to change the background color of the "Cancel"-button (must be a HEX value).</td>
</tr>
<tr>
<td><b>confirmButtonClass</b></td>
<td><i>null</i></td>
<td>A custom CSS class for the "Confirm"-button.</td>
</tr>
<tr>
<td><b>cancelButtonClass</b></td>
<td><i>null</i></td>
<td>A custom CSS class for the "Cancel"-button.</td>
</tr>
<tr>
<td><b>confirmButtonAriaLabel</b></td>
<td><i>''</i></td>
<td>Use this to change the <strong>aria-label</strong> for the "Confirm"-button.</td>
</tr>
<tr>
<td><b>cancelButtonAriaLabel</b></td>
<td><i>''</i></td>
<td>Use this to change the <strong>aria-label</strong> for the "Cancel"-button.</td>
</tr>
<tr>
<td><b>buttonsStyling</b></td>
<td><i>true</i></td>
<td>Apply default swal2 styling to buttons. If you want to use your own classes (e.g. Bootstrap classes) set this parameter to <strong>false</strong>.</td>
</tr>
<tr>
<td><b>reverseButtons</b></td>
<td><i>false</i></td>
<td>Set to <strong>true</strong> if you want to invert default buttons positions ("Confirm"-button on the right side).</td>
</tr>
<tr>
<td><b>focusConfirm</b></td>
<td><i>true</i></td>
<td> Set to <strong>false</strong> if you want to focus the first element in tab order instead of "Confirm"-button by default.</td>
</tr>
<tr>
<td><b>focusCancel</b></td>
<td><i>false</i></td>
<td>Set to <strong>true</strong> if you want to focus the "Cancel"-button by default.</td>
</tr>
<tr id="show-close-button">
<td><b>showCloseButton</b></td>
<td><i>false</i></td>
<td>Set to <strong>true</strong> to show close button in top right corner of the modal.</td>
</tr>
<tr>
<td><b>closeButtonAriaLabel</b></td>
<td><i>'Close this dialog'</i></td>
<td>Use this to change the <strong>aria-label</strong> for the close button.</td>
</tr>
<tr>
<td><b>showLoaderOnConfirm</b></td>
<td><i>false</i></td>
<td>Set to <strong>true</strong> to disable buttons and show that something is loading. Use it in combination with the <a href="#pre-confirm"><strong>preConfirm</strong></a> parameter.</td>
</tr>
<tr id="pre-confirm">
<td><b>preConfirm</b></td>
<td><i>null</i></td>
<td>Function to execute before confirm, may be async (Promise-returning) or sync, see <a href="#ajax-request">usage example</a>.</td>
</tr>
<tr id="image">
<td><b>imageUrl</b></td>
<td><i>null</i></td>
<td>Add a customized icon for the modal. Should contain a string with the path or URL to the image.</td>
</tr>
<tr>
<td><b>imageWidth</b></td>
<td><i>null</i></td>
<td>If imageUrl is set, you can specify imageWidth to describes image width in px.</td>
</tr>
<tr>
<td><b>imageHeight</b></td>
<td><i>null</i></td>
<td>Custom image height in px.</td>
</tr>
<tr>
<td><b>imageAlt</b></td>
<td><i>''</i></td>
<td>An alternative text for the custom image icon.</td>
</tr>
<tr>
<td><b>imageClass</b></td>
<td><i>null</i></td>
<td>A custom CSS class for the customized icon.</td>
</tr>
<tr id="input-placeholder">
<td><b>inputPlaceholder</b></td>
<td><i>''</i></td>
<td>Input field placeholder.</td>
</tr>
<tr id="input-value">
<td><b>inputValue</b></td>
<td><i>''</i></td>
<td>Input field initial value.</td>
</tr>
<tr id="input-options">
<td><b>inputOptions</b></td>
<td><i>{} or Promise</i></td>
<td>If <strong>input</strong> parameter is set to <strong>"select"</strong> or <strong>"radio"</strong>, you can provide options. Object keys will represent options values, object values will represent options text values.</td>
</tr>
<tr id="input-auto-trim">
<td><b>inputAutoTrim</b></td>
<td><i>true</i></td>
<td>Automatically remove whitespaces from both ends of a result string. Set this parameter to <strong>false</strong> to disable auto-trimming.</td>
</tr>
<tr id="input-attributes">
<td><b>inputAttributes</b></td>
<td><i>{}</i></td>
<td>HTML input attributes (e.g. <strong>min</strong>, <strong>max</strong>, <strong>autocomplete</strong>, <strong>accept</strong>), that are added to the input field. Object keys will represent attributes names, object values will represent attributes values.</td>
</tr>
<tr id="input-validator">
<td><b>inputValidator</b></td>
<td><i>null</i></td>
<td>Validator for input field, may be async (Promise-returning) or sync, see <a href="#input-select">usage example</a>.</td>
</tr>
<tr id="input-class">
<td><b>inputClass</b></td>
<td><i>null</i></td>
<td>A custom CSS class for the input field.</td>
</tr>
<tr>
<td><b>progressSteps</b></td>
<td><i>[]</i></td>
<td>Progress steps, useful for modal queues, see <a href="#chaining-modals">usage example</a>.</td>
</tr>
<tr>
<td><b>currentProgressStep</b></td>
<td><i>null</i></td>
<td>Current active progress step. The default is <strong>swal.getQueueStep()</strong></td>
</tr>
<tr>
<td><b>progressStepsDistance</b></td>
<td><i>'40px'</i></td>
<td>Distance between progress steps.</td>
</tr>
<tr>
<td><b>onBeforeOpen</b></td>
<td><i>null</i></td>
<td>Function to run when modal built, but not shown yet. Provides modal DOM element as the first argument.</td>
</tr>
<tr>
<td><b>onOpen</b></td>
<td><i>null</i></td>
<td>Function to run when modal opens, provides modal DOM element as the first argument.</td>
</tr>
<tr>
<td><b>onClose</b></td>
<td><i>null</i></td>
<td>Function to run when modal closes, provides modal DOM element as the first argument.</td>
</tr>
<tr>
<td><b>useRejections</b></td>
<td><i>false</i></td>
<td><strong>Deprecated and will be removed in the next major release.</strong> Determines whether dismissals (outside click, cancel button, close button, Esc key, timer) should resolve with an object of the format <strong>{ dismiss: reason }</strong> or reject the promise.</td>
</tr>
<tr>
<td><b>expectRejections</b></td>
<td><i>false</i></td>
<td><strong>Deprecated and will be removed in the next major release.</strong> Determines whether given <strong>inputValidator</strong> and <strong>preConfirm</strong> functions should be expected to to signal validation errors by rejecting, or by their respective means (see documentation for each option). </td>
</tr>
</table>
<p class="center">
You can redefine default params by using <strong>swal.setDefaults(customParams)</strong>.
</p>
</div>
<!-- Handling Dismissals -->
<div class="center-container">
<h3>Handling Dismissals</h3>
<p class="center">When an alert is dismissed by the user, the Promise returned by <strong>swal()</strong> will be resolved with an object <strong>{ dismiss: reason }</strong> documenting the reason it was dismissed:</p>
<table>
<tr class="titles">
<th>String</th>
<th>Description</th>
<th>Related configuration</th>
</tr>
<tr>
<td><strong>'overlay'</strong></td>
<td>The user clicked the overlay.</td>
<td><a href="#allow-outside-click">allowOutsideClick</a></td>
</tr>
<tr>
<td><strong>'cancel'</strong></td>
<td>The user clicked the cancel button.</td>
<td><a href="#show-cancel-button">showCancelButton</a></td>
</tr>
<tr>
<td><strong>'close'</strong></td>
<td>The user clicked the close button.</td>
<td><a href="#show-close-button">showCloseButton</a></td>
</tr>
<tr>
<td><strong>'esc'</strong></td>
<td>The user clicked the Esc key.</td>
<td><a href="#allow-escape-key">allowEscapeKey</a></td>
</tr>
<tr>
<td><strong>'timer'</strong></td>
<td>The timer ran out, and the alert closed automatically.</td>
<td><a href="#timer">timer</a></td>
</tr>
</table>
<!-- Modal Types -->
<h3>Modal Types</h3>
<table class="modal-types">
<tr>
<td><strong>success</strong></td>
<td>
<div class="swal2-icon swal2-success">
<div class="swal2-success-circular-line-left"></div>
<span class="swal2-success-line-tip"></span> <span class="swal2-success-line-long"></span>
<div class="swal2-success-ring"></div> <div class="swal2-success-fix"></div>
<div class="swal2-success-circular-line-right"></div>
</div>
</td>
<td><button class="type-success" aria-label="Try me! Example: success modal">Try me!</button></td>
</tr>
<tr>
<td><strong>error</strong></td>
<td>
<div class="swal2-icon swal2-error">
<span class="swal2-x-mark"><span class="swal2-x-mark-line-left"></span><span class="swal2-x-mark-line-right"></span></span>
</div>
</td>
<td><button class="type-error" aria-label="Try me! Example: error modal">Try me!</button></td>
</tr>
<tr>
<td><strong>warning</strong></td>
<td><div class="swal2-icon swal2-warning">!</div></td>
<td><button class="type-warning" aria-label="Try me! Example: warning modal">Try me!</button></td>
</tr>
<tr>
<td><strong>info</strong></td>
<td><div class="swal2-icon swal2-info">i</div></td>
<td><button class="type-info" aria-label="Try me! Example: info modal">Try me!</button></td>
</tr>
<tr>
<td><strong>question</strong></td>
<td><div class="swal2-icon swal2-question">?</div></td>
<td><button class="type-question" aria-label="Try me! Example: question modal">Try me!</button></td>
</tr>
</table>
<!-- Input Types -->
<h3>Input Types</h3>
<table class="modal-input-types">
<tr id="input-text">
<td><strong>text</strong></td>
<td>
<pre>
<span class="val">const</span> {value: name} = <span class="func">await</span> swal({
title: <span class="str">'What is your name?'</span>,
input: <span class="str">'text'</span>,
inputPlaceholder: <span class="str">'Enter your name or nickname'</span>,
showCancelButton: <span class="val">true</span>,
inputValidator: (value) => {
<span class="tag">return</span> !value <span class="val">&&</span> <span class="str">'You need to write something!'</span>
}
})
<span class="tag">if</span> (name) {
swal({type: <span class="str">'success'</span>, title: <span class="str">'Hi, '</span> + name})
}</pre>
</td>
<td><button class="input-type-text" aria-label="Try me! Example: input type text">Try me!</button></td>
</tr>
<tr id="input-email">
<td><strong>email</strong></td>
<td>
<pre>
<span class="val">const</span> {value: email} = <span class="func">await</span> swal({
title: <span class="str">'Input email address'</span>,
input: <span class="str">'email'</span>,
inputPlaceholder: <span class="str">'Enter your email address'</span>
})
<span class="tag">if</span> (email) {
swal(<span class="str">'Entered email: '</span> + email)
}</pre>
</td>
<td><button class="input-type-email" aria-label="Try me! Example: input type email">Try me!</button></td>
</tr>
<tr id="input-url">
<td><strong>url</strong></td>
<td>
<pre>
<span class="val">const</span> {value: url} = <span class="func">await</span> swal({
input: <span class="str">'url'</span>,
inputPlaceholder: <span class="str">'Enter the URL'</span>
})
<span class="tag">if</span> (url) {
swal(<span class="str">'Entered URL: '</span> + url)
}</pre>
</td>
<td><button class="input-type-url">Try me!</button></td>
</tr>
<tr id="input-password">
<td><strong>password</strong></td>
<td>
<pre>
<span class="val">const</span> {value: password} = <span class="func">await</span> swal({
title: <span class="str">'Enter your password'</span>,
input: <span class="str">'password'</span>,
inputPlaceholder: <span class="str">'Enter your password'</span>,
inputAttributes: {
<span class="str">'maxlength'</span>: <span class="val">10</span>,
<span class="str">'autocapitalize'</span>: <span class="str">'off'</span>,
<span class="str">'autocorrect'</span>: <span class="str">'off'</span>
}
})
<span class="tag">if</span> (password) {
swal(<span class="str">'Entered password: '</span> + password)
}</pre>
</td>
<td><button class="input-type-password" aria-label="Try me! Example: input type password">Try me!</button></td>
</tr>
<tr id="input-textarea">
<td><strong>textarea</strong></td>
<td>
<pre>
<span class="val">const</span> {value: text} = <span class="func">await</span> swal({
input: <span class="str">'textarea'</span>,
inputPlaceholder: <span class="str">'Type your message here'</span>,
showCancelButton: <span class="val">true</span>
})
<span class="tag">if</span> (text) {
swal(text)
}</pre>
</td>
<td><button class="input-type-textarea" aria-label="Try me! Example: input type textarea">Try me!</button></td>
</tr>
<tr id="input-select">
<td><strong>select</strong></td>
<td>
<pre>
<span class="val">const</span> {value: country} = <span class="func">await</span> swal({
title: <span class="str">'Select Ukraine'</span>,
input: <span class="str">'select'</span>,
inputOptions: {
<span class="str">'SRB'</span>: <span class="str">'Serbia'</span>,
<span class="str">'UKR'</span>: <span class="str">'Ukraine'</span>,
<span class="str">'HRV'</span>: <span class="str">'Croatia'</span>
},
inputPlaceholder: <span class="str">'Select country'</span>,
showCancelButton: <span class="val">true</span>,
inputValidator: (value) => {
<span class="tag">return new</span> <span class="func">Promise</span>((resolve) => {
<span class="tag">if</span> (value === <span class="str">'UKR'</span>) {
resolve()
} <span class="tag">else</span> {
resolve(<span class="str">'You need to select Ukraine :)'</span>)
}
})
}
})
<span class="tag">if</span> (country) {
swal(<span class="str">'You selected: '</span> + country)
}</pre>
</td>
<td><button class="input-type-select" aria-label="Try me! Example: input type select">Try me!</button></td>
</tr>
<tr id="input-radio">
<td><strong>radio</strong></td>
<td>
<pre>
<span class="comment">// inputOptions can be an object or Promise</span>
<span class="func">var</span> inputOptions = <span class="tag">new</span> <span class="func">Promise</span>((resolve) => {
<span class="func">setTimeout</span>(() => {
resolve({
<span class="str">'#ff0000'</span>: <span class="str">'Red'</span>,
<span class="str">'#00ff00'</span>: <span class="str">'Green'</span>,
<span class="str">'#0000ff'</span>: <span class="str">'Blue'</span>
})
}, <span class="val">2000</span>)
})
<span class="val">const</span> {value: color} = <span class="func">await</span> swal({
title: <span class="str">'Select color'</span>,
input: <span class="str">'radio'</span>,
inputOptions: inputOptions,
inputValidator: (value) => {
<span class="tag">return</span> !value && <span class="str">'You need to choose something!'</span>
}
})
<span class="tag">if</span> (color) {
swal({html: <span class="str">'You selected: '</span> + result})
}</pre>
</td>
<td><button class="input-type-radio" aria-label="Try me! Example: input type radio">Try me!</button></td>
</tr>
<tr id="input-checkbox">
<td><strong>checkbox</strong></td>
<td>
<pre>
<span class="val">const</span> {value: accept} = <span class="func">await</span> swal({