Add modal controller

This commit is contained in:
2026-05-21 09:36:17 +02:00
parent 4dccd58bf3
commit c837a6e55f
4 changed files with 43 additions and 34 deletions

View File

@@ -0,0 +1,39 @@
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
static targets = ['modal'];
connect() {
console.log('#modal controller connected');
}
/**
*
* @param {Event} event
*/
showSemanticModal(event) {
const modal = this.modalTarget;
const title = modal.querySelector('.modal-title');
// Clear any existing content first
title.innerHTML = '';
title.innerHTML = event.content?.title;
const body = modal.querySelector('.modal-body');
body.innerHTML = '';
const contentType = event.content?.type;
const content = document.createElement(contentType);
if (contentType === 'img') {
content.src = event.content?.imgSrc;
content.classList.add('img-fluid');
}
const description = document.createElement('p');
description.textContent = event.content?.description;
description.classList.add('py-3', 'my-2', 'fst-italic');
body.appendChild(content);
body.appendChild(description);
bootstrap.Modal.getOrCreateInstance(modal).show();
}
}