Coder Social home page Coder Social logo

livewire-modal's Introduction

Livewire Modal

Latest Version on Packagist Total Downloads

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/[email protected]/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 --force flag

php artisan vendor:publish --provider="devsrv\LivewireModal\LivewireModalServiceProvider" --tag=public --force

โš—๏ธ Usage

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 sm lg xl // 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

livewire-modal's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

livewire-modal's Issues

parameters are not accessible in the mount method

hi, I am trying to pass the parameters to the modal, but in mount method of modal component I get the following error

Illuminate\Contracts\Container\BindingResolutionException
Unable to resolve dependency [Parameter #0 [ $args ]] in class App\Http\Livewire\Contact\EditModel (View: D:\laragon\www\sms-livewire\vendor\devsrv\livewire-modal\resources\views\livewire\modal.blade.php)

<x-livewiremodal-trigger class="btn" title="Edit Contact" modal="contact.edit-model" :args="['id' => '{{ $chat_list_id }}']"> <i class="fa-solid fa-user-pen fa-xl"></i> </x-livewiremodal-trigger>

and in my EditModel Component class in mount method i am accept the $args parameter

public function mount($args){ dump($args); }

please help me with this issue.

Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.