Skip to content

Commit 67c6489

Browse files
authored
Merge pull request #1676 from rappasoft/develop
V3.2.3 Pre-Release Merge (#1675)
2 parents d07354a + ac641df commit 67c6489

File tree

11 files changed

+196
-13
lines changed

11 files changed

+196
-13
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/.phpunit.cache export-ignore
77
/build export-ignore
88
/database/database.sqlite export-ignore
9-
/database/sqlite.database. export-ignore
9+
/database/sqlite.database export-ignore
1010
/docs export-ignore
1111
/resources/views/tests export-ignore
1212
/tests export-ignore

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

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

5+
## [v3.2.3] - 2024-03-01
6+
### New Features
7+
- Add capability to customise colors/styling on the Pagination Per-Page Dropdown by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1677
8+
9+
### Docs
10+
- Amend Lifecycle Hooks document to use "public" rather than "protected" methods
11+
512
## [v3.2.2] - 2024-02-29
613
### New Features
714
- Add setDefaultPerPage by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1671
@@ -1149,4 +1156,4 @@ Ground Up Rebuild
11491156
[0.1.4]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.3...v0.1.4
11501157
[0.1.3]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.2...v0.1.3
11511158
[0.1.2]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.1...v0.1.2
1152-
[0.1.1]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.0...v0.1.1
1159+
[0.1.1]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.0...v0.1.1

docs/misc/lifecycle-hooks.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,26 @@ This is called immediately after the Columns are set up
2323
This is called immediately after the query is executed, and is passed the result from the executed query.
2424

2525
## Use in Traits
26-
To use these in a trait, append the Lifecycle Hook with your trait name, e.g.
26+
To use these in a trait, allowing you to easily set defaults across multiple tables, you should ensure that you append the Lifecycle Hook with your trait name, e.g.
27+
28+
You can then add the trait to your tables, allowing you to centralise your defaults, and avoid code duplication.
2729

2830
```php
2931
trait StandardTableMethods
3032
{
3133

32-
protected function configuringStandardTableMethods()
34+
public function configuringStandardTableMethods()
3335
{
3436
// Your standard configure() options go here, anything set here will be over-ridden by the configure() method
37+
// For Example
38+
$this->setColumnSelectDisabled();
3539
}
3640

37-
protected function configuredStandardTableMethods()
41+
public function configuredStandardTableMethods()
3842
{
3943
// Your standard configure() options go here, anything set here will override those set in the configure() method
44+
// For Example
45+
$this->setColumnSelectDisabled();
4046
}
4147

4248
}

docs/pagination/available-methods.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,38 @@ public function configure(): void
228228
$this->setDisplayPaginationDetailsDisabled();
229229
}
230230
```
231+
232+
## setPerPageFieldAttributes
233+
Allows for customisation of the appearance of the "Per Page" dropdown
234+
235+
Note that this utilises a refreshed approach for attributes, and allows for appending to, or replacing the styles and colors independently, via the below methods.
236+
237+
### default-colors
238+
Setting to false will disable the default colors for the Per Page dropdown, the default colors are:
239+
Bootstrap:
240+
None
241+
242+
Tailwind:
243+
border-gray-300 focus:border-indigo-300 focus:ring-indigo-200 dark:bg-gray-700 dark:text-white dark:border-gray-600
244+
245+
### default-styling
246+
Setting to false will disable the default styling for the Per Page dropdown, the default styling is:
247+
Bootstrap 4:
248+
form-control
249+
250+
Bootstrap 5:
251+
form-select
252+
253+
Tailwind:
254+
block w-full rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 focus:ring focus:ring-opacity-50
255+
256+
```php
257+
public function configure(): void
258+
{
259+
$this->setPerPageFieldAttributes([
260+
'class' => 'border-red-300 focus:border-indigo-300 focus:ring-indigo-200 dark:bg-red-700 dark:text-white dark:border-red-600', // Add these classes to the dropdown
261+
'default-colors' => false, // Do not output the default colors
262+
'default-styles' => true, // Output the default styling
263+
]);
264+
}
265+
```

resources/views/components/tools/toolbar/items/pagination-dropdown.blade.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
'ms-0 ms-md-2' => $component->isBootstrap5(),
55
])
66
>
7-
<select
8-
wire:model.live="perPage" id="{{ $tableName }}-perPage"
9-
10-
@class([
11-
'form-control' => $component->isBootstrap4(),
12-
'form-select' => $component->isBootstrap5(),
13-
'block w-full border-gray-300 rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-700 dark:text-white dark:border-gray-600' => $component->isTailwind(),
7+
<select wire:model.live="perPage" id="{{ $tableName }}-perPage"
8+
{{
9+
$attributes->merge($component->getPerPageFieldAttributes())
10+
->class([
11+
'form-control' => $component->isBootstrap4() && $component->getPerPageFieldAttributes()['default-styling'],
12+
'form-select' => $component->isBootstrap5() && $component->getPerPageFieldAttributes()['default-styling'],
13+
'block w-full rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 focus:ring focus:ring-opacity-50' => $component->isTailwind() && $component->getPerPageFieldAttributes()['default-styling'],
14+
'border-gray-300 focus:border-indigo-300 focus:ring-indigo-200 dark:bg-gray-700 dark:text-white dark:border-gray-600' => $component->isTailwind() && $component->getPerPageFieldAttributes()['default-colors'],
1415
])
16+
->except(['default','default-styling','default-colors'])
17+
}}
1518
>
1619
@foreach ($component->getPerPageAccepted() as $item)
1720
<option

src/LaravelLivewireTablesServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class LaravelLivewireTablesServiceProvider extends ServiceProvider
1414
public function boot(): void
1515
{
1616

17-
AboutCommand::add('Rappasoft Laravel Livewire Tables', fn () => ['Version' => '3.2.2']);
17+
AboutCommand::add('Rappasoft Laravel Livewire Tables', fn () => ['Version' => '3.2.3']);
1818

1919
$this->mergeConfigFrom(
2020
__DIR__.'/../config/livewire-tables.php', 'livewire-tables'

src/Traits/Configuration/PaginationConfiguration.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,11 @@ public function setDefaultPerPage(int $perPage): self
148148

149149
return $this;
150150
}
151+
152+
public function setPerPageFieldAttributes(array $attributes = []): self
153+
{
154+
$this->perPageFieldAttributes = [...$this->perPageFieldAttributes, ...$attributes];
155+
156+
return $this;
157+
}
151158
}

src/Traits/Helpers/PaginationHelpers.php

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

33
namespace Rappasoft\LaravelLivewireTables\Traits\Helpers;
44

5+
use Livewire\Attributes\Computed;
6+
57
trait PaginationHelpers
68
{
79
public function getPageName(): ?string
@@ -141,4 +143,10 @@ private function getPerPagePaginationSessionKey(): string
141143
{
142144
return $this->tableName.'-perPage';
143145
}
146+
147+
#[Computed]
148+
public function getPerPageFieldAttributes(): array
149+
{
150+
return $this->perPageFieldAttributes;
151+
}
144152
}

src/Traits/WithPagination.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ trait WithPagination
3939

4040
protected bool $shouldShowPaginationDetails = true;
4141

42+
protected array $perPageFieldAttributes = ['default-styling' => true, 'default-colors' => true, 'class' => ''];
43+
4244
public function mountWithPagination(): void
4345
{
4446
$sessionPerPage = session()->get($this->getPerPagePaginationSessionKey(), $this->getPerPageAccepted()[0] ?? 10);

tests/Traits/Helpers/PaginationHelpersTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,29 @@ public function can_disable_detailed_pagination(): void
128128
$this->assertFalse($this->basicTable->showPaginationDetails());
129129

130130
}
131+
132+
/** @test */
133+
public function can_get_pagination_field_attributes(): void
134+
{
135+
136+
$this->assertSame(['default-styling' => true, 'default-colors' => true, 'class' => ''], $this->basicTable->getPerPageFieldAttributes());
137+
138+
$this->basicTable->setPerPageFieldAttributes(
139+
[
140+
'class' => 'bg-blue-500 dark:bg-red-500',
141+
'default-colors' => true,
142+
]
143+
);
144+
145+
$this->assertSame(['default-styling' => true, 'default-colors' => true, 'class' => 'bg-blue-500 dark:bg-red-500'], $this->basicTable->getPerPageFieldAttributes());
146+
147+
$this->basicTable->setPerPageFieldAttributes(
148+
[
149+
'default-styling' => false,
150+
]
151+
);
152+
153+
$this->assertSame(['default-styling' => false, 'default-colors' => true, 'class' => 'bg-blue-500 dark:bg-red-500'], $this->basicTable->getPerPageFieldAttributes());
154+
155+
}
131156
}

0 commit comments

Comments
 (0)