Skip to content

Commit

Permalink
Add initial commit for setPaginationWrapperAttributes (#1978)
Browse files Browse the repository at this point in the history
* Add initial commit for setPaginationWrapperAttributes

* Fix styling

* Update ChangeLog

* Adjust Tests & Methods

* Fix styling

---------

Co-authored-by: lrljoe <[email protected]>
  • Loading branch information
lrljoe and lrljoe authored Sep 29, 2024
1 parent fd13aa9 commit 6bf0d09
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions docs/pagination/available-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
```
22 changes: 13 additions & 9 deletions resources/views/components/pagination.blade.php
Original file line number Diff line number Diff line change
@@ -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)
<div>
<div {{ $this->getPaginationWrapperAttributesBag() }}>
@if ($this->paginationVisibilityIsEnabled())
<div class="mt-4 px-4 md:p-0 sm:flex justify-between items-center space-y-4 sm:space-y-0">
<div>
Expand Down Expand Up @@ -47,7 +49,7 @@
@endif
</div>
@elseif ($this->isBootstrap4)
<div >
<div {{ $this->getPaginationWrapperAttributesBag() }}>
@if ($this->paginationVisibilityIsEnabled())
@if ($this->paginationIsEnabled() && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1)
<div class="row mt-3">
Expand Down Expand Up @@ -100,7 +102,7 @@
@endif
</div>
@elseif ($this->isBootstrap5)
<div >
<div {{ $this->getPaginationWrapperAttributesBag() }} >
@if ($this->paginationVisibilityIsEnabled())
@if ($this->paginationIsEnabled() && $this->isPaginationMethod('standard') && $this->getRows->lastPage() > 1)
<div class="row mt-3">
Expand Down Expand Up @@ -152,6 +154,8 @@
</div>
@endif

@if ($this->hasConfigurableAreaFor('after-pagination'))
@include($this->getConfigurableAreaFor('after-pagination'), $this->getParametersForConfigurableArea('after-pagination'))
@endif
@includeWhen(
$this->hasConfigurableAreaFor('after-pagination'),
$this->getConfigurableAreaFor('after-pagination'),
$this->getParametersForConfigurableArea('after-pagination')
)
7 changes: 7 additions & 0 deletions src/Traits/Configuration/PaginationConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,11 @@ public function setShouldRetrieveTotalItemCountDisabled(): self

return $this;
}

public function setPaginationWrapperAttributes(array $paginationWrapperAttributes): self
{
$this->paginationWrapperAttributes = array_merge(['class' => ''], $paginationWrapperAttributes);

return $this;
}
}
12 changes: 12 additions & 0 deletions src/Traits/Helpers/PaginationHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Rappasoft\LaravelLivewireTables\Traits\Helpers;

use Illuminate\View\ComponentAttributeBag;
use Livewire\Attributes\Computed;

trait PaginationHelpers
Expand Down Expand Up @@ -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());
}
}
3 changes: 3 additions & 0 deletions src/Traits/WithPagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions tests/Traits/Helpers/PaginationHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

}
}

0 comments on commit 6bf0d09

Please sign in to comment.