Projekt

Obecné

Profil

Stáhnout (1.66 KB) Statistiky
| Větev: | Tag: | Revize:
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
export function ShowConfirm(action: () => void, actionLabel: string) {
47
    Swal.fire({
48
        icon: 'question',
49
        title: 'Opravdu si přejete ' + actionLabel + '?',
50
        showCancelButton: true,
51
        confirmButtonText: 'Potvrdit',
52
        confirmButtonColor: '#5278ff',
53
        cancelButtonText: 'Zrušit',
54
        cancelButtonColor: '#c0c0c0',
55
    }).then((result) => {
56
        if (result.isConfirmed) {
57
            action();
58
        }
59
    });
60
}