Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal to dialog conversion #15505

Closed
wants to merge 13 commits into from
2 changes: 1 addition & 1 deletion docs-assets/app/public/css/filament/support/support.css

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs-assets/app/public/js/filament/support/support.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/support/dist/index.css

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions packages/support/dist/index.js

Large diffs are not rendered by default.

15 changes: 5 additions & 10 deletions packages/support/resources/css/components/modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
@apply fixed inset-0 z-40 bg-gray-950/50 dark:bg-gray-950/75;
}

dialog::backdrop {
@apply hidden;
}

& .fi-modal-header {
@apply flex px-6 pt-6;

Expand Down Expand Up @@ -136,7 +140,7 @@
}

& .fi-modal-window {
@apply pointer-events-auto relative row-start-2 flex w-full cursor-default flex-col bg-white ring-1 shadow-xl ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10;
@apply pointer-events-auto relative row-start-2 flex w-full cursor-default flex-col bg-white ring-1 shadow-xl ring-gray-950/5 duration-300 dark:bg-gray-900 dark:ring-white/10;

&.fi-align-start,
&.fi-align-left {
Expand Down Expand Up @@ -255,11 +259,6 @@
@apply fixed inset-0;
}

&.fi-transition-enter,
&.fi-transition-leave {
@apply duration-300;
}

&:not(.fi-modal-window-has-content) {
& .fi-modal-footer {
&:not(.fi-sticky) {
Expand Down Expand Up @@ -361,7 +360,3 @@
}
}
}

& .fi-modal-trigger {
@apply flex;
}
35 changes: 33 additions & 2 deletions packages/support/resources/js/components/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,45 @@ export default ({ id }) => ({
this.$nextTick(() => {
this.isWindowVisible = this.isOpen

this.$watch('isOpen', () => (this.isWindowVisible = this.isOpen))
this.$watch('isOpen', () => {
if (this.isOpen) {
this.$root?.showModal()

this.isWindowVisible = true

return
}

this.isWindowVisible = false

setTimeout(
() => this.$root?.close(),
this.$refs.window
? parseFloat(
window.getComputedStyle(this.$refs.window)
.transitionDuration,
) * 1000
: 0,
)
})
})
},

close: function () {
this.closeQuietly()

this.$root.dispatchEvent(new CustomEvent('modal-closed', { id }))
setTimeout(
() =>
this.$root.dispatchEvent(
new CustomEvent('modal-closed', { id }),
),
this.$refs.window
? parseFloat(
window.getComputedStyle(this.$refs.window)
.transitionDuration,
) * 1000
: 0,
)
},

closeQuietly: function () {
Expand Down
46 changes: 20 additions & 26 deletions packages/support/resources/views/components/modal/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
@endphp

@if ($trigger)
{!! '<div>' !!}

<div
x-on:click="$el.nextElementSibling.dispatchEvent(new CustomEvent(@js($openEventName)))"
{{ $trigger->attributes->class(['fi-modal-trigger']) }}
Expand All @@ -67,32 +65,32 @@
</div>
@endif

<div
@if ($ariaLabelledby)
aria-labelledby="{{ $ariaLabelledby }}"
@elseif ($heading)
aria-labelledby="{{ "{$id}.heading" }}"
@endif
aria-modal="true"
id="{{ $id }}"
role="dialog"
<dialog
x-data="filamentModal({
id: @js($id),
})"
@if ($id)
x-on:{{ $closeEventName }}.window="if (($event.detail.id === @js($id)) && isOpen) close()"
x-on:{{ $closeQuietlyEventName }}.window="if (($event.detail.id === @js($id)) && isOpen) closeQuietly()"
x-on:{{ $openEventName }}.window="if (($event.detail.id === @js($id)) && (! isOpen)) open()"
@else
x-on:{{ $closeEventName }}.stop="if (isOpen) close()"
x-on:{{ $closeQuietlyEventName }}.stop="if (isOpen) closeQuietly()"
x-on:{{ $openEventName }}.stop="if (! isOpen) open()"
@endif
x-on:{{ $closeEventName }}.stop="if (isOpen) close()"
x-on:{{ $closeQuietlyEventName }}.stop="if (isOpen) closeQuietly()"
x-on:{{ $openEventName }}.stop="if (! isOpen) open()"
{{-- Prevents the dialog from closing when the escape key is pressed, we do that ourselves to properly transition it. --}}
x-on:cancel.prevent
id="{{ $id }}"
wire:ignore.self
x-trap.noscroll{{ $autofocus ? '' : '.noautofocus' }}="isOpen"
x-bind:class="{
'fi-modal-open': isOpen,
}"
x-cloak
x-show="isOpen"
x-trap.noscroll{{ $autofocus ? '' : '.noautofocus' }}="isOpen"
@if ($ariaLabelledby)
aria-labelledby="{{ $ariaLabelledby }}"
@elseif ($heading)
aria-labelledby="{{ "{$id}.heading" }}"
@endif
{{
$attributes->class([
'fi-modal',
Expand All @@ -103,12 +101,13 @@
>
<div
aria-hidden="true"
x-show="isOpen"
x-show="isWindowVisible"
x-transition.duration.300ms.opacity
class="fi-modal-close-overlay"
></div>

<div
x-ref="windowContainer"
@if ($closeByClickingAway)
{{-- Ensure that the click element is not triggered from a user selecting text inside an input. --}}
x-on:click.self="
Expand All @@ -123,12 +122,11 @@ class="fi-modal-close-overlay"
])
>
<div
x-show="isWindowVisible"
x-ref="window"
@if ($closeByEscaping)
x-on:keydown.window.escape="{{ $closeEventHandler }}"
@endif
x-show="isWindowVisible"
x-transition:enter="fi-transition-enter"
x-transition:leave="fi-transition-leave"
@if ($width !== Width::Screen)
x-transition:enter-start="fi-transition-enter-start"
x-transition:enter-end="fi-transition-enter-end"
Expand Down Expand Up @@ -232,8 +230,4 @@ class="fi-modal-close-btn"
@endif
</div>
</div>
</div>

@if ($trigger)
{!! '</div>' !!}
@endif
</dialog>
Loading