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

Support Livewire V2 #23

Merged
merged 9 commits into from
Sep 2, 2020
Next Next commit
Refactor modals
  • Loading branch information
calebporzio committed Sep 2, 2020
commit 79bef5c2d8da11f0ae48f138ba5b6d19c3e1a20f
4 changes: 2 additions & 2 deletions resources/views/components/confirmation-modal.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@props(['id' => null, 'show', 'maxWidth'])
@props(['id' => null, 'maxWidth' => null])

<x-jet-modal :id="$id" :show="$show" :max-width="$maxWidth ?? '2xl'">
<x-jet-modal :id="$id" :maxWidth="$maxWidth" {{ $attributes }}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default of $maxWidth ?? '2xl' is already declared in the underlying modal component.

I figure it's best to forward all props as well as $attributes.

<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
<div class="sm:flex sm:items-start">
<div class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10">
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/dialog-modal.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@props(['show', 'maxWidth'])
@props(['id' => null, 'maxWidth' => null])

<x-jet-modal :show="$show" :max-width="$maxWidth ?? '2xl'">
<x-jet-modal :id="$id" :maxWidth="$maxWidth" {{ $attributes }}>
<div class="px-6 py-4">
<div class="text-lg">
{{ $title }}
Expand Down
20 changes: 6 additions & 14 deletions resources/views/components/modal.blade.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
@props(['id' => null, 'show', 'maxWidth'])
@props(['id', 'maxWidth'])

@php
if (is_null($id)) {
$id = md5($show);
}

if (is_bool($_instance->{$show})) {
$shouldShow = $_instance->{$show};
} else {
$shouldShow = ! is_null($_instance->{$show});
}
$id = $id ?? md5($attributes->wire('model'));

switch ($maxWidth ?? '2xl') {
case 'sm':
Expand All @@ -31,13 +23,13 @@
}
@endphp

<div id="{{ $id }}" x-data="{ show: {{ var_export($shouldShow ?? false, true) }} }"
<div id="{{ $id }}" x-data="{ show: @entangle($attributes->wire('model')) }"
x-show="show"
x-on:close.stop="@this.set('{{ $show }}', false)"
x-on:keydown.escape.window="if (! show) { return; } @this.set('{{ $show }}', false)"
x-on:close.stop="show = false"
x-on:keydown.escape.window="show = false"
class="fixed top-0 inset-x-0 px-4 pt-6 sm:px-0 sm:flex sm:items-top sm:justify-center"
style="display: none;">
<div x-show="show" class="fixed inset-0 transform transition-all" x-on:click="@this.set('{{ $show }}', false)" x-transition:enter="ease-out duration-300"
<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"
Expand Down