diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f9c6c307..329d7b70a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `laravel-livewire-tables` will be documented in this file +## UNRELEASED +### New Features +- Add setPaginationWrapperAttributes by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1978 + ## [v3.4.22] - 2024-09-27 ### Bug Fixes - Fix Loading Placeholder Bug - Breaking Table by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1969 diff --git a/docs/pagination/available-methods.md b/docs/pagination/available-methods.md index 638e58a4b..eae078132 100644 --- a/docs/pagination/available-methods.md +++ b/docs/pagination/available-methods.md @@ -296,3 +296,14 @@ public function configure(): void $this->setShouldRetrieveTotalItemCountDisabled(); } ``` + +## setPaginationWrapperAttributes + +Used to set attributes for the "div" that wraps the pagination section + +```php +public function configure(): void +{ + $this->setPaginationWrapperAttributes(['class' => 'text-lg']); +} +``` diff --git a/resources/views/components/pagination.blade.php b/resources/views/components/pagination.blade.php index b69ca77ff..836609b67 100644 --- a/resources/views/components/pagination.blade.php +++ b/resources/views/components/pagination.blade.php @@ -1,11 +1,13 @@ @aware(['component','isTailwind','isBootstrap','isBootstrap4','isBootstrap5']) -@if ($this->hasConfigurableAreaFor('before-pagination')) - @include($this->getConfigurableAreaFor('before-pagination'), $this->getParametersForConfigurableArea('before-pagination')) -@endif +@includeWhen( + $this->hasConfigurableAreaFor('before-pagination'), + $this->getConfigurableAreaFor('before-pagination'), + $this->getParametersForConfigurableArea('before-pagination') +) @if ($this->isTailwind) -
+
getPaginationWrapperAttributesBag() }}> @if ($this->paginationVisibilityIsEnabled())
@@ -47,7 +49,7 @@ @endif
@elseif ($this->isBootstrap4) -
+
getPaginationWrapperAttributesBag() }}> @if ($this->paginationVisibilityIsEnabled()) @if ($this->paginationIsEnabled() && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1)
@@ -100,7 +102,7 @@ @endif
@elseif ($this->isBootstrap5) -
+
getPaginationWrapperAttributesBag() }} > @if ($this->paginationVisibilityIsEnabled()) @if ($this->paginationIsEnabled() && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1)
@@ -152,6 +154,8 @@
@endif -@if ($this->hasConfigurableAreaFor('after-pagination')) - @include($this->getConfigurableAreaFor('after-pagination'), $this->getParametersForConfigurableArea('after-pagination')) -@endif \ No newline at end of file +@includeWhen( + $this->hasConfigurableAreaFor('after-pagination'), + $this->getConfigurableAreaFor('after-pagination'), + $this->getParametersForConfigurableArea('after-pagination') +) diff --git a/src/Traits/Configuration/PaginationConfiguration.php b/src/Traits/Configuration/PaginationConfiguration.php index a8877653a..35c618e0c 100644 --- a/src/Traits/Configuration/PaginationConfiguration.php +++ b/src/Traits/Configuration/PaginationConfiguration.php @@ -177,4 +177,11 @@ public function setShouldRetrieveTotalItemCountDisabled(): self return $this; } + + public function setPaginationWrapperAttributes(array $paginationWrapperAttributes): self + { + $this->paginationWrapperAttributes = array_merge(['class' => ''], $paginationWrapperAttributes); + + return $this; + } } diff --git a/src/Traits/Helpers/PaginationHelpers.php b/src/Traits/Helpers/PaginationHelpers.php index 717af7c12..9654b3a72 100644 --- a/src/Traits/Helpers/PaginationHelpers.php +++ b/src/Traits/Helpers/PaginationHelpers.php @@ -2,6 +2,7 @@ namespace Rappasoft\LaravelLivewireTables\Traits\Helpers; +use Illuminate\View\ComponentAttributeBag; use Livewire\Attributes\Computed; trait PaginationHelpers @@ -155,4 +156,15 @@ public function getShouldRetrieveTotalItemCount(): bool { return $this->shouldRetrieveTotalItemCount; } + + public function getPaginationWrapperAttributes(): array + { + return $this->paginationWrapperAttributes ?? ['class' => '']; + } + + #[Computed] + public function getPaginationWrapperAttributesBag(): ComponentAttributeBag + { + return new ComponentAttributeBag($this->getPaginationWrapperAttributes()); + } } diff --git a/src/Traits/WithPagination.php b/src/Traits/WithPagination.php index c8c56a3c9..8e6a44aa0 100644 --- a/src/Traits/WithPagination.php +++ b/src/Traits/WithPagination.php @@ -52,6 +52,9 @@ trait WithPagination protected bool $shouldRetrieveTotalItemCount = true; + // Used In Frontend + protected array $paginationWrapperAttributes = ['class' => '']; + public function mountWithPagination(): void { $sessionPerPage = session()->get($this->getPerPagePaginationSessionKey(), $this->getPerPageAccepted()[0] ?? 10); diff --git a/tests/Traits/Helpers/PaginationHelpersTest.php b/tests/Traits/Helpers/PaginationHelpersTest.php index d3744c326..067c0e208 100644 --- a/tests/Traits/Helpers/PaginationHelpersTest.php +++ b/tests/Traits/Helpers/PaginationHelpersTest.php @@ -173,4 +173,33 @@ public function test_can_toggle_total_item_count_retrieval_via_status(): void $this->assertTrue($this->basicTable->getShouldRetrieveTotalItemCount()); } + + public function test_can_get_pagination_wrapper_attributes(): void + { + + $this->assertSame(['class' => ''], $this->basicTable->getPaginationWrapperAttributes()); + + $this->basicTable->setPaginationWrapperAttributes(['class' => 'text-lg']); + + $this->assertSame(['class' => 'text-lg'], $this->basicTable->getPaginationWrapperAttributes()); + + $this->basicTable->setPaginationWrapperAttributes(['class' => 'text-lg', 'testval' => '456']); + + $this->assertSame(['class' => 'text-lg', 'testval' => '456'], $this->basicTable->getPaginationWrapperAttributes()); + + } + + public function test_can_get_pagination_wrapper_attributes_bag(): void + { + $this->assertSame((new \Illuminate\View\ComponentAttributeBag(['class' => '']))->getAttributes(), $this->basicTable->getPaginationWrapperAttributesBag()->getAttributes()); + + $this->basicTable->setPaginationWrapperAttributes(['class' => 'text-lg']); + + $this->assertSame((new \Illuminate\View\ComponentAttributeBag(['class' => 'text-lg']))->getAttributes(), $this->basicTable->getPaginationWrapperAttributesBag()->getAttributes()); + + $this->basicTable->setPaginationWrapperAttributes(['class' => 'text-lg', 'testval' => '123']); + + $this->assertSame((new \Illuminate\View\ComponentAttributeBag(['class' => 'text-lg', 'testval' => '123']))->getAttributes(), $this->basicTable->getPaginationWrapperAttributesBag()->getAttributes()); + + } }