The confirm function is exported from the @ymlluo/bs5dialog package and is used to display a confirmation modal with customizable options.
import { confirm } from '@ymlluo/bs5dialog';
const options = {
title: 'Are you sure?',
type: 'danger',
btnOkText: 'Yes',
btnCancelText: 'No',
onConfirm: () => {
console.log('Confirmed!');
},
onCancel: () => {
console.log('Cancelled!');
}
};
const { el, content, options: confirmedOptions } = confirm('Are you sure you want to do this?', options);
const { confirm } = require('@ymlluo/bs5dialog');
const options = {
title: 'Are you sure?',
type: 'danger',
btnOkText: 'Yes',
btnCancelText: 'No',
onConfirm: () => {
console.log('Confirmed!');
},
onCancel: () => {
console.log('Cancelled!');
}
};
const { el, content, options: confirmedOptions } = confirm('Are you sure you want to do this?', options);
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Confirm Modal Example</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="../bs5dialog.css">
<script src="../bs5dialog.js"></script>
</head>
<body>
<button id="confirm-btn">Confirm</button>
<script>
const confirmBtn = document.getElementById('confirm-btn');
confirmBtn.addEventListener('click', () => {
const options = {
title: 'Are you sure?',
type: 'danger',
btnOkText: 'Yes',
btnCancelText: 'No',
onConfirm: () => {
console.log('Confirmed!');
},
onCancel: () => {
console.log('Cancelled!');
}
};
const { el, content, options: confirmedOptions } = bs5dialog.confirm('Are you sure you want to do this?', options);
});
</script>
</body>
</html>
The confirm function takes in two parameters:
options (object): The options for the modal. It can contain the following properties:
const confirmBtn = document.getElementById('confirm-btn');
confirmBtn.addEventListener('click', () => {
bs5dialog.confirm('Are you sure you want to do this?');
})
confirmBtn.addEventListener('bs5:dialog:confirm:ok', () => {
console.log('OK button clicked.');
});