PHP code example of mrclln / wire-sileo

1. Go to this page and download the library: Download mrclln/wire-sileo 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/ */

    

mrclln / wire-sileo example snippets


use Livewire\Attributes\On;
use Sileo\Facades\Sileo;

class MyComponent extends Component
{
    public function success(): void
    {
        Sileo::success('Saved successfully');
    }

    public function action(): void
    {
        Sileo::action()
            ->title('New sale')
            ->description('A new order was placed.')
            ->button('View', 'openOrder', ['id' => $order->id])
            ->send();
    }

    #[On('deleteRecord')]
    public function deleteRecord(): void
    {
        // Handle deletion
        $this->record->delete();
    }
}

Sileo::success()
    ->title('Success!')
    ->description('Your changes have been saved.')
    ->position('top-right') // or Position::TopRight
    ->duration(5000)
    ->theme('dark')
    ->fill('#1f2937')
    ->roundness(20)
    ->styles(['title' => 'text-white', 'description' => 'text-slate-300'])
    ->send();

Sileo::success()
    ->title('Done!')
    ->html('<strong>Item</strong> was saved successfully.')
    ->send();

Sileo::success()
    ->title('Deployed!')
    ->icon('rocket')
    ->send();

Sileo::success([
    'title' => 'Success!',
    'description' => 'Your changes have been saved.',
    'position' => 'top-right',
    'duration' => 5000,
    'theme' => 'dark',
    'fill' => '#1f2937',
    'roundness' => 20,
    'styles' => ['title' => 'text-white'],
])->send();

Sileo::action()
    ->title('Delete record?')
    ->description('This cannot be undone.')
    ->fill('white')
    ->icon('trash')
    ->button('Delete', 'deleteRecord', ['id' => $id])
    ->styles([
        'title' => '!text-red-500 font-bold',
        'description' => '!text-red-400',
        'badge' => '!bg-red-100 !text-red-700',
        'button' => '!bg-red-100 !hover:bg-red-200 !text-red-700 !hover:text-red-800',
    ])
    ->send();

use Livewire\Attributes\On;

class MyComponent extends Component
{
    public function triggerSave(): void
    {
        Sileo::promise()
            ->event('saveRecord')
            ->loadingOptions(['title' => 'Saving...', 'description' => 'Please wait'])
            ->successOptions(['title' => 'Saved!', 'description' => 'Record updated'])
            ->errorOptions(['title' => 'Failed!', 'description' => 'Could not save'])
            ->send();
    }

    #[On('saveRecord')]
    public function saveRecord(): void
    {
        try {
            $this->record->save();
            Sileo::promiseResolve('saveRecord');
        } catch (\Exception $e) {
            Sileo::promiseReject('saveRecord');
        }
    }
}

#[On('processData')]
public function processData(): void
{
    try {
        // Your logic here
        Sileo::promiseResolve('processData');
    } catch (\Exception $e) {
        Sileo::promiseReject('processData');
    }
}

public function triggerProcess(): void
{
    Sileo::promise([
        'event' => 'processData',
        'loading' => ['title' => 'Processing...', 'description' => 'Please wait'],
        'success' => ['title' => 'Done!', 'description' => 'Data processed'],
        'error' => ['title' => 'Failed!', 'description' => 'An error occurred'],
    ])->send();
}

// Resolve with optional data payload
Sileo::promiseResolve('eventName', ['message' => 'Custom message']);

// Reject with optional error data
Sileo::promiseReject('eventName', ['error' => 'Custom error']);

Sileo::success()
    ->title('Custom styled')
    ->customClasses(['font-bold', 'shadow-lg'])
    ->send();

return [
    'position' => 'top-right',
    'theme' => 'system',
    'fill' => null,
    'roundness' => 16,
];
bash
php artisan vendor:publish --tag=wire-sileo
bash
php artisan vendor:publish --tag=wire-sileo-config