Skip to content

Instantly share code, notes, and snippets.

@rw3iss
Last active October 20, 2020 16:08
Show Gist options
  • Save rw3iss/526159aeff1c42b0357e7af197c0c05f to your computer and use it in GitHub Desktop.
Save rw3iss/526159aeff1c42b0357e7af197c0c05f to your computer and use it in GitHub Desktop.
toastr Notifications
import toastr from 'toastr';
export function notify(message, type?, timeout?) {
// todo, set options elsewhere/on init ?
toastr.options = {
"closeButton": false,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-bottom-right",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": timeout ? timeout : "2000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
toastr.clear();
switch(type) {
case 'error':
return toastr.error(message);
case 'success':
return toastr.success(message);
default:
return toastr.success(message);
}
}
// Usage:
import notify from 'notify';
notify('Message', 'success', 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment