diff --git a/resources/views/components/pagination.blade.php b/resources/views/components/pagination.blade.php index 836609b67..59c2ca280 100644 --- a/resources/views/components/pagination.blade.php +++ b/resources/views/components/pagination.blade.php @@ -6,150 +6,148 @@ $this->getParametersForConfigurableArea('before-pagination') ) -@if ($this->isTailwind) -
getPaginationWrapperAttributesBag() }}> - @if ($this->paginationVisibilityIsEnabled()) -
-
- @if ($this->paginationIsEnabled() && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1) -

- @if($this->showPaginationDetails()) - @lang('livewire-tables::Showing') - {{ $this->getRows->firstItem() }} - @lang('livewire-tables::to') - {{ $this->getRows->lastItem() }} - @lang('livewire-tables::of') - - @lang('livewire-tables::results') - @endif -

- @elseif ($this->paginationIsEnabled() && $this->isPaginationMethod('simple')) -

- @if($this->showPaginationDetails()) - @lang('livewire-tables::Showing') - {{ $this->getRows->firstItem() }} - @lang('livewire-tables::to') - {{ $this->getRows->lastItem() }} - @endif -

- @elseif ($this->paginationIsEnabled() && $this->isPaginationMethod('cursor')) - @else -

- @lang('livewire-tables::Showing') - {{ $this->getRows->count() }} - @lang('livewire-tables::results') -

- @endif -
- - @if ($this->paginationIsEnabled()) - {{ $this->getRows->links('livewire-tables::specific.tailwind.'.(!$this->isPaginationMethod('standard') ? 'simple-' : '').'pagination') }} +@if ($this->isTailwind && $this->paginationIsEnabled() && $this->paginationVisibilityIsEnabled()) +
getPaginationWrapperAttributesBag()->class([ + "mt-4 px-4 md:p-0 sm:flex justify-between items-center space-y-4 sm:space-y-0" => $this->isTailwind && ($this->getPaginationWrapperAttributes['default'] ?? true) + ]) + ->except(['default', 'default-colors', 'default-styling']) + }} + > + @if ($this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1) +

+ @if($this->showPaginationDetails()) + @lang('livewire-tables::Showing') + {{ $this->getRows->firstItem() }} + @lang('livewire-tables::to') + {{ $this->getRows->lastItem() }} + @lang('livewire-tables::of') + + @lang('livewire-tables::results') @endif -

+

+ @elseif ($this->isPaginationMethod('simple')) +

+ @if($this->showPaginationDetails()) + @lang('livewire-tables::Showing') + {{ $this->getRows->firstItem() }} + @lang('livewire-tables::to') + {{ $this->getRows->lastItem() }} + @endif +

+ @elseif ($this->isPaginationMethod('cursor')) + @else +

+ @lang('livewire-tables::Showing') + {{ $this->getRows->count() }} + @lang('livewire-tables::results') +

@endif + {{ $this->getRows->links('livewire-tables::specific.tailwind.'.(!$this->isPaginationMethod('standard') ? 'simple-' : '').'pagination') }}
-@elseif ($this->isBootstrap4) -
getPaginationWrapperAttributesBag() }}> - @if ($this->paginationVisibilityIsEnabled()) - @if ($this->paginationIsEnabled() && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1) -
-
- {{ $this->getRows->links('livewire-tables::specific.bootstrap-4.pagination') }} -
+@elseif ($this->isBootstrap4 && $this->paginationIsEnabled() && $this->paginationVisibilityIsEnabled()) +
getPaginationWrapperAttributesBag() + ->except(['default', 'default-colors', 'default-styling']) + }} + > + @if ($this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1) +
+
+ {{ $this->getRows->links('livewire-tables::specific.bootstrap-4.pagination') }} +
-
- @if($this->showPaginationDetails()) - @lang('livewire-tables::Showing') - {{ $this->getRows->count() ? $this->getRows->firstItem() : 0 }} - @lang('livewire-tables::to') - {{ $this->getRows->count() ? $this->getRows->lastItem() : 0 }} - @lang('livewire-tables::of') - - @lang('livewire-tables::results') - @endif -
+
+ @if($this->showPaginationDetails()) + @lang('livewire-tables::Showing') + {{ $this->getRows->count() ? $this->getRows->firstItem() : 0 }} + @lang('livewire-tables::to') + {{ $this->getRows->count() ? $this->getRows->lastItem() : 0 }} + @lang('livewire-tables::of') + + @lang('livewire-tables::results') + @endif +
+
+ @elseif ($this->isPaginationMethod('simple')) +
+
+ {{ $this->getRows->links('livewire-tables::specific.bootstrap-4.simple-pagination') }}
- @elseif ($this->paginationIsEnabled() && $this->isPaginationMethod('simple')) -
-
- {{ $this->getRows->links('livewire-tables::specific.bootstrap-4.simple-pagination') }} -
-
- @if($this->showPaginationDetails()) - @lang('livewire-tables::Showing') - {{ $this->getRows->count() ? $this->getRows->firstItem() : 0 }} - @lang('livewire-tables::to') - {{ $this->getRows->count() ? $this->getRows->lastItem() : 0 }} - @endif -
+
+ @if($this->showPaginationDetails()) + @lang('livewire-tables::Showing') + {{ $this->getRows->count() ? $this->getRows->firstItem() : 0 }} + @lang('livewire-tables::to') + {{ $this->getRows->count() ? $this->getRows->lastItem() : 0 }} + @endif
- @elseif ($this->paginationIsEnabled() && $this->isPaginationMethod('cursor')) -
-
- {{ $this->getRows->links('livewire-tables::specific.bootstrap-4.simple-pagination') }} -
+
+ @elseif ($this->isPaginationMethod('cursor')) +
+
+ {{ $this->getRows->links('livewire-tables::specific.bootstrap-4.simple-pagination') }}
- @else -
-
- @lang('livewire-tables::Showing') - {{ $this->getRows->count() }} - @lang('livewire-tables::results') -
+
+ @else +
+
+ @lang('livewire-tables::Showing') + {{ $this->getRows->count() }} + @lang('livewire-tables::results')
- @endif +
@endif
-@elseif ($this->isBootstrap5) -
getPaginationWrapperAttributesBag() }} > - @if ($this->paginationVisibilityIsEnabled()) - @if ($this->paginationIsEnabled() && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1) -
-
- {{ $this->getRows->links('livewire-tables::specific.bootstrap-4.pagination') }} -
-
- @if($this->showPaginationDetails()) - @lang('livewire-tables::Showing') - {{ $this->getRows->count() ? $this->getRows->firstItem() : 0 }} - @lang('livewire-tables::to') - {{ $this->getRows->count() ? $this->getRows->lastItem() : 0 }} - @lang('livewire-tables::of') - - @lang('livewire-tables::results') - @endif -
+@elseif ($this->isBootstrap5 && $this->paginationIsEnabled() && $this->paginationVisibilityIsEnabled()) +
getPaginationWrapperAttributesBag() + ->except(['default', 'default-colors', 'default-styling']) + }} + > + @if ($this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1) +
+
+ {{ $this->getRows->links('livewire-tables::specific.bootstrap-4.pagination') }} +
+
+ @if($this->showPaginationDetails()) + @lang('livewire-tables::Showing') + {{ $this->getRows->count() ? $this->getRows->firstItem() : 0 }} + @lang('livewire-tables::to') + {{ $this->getRows->count() ? $this->getRows->lastItem() : 0 }} + @lang('livewire-tables::of') + + @lang('livewire-tables::results') + @endif +
+
+ @elseif ($this->isPaginationMethod('simple')) +
+
+ {{ $this->getRows->links('livewire-tables::specific.bootstrap-4.simple-pagination') }}
- @elseif ($this->paginationIsEnabled() && $this->isPaginationMethod('simple')) -
-
- {{ $this->getRows->links('livewire-tables::specific.bootstrap-4.simple-pagination') }} -
-
- @if($this->showPaginationDetails()) - @lang('livewire-tables::Showing') - {{ $this->getRows->count() ? $this->getRows->firstItem() : 0 }} - @lang('livewire-tables::to') - {{ $this->getRows->count() ? $this->getRows->lastItem() : 0 }} - @endif -
+
+ @if($this->showPaginationDetails()) + @lang('livewire-tables::Showing') + {{ $this->getRows->count() ? $this->getRows->firstItem() : 0 }} + @lang('livewire-tables::to') + {{ $this->getRows->count() ? $this->getRows->lastItem() : 0 }} + @endif
- @elseif ($this->paginationIsEnabled() && $this->isPaginationMethod('cursor')) -
-
- {{ $this->getRows->links('livewire-tables::specific.bootstrap-4.simple-pagination') }} -
+
+ @elseif ($this->isPaginationMethod('cursor')) +
+
+ {{ $this->getRows->links('livewire-tables::specific.bootstrap-4.simple-pagination') }}
- @else -
-
- @lang('livewire-tables::Showing') - {{ $this->getRows->count() }} - @lang('livewire-tables::results') -
+
+ @else +
+
+ @lang('livewire-tables::Showing') + {{ $this->getRows->count() }} + @lang('livewire-tables::results')
- @endif +
@endif
@endif diff --git a/src/Traits/Styling/HasPaginationStyling.php b/src/Traits/Styling/HasPaginationStyling.php index 2e54ef03b..1d7682315 100644 --- a/src/Traits/Styling/HasPaginationStyling.php +++ b/src/Traits/Styling/HasPaginationStyling.php @@ -11,6 +11,7 @@ trait HasPaginationStyling use PaginationStylingConfiguration, PaginationStylingHelpers; + // Used In Frontend #[Locked] public string $paginationTheme = 'tailwind'; @@ -22,6 +23,7 @@ trait HasPaginationStyling // Used In Frontend protected array $paginationWrapperAttributes = ['class' => '']; - + + // Used In Frontend protected ?string $customPaginationBlade; } diff --git a/src/Traits/Styling/Helpers/PaginationStylingHelpers.php b/src/Traits/Styling/Helpers/PaginationStylingHelpers.php index ce3ad2021..e33398303 100644 --- a/src/Traits/Styling/Helpers/PaginationStylingHelpers.php +++ b/src/Traits/Styling/Helpers/PaginationStylingHelpers.php @@ -61,7 +61,7 @@ public function hasCustomPaginationBlade(): bool #[Computed] public function getCustomPaginationBlade(): string { - return $this->customPaginationBlade ? ''; + return $this->customPaginationBlade ?? ''; } } \ No newline at end of file diff --git a/tests/Traits/Styling/PaginationStylingTest.php b/tests/Traits/Styling/PaginationStylingTest.php index 621324189..e50eb81b7 100644 --- a/tests/Traits/Styling/PaginationStylingTest.php +++ b/tests/Traits/Styling/PaginationStylingTest.php @@ -2,8 +2,10 @@ namespace Rappasoft\LaravelLivewireTables\Tests\Traits\Styling; +use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable; use Rappasoft\LaravelLivewireTables\Tests\TestCase; use Illuminate\View\ComponentAttributeBag; +use Livewire\Livewire; final class PaginationStylingTest extends TestCase { @@ -66,32 +68,73 @@ public function test_can_get_per_page_wrapper_attributes(): void public function test_can_get_pagination_wrapper_attributes(): void { - $this->assertSame(['class' => ''], $this->basicTable->getPaginationWrapperAttributes()); + $this->assertSame(['class' => '', 'default' => false, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getPaginationWrapperAttributes()); $this->basicTable->setPaginationWrapperAttributes(['class' => 'text-lg']); - $this->assertSame(['class' => 'text-lg'], $this->basicTable->getPaginationWrapperAttributes()); + $this->assertSame(['class' => 'text-lg', 'default' => false, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getPaginationWrapperAttributes()); $this->basicTable->setPaginationWrapperAttributes(['class' => 'text-lg', 'testval' => '456']); - $this->assertSame(['class' => 'text-lg', 'testval' => '456'], $this->basicTable->getPaginationWrapperAttributes()); + $this->assertSame(['class' => 'text-lg', 'default' => false, 'default-colors' => false, 'default-styling' => false, 'testval' => '456'], $this->basicTable->getPaginationWrapperAttributes()); } public function test_can_get_pagination_wrapper_attributes_bag(): void { - $this->assertSame((new ComponentAttributeBag(['class' => '']))->getAttributes(), $this->basicTable->getPaginationWrapperAttributesBag()->getAttributes()); + $this->assertSame((new ComponentAttributeBag(['class' => '', 'default' => false, 'default-colors' => false, 'default-styling' => false]))->getAttributes(), $this->basicTable->getPaginationWrapperAttributesBag()->getAttributes()); $this->basicTable->setPaginationWrapperAttributes(['class' => 'text-lg']); - $this->assertSame((new ComponentAttributeBag(['class' => 'text-lg']))->getAttributes(), $this->basicTable->getPaginationWrapperAttributesBag()->getAttributes()); + $this->assertSame((new ComponentAttributeBag(['class' => 'text-lg', 'default' => false, 'default-colors' => false, 'default-styling' => false]))->getAttributes(), $this->basicTable->getPaginationWrapperAttributesBag()->getAttributes()); $this->basicTable->setPaginationWrapperAttributes(['class' => 'text-lg', 'testval' => '123']); - $this->assertSame((new ComponentAttributeBag(['class' => 'text-lg', 'testval' => '123']))->getAttributes(), $this->basicTable->getPaginationWrapperAttributesBag()->getAttributes()); + $this->assertSame((new ComponentAttributeBag(['class' => 'text-lg', 'default' => false, 'default-colors' => false, 'default-styling' => false, 'testval' => '123']))->getAttributes(), $this->basicTable->getPaginationWrapperAttributesBag()->getAttributes()); } + public function test_pagination_wrapper_merges_classes_in_frontend(): void + { + + Livewire::test(new class extends PetsTable + { + public function configure(): void + { + $this->setPrimaryKey('id') + ->setPaginationWrapperAttributes(['class' => 'pagiclass text-lg', 'testval' => '592', 'default' => true, 'default-colors' => true, 'default-styling' => true]); + } + }) + ->assertSeeHtml('
setPrimaryKey('id') + ->setPaginationWrapperAttributes(['class' => 'pagiclass text-lg', 'testval' => '592', 'default' => true, 'default-colors' => false, 'default-styling' => false]); + } + }) + ->assertSeeHtml('
setPrimaryKey('id') + ->setPaginationWrapperAttributes(['class' => 'pagiclass text-lg', 'testval' => '592', 'default' => false, 'default-colors' => false, 'default-styling' => false]); + } + }) + ->assertSeeHtml('
assertFalse($this->basicTable->hasCustomPaginationBlade()); @@ -105,4 +148,5 @@ public function test_can_use_custom_pagination_blade(): void $this->assertTrue($this->basicTable->hasCustomPaginationBlade()); } + } \ No newline at end of file