Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tblivet committed Nov 26, 2024
1 parent 2eadd96 commit 099ad80
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
7 changes: 7 additions & 0 deletions _dev/src/scss/components/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

$e: ".modal";

@at-root {
::backdrop {
background-color: rgba(0, 0, 0, 0.5);
}
}

#{$ua-id} {

#{$e} {
&-content {
display: flex;
Expand Down
15 changes: 9 additions & 6 deletions _dev/src/ts/components/ModalContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,31 @@ export default class ModalContainer implements DomLifecycle {
}

#displayModal(): void {
$(
document.getElementById(ModalContainer.containerId)?.getElementsByClassName('modal') || []
).modal('show');
const modal = document.getElementById(ModalContainer.containerId)?.getElementsByClassName('dialog')[0] as HTMLDialogElement;
if (modal) {
modal.showModal();
}
}

#onClick(ev: Event): void {
const target = ev.target ? (ev.target as HTMLElement) : null;
const modal = target?.closest('.modal');
const modal = target?.closest('.dialog');

if (modal) {
if (target?.closest("[data-dismiss='modal']")) {
modal.dispatchEvent(new Event(ModalContainer.cancelEvent, { bubbles: true }));
} else if (!modal.contains(target) || target === modal) {
modal.dispatchEvent(new Event(ModalContainer.cancelEvent, { bubbles: true }));
} else if (target?.closest(".modal-footer button:not([data-dismiss='modal'])")) {
modal.dispatchEvent(new Event(ModalContainer.okEvent, { bubbles: true }));
}
}
}

#closeModal(ev: Event): void {
const modal = ev.target;
const modal = ev.target as HTMLDialogElement;
if (modal) {
$(modal).modal('hide');
modal.close();
}
}
}
4 changes: 2 additions & 2 deletions views/templates/components/modal.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="modal fade {% if modalDanger %}modal--danger{% endif %}"
<dialog class="dialog {% if modalDanger %}modal--danger{% endif %}"
{% if modalId %}id="{{ modalId }}"{% endif %}
aria-label="{{ title }}"
role="dialog"
Expand Down Expand Up @@ -44,4 +44,4 @@
{% endblock %}
</div>
</div>
</div>
</dialog>

0 comments on commit 099ad80

Please sign in to comment.