PHP code example of leenuxus / jarenui

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

    

leenuxus / jarenui example snippets


// From Livewire:
$this->dispatch('jaren-toast', type: 'success', title: 'Saved!', message: 'All good.', duration: 4000);

// Using HasToast trait:
use jarenui\Concerns\HasToast;
$this->toast()->success('Saved!', 'Changes applied.');
$this->toast()->persistent()->action('Undo', 'undo-delete')->danger('Deleted', 'Row removed.');

public array $dates = [];

use JarenUI\DateRange;

public ?DateRange $range;

public function mount(): void
{
    $this->range = new DateRange(now(), now()->addDays(7));
}

use JarenUI\DateRange;

$range = new DateRange(now()->subDays(6), now());

$range->start();          // Carbon — start date
$range->end();            // Carbon — end date
$range->length();         // int — number of days inclusive
$range->contains($date);  // bool
$range->toArray();        // Carbon[] — one per day
(string) $range;          // '2026-05-22/2026-05-29'

// With Eloquent:
Order::whereBetween('created_at', $range)->get();

use Livewire\Attributes\Session;

#[Session]
public ?DateRange $range;

class MeetingsCalendar extends \JarenUI\Livewire\EventCalendar
{
    public function fetchEvents(Carbon $from, Carbon $to): array
    {
        return CalendarEvent::fromCollection(
            Meeting::whereBetween('starts_at', [$from, $to])->get(),
            startKey:       'starts_at',
            endKey:         'ends_at',
            titleKey:       'title',
            colorKey:       'category_color',
            descriptionKey: 'notes',
        );
    }
}

use JarenUI\CalendarEvent;

// Construct directly
$event = new CalendarEvent(
    id:          1,
    title:       'Sprint planning',
    start:       '2026-05-30 10:00',
    end:         '2026-05-30 12:00',
    color:       'green',        // blue|green|amber|red|purple|teal|pink|coral|gray
    description: 'Plan Q3 sprint backlog',
    url:         'https://notion.so/sprint-doc',
    allDay:      false,
    meta:        ['room' => 'Conf room A'],
);

// Cast from an Eloquent model
$event = CalendarEvent::from($meeting,
    startKey: 'starts_at',
    endKey:   'ends_at',
);

// Cast from a collection
$events = CalendarEvent::fromCollection(
    Meeting::inMonth(2026, 5)->get(),
    startKey: 'starts_at',
    endKey:   'ends_at',
);

// Accessors
$event->date();             // '2026-05-30'
$event->startTime();        // '10:00'
$event->endTime();          // '12:00'
$event->durationMinutes();  // 120
$event->spansMultipleDays();// false
$event->toArray();          // array for wire:model / JSON

class MeetingsCalendar extends \JarenUI\Livewire\EventCalendar
{
    public array  $availableViews = ['month', 'week'];  // hide day view
    public bool   $creatable      = true;
    public int    $startDay       = 1;                  // Monday
    public string $view           = 'week';             // default to week view
    public int    $dayStartHour   = 8;
    public int    $dayEndHour     = 18;

    public function fetchEvents(Carbon $from, Carbon $to): array { ... }
}

#[On('jaren-event-selected')]
public function onEventSelected(array $event): void
{
    $this->selectedId = $event['id'];
}

#[On('jaren-event-created')]
public function onEventCreated(string $date): void
{
    $this->dispatch('open-modal', name: 'create-event', date: $date);
}

class OnboardingWizard extends \JarenUI\Livewire\Wizard
{
    // Step definitions — id + label (+ optional icon)
    public array $steps = [
        ['id' => 'account',  'label' => 'Account'],
        ['id' => 'plan',     'label' => 'Plan'],
        ['id' => 'review',   'label' => 'Review'],
    ];

    // One property bag per step
    public array $account = ['name' => '', 'email' => ''];
    public array $plan    = ['plan_id' => null];

    // Per-step validation rules
    protected array $stepRules = [
        'account' => [
            'account.name'  => 'n the last step
    public function submit(): void
    {
        User::create($this->account);
        Subscription::create(['user_id' => auth()->id(), ...$this->plan]);

        $this->complete();  // marks wizard as done, shows success panel
    }

    // Data attached to the jaren-wizard-completed event
    protected function completedData(): array
    {
        return ['account' => $this->account, 'plan' => $this->plan];
    }
}

// Called when about to leave a step — useful for cleanup
protected function onStepLeaving(string $stepId): void
{
    if ($stepId === 'payment') {
        // release any held resources
    }
}

// Called just after entering a step — useful for loading data
protected function onStepEntering(string $stepId): void
{
    if ($stepId === 'review') {
        $this->summary = $this->buildSummary();
    }
}

// Called when cancel() is triggered
protected function onCancel(): void
{
    session()->forget('wizard_progress');
}

#[On('jaren-wizard-completed')]
public function onWizardDone(array $data): void
{
    $this->redirect(route('dashboard'));
}

[
    'value'       => 1,           // equired — display text
    'group'       => 'Engineering', // optional — group header
    'meta'        => 'Admin',     // optional — right-aligned text
    'description' => 'Lead engineer', // optional — sub-label (with-descriptions)
    'badge'       => 'Pro',       // optional — pill badge (with-badges)
    'initials'    => 'JD',        // optional — avatar letters (with-avatars)
    'color'       => '#185FA5',   // optional — avatar background colour
    'disabled'    => false,       // optional — grey out and prevent selection
]

class CountryCombobox extends \JarenUI\Livewire\AsyncCombobox
{
    public string $label       = 'Country';
    public string $placeholder = 'Search countries…';
    public int    $minChars    = 2;
    public int    $limit       = 20;

    public function search(string $query): array
    {
        return Country::where('name', 'like', "%{$query}%")
            ->orderBy('name')
            ->limit($this->limit)
            ->get()
            ->map(fn ($c) => [
                'value'    => $c->code,
                'label'    => $c->name,
                'meta'     => $c->code,
                'badge'    => $c->region,
            ])
            ->toArray();
    }
}
blade
<x-jaren::avatar name="Jane Doe" src="/photo.jpg" size="xs|sm|md|lg|xl"
    color="blue|auto" status="online|away|busy|offline" shape="circle|square"/>
bash
php artisan jaren:make-kanban ProjectKanban
bash
php artisan jaren:make-event-calendar MeetingsCalendar --model=Meeting
blade
@php
use JarenUI\CalendarEvent;

$events = [
    new CalendarEvent(
        id:    1,
        title: 'Team standup',
        start: '2026-05-30 09:00',
        end:   '2026-05-30 09:30',
        color: 'blue',
        description: 'Daily sync',
    ),
];
@endphp

<livewire:jaren.event-calendar :events="$events" />
bash
php artisan jaren:make-wizard OnboardingWizard --steps=account,plan,features,review
bash
php artisan jaren:make-combobox UserCombobox --model=User --search=name,email
bash
php artisan jaren:publish --views