PHP code example of sobitnl / livewire-modal-sheet

1. Go to this page and download the library: Download sobitnl/livewire-modal-sheet library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sobitnl / livewire-modal-sheet example snippets




namespace App\Livewire;

use SobitNL\LivewireModalSheet\ModalComponent;

class EditUser extends ModalComponent
{
    public $user;

    public function mount($userId)
    {
        $this->user = User::findOrFail($userId);
    }

    public function save()
    {
        // Save logic...
        
        $this->closeModal();
    }

    public function render()
    {
        return view('livewire.edit-user');
    }
}

class EditUser extends ModalComponent
{
    public User $user; // Automatically resolved from route binding

    public function render()
    {
        return view('livewire.edit-user');
    }
}

public function save()
{
    // Save logic...
    
    $this->closeModal();
}

public function save()
{
    $this->user->save();
    
    $this->closeModalWithEvents([
        UserList::class => 'refreshList',
    ]);
}

$this->forceClose()->closeModal();

$this->skipPreviousModal()->closeModal();
// or skip multiple
$this->skipPreviousModals(2)->closeModal();

class EditUser extends ModalComponent
{
    // should it behave as a bottomsheet
    public static function asBottomSheet(): bool
    {
        return true; //default is false
    }
    
    // Modal width: 'full', 'sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl', '5xl', '6xl', '7xl'
    public static function modalMaxWidth(): string
    {
        return 'lg';
    }

    // Close when clicking outside
    public static function closeModalOnClickAway(): bool
    {
        return false;
    }

    // Close when pressing Escape
    public static function closeModalOnEscape(): bool
    {
        return true;
    }

    // Destroy component state on close
    public static function destroyOnClose(): bool
    {
        return true;
    }
}
javascript
export default {
    content: [
        './vendor/sobitnl/livewire-modal-sheet/resources/views/*.blade.php',
        // ... your other paths
    ],
    safelist: [
        {
            pattern: /max-w-(full|sm|md|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl)/,
            variants: ['full','sm', 'md', 'lg', 'xl', '2xl']
        }
    ],
}
bash
php artisan vendor:publish --tag=livewire-modal-sheet-config
bash
php artisan vendor:publish --tag=livewire-modal-sheet-views