1
|
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
|
|
30
|
export function ShowConfirmDelete(deleteAction: () => void, deleteSubjectLabel: string) {
|
31
|
Swal.fire({
|
32
|
icon: 'question',
|
33
|
title: 'Opravdu si přejete smazat ' + deleteSubjectLabel + '?',
|
34
|
showCancelButton: true,
|
35
|
confirmButtonText: 'Smazat',
|
36
|
confirmButtonColor: '#d33',
|
37
|
cancelButtonText: 'Zrušit',
|
38
|
cancelButtonColor: '#c0c0c0',
|
39
|
}).then((result) => {
|
40
|
if (result.isConfirmed) {
|
41
|
deleteAction();
|
42
|
}
|
43
|
});
|
44
|
}
|
45
|
|
46
|
export function ShowConfirm(
|
47
|
action: () => void,
|
48
|
actionLabel: string,
|
49
|
description: string = '',
|
50
|
icon: SweetAlertIcon = 'question'
|
51
|
) {
|
52
|
Swal.fire({
|
53
|
icon: icon,
|
54
|
title: 'Opravdu si přejete ' + actionLabel + '?',
|
55
|
html: description,
|
56
|
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
|
}
|