devsrv / livewire-modal
turn laravel livewire component into modal
Installs: 7 321
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 1
Forks: 4
Open Issues: 5
pkg:composer/devsrv/livewire-modal
Requires
- php: ^7.3|^8.0|^8.2
- illuminate/view: ^7.0|^8.0|^9.0|^10.0
- livewire/livewire: ^2.12
Requires (Dev)
- phpunit/phpunit: ^10.0
README
Turn Laravel Livewire Component into Modal.
๐ท Features
- Modal triggered by javascript i.e. opens instantly without waiting for livewire network round trip to finish ( no laggy feeling )
- Skeleton loading indicator
- Support alert message ( info, warning, success, danger )
- Trigger from Alpine Component / Vanilla JS / Livewire Class Component
๐งพ Requirements
| Bootstrap | 4 or 5 | no bootstrap support coming soon | 
|---|---|---|
| Jquery | for bootstrap 4 only | |
| Laravel | >= 7 | |
| Livewire | >= 2.0 | |
| Alpine JS | 
๐ฅ Installation
composer require devsrv/livewire-modal
Include the base modal component
<html> <head> ... @livewireStyles <script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer></script> </head> <body> ... <x-livewiremodal-base /> ๐ @livewireScripts </body> </html>
Publish assets
php artisan vendor:publish --provider="devsrv\LivewireModal\LivewireModalServiceProvider" --tag=public
Publish config
php artisan vendor:publish --provider="devsrv\LivewireModal\LivewireModalServiceProvider" --tag=config
config support bootstrap theme: bs4 | bs5
๐ Updating
Important: when updating the package make sure to re-publish the assets with
--forceflag
php artisan vendor:publish --provider="devsrv\LivewireModal\LivewireModalServiceProvider" --tag=public --force
โ๏ธ Usage
 Create Livewire Component
 Create Livewire Component
No consideration required, create livewire component as usual. Use livewire's mount to handle passed parameters
โจ Open Modal
โ๏ธ From Alpine Component
<div x-data> <button type="button" x-on:click='$dispatch("open-x-modal", { title: "Heading Title", modal: "livewire-component-name", size: "xl", args: {{ json_encode($data_array) }} })'>open </button> </div>
โ๏ธ Via Vanilla JS
<button type="button" onclick='_openModal("Heading", "component-name", {{ json_encode($data) }}, "sm")'> open </button>
โ๏ธ Via Trigger Blade Component
<x-livewiremodal-trigger class="btn" title="Modal Heading" modal="component-name" :args="['sky' => 'blue', 'moon' => 1]" lg>open </x-livewiremodal-trigger>
โ๏ธ From Livewire Class
$this->dispatchBrowserEvent('open-x-modal', ['title' => 'My Modal', 'modal' => 'product.order', 'args' => ['id' => 1, 'rate' => 20]]);
๐ก Modal size supports
smlgxl// completely optional
๐ Bonus
you are free to put content in livewire view file in any structure, however the package provides an blade component for bootstrap modal which you can use as:
<x-livewiremodal-modal> <div class="row"> ... </div> ... <x-slot name="footer"> ... <button type="button" class="..">Save</button> </x-slot> </x-livewiremodal-modal>
โ๐ผ Two reasons to use this component
๐ข a pretty line progress loading indicator which appears in the top when livewire loading state changes
๐ข alert notification message which can be triggered by:
$this->info('<strong>Hi !</strong>, i am an alert'); // support `info` `warning` `success` `danger`
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
๐๐ผ Say Hi!
Leave a โญ if you find this package useful ๐๐ผ, don't forget to let me know in Twitter