The alert function displays an alert modal with the given content and options. It returns an object containing the alert modal element, content, and options.
import { alert } from '@ymlluo/bs5dialog';
alert('This is an alert message.', {
title: 'Alert',
type: 'warning',
size: 'md',
btnOkText: 'OK',
onOk: () => {
console.log('OK button clicked.');
},
timeout: 5000
});
const { alert } = require('@ymlluo/bs5dialog');
alert('This is an alert message.', {
title: 'Alert',
type: 'warning',
size: 'md',
btnOkText: 'OK',
onOk: () => {
console.log('OK button clicked.');
},
timeout: 5000
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>UMD Example</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
<script src="../bs5dialog.js"></script>
</head>
<body>
<button id="alertBtn">Show Alert</button>
<script>
const alertBtn = document.getElementById('alertBtn');
alertBtn.addEventListener('click', () => {
bs5dialog.alert('This is an alert message.', {
title: 'Alert',
type: 'warning',
size: 'md',
btnOkText: 'OK',
onOk: () => {
console.log('OK button clicked.');
},
timeout: 5000
});
});
</script>
</body>
</html>
const alertBtn = document.getElementById('alertBtn');
alertBtn.addEventListener('click', () => {
bs5dialog.alert('This is an alert message.');
});
alertBtn.addEventListener('bs5:dialog:alert:ok', (event) => {
console.log('ok.');
});