Sweet Alert 2 w/ Promises
HTML
<script src="https://cdn.jsdelivr.net/sweetalert2/6.5.6/sweetalert2.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/sweetalert2/6.5.6/sweetalert2.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
<button>Try me!</button>
CSS
body {
font-family: 'Open Sans', sans-serif;
}
p {
line-height: 25px; margin: 30px auto;
font-size: 17px; font-weight: 300;
color: #848d94;
}
button {
background-color: #3085d6; color: #fff;
border: 0; box-shadow: none; border-radius: 3px;
font-size: 17px; font-weight: 500;
padding: 15px 35px; margin: 26px 5px 0;
cursor: pointer;
white-space: nowrap;
}
Babel + JSX
$('button').on('click', () => {
return swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, cancel!',
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
buttonsStyling: false
})
.then( () => {
swal(
'Deleted!',
'Your file has been deleted.',
'success'
)
alert('hunain')
})
.catch( (dismiss) => {
// dismiss can be 'cancel', 'overlay',
// 'close', and 'timer'
if (dismiss === 'cancel') {
swal(
'Cancelled',
'Your imaginary file is safe :)',
'error'
)
}
})
})