Created
February 25, 2017 17:07
-
-
Save dammyammy/314e23d62584b37d6965b7ad088b7df0 to your computer and use it in GitHub Desktop.
A simple ES6 class Wrapping sweetAlert2
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
import swal from 'sweetalert2'; | |
class Alert { | |
static success(title = 'Success!', body = 'Action Completed Successfully!', timer = 2500, confirm = false) { | |
return swal({ | |
title, | |
timer, | |
html: body + '<div class="m-b-50"></div>', | |
type: 'success', | |
showConfirmButton: confirm, | |
}).catch(swal.noop); | |
} | |
static error(title = 'Error!', body = 'There was a problem!', timer = 2500, confirm = false) { | |
return swal({ | |
title, | |
timer, | |
html: body + '<div class="m-b-50"></div>', | |
type: 'error', | |
showConfirmButton: confirm, | |
}).catch(swal.noop); | |
} | |
static delete(data, then) { | |
return swal({ | |
title: data.title || "Are you sure?", | |
text: data.text || "You will not be able to recover data!", | |
type: "warning", | |
showCancelButton: true, | |
showLoaderOnConfirm: true, | |
confirmButtonColor: "hsl(348, 100%, 61%)", | |
confirmButtonText: data.confirmText || 'Yes, delete!', | |
}).then(() => then()).catch(swal.noop); | |
} | |
} | |
export default Alert; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment