Created
February 13, 2022 19:25
-
-
Save mtk3d/699502a70ee9af1cd412ddcb805e20da to your computer and use it in GitHub Desktop.
Working example of Livewire modal with transition using Alpine.js
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
<?php | |
namespace App\Http\Livewire; | |
use Livewire\Component; | |
class Modal extends Component | |
{ | |
public string $content; | |
public bool $show = false; | |
public function mount(): void | |
{ | |
$this->content = 'Modal content'; | |
} | |
public function render() | |
{ | |
return <<<'blade' | |
<div x-data> | |
<button wire:click="$set('show', true)"> | |
Open | |
</button> | |
<div x-cloak | |
x-show="$wire.show" | |
x-transition.opacity.duration.500ms | |
> | |
<div>{{ $content }}</div> | |
<button wire:click="$set('show', false)"> | |
Close | |
</button> | |
</div> | |
</div> | |
blade; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment