Last active
August 6, 2021 19:23
-
-
Save Fernando74lr/f5de8f0059e1666e653024cbe3c9ae0c to your computer and use it in GitHub Desktop.
Simple sweet alert toast for JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Sweet Alert 2 | |
INSTALLATION: | |
npm i sweetalert2 | |
ICONS: | |
- success | |
- error | |
- warning | |
- info | |
- question | |
USAGE: | |
toast('success', 'Data updated!'); | |
*/ | |
import Swal from 'sweetalert2'; | |
const Toast = Swal.mixin({ | |
toast: true, | |
position: 'top-end', | |
showConfirmButton: false, | |
timer: 2500, | |
timerProgressBar: true, | |
didOpen: (toast) => { | |
toast.addEventListener('mouseenter', Swal.stopTimer) | |
toast.addEventListener('mouseleave', Swal.resumeTimer) | |
} | |
}); | |
export const toast = (icon, message) => { | |
Toast.fire({ | |
icon: icon, | |
title: message | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment