SweetAlert
Dialog yang aksesibel untuk konfirmasi, isian singkat, dan umpan balik cepat — bergaya Selaras, di setiap tema dan mode.
SweetAlert2 11.26 · MIT Dokumentasi
Sekali atur, semua dialog
Buat mixin sekali saja. Mixin ini mengganti tombol bawaan SweetAlert dengan tombol Selaras (utama di kanan), dan warnanya diambil dari token tema — tak ada yang perlu diubah untuk mode gelap.
const SL_CLASSES = {
popup: 'sl-swal',
confirmButton: 'sl-btn sl-btn-primary',
denyButton: 'sl-btn sl-btn-danger-soft',
cancelButton: 'sl-btn sl-btn-light',
input: 'sl-control'
};
const SlSwal = Swal.mixin({
buttonsStyling: false, // use Selaras buttons instead
reverseButtons: true, // Cancel left, main action right
customClass: SL_CLASSES
});
// customClass in fire() REPLACES the mixin's object — spread SL_CLASSES when you change one button Contoh
Tekan tombol untuk membuka dialog sungguhan. Fokus pindah ke dialog, Escape menutupnya, dan fokus kembali ke tombol.
Berhasil
SlSwal.fire({
icon: 'success',
title: 'Invoice sent',
text: 'INV-2026-0146 is on its way to ava@harborcoffee.com.'
}); Konfirmasi hapus
const r = await SlSwal.fire({
icon: 'warning',
title: 'Delete INV-2026-0147?',
text: 'The draft for Pinecrest HR will be removed. You can’t undo this.',
showCancelButton: true,
confirmButtonText: 'Delete draft',
customClass: { ...SL_CLASSES, confirmButton: 'sl-btn sl-btn-danger' },
showLoaderOnConfirm: true,
preConfirm: () => new Promise((ok) => setTimeout(ok, 800))
});
if (r.isConfirmed) SlToast.fire({ icon: 'success', title: 'Draft deleted' }); Isian dengan validasi
const { value } = await SlSwal.fire({
title: 'Rename workspace',
input: 'text',
inputLabel: 'Workspace name',
inputValue: 'Selaras Studio',
showCancelButton: true,
confirmButtonText: 'Save',
inputValidator: (v) => !v.trim() ? 'Enter a name.' : v.trim().length > 40 ? 'Keep it under 40 characters.' : null
});
if (value) SlToast.fire({ icon: 'success', title: 'Renamed to ' + value.trim() }); Tiga pilihan
const r = await SlSwal.fire({
icon: 'question',
title: 'Save changes to INV-2026-0148?',
text: 'You edited 2 line items.',
showDenyButton: true,
showCancelButton: true,
confirmButtonText: 'Save',
denyButtonText: 'Discard',
cancelButtonText: 'Keep editing'
});
// r.isConfirmed → save · r.isDenied → discard · r.isDismissed → stay Tutup otomatis dengan pengatur waktu
SlSwal.fire({
icon: 'info',
title: 'Syncing your calendar…',
text: 'This window closes by itself.',
timer: 3000,
timerProgressBar: true,
showConfirmButton: false
}); Toast
const SlToast = SlSwal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 4000,
timerProgressBar: true,
didOpen: (t) => { // pause while the pointer is on it
t.addEventListener('mouseenter', Swal.stopTimer);
t.addEventListener('mouseleave', Swal.resumeTimer);
}
});
SlToast.fire({ icon: 'success', title: 'Payment received from Atlas Law' }); Konten kaya
SlSwal.fire({
title: 'Send INV-2026-0146?',
html: `<dl class="sl-swal-list">
<div><dt>Client</dt><dd>Harbor Coffee</dd></div>
<div><dt>Due</dt><dd>Sep 29, 2026</dd></div>
<div><dt>Total</dt><dd>$7,700.00</dd></div>
</dl>`,
showCancelButton: true,
confirmButtonText: 'Send invoice',
footer: '<a href="app-invoice.html?no=INV-2026-0146">Open the invoice</a>'
});