Skip to content

Instantly share code, notes, and snippets.

@mtk3d
Created February 13, 2022 19:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mtk3d/699502a70ee9af1cd412ddcb805e20da to your computer and use it in GitHub Desktop.
Save mtk3d/699502a70ee9af1cd412ddcb805e20da to your computer and use it in GitHub Desktop.
Working example of Livewire modal with transition using Alpine.js
<?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