Created
April 10, 2024 23:31
-
-
Save nicekiwi/dc8d7df5624629c4c4af8f02c5301936 to your computer and use it in GitHub Desktop.
Bootstrap 5 - Livewire Modal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@props(['open' => false, 'title', 'trigger', 'content']) | |
<div x-data="{ | |
open: @js($open), | |
hide() { this.open = false }, | |
show() { this.open = true }, | |
whenOpen(func) { if (this.open) $nextTick(func) }, | |
}"> | |
<div | |
x-on:click="show()" | |
x-on:keyup.escape="close()" | |
> | |
{{ $trigger }} | |
</div> | |
<template x-teleport="body"> | |
<div> | |
<div class="modal" | |
tabindex="-1" | |
x-transition | |
x-show="open" | |
:class="{ 'd-block': open }" | |
x-on:click.self="hide()" | |
x-on:keyup.escape="hide()"> | |
<div class="modal-dialog modal-dialog-centered"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<h5 class="modal-title">{{ $title ?? 'Title' }}</h5> | |
<button x-on:click.prevent="hide()" type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | |
</div> | |
{{ $content }} | |
</div> | |
</div> | |
</div> | |
<div class="modal-backdrop show fade" x-show="open"></div> | |
</div> | |
</template> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment