From b35a64bd3f9a754c50a19244cacbe08aea3c3252 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Thu, 1 Aug 2024 02:18:05 +0100 Subject: [PATCH 1/6] Initial Commit --- .../views/components/table/th/reorder.blade.php | 11 +++++++++-- .../Configuration/ReorderingConfiguration.php | 12 ++++++++++++ src/Traits/Helpers/ReorderingHelpers.php | 14 ++++++++++++++ src/Traits/WithReordering.php | 2 ++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/resources/views/components/table/th/reorder.blade.php b/resources/views/components/table/th/reorder.blade.php index 24efb20a5..f425a6019 100644 --- a/resources/views/components/table/th/reorder.blade.php +++ b/resources/views/components/table/th/reorder.blade.php @@ -1,5 +1,12 @@ -@aware(['component', 'tableName']) +@aware(['tableName']) - +merge($this->getReorderThAttributes())->class([ + 'table-cell px-3 py-2 md:px-6 md:py-3 text-center md:text-left bg-gray-50 dark:bg-gray-800 laravel-livewire-tables-reorderingMinimised' => ($this->isTailwind()) && ($this->getReorderThAttributes['default'] ?? true), + 'laravel-livewire-tables-reorderingMinimised' => ($this->isBootstrap()) && ($this->getReorderThAttributes['default'] ?? true), + ]) + }} +>
+ diff --git a/src/Traits/Configuration/ReorderingConfiguration.php b/src/Traits/Configuration/ReorderingConfiguration.php index f926b0227..a70d32a81 100644 --- a/src/Traits/Configuration/ReorderingConfiguration.php +++ b/src/Traits/Configuration/ReorderingConfiguration.php @@ -81,4 +81,16 @@ public function setDefaultReorderSort(string $field, string $direction = 'asc'): return $this; } + + /** + * Used to set attributes for the for Reorder Column + */ + public function setReorderThAttributes(array $reorderThAttributes): self + { + $this->reorderThAttributes = [...$this->reorderThAttributes, ...$reorderThAttributes]; + + return $this; + } + + } diff --git a/src/Traits/Helpers/ReorderingHelpers.php b/src/Traits/Helpers/ReorderingHelpers.php index ea11dbaa0..27c0c9dc1 100644 --- a/src/Traits/Helpers/ReorderingHelpers.php +++ b/src/Traits/Helpers/ReorderingHelpers.php @@ -91,4 +91,18 @@ public function getReorderingBackupSessionKey(): string { return $this->getTableName().'-reordering-backup'; } + + + /** + * Used to get attributes for the for Bulk Actions + * + * @return array + */ + #[Computed] + public function getReorderThAttributes(): array + { + return $this->reorderThAttributes ?? ['default' => true]; + } + + } diff --git a/src/Traits/WithReordering.php b/src/Traits/WithReordering.php index 553c7c42e..667183c98 100644 --- a/src/Traits/WithReordering.php +++ b/src/Traits/WithReordering.php @@ -26,6 +26,8 @@ trait WithReordering public array $orderedItems = []; + protected array $reorderThAttributes = ['default' => true]; + public function setupReordering(): void { if ($this->reorderIsDisabled()) { From 95f20f5b5349afdb894deaebf461e93687a01c44 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Thu, 1 Aug 2024 01:18:32 +0000 Subject: [PATCH 2/6] Fix styling --- src/Traits/Configuration/ReorderingConfiguration.php | 2 -- src/Traits/Helpers/ReorderingHelpers.php | 3 --- 2 files changed, 5 deletions(-) diff --git a/src/Traits/Configuration/ReorderingConfiguration.php b/src/Traits/Configuration/ReorderingConfiguration.php index a70d32a81..8dae181ea 100644 --- a/src/Traits/Configuration/ReorderingConfiguration.php +++ b/src/Traits/Configuration/ReorderingConfiguration.php @@ -91,6 +91,4 @@ public function setReorderThAttributes(array $reorderThAttributes): self return $this; } - - } diff --git a/src/Traits/Helpers/ReorderingHelpers.php b/src/Traits/Helpers/ReorderingHelpers.php index 27c0c9dc1..3dc694b0a 100644 --- a/src/Traits/Helpers/ReorderingHelpers.php +++ b/src/Traits/Helpers/ReorderingHelpers.php @@ -92,7 +92,6 @@ public function getReorderingBackupSessionKey(): string return $this->getTableName().'-reordering-backup'; } - /** * Used to get attributes for the for Bulk Actions * @@ -103,6 +102,4 @@ public function getReorderThAttributes(): array { return $this->reorderThAttributes ?? ['default' => true]; } - - } From ca9386463840bef86f5d39fb4067cd0d5ba480a5 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Thu, 1 Aug 2024 02:20:40 +0100 Subject: [PATCH 3/6] Add Docs --- docs/reordering/available-methods.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/reordering/available-methods.md b/docs/reordering/available-methods.md index 101848599..6534c92ec 100644 --- a/docs/reordering/available-methods.md +++ b/docs/reordering/available-methods.md @@ -142,3 +142,19 @@ public function configure(): void $this->setDefaultReorderSort('order', 'desc'); } ``` + + +## setReorderThAttributes + +You may pass an array to this method, which allows you to pass Custom Attributes into the table header for the Reorder Column + +```php +public function configure(): void +{ + + $this->setReorderThAttributes([ + 'class' => 'bg-red-500', + 'default' => false + ]); +} +``` \ No newline at end of file From 87b93d4ac61b513aed292bb80405aad8f4e16582 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Thu, 1 Aug 2024 02:23:15 +0100 Subject: [PATCH 4/6] Update generic styling doc --- docs/datatable/styling.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/datatable/styling.md b/docs/datatable/styling.md index 1b0730248..612cf7a47 100644 --- a/docs/datatable/styling.md +++ b/docs/datatable/styling.md @@ -130,6 +130,7 @@ public function configure(): void Set a list of attributes to override on the th elements. Note: If you are using Bulk Actions, then the th for Bulk Actions is [styled separately](../bulk-actions/customisations). +Note: If you are using Reorder, then the th for Reorder is [styled separately](../reordering/available-methods). ```php public function configure(): void From 9c78e58ffc296975803313707e707c98cd534f31 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sat, 3 Aug 2024 09:13:36 +0100 Subject: [PATCH 5/6] Add test for setReorderThAttributes --- .../ReorderingConfigurationTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Traits/Configuration/ReorderingConfigurationTest.php b/tests/Traits/Configuration/ReorderingConfigurationTest.php index 848e4945a..dfc9e0249 100644 --- a/tests/Traits/Configuration/ReorderingConfigurationTest.php +++ b/tests/Traits/Configuration/ReorderingConfigurationTest.php @@ -88,4 +88,23 @@ public function test_can_set_default_reorder_column_and_direction(): void $this->assertSame('sort2', $this->basicTable->getDefaultReorderColumn()); $this->assertSame('desc', $this->basicTable->getDefaultReorderDirection()); } + + public function test_can_set_reorder_th_attributes(): void + { + $this->assertSame(['default' => true], $this->basicTable->getReorderThAttributes()); + + $this->basicTable->setReorderThAttributes(['class' => 'bg-blue-500']); + + $this->assertSame(['default' => true, 'class' => 'bg-blue-500'], $this->basicTable->getReorderThAttributes()); + + $this->basicTable->setReorderThAttributes(['class' => 'bg-red-500', 'default' => false]); + + $this->assertSame(['default' => false, 'class' => 'bg-red-500'], $this->basicTable->getReorderThAttributes()); + + $this->basicTable->setReorderThAttributes(['style' => 'font:black', 'default' => true]); + + $this->assertSame(['default' => true, 'class' => 'bg-red-500', 'style' => 'font:black'], $this->basicTable->getReorderThAttributes()); + + } + } From add79163dcf0d07f1f0db9c582d68e0686643799 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Sat, 3 Aug 2024 08:14:00 +0000 Subject: [PATCH 6/6] Fix styling --- tests/Traits/Configuration/ReorderingConfigurationTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Traits/Configuration/ReorderingConfigurationTest.php b/tests/Traits/Configuration/ReorderingConfigurationTest.php index dfc9e0249..9a6d563ca 100644 --- a/tests/Traits/Configuration/ReorderingConfigurationTest.php +++ b/tests/Traits/Configuration/ReorderingConfigurationTest.php @@ -106,5 +106,4 @@ public function test_can_set_reorder_th_attributes(): void $this->assertSame(['default' => true, 'class' => 'bg-red-500', 'style' => 'font:black'], $this->basicTable->getReorderThAttributes()); } - }