Skip to content

Commit 94fc1f9

Browse files
committed
feat: open and close modal
1 parent 1c82ec5 commit 94fc1f9

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

resources/css/app.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
}
2222

23-
@layer utils {
23+
@layer utilities {
2424
.hide-scrollbar::-webkit-scrollbar {
2525
display: none;
2626
}
@@ -29,4 +29,9 @@
2929
-ms-overflow-style: none;
3030
scrollbar-width: none;
3131
}
32+
33+
/* this is used by alpine.js to properly hide elements on load */
34+
[x-cloak] {
35+
@apply hidden;
36+
}
3237
}
Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,42 @@
1-
<div class="modal fixed inset-0 flex justify-center overflow-y-scroll">
2-
<div class="absolute inset-0 bg-slate-800/80 backdrop-blur-sm"></div>
1+
@props([
2+
'name',
3+
'show' => false,
4+
])
5+
6+
<div
7+
x-data="{
8+
show: @js($show),
9+
}"
10+
x-show="show"
11+
x-on:open-modal.window="
12+
if ($event.detail === '{{ $name }}') {
13+
show = true
14+
}
15+
"
16+
x-on:close-modal.window="
17+
if ($event.detail === '{{ $name }}') {
18+
show = false
19+
}
20+
"
21+
x-init="
22+
$watch('show', (show) => {
23+
if (show) {
24+
document.body.classList.add('overflow-hidden')
25+
} else {
26+
document.body.classList.remove('overflow-hidden')
27+
}
28+
})
29+
"
30+
x-cloak
31+
@class([
32+
'flex' => $show,
33+
'hidden' => "$show",
34+
'fixed inset-0 flex justify-center overflow-y-scroll',
35+
])
36+
>
37+
<div
38+
@click="show = false"
39+
class="absolute inset-0 bg-slate-800/80 backdrop-blur-sm"
40+
></div>
341
{{ $slot }}
442
</div>

0 commit comments

Comments
 (0)