Skip to content

Commit 2517451

Browse files
committed
switch to sweetalert2
1 parent 4914d88 commit 2517451

File tree

8 files changed

+64
-57
lines changed

8 files changed

+64
-57
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ These requirements must be referenced in your main HTML file. For example:
145145
* [Moment.js](http://momentjs.com/)
146146
* [Semantic UI](https://github.com/Semantic-Org/Semantic-UI)
147147
* [Semantic UI Calendar](https://github.com/mdehoog/Semantic-UI-Calendar)
148-
* [SweetAlert](http://t4t5.github.io/sweetalert/)
148+
* [SweetAlert2](https://limonte.github.io/sweetalert2/)
149149
* [Toastr](http://codeseven.github.io/toastr/)
150150

151151
### <a id="License_44"></a>License

demo/src/docs/home/view.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
li
122122
a(href='https://github.com/mdehoog/Semantic-UI-Calendar') Semantic UI Calendar
123123
li
124-
a(href='http://t4t5.github.io/sweetalert/') SweetAlert
124+
a(href='https://limonte.github.io/sweetalert2/') SweetAlert2
125125
li
126126
a(href='http://codeseven.github.io/toastr/') Toastr
127127
h3

demo/src/docs/modules/alert/index.ts

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ export class Alert extends Virtual<Vue>() {
2626
showCancelButton: true,
2727
confirmButtonColor: "#DD6B55",
2828
confirmButtonText: "Yes, delete it!",
29-
closeOnConfirm: false
30-
},
31-
function () {
32-
swal("Deleted!", "Your imaginary file has been deleted.", "success");
33-
})
29+
}).then(() => {
30+
this.$ui.alert("Deleted!", "Your imaginary file has been deleted.", "success");
31+
})
3432
}
3533

3634
sample5() {
@@ -41,17 +39,20 @@ export class Alert extends Virtual<Vue>() {
4139
showCancelButton: true,
4240
confirmButtonColor: "#DD6B55",
4341
confirmButtonText: "Yes, delete it!",
44-
cancelButtonText: "No, cancel plx!",
45-
closeOnConfirm: false,
46-
closeOnCancel: false
47-
},
48-
function (isConfirm) {
49-
if (isConfirm) {
50-
swal("Deleted!", "Your imaginary file has been deleted.", "success");
51-
} else {
52-
swal("Cancelled", "Your imaginary file is safe :)", "error");
53-
}
54-
})
42+
cancelButtonText: "No, cancel plx!"
43+
}).then(() => {
44+
this.$ui.alert("Deleted!", "Your imaginary file has been deleted.", "success");
45+
}, (dismiss) => {
46+
// dismiss can be 'cancel', 'overlay',
47+
// 'close', and 'timer'
48+
if (dismiss === 'cancel') {
49+
this.$ui.alert(
50+
'Cancelled',
51+
'Your imaginary file is safe :)',
52+
'error'
53+
)
54+
}
55+
})
5556
}
5657

5758
sample6() {
@@ -65,8 +66,7 @@ export class Alert extends Virtual<Vue>() {
6566
sample7() {
6667
this.$ui.alert({
6768
title: "HTML <small>Title</small>!",
68-
text: "A custom <span style=\"color: #F8BB86\">html<span> message.",
69-
html: true
69+
html: "A custom <span style=\"color: #F8BB86\">html<span> message."
7070
})
7171
}
7272

@@ -84,38 +84,45 @@ export class Alert extends Virtual<Vue>() {
8484
this.$ui.alert({
8585
title: "An input!",
8686
text: "Write something interesting:",
87-
type: "input",
87+
input: 'text',
8888
showCancelButton: true,
89-
closeOnConfirm: false,
90-
animation: "slide-from-top",
91-
inputPlaceholder: "Write something"
92-
},
93-
function (inputValue) {
94-
if (inputValue === false) return false;
95-
96-
if (inputValue === "") {
97-
swal.showInputError("You need to write something!");
98-
return false
99-
}
100-
101-
swal("Nice!", "You wrote: " + inputValue, "success");
102-
})
89+
animation: true,
90+
inputPlaceholder: "Write something",
91+
inputValidator: (value) => {
92+
return new Promise((resolve, reject) => {
93+
if (value) {
94+
resolve()
95+
} else {
96+
reject('You need to write something!')
97+
}
98+
}) as any
99+
}
100+
}).then((inputValue) => {
101+
this.$ui.alert("Nice!", "You wrote: " + inputValue, "success");
102+
})
103103
}
104104

105105
sample10() {
106106
this.$ui.alert({
107107
title: "Ajax request example",
108-
text: "Submit to run ajax request",
109-
type: "info",
108+
input: 'email',
110109
showCancelButton: true,
111-
closeOnConfirm: false,
112-
showLoaderOnConfirm: true,
113-
},
114-
function () {
115-
setTimeout(function () {
116-
swal("Ajax request finished!");
117-
}, 2000);
118-
})
110+
showLoaderOnConfirm: true,
111+
preConfirm: function (email) {
112+
return new Promise(function (resolve, reject) {
113+
setTimeout(function () {
114+
if (email === '[email protected]') {
115+
reject('This email is already taken.')
116+
} else {
117+
resolve()
118+
}
119+
}, 2000)
120+
})
121+
},
122+
allowOutsideClick: false
123+
}).then((email) => {
124+
this.$ui.alert("Email submitted to '" + email + "'!");
125+
})
119126
}
120127

121128

demo/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010

1111
entry: {
1212
bundle: ['./src/index.ts'],
13-
vendor: ['vue', 'vue-router', 'vue-typed', 'moment', 'lodash', 'autonumeric', 'js-beautify', 'sweetalert', 'toastr']
13+
vendor: ['vue', 'vue-router', 'vue-typed', 'moment', 'lodash', 'autonumeric', 'js-beautify', 'sweetalert2', 'toastr']
1414
},
1515

1616
output: {

dist/vue-typed-ui.js

Lines changed: 5 additions & 4 deletions
Large diffs are not rendered by default.

lib/modules.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as swal from 'sweetalert'
1+
import { default as swal } from 'sweetalert2'
22
import * as toastr from 'toastr'
33

4-
export type Alert = typeof swal
4+
export type Alert = typeof swal
55
export type Toastr = typeof toastr
66
export type Focus = (element: string | HTMLElement | JQuery) => JQuery
77

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
"author": "Budi Adiono <[email protected]>",
1414
"license": "MIT",
1515
"dependencies": {
16-
"@types/sweetalert": "^1.1.27",
1716
"@types/toastr": "^2.1.32",
1817
"autonumeric": "^1.9.46",
1918
"moment": "^2.16.0",
20-
"sweetalert": "^1.1.3",
19+
"sweetalert2": "^6.4.0",
2120
"toastr": "^2.1.2",
2221
"vue": "^2.0.5",
2322
"vue-typed": "^2.0.3"

src/modules/alert/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as Vue from 'vue'
2-
import * as swal from 'sweetalert'
3-
import '../../../node_modules/sweetalert/dist/sweetalert.css';
2+
import { default as swal } from 'sweetalert2'
3+
import '../../../node_modules/sweetalert2/dist/sweetalert2.css';
44

55
export function alert(instance, $this: Vue) {
66
return function (options: any) {
7-
swal.apply(this, arguments)
7+
return swal.apply(this, arguments)
88
}
99
}

0 commit comments

Comments
 (0)