1 |
8c45ccb0
|
hrubyjar
|
import Swal, { SweetAlertIcon, SweetAlertPosition } from 'sweetalert2';
|
2 |
|
|
import withReactContent from 'sweetalert2-react-content';
|
3 |
|
|
|
4 |
|
|
const MySwal = withReactContent(Swal);
|
5 |
|
|
|
6 |
|
|
export function ShowToast(
|
7 |
|
|
text: string,
|
8 |
|
|
icon: SweetAlertIcon = 'success',
|
9 |
|
|
timer = 3000,
|
10 |
|
|
position: SweetAlertPosition = 'top-right'
|
11 |
|
|
) {
|
12 |
|
|
const Toast = Swal.mixin({
|
13 |
|
|
toast: true,
|
14 |
|
|
position: position,
|
15 |
|
|
showConfirmButton: false,
|
16 |
|
|
timer: timer,
|
17 |
|
|
timerProgressBar: true,
|
18 |
|
|
didOpen: (toast) => {
|
19 |
|
|
toast.addEventListener('mouseenter', Swal.stopTimer);
|
20 |
|
|
toast.addEventListener('mouseleave', Swal.resumeTimer);
|
21 |
|
|
},
|
22 |
|
|
});
|
23 |
|
|
|
24 |
|
|
Toast.fire({
|
25 |
|
|
icon: icon,
|
26 |
|
|
title: text,
|
27 |
|
|
});
|
28 |
|
|
}
|
29 |
43d49a98
|
Jaroslav Hrubý
|
|
30 |
|
|
export function ShowConfirmDelete(deleteAction: () => void, deleteSubjectLabel: string) {
|
31 |
|
|
Swal.fire({
|
32 |
d7167305
|
Jaroslav Hrubý
|
icon: 'question',
|
33 |
43d49a98
|
Jaroslav Hrubý
|
title: 'Opravdu si přejete smazat ' + deleteSubjectLabel + '?',
|
34 |
|
|
showCancelButton: true,
|
35 |
|
|
confirmButtonText: 'Smazat',
|
36 |
d7167305
|
Jaroslav Hrubý
|
confirmButtonColor: '#d33',
|
37 |
|
|
cancelButtonText: 'Zrušit',
|
38 |
|
|
cancelButtonColor: '#c0c0c0',
|
39 |
43d49a98
|
Jaroslav Hrubý
|
}).then((result) => {
|
40 |
|
|
if (result.isConfirmed) {
|
41 |
|
|
deleteAction();
|
42 |
|
|
}
|
43 |
|
|
});
|
44 |
|
|
}
|
45 |
b51488cd
|
Jaroslav Hrubý
|
|
46 |
c4f198c3
|
Jaroslav Hrubý
|
export function ShowConfirm(
|
47 |
|
|
action: () => void,
|
48 |
|
|
actionLabel: string,
|
49 |
|
|
description: string = '',
|
50 |
|
|
icon: SweetAlertIcon = 'question'
|
51 |
|
|
) {
|
52 |
b51488cd
|
Jaroslav Hrubý
|
Swal.fire({
|
53 |
c4f198c3
|
Jaroslav Hrubý
|
icon: icon,
|
54 |
b51488cd
|
Jaroslav Hrubý
|
title: 'Opravdu si přejete ' + actionLabel + '?',
|
55 |
c4f198c3
|
Jaroslav Hrubý
|
html: description,
|
56 |
b51488cd
|
Jaroslav Hrubý
|
showCancelButton: true,
|
57 |
|
|
confirmButtonText: 'Potvrdit',
|
58 |
|
|
confirmButtonColor: '#5278ff',
|
59 |
|
|
cancelButtonText: 'Zrušit',
|
60 |
|
|
cancelButtonColor: '#c0c0c0',
|
61 |
|
|
}).then((result) => {
|
62 |
|
|
if (result.isConfirmed) {
|
63 |
|
|
action();
|
64 |
|
|
}
|
65 |
|
|
});
|
66 |
|
|
}
|