Skip to content

Commit

Permalink
feat: Paginator component
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Nov 11, 2024
1 parent b0b8776 commit a115858
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Laravel/src/Components/Paginator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace MoonShine\Laravel\Components;

use Illuminate\Contracts\Pagination\CursorPaginator;
use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
use Illuminate\Contracts\Support\Arrayable;
use MoonShine\Laravel\TypeCasts\PaginatorCaster;
use MoonShine\UI\Components\MoonShineComponent;

/**
* @method static static make(PaginatorContract|CursorPaginator $paginator)
*/
final class Paginator extends MoonShineComponent
{
protected string $view = 'moonshine::components.pagination';

public function getTranslates(): array
{
return $this->getCore()->getTranslator()->get('moonshine::pagination');
}

public function __construct(
private readonly PaginatorContract|CursorPaginator $paginator
)
{
parent::__construct();
}

protected function viewData(): array
{
/**
* @phpstan-var (PaginatorContract|CursorPaginator)&Arrayable $data
*/
$data = $this->paginator;

$paginator = (new PaginatorCaster(
$data->appends(
$this->getCore()->getRequest()->getExcept('page')
)->toArray(),
$data->items()
))->cast();

return $paginator->toArray();
}
}
1 change: 1 addition & 0 deletions src/Laravel/src/Providers/MoonShineServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public function boot(): void
}

Blade::componentNamespace('MoonShine\UI\Components', 'moonshine');
Blade::componentNamespace('MoonShine\Laravel\Components', 'moonshine-laravel');

$this
->registerBladeDirectives()
Expand Down

0 comments on commit a115858

Please sign in to comment.