bs5dialog

Introduction

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.

Usage Example

ESM

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
});

CJS

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
});

UMD

<!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>

Parameters

List of Event Listeners

Usage of addEventListener

 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.');
});