Skip to content

Commit 6bf0d09

Browse files
authored
Add initial commit for setPaginationWrapperAttributes (rappasoft#1978)
* Add initial commit for setPaginationWrapperAttributes * Fix styling * Update ChangeLog * Adjust Tests & Methods * Fix styling --------- Co-authored-by: lrljoe <[email protected]>
1 parent fd13aa9 commit 6bf0d09

File tree

7 files changed

+79
-9
lines changed

7 files changed

+79
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `laravel-livewire-tables` will be documented in this file
44

5+
## UNRELEASED
6+
### New Features
7+
- Add setPaginationWrapperAttributes by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1978
8+
59
## [v3.4.22] - 2024-09-27
610
### Bug Fixes
711
- Fix Loading Placeholder Bug - Breaking Table by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1969

docs/pagination/available-methods.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,14 @@ public function configure(): void
296296
$this->setShouldRetrieveTotalItemCountDisabled();
297297
}
298298
```
299+
300+
## setPaginationWrapperAttributes
301+
302+
Used to set attributes for the "div" that wraps the pagination section
303+
304+
```php
305+
public function configure(): void
306+
{
307+
$this->setPaginationWrapperAttributes(['class' => 'text-lg']);
308+
}
309+
```

resources/views/components/pagination.blade.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
@aware(['component','isTailwind','isBootstrap','isBootstrap4','isBootstrap5'])
22

3-
@if ($this->hasConfigurableAreaFor('before-pagination'))
4-
@include($this->getConfigurableAreaFor('before-pagination'), $this->getParametersForConfigurableArea('before-pagination'))
5-
@endif
3+
@includeWhen(
4+
$this->hasConfigurableAreaFor('before-pagination'),
5+
$this->getConfigurableAreaFor('before-pagination'),
6+
$this->getParametersForConfigurableArea('before-pagination')
7+
)
68

79
@if ($this->isTailwind)
8-
<div>
10+
<div {{ $this->getPaginationWrapperAttributesBag() }}>
911
@if ($this->paginationVisibilityIsEnabled())
1012
<div class="mt-4 px-4 md:p-0 sm:flex justify-between items-center space-y-4 sm:space-y-0">
1113
<div>
@@ -47,7 +49,7 @@
4749
@endif
4850
</div>
4951
@elseif ($this->isBootstrap4)
50-
<div >
52+
<div {{ $this->getPaginationWrapperAttributesBag() }}>
5153
@if ($this->paginationVisibilityIsEnabled())
5254
@if ($this->paginationIsEnabled() && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1)
5355
<div class="row mt-3">
@@ -100,7 +102,7 @@
100102
@endif
101103
</div>
102104
@elseif ($this->isBootstrap5)
103-
<div >
105+
<div {{ $this->getPaginationWrapperAttributesBag() }} >
104106
@if ($this->paginationVisibilityIsEnabled())
105107
@if ($this->paginationIsEnabled() && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1)
106108
<div class="row mt-3">
@@ -152,6 +154,8 @@
152154
</div>
153155
@endif
154156

155-
@if ($this->hasConfigurableAreaFor('after-pagination'))
156-
@include($this->getConfigurableAreaFor('after-pagination'), $this->getParametersForConfigurableArea('after-pagination'))
157-
@endif
157+
@includeWhen(
158+
$this->hasConfigurableAreaFor('after-pagination'),
159+
$this->getConfigurableAreaFor('after-pagination'),
160+
$this->getParametersForConfigurableArea('after-pagination')
161+
)

src/Traits/Configuration/PaginationConfiguration.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,11 @@ public function setShouldRetrieveTotalItemCountDisabled(): self
177177

178178
return $this;
179179
}
180+
181+
public function setPaginationWrapperAttributes(array $paginationWrapperAttributes): self
182+
{
183+
$this->paginationWrapperAttributes = array_merge(['class' => ''], $paginationWrapperAttributes);
184+
185+
return $this;
186+
}
180187
}

src/Traits/Helpers/PaginationHelpers.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Traits\Helpers;
44

5+
use Illuminate\View\ComponentAttributeBag;
56
use Livewire\Attributes\Computed;
67

78
trait PaginationHelpers
@@ -155,4 +156,15 @@ public function getShouldRetrieveTotalItemCount(): bool
155156
{
156157
return $this->shouldRetrieveTotalItemCount;
157158
}
159+
160+
public function getPaginationWrapperAttributes(): array
161+
{
162+
return $this->paginationWrapperAttributes ?? ['class' => ''];
163+
}
164+
165+
#[Computed]
166+
public function getPaginationWrapperAttributesBag(): ComponentAttributeBag
167+
{
168+
return new ComponentAttributeBag($this->getPaginationWrapperAttributes());
169+
}
158170
}

src/Traits/WithPagination.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ trait WithPagination
5252

5353
protected bool $shouldRetrieveTotalItemCount = true;
5454

55+
// Used In Frontend
56+
protected array $paginationWrapperAttributes = ['class' => ''];
57+
5558
public function mountWithPagination(): void
5659
{
5760
$sessionPerPage = session()->get($this->getPerPagePaginationSessionKey(), $this->getPerPageAccepted()[0] ?? 10);

tests/Traits/Helpers/PaginationHelpersTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,33 @@ public function test_can_toggle_total_item_count_retrieval_via_status(): void
173173
$this->assertTrue($this->basicTable->getShouldRetrieveTotalItemCount());
174174

175175
}
176+
177+
public function test_can_get_pagination_wrapper_attributes(): void
178+
{
179+
180+
$this->assertSame(['class' => ''], $this->basicTable->getPaginationWrapperAttributes());
181+
182+
$this->basicTable->setPaginationWrapperAttributes(['class' => 'text-lg']);
183+
184+
$this->assertSame(['class' => 'text-lg'], $this->basicTable->getPaginationWrapperAttributes());
185+
186+
$this->basicTable->setPaginationWrapperAttributes(['class' => 'text-lg', 'testval' => '456']);
187+
188+
$this->assertSame(['class' => 'text-lg', 'testval' => '456'], $this->basicTable->getPaginationWrapperAttributes());
189+
190+
}
191+
192+
public function test_can_get_pagination_wrapper_attributes_bag(): void
193+
{
194+
$this->assertSame((new \Illuminate\View\ComponentAttributeBag(['class' => '']))->getAttributes(), $this->basicTable->getPaginationWrapperAttributesBag()->getAttributes());
195+
196+
$this->basicTable->setPaginationWrapperAttributes(['class' => 'text-lg']);
197+
198+
$this->assertSame((new \Illuminate\View\ComponentAttributeBag(['class' => 'text-lg']))->getAttributes(), $this->basicTable->getPaginationWrapperAttributesBag()->getAttributes());
199+
200+
$this->basicTable->setPaginationWrapperAttributes(['class' => 'text-lg', 'testval' => '123']);
201+
202+
$this->assertSame((new \Illuminate\View\ComponentAttributeBag(['class' => 'text-lg', 'testval' => '123']))->getAttributes(), $this->basicTable->getPaginationWrapperAttributesBag()->getAttributes());
203+
204+
}
176205
}

0 commit comments

Comments
 (0)