Modal

<div class="modal-container">
    <div class="w-100 h-100 d-flex justify-content-center align-items-center my-5">
        <button type="button" class="button buttpon--primary" data-bs-toggle="modal" data-bs-target="#modal-dialog">
            Launch demo modal
        </button>
    </div>

    <div class="modal fade show " style="display: block;" id="modal-dialog" tabindex="-1" aria-labelledby="modal-label" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable  modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <p class="modal-title" id="moda-label">Modal title</p>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">

                    empty layout

                </div>
                <div class="modal-footer">
                    <button type="button" class="button" data-bs-dismiss="modal">Close</button>
                    <button type="button" class="button">Save changes</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-backdrop fade show"></div>
</div>
<div class="modal-container">
  {{#if trigger}}
    <div class="w-100 h-100 d-flex justify-content-center align-items-center my-5">
      <button type="button" class="button buttpon--primary" data-bs-toggle="modal" data-bs-target="#{{ id }}">
        Launch demo modal
      </button>
    </div>
  {{/if}}

  <div
    class="modal fade{{#if show}} show{{/if}} {{ className }}"
    {{#if show }} style="display: block;"{{/if}}
    id="{{ id }}"
    tabindex="-1"
    aria-labelledby="modal-label"
    aria-hidden="true"
    >
    <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable {{#if size}} modal-{{size}}{{else}} modal-lg{{/if}}">
      <div class="modal-content">
        <div class="modal-header">
          <p class="modal-title" id="moda-label">{{ title }}</p>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">

          {{#>@partial-block }}
            empty layout
          {{/@partial-block }}

        </div>
        {{#if footer}}
          <div class="modal-footer">
            <button type="button" class="button" data-bs-dismiss="modal">Close</button>
            <button type="button" class="button">Save changes</button>
          </div>
        {{/if}}
      </div>
    </div>
  </div>
  {{#if show}}
    <div class="modal-backdrop fade show"></div>
  {{/if}}
</div>
{
  "id": "modal-dialog",
  "show": true,
  "trigger": true,
  "title": "Modal title",
  "footer": true
}
  • Content:
    import { Modal } from 'bootstrap'; 
    import * as Popper from "@popperjs/core";
    
    export const BootstrapModal = (() => {
      async function fetchUrl(url) {
        const html = await fetch(url)
          .then((response) => response.text());
    
        const parser = new DOMParser();
        const doc = parser.parseFromString(html, 'text/html');
        // const update = doc.querySelector('.page-section');
    
        return doc;
      }
    
      document.addEventListener('click', async (event) => {
        const trigger = event.target.closest('[data-bs-target]');
        const id = trigger && trigger.dataset.bsTarget;
        const target = id && document.querySelector(id);
    
        if (trigger && (!target || !target.childNodes.length)) {
          event.preventDefault();
          event.stopPropagation();
          event.stopImmediatePropagation();
    
          const url = trigger.dataset.bsUrl;
          const response = url && await fetchUrl(url);
          document.body.appendChild(response.body.firstElementChild);
    
          if (!trigger.dataset.bsToggle) {
            trigger.dataset.bsToggle = 'modal';
    
            trigger.dispatchEvent(new Event('click', {
              bubbles: true,
              cancelable: true
            }));
    
            window.dispatchEvent(new Event('DOMContentLoaded', {
              bubbles: true,
              cancelable: true
            }));
      
            window.dispatchEvent(new Event('load', {
              bubbles: true,
              cancelable: true
            }));
          }
        }
      });
    
      document.addEventListener('DOMContentLoaded', function () {
        const modals = Array.from(document.querySelectorAll('.modal'));
        if (modals.length) {
          modals.forEach(modal => {
            modal.addEventListener('show.bs.modal', async (event) => {
              const target = event.relatedTarget;
              const url = target && target.dataset.bsUrl;
              if (url && ! modal.childNodes.length) {
                event.preventDefault();
                event.stopPropagation();
                const response = url && await fetchUrl(url);
                const update = response.querySelector('[data-fetch-body]');
                modal.parentNode.replaceChild(update, modal);
                const newModal = new Modal(update);
                newModal.show();
    
                window.dispatchEvent(new Event('DOMContentLoaded', {
                  bubbles: true,
                  cancelable: true
                }));
    
                window.dispatchEvent(new Event('load', {
                  bubbles: true,
                  cancelable: true
                }));
              }
            })
          });
        }
      });
    })();
    
    export default BootstrapModal;
    
  • URL: /components/raw/modal/modal.js
  • Filesystem Path: src/components/templates/modal/modal.js
  • Size: 2.5 KB
  • Content:
    .modal-content {
      --bs-modal-color: var(--body-color)
    }
    
    .modal-backdrop {
      backdrop-filter: blur(1.25rem);
      box-shadow: .5rem .5rem 1rem 0 rgba(15, 15, 15, 0.1);
    }
    
    .button--modal-close {
      position: absolute;
      top: 1.5rem;
      right: 1.5rem;
    }
  • URL: /components/raw/modal/modal.scss
  • Filesystem Path: src/components/templates/modal/modal.scss
  • Size: 247 Bytes

No notes defined.