-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,68 @@ | ||
@props(['formAction' => false]) | ||
@props(['id', 'maxWidth']) | ||
|
||
<div class="text-slate-900 bg-white dark:text-slate-100 dark:bg-slate-800"> | ||
@if($formAction) | ||
<form wire:submit.prevent="{{ $formAction }}"> | ||
@csrf | ||
@endif | ||
<div class="px-4 py-2 border-b border-slate-100 dark:border-slate-700 sm:px-6 sm:py-4"> | ||
@if(isset($title)) | ||
<h3 class="text-lg font-medium leading-6"> | ||
{{ $title }} | ||
</h3> | ||
@endif | ||
</div> | ||
<div class="px-4 py-2 sm:p-6"> | ||
{{ $content }} | ||
</div> | ||
@php | ||
$id = $id ?? md5($attributes->wire('model')); | ||
<div class="justify-end px-4 py-2 space-x-2 border-t border-slate-100 dark:border-slate-700 sm:p-4 sm:flex"> | ||
{{ $buttons }} | ||
</div> | ||
@if($formAction) | ||
</form> | ||
@endif | ||
$maxWidth = [ | ||
'sm' => 'sm:max-w-sm', | ||
'md' => 'sm:max-w-md', | ||
'lg' => 'sm:max-w-lg', | ||
'xl' => 'sm:max-w-xl', | ||
'2xl' => 'sm:max-w-2xl', | ||
][$maxWidth ?? '2xl']; | ||
@endphp | ||
|
||
<div | ||
x-data="{ | ||
show: @entangle($attributes->wire('model')).live, | ||
focusables() { | ||
// All focusable element types... | ||
let selector = 'a, button, input:not([type=\'hidden\']), textarea, select, details, [tabindex]:not([tabindex=\'-1\'])' | ||
return [...$el.querySelectorAll(selector)] | ||
// All non-disabled elements... | ||
.filter(el => ! el.hasAttribute('disabled')) | ||
}, | ||
firstFocusable() { return this.focusables()[0] }, | ||
lastFocusable() { return this.focusables().slice(-1)[0] }, | ||
nextFocusable() { return this.focusables()[this.nextFocusableIndex()] || this.firstFocusable() }, | ||
prevFocusable() { return this.focusables()[this.prevFocusableIndex()] || this.lastFocusable() }, | ||
nextFocusableIndex() { return (this.focusables().indexOf(document.activeElement) + 1) % (this.focusables().length + 1) }, | ||
prevFocusableIndex() { return Math.max(0, this.focusables().indexOf(document.activeElement)) -1 }, | ||
}" | ||
x-init="$watch('show', value => { | ||
if (value) { | ||
document.body.classList.add('overflow-y-hidden'); | ||
{{ $attributes->has('focusable') ? 'setTimeout(() => firstFocusable().focus(), 100)' : '' }} | ||
} else { | ||
document.body.classList.remove('overflow-y-hidden'); | ||
} | ||
})" | ||
x-on:close.stop="show = false" | ||
x-on:keydown.escape.window="show = false" | ||
x-on:keydown.tab.prevent="$event.shiftKey || nextFocusable().focus()" | ||
x-on:keydown.shift.tab.prevent="prevFocusable().focus()" | ||
x-show="show" | ||
id="{{ $id }}" | ||
class="jetstream-modal fixed inset-0 overflow-y-auto px-4 py-6 sm:px-0 z-50" | ||
style="display: none;" | ||
> | ||
<div x-show="show" class="fixed inset-0 transform transition-all" x-on:click="show = false" x-transition:enter="ease-out duration-300" | ||
x-transition:enter-start="opacity-0" | ||
x-transition:enter-end="opacity-100" | ||
x-transition:leave="ease-in duration-200" | ||
x-transition:leave-start="opacity-100" | ||
x-transition:leave-end="opacity-0"> | ||
<div class="absolute inset-0 bg-gray-500 opacity-75"></div> | ||
</div> | ||
|
||
<div x-show="show" class="mb-6 bg-white rounded-lg overflow-hidden shadow-xl transform transition-all sm:w-full {{ $maxWidth }} sm:mx-auto" | ||
x-transition:enter="ease-out duration-300" | ||
x-transition:enter-start="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" | ||
x-transition:enter-end="opacity-100 translate-y-0 sm:scale-100" | ||
x-transition:leave="ease-in duration-200" | ||
x-transition:leave-start="opacity-100 translate-y-0 sm:scale-100" | ||
x-transition:leave-end="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"> | ||
{{ $slot }} | ||
</div> | ||
</div> |