Skip to content

Instantly share code, notes, and snippets.

@Fernando74lr
Last active August 6, 2021 19:23
Show Gist options
  • Save Fernando74lr/f5de8f0059e1666e653024cbe3c9ae0c to your computer and use it in GitHub Desktop.
Save Fernando74lr/f5de8f0059e1666e653024cbe3c9ae0c to your computer and use it in GitHub Desktop.
Simple sweet alert toast for JavaScript
/*
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