bs5dialog

Introduction

The offcanvas function is a part of the @ymlluo/bs5dialog package, which is based on Bootstrap 5. This function creates an offcanvas element with the given content and options.

Usage Example

ESM

import { offcanvas } from '@ymlluo/bs5dialog';

const content = 'This is the content of the offcanvas.';
const options = {
  title: 'Offcanvas Title',
  direction: 'start',
  size: '300px',
  id: 'offcanvas-id',
  backdrop: true,
  scroll: true,
  dark: false,
  accordion: true,
  container: '',
  onStart: function () {},
  onShown: function () {},
  onHidden: function () {}
};

const offcanvasInstance = offcanvas(content, options);

CJS

const { offcanvas } = require('@ymlluo/bs5dialog');

const content = 'This is the content of the offcanvas.';
const options = {
  title: 'Offcanvas Title',
  direction: 'start',
  size: '300px',
  id: 'offcanvas-id',
  backdrop: true,
  scroll: true,
  dark: false,
  accordion: true,
  container: '',
  onStart: function () {},
  onShown: function () {},
  onHidden: function () {}
};

const offcanvasInstance = offcanvas(content, options);

UMD

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Offcanvas Example</title>
    <!-- Include Bootstrap 5 CSS -->
    <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="open-offcanvas">Open Offcanvas</button>
    <script>
      const content = 'This is the content of the offcanvas.';
      const options = {
        title: 'Offcanvas Title',
        direction: 'start',
        size: '300px',
        id: 'offcanvas-id',
        backdrop: true,
        scroll: true,
        dark: false,
        accordion: true,
        container: '',
        onStart: function () {},
        onShown: function () {},
        onHidden: function () {}
      };

      const openOffcanvasButton = document.getElementById('open-offcanvas');
      openOffcanvasButton.addEventListener('click', function () {
        const offcanvasInstance = bs5dialog.offcanvas(content, options);
      });
    </script>
  </body>
</html>

Parameters

The offcanvas function takes two parameters:

List of Event Listeners

These events can be listened to using the addEventListener method. For example:

offcanvasInstance.el.addEventListener(‘bs5:dialog:shown’, (event) => { console.log(event.detail); }); ```