From 54f0e534232913f3c5ff9f6fe3de355cbb4d4d94 Mon Sep 17 00:00:00 2001 From: LRLJoe Date: Sun, 29 Dec 2024 04:49:45 +0000 Subject: [PATCH 1/3] Add Blade Defaults --- .gitignore | 1 + .../views/components/table/empty.blade.php | 19 ++-- resources/views/components/table/td.blade.php | 20 ++-- .../table/td/bulk-actions.blade.php | 28 ++--- .../table/td/collapsed-columns.blade.php | 21 ++-- .../views/components/table/td/plain.blade.php | 36 +++--- resources/views/components/table/th.blade.php | 103 ++++++------------ .../table/th/collapsed-columns.blade.php | 39 +++---- .../views/components/table/th/plain.blade.php | 8 +- .../components/table/th/reorder.blade.php | 1 + resources/views/components/table/tr.blade.php | 25 +---- .../table/tr/bulk-actions.blade.php | 2 +- .../views/components/table/tr/plain.blade.php | 30 ++--- src/Traits/Helpers/TableAttributeHelpers.php | 52 +++++++++ .../Helpers/BulkActionStylingHelpers.php | 36 ++++++ .../BulkActionsStylingConfigurationTest.php | 59 ++++++++++ 16 files changed, 264 insertions(+), 216 deletions(-) diff --git a/.gitignore b/.gitignore index 848cfaa9b..39ce23330 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ phpunit.xml.bak phpstan.txt coverage.xml ./tmp/** +tests.txt diff --git a/resources/views/components/table/empty.blade.php b/resources/views/components/table/empty.blade.php index 705f93d48..18994fa12 100644 --- a/resources/views/components/table/empty.blade.php +++ b/resources/views/components/table/empty.blade.php @@ -2,18 +2,15 @@ @php($attributes = $attributes->merge(['wire:key' => 'empty-message-'.$this->getId()])) -@if ($isTailwind) - - + + + @if ($isTailwind)
{{ $this->getEmptyMessage() }}
- - -@elseif ($isBootstrap) - - + @else {{ $this->getEmptyMessage() }} - - -@endif + + @endif + + diff --git a/resources/views/components/table/td.blade.php b/resources/views/components/table/td.blade.php index 546bf33fe..459f031c7 100644 --- a/resources/views/components/table/td.blade.php +++ b/resources/views/components/table/td.blade.php @@ -2,18 +2,13 @@ @props(['column', 'colIndex']) @php - $customAttributes = $this->getTdAttributes($column, $row, $colIndex, $rowIndex) + $customAttributes = $this->getTdAttributesBag($column, $row, $colIndex, $rowIndex) @endphp -isClickable()) - @if($this->getTableRowUrlTarget($row) === 'navigate') wire:navigate href="{{ $this->getTableRowUrl($row) }}" - @else onclick="window.open('{{ $this->getTableRowUrl($row) }}', '{{ $this->getTableRowUrlTarget($row) ?? '_self' }}')" - @endif - @endif - {{ - $attributes->merge($customAttributes) - ->class(['px-6 py-4 whitespace-nowrap text-sm font-medium dark:text-white' => $isTailwind && ($customAttributes['default'] ?? true)]) +merge() + ->class(['px-6 py-4 whitespace-nowrap text-sm font-medium' => $isTailwind && ($customAttributes['default-styling'] ?? ($customAttributes['default'] ?? true))]) + ->class(['dark:text-white' => $isTailwind && ($customAttributes['default-colors'] ?? ($customAttributes['default'] ?? true))]) ->class(['hidden' => $isTailwind && $column && $column->shouldCollapseAlways()]) ->class(['hidden md:table-cell' => $isTailwind && $column && $column->shouldCollapseOnMobile()]) ->class(['hidden lg:table-cell' => $isTailwind && $column && $column->shouldCollapseOnTablet()]) @@ -23,7 +18,6 @@ ->class(['d-none d-lg-table-cell' => $isBootstrap && $column && $column->shouldCollapseOnTablet()]) ->class(['laravel-livewire-tables-cursor' => $isBootstrap && $column && $column->isClickable()]) ->except(['default','default-styling','default-colors']) - }} - > - {{ $slot }} + }}> + {{ $slot }} diff --git a/resources/views/components/table/td/bulk-actions.blade.php b/resources/views/components/table/td/bulk-actions.blade.php index df5338f7f..622ffeabc 100644 --- a/resources/views/components/table/td/bulk-actions.blade.php +++ b/resources/views/components/table/td/bulk-actions.blade.php @@ -2,31 +2,23 @@ @props(['row', 'rowIndex']) @php - $customAttributes = $this->getBulkActionsTdAttributes(); - $bulkActionsTdCheckboxAttributes = $this->getBulkActionsTdCheckboxAttributes(); - $theme = $this->getTheme(); + $customAttributes = $this->getBulkActionsTdAttributesNew($row->{$primaryKey}); + $bulkActionsTdCheckboxAttributes = $this->getBulkActionsTdCheckboxAttributesNew($row->{$primaryKey}); @endphp @if ($this->bulkActionsAreEnabled() && $this->hasBulkActions()) - +
$theme === 'tailwind', - 'form-check' => $theme === 'bootstrap-5', + 'inline-flex rounded-md shadow-sm' => $this->isTailwind, + 'form-check' => $this->isBootstrap, ])> - merge($bulkActionsTdCheckboxAttributes)->class([ - 'rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600' => ($theme === 'tailwind') && ($bulkActionsTdCheckboxAttributes['default'] ?? true), - 'form-check-input' => ($theme === 'bootstrap-5') && ($bulkActionsTdCheckboxAttributes['default'] ?? true), + 'rounded shadow-sm transition duration-150 ease-in-out focus:ring focus:ring-opacity-50' => $this->isTailwind && (($bulkActionsTdCheckboxAttributes['default'] ?? true) || ($bulkActionsTdCheckboxAttributes['default-styling'] ?? true)), + 'border-gray-300 text-indigo-600 focus:border-indigo-300 focus:ring-indigo-200 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600' => $this->isTailwind && (($bulkActionsTdCheckboxAttributes['default'] ?? true) || ($bulkActionsTdCheckboxAttributes['default-colors'] ?? true)), + 'form-check-input' => $this->isBootstrap && ($bulkActionsTdCheckboxAttributes['default'] ?? true), ])->except(['default','default-styling','default-colors']) - }} - /> + }} />
@endif diff --git a/resources/views/components/table/td/collapsed-columns.blade.php b/resources/views/components/table/td/collapsed-columns.blade.php index 3bf65e170..d836e32bd 100644 --- a/resources/views/components/table/td/collapsed-columns.blade.php +++ b/resources/views/components/table/td/collapsed-columns.blade.php @@ -5,11 +5,15 @@ @if ($isTailwind) merge(['class' => 'p-3 table-cell text-center ']) - ->class(['sm:hidden' => !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet()]) - ->class(['md:hidden' => !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet() && $this->shouldCollapseOnMobile()]) - ->class(['lg:hidden' => !$this->shouldCollapseAlways() && ($this->shouldCollapseOnTablet() || $this->shouldCollapseOnMobile())]) + $attributes->merge() + ->class(['p-3 table-cell text-center' => $this->isTailwind]) + ->class(['sm:hidden' => $this->isTailwind && !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet()]) + ->class(['md:hidden' => $this->isTailwind && !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet() && $this->shouldCollapseOnMobile()]) + ->class(['lg:hidden' => $this->isTailwind && !$this->shouldCollapseAlways() && ($this->shouldCollapseOnTablet() || $this->shouldCollapseOnMobile())]) + ->class(['d-sm-none' => $this->isBootstrap && !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet()]) + ->class(['d-md-none' => $this->isBootstrap && !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet() && $this->shouldCollapseOnMobile()]) + ->class(['d-lg-none' => $this->isBootstrap && !$this->shouldCollapseAlways() && ($this->shouldCollapseOnTablet() || $this->shouldCollapseOnMobile())]) + }} :class="currentlyReorderingStatus ? 'laravel-livewire-tables-reorderingMinimised' : ''" > @@ -43,12 +47,7 @@ @elseif ($isBootstrap) class(['d-sm-none' => !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet()]) - ->class(['d-md-none' => !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet() && $this->shouldCollapseOnMobile()]) - ->class(['d-lg-none' => !$this->shouldCollapseAlways() && ($this->shouldCollapseOnTablet() || $this->shouldCollapseOnMobile())]) - }} + :class="currentlyReorderingStatus ? 'laravel-livewire-tables-reorderingMinimised' : ''" > @if (! $hidden) diff --git a/resources/views/components/table/td/plain.blade.php b/resources/views/components/table/td/plain.blade.php index 417f6c6b6..12af0e796 100644 --- a/resources/views/components/table/td/plain.blade.php +++ b/resources/views/components/table/td/plain.blade.php @@ -2,26 +2,16 @@ @props(['column' => null, 'customAttributes' => [], 'displayMinimisedOnReorder' => false, 'hideUntilReorder' => false]) -@if ($isTailwind) - merge($customAttributes) - ->class(['px-6 py-4 whitespace-nowrap text-sm font-medium dark:text-white' => $customAttributes['default'] ?? true]) - ->class(['hidden' => $column && $column->shouldCollapseAlways()]) - ->class(['hidden md:table-cell' => $column && $column->shouldCollapseOnMobile()]) - ->class(['hidden lg:table-cell' => $column && $column->shouldCollapseOnTablet()]) - ->except(['default','default-styling','default-colors']) - }} @if($hideUntilReorder) x-show="reorderDisplayColumn" @endif > - {{ $slot }} - -@elseif ($isBootstrap) - merge($customAttributes) - ->class(['' => $customAttributes['default'] ?? true]) - ->class(['d-none' => $column && $column->shouldCollapseAlways()]) - ->class(['d-none d-md-table-cell' => $column && $column->shouldCollapseOnMobile()]) - ->class(['d-none d-lg-table-cell' => $column && $column->shouldCollapseOnTablet()]) - ->except(['default','default-styling','default-colors']) - }}> - {{ $slot }} - -@endif +merge($customAttributes) + ->class(['px-6 py-4 whitespace-nowrap text-sm font-medium dark:text-white' => $isTailwind && ($customAttributes['default'] ?? true)]) + ->class(['hidden' => $isTailwind && $column && $column->shouldCollapseAlways()]) + ->class(['hidden md:table-cell' => $isTailwind && $column && $column->shouldCollapseOnMobile()]) + ->class(['hidden lg:table-cell' => $isTailwind && $column && $column->shouldCollapseOnTablet()]) + ->class(['d-none' => $isBootstrap && $column && $column->shouldCollapseAlways()]) + ->class(['d-none d-md-table-cell' => $isBootstrap && $column && $column->shouldCollapseOnMobile()]) + ->class(['d-none d-lg-table-cell' => $isBootstrap && $column && $column->shouldCollapseOnTablet()]) + ->except(['default','default-styling','default-colors']) +}} @if($hideUntilReorder) x-show="reorderDisplayColumn" @endif > + {{ $slot }} + diff --git a/resources/views/components/table/th.blade.php b/resources/views/components/table/th.blade.php index 525833fe7..3857d3fff 100644 --- a/resources/views/components/table/th.blade.php +++ b/resources/views/components/table/th.blade.php @@ -10,81 +10,50 @@ $customSortIconAttributes = $allThAttributes['sortIconAttributes']; $customLabelAttributes = $allThAttributes['labelAttributes']; - //$customThAttributes = $this->getThAttributes($column); - //$customSortButtonAttributes = $this->getThSortButtonAttributes($column); - //$customSortIconAttributes = $this->getThSortIconAttributes($column); - $direction = $column->hasField() ? $this->getSort($column->getColumnSelectName()) : $this->getSort($column->getSlug()) ?? null ; @endphp -@if ($isTailwind) - merge($customThAttributes) - ->class(['text-gray-500 dark:bg-gray-800 dark:text-gray-400' => (($customThAttributes['default-colors'] ?? true) || ($customThAttributes['default'] ?? true))]) - ->class(['px-6 py-3 text-left text-xs font-medium whitespace-nowrap uppercase tracking-wider' => (($customThAttributes['default-styling'] ?? true) || ($customThAttributes['default'] ?? true))]) - ->class(['hidden' => $column->shouldCollapseAlways()]) - ->class(['hidden md:table-cell' => $column->shouldCollapseOnMobile()]) - ->class(['hidden lg:table-cell' => $column->shouldCollapseOnTablet()]) - ->except(['default', 'default-colors', 'default-styling']) - }} - > - @if($column->getColumnLabelStatus()) - @unless ($this->sortingIsEnabled() && ($column->isSortable() || $column->getSortCallback())) - except(['default', 'default-colors', 'default-styling']) }}>{{ $column->getTitle() }} - @else - - @endunless - @endif - -@elseif ($isBootstrap) - merge($customThAttributes) - ->class(['' => $customThAttributes['default'] ?? true]) - ->class(['d-none' => $column->shouldCollapseAlways()]) - ->class(['d-none d-md-table-cell' => $column->shouldCollapseOnMobile()]) - ->class(['d-none d-lg-table-cell' => $column->shouldCollapseOnTablet()]) - ->except(['default','default-styling','default-colors']) - }} - > - @if($column->getColumnLabelStatus()) - @unless ($this->sortingIsEnabled() && ($column->isSortable() || $column->getSortCallback())) - except(['default', 'default-colors', 'default-styling']) }}>{{ $column->getTitle() }} - @else -
merge($customSortButtonAttributes) + @if ($isTailwind) + + @elseif ($isBootstrap) +
merge($customSortButtonAttributes) ->class(['' => (($customSortButtonAttributes['default-styling'] ?? true) || ($customSortButtonAttributes['default'] ?? true))]) ->except(['default', 'default-colors', 'default-styling', 'wire:key']) - }} - > + }}> except(['default', 'default-colors', 'default-styling']) }}>{{ $column->getTitle() }} - merge($customSortButtonAttributes) + merge($customSortButtonAttributes) ->class(['' => (($customSortButtonAttributes['default-colors'] ?? true) || ($customSortButtonAttributes['default'] ?? true))]) ->except(['default', 'default-colors', 'default-styling', 'wire:key']) - }} - /> + }} />
- @endunless - @endif - -@endif + @endif + @endunless + @endif + diff --git a/resources/views/components/table/th/collapsed-columns.blade.php b/resources/views/components/table/th/collapsed-columns.blade.php index eebc53e70..6be3dfa6c 100644 --- a/resources/views/components/table/th/collapsed-columns.blade.php +++ b/resources/views/components/table/th/collapsed-columns.blade.php @@ -1,29 +1,18 @@ @aware([ 'tableName','isTailwind','isBootstrap']) @if ($this->collapsingColumnsAreEnabled() && $this->hasCollapsedColumns()) - @if ($isTailwind) - merge(['class' => 'table-cell dark:bg-gray-800 laravel-livewire-tables-reorderingMinimised']) - ->class(['sm:hidden' => !$this->shouldCollapseOnTablet() && !$this->shouldCollapseAlways()]) - ->class(['md:hidden' => !$this->shouldCollapseOnMobile() && !$this->shouldCollapseOnTablet() && !$this->shouldCollapseAlways()]) - ->class(['lg:hidden' => !$this->shouldCollapseAlways()]) - }} - :class="{ 'laravel-livewire-tables-reorderingMinimised': ! currentlyReorderingStatus }" - > - @elseif ($isBootstrap) - merge(['class' => 'd-table-cell laravel-livewire-tables-reorderingMinimised']) - ->class(['d-sm-none' => !$this->shouldCollapseOnTablet() && !$this->shouldCollapseAlways()]) - ->class(['d-md-none' => !$this->shouldCollapseOnMobile() && !$this->shouldCollapseOnTablet() && !$this->shouldCollapseAlways()]) - ->class(['d-lg-none' => !$this->shouldCollapseAlways()]) - }} - :class="{ 'laravel-livewire-tables-reorderingMinimised': ! currentlyReorderingStatus }" - > - @endif + merge() + ->class(['table-cell dark:bg-gray-800 laravel-livewire-tables-reorderingMinimised' => $isTailwind]) + ->class(['sm:hidden' => $isTailwind && !$this->shouldCollapseOnTablet() && !$this->shouldCollapseAlways()]) + ->class(['md:hidden' => $isTailwind && !$this->shouldCollapseOnMobile() && !$this->shouldCollapseOnTablet() && !$this->shouldCollapseAlways()]) + ->class(['lg:hidden' => $isTailwind && !$this->shouldCollapseAlways()]) + ->class(['d-table-cell laravel-livewire-tables-reorderingMinimised' => $isBootstrap]) + ->class(['d-sm-none' => $isBootstrap && !$this->shouldCollapseOnTablet() && !$this->shouldCollapseAlways()]) + ->class(['d-md-none' => $isBootstrap && !$this->shouldCollapseOnMobile() && !$this->shouldCollapseOnTablet() && !$this->shouldCollapseAlways()]) + ->class(['d-lg-none' => $isBootstrap && !$this->shouldCollapseAlways()]) + + }} + :class="{ 'laravel-livewire-tables-reorderingMinimised': ! currentlyReorderingStatus }" + > @endif diff --git a/resources/views/components/table/th/plain.blade.php b/resources/views/components/table/th/plain.blade.php index 0b9c8326e..ff5566cf1 100644 --- a/resources/views/components/table/th/plain.blade.php +++ b/resources/views/components/table/th/plain.blade.php @@ -1,14 +1,12 @@ @aware(['isTailwind','isBootstrap']) @props(['displayMinimisedOnReorder' => false, 'hideUntilReorder' => false, 'customAttributes' => ['default' => true]]) -merge($customAttributes)->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' => ($isTailwind) && (($customAttributes['default-colors'] ?? true) || ($customAttributes['default'] ?? true)), 'laravel-livewire-tables-reorderingMinimised' => ($isBootstrap) && (($customAttributes['default-colors'] ?? true) || ($customAttributes['default'] ?? true)), - ]) - }} - @if($hideUntilReorder) :class="!reorderDisplayColumn && 'w-0 p-0 hidden'" @endif + ])->except(['default','default-styling','default-colors']) + }} @if($hideUntilReorder) :class="!reorderDisplayColumn && 'w-0 p-0 hidden'" @endif > {{ $slot }} diff --git a/resources/views/components/table/th/reorder.blade.php b/resources/views/components/table/th/reorder.blade.php index e4fe7cecb..903b7340b 100644 --- a/resources/views/components/table/th/reorder.blade.php +++ b/resources/views/components/table/th/reorder.blade.php @@ -9,6 +9,7 @@ ->class(['text-gray-500 dark:bg-gray-800 dark:text-gray-400' => (($customThAttributes['default-colors'] ?? true) || ($customThAttributes['default'] ?? true))]) ->class(['table-cell px-6 py-3 text-left text-xs font-medium whitespace-nowrap uppercase tracking-wider' => (($customThAttributes['default-styling'] ?? true) || ($customThAttributes['default'] ?? true))]) ->class(['laravel-livewire-tables-reorderingMinimised' => ($isBootstrap) && ($customThAttributes['default'] ?? true)]) + ->except(['default','default-styling','default-colors']) }} >
diff --git a/resources/views/components/table/tr.blade.php b/resources/views/components/table/tr.blade.php index 9f5f84b20..838240d82 100644 --- a/resources/views/components/table/tr.blade.php +++ b/resources/views/components/table/tr.blade.php @@ -2,34 +2,17 @@ @props(['row', 'rowIndex']) @php - $customAttributes = $this->getTrAttributes($row, $rowIndex); + $customAttributes = $this->getTrAttributesBag($row, $rowIndex); @endphp -hasDisplayLoadingPlaceholder()) - wire:loading.class.add="hidden d-none" - @else - wire:loading.class.delay="opacity-50 dark:bg-gray-900 dark:opacity-60" - @endif - id="{{ $tableName }}-row-{{ $row->{$primaryKey} }}" - :draggable="currentlyReorderingStatus" - wire:key="{{ $tableName }}-tablerow-tr-{{ $row->{$primaryKey} }}" - loopType="{{ ($rowIndex % 2 === 0) ? 'even' : 'odd' }}" - {{ - $attributes->merge($customAttributes) +merge() ->class(['bg-white dark:bg-gray-700 dark:text-white rappasoft-striped-row' => ($isTailwind && ($customAttributes['default'] ?? true) && $rowIndex % 2 === 0)]) ->class(['bg-gray-50 dark:bg-gray-800 dark:text-white rappasoft-striped-row' => ($isTailwind && ($customAttributes['default'] ?? true) && $rowIndex % 2 !== 0)]) ->class(['cursor-pointer' => ($isTailwind && $this->hasTableRowUrl() && ($customAttributes['default'] ?? true))]) ->class(['bg-light rappasoft-striped-row' => ($isBootstrap && $rowIndex % 2 === 0 && ($customAttributes['default'] ?? true))]) ->class(['bg-white rappasoft-striped-row' => ($isBootstrap && $rowIndex % 2 !== 0 && ($customAttributes['default'] ?? true))]) ->except(['default','default-styling','default-colors']) - }} - -> + }}> {{ $slot }} diff --git a/resources/views/components/table/tr/bulk-actions.blade.php b/resources/views/components/table/tr/bulk-actions.blade.php index e63d18df2..e1b2b1f7b 100644 --- a/resources/views/components/table/tr/bulk-actions.blade.php +++ b/resources/views/components/table/tr/bulk-actions.blade.php @@ -32,7 +32,7 @@ 'ml-1 underline text-sm leading-5 font-medium focus:outline-none focus:underline transition duration-150 ease-in-out' => $this->isTailwind && ($this->getBulkActionsRowButtonAttributes['default-styling'] ?? true), 'text-blue-600 text-gray-700 focus:text-gray-800 dark:text-white dark:hover:text-gray-400' => $this->isTailwind && ($this->getBulkActionsRowButtonAttributes['default-colors'] ?? true), 'btn btn-primary btn-sm' => $this->isBootstrap && ($this->getBulkActionsRowButtonAttributes['default-styling'] ?? true) - ]) + ])->except(['default','default-styling','default-colors']) }} > {{ __($this->getLocalisationPath.'Deselect All') }} diff --git a/resources/views/components/table/tr/plain.blade.php b/resources/views/components/table/tr/plain.blade.php index f299b3c0a..1afdd833c 100644 --- a/resources/views/components/table/tr/plain.blade.php +++ b/resources/views/components/table/tr/plain.blade.php @@ -1,24 +1,12 @@ @aware(['isTailwind','isBootstrap']) @props(['customAttributes' => [], 'displayMinimisedOnReorder' => true]) -@if ($isTailwind) - merge($customAttributes) - ->class(['bg-white dark:bg-gray-700 dark:text-white' => $customAttributes['default'] ?? true]) - ->class(['laravel-livewire-tables-reorderingMinimised']) - ->except(['default','default-styling','default-colors']) - }} - > - {{ $slot }} - -@elseif ($isBootstrap) - merge($customAttributes) - ->class(['' => $customAttributes['default'] ?? true]) - ->class(['laravel-livewire-tables-reorderingMinimised']) - ->except(['default','default-styling','default-colors']) - }} - > - {{ $slot }} - -@endif +merge($customAttributes) + ->class(['bg-white dark:bg-gray-700 dark:text-white' => $isTailwind && ($customAttributes['default'] ?? true)]) + ->class(['laravel-livewire-tables-reorderingMinimised']) + ->except(['default','default-styling','default-colors']) + }} +> + {{ $slot }} + diff --git a/src/Traits/Helpers/TableAttributeHelpers.php b/src/Traits/Helpers/TableAttributeHelpers.php index 5c8125fa9..15d95aa7e 100644 --- a/src/Traits/Helpers/TableAttributeHelpers.php +++ b/src/Traits/Helpers/TableAttributeHelpers.php @@ -99,12 +99,64 @@ public function getTrAttributes(Model $row, int $index): array return isset($this->trAttributesCallback) ? call_user_func($this->trAttributesCallback, $row, $index) : ['default' => true]; } + #[Computed] + public function getTrAttributesBag(Model $row, int $index): ComponentAttributeBag + { + $default = [ + 'id' => $this->getTableName()."-row-".$row->{$this->getPrimaryKey()}, + 'loopType' => $index % 2 === 0 ? 'even' : 'odd', + 'rowpk' => $row->{$this->getPrimaryKey()}, + 'x-on:dragstart.self' => "currentlyReorderingStatus && dragStart(event)", + 'x-on:drop.prevent' => "currentlyReorderingStatus && dropEvent(event)", + 'x-on:dragover.prevent.throttle.500ms' => "currentlyReorderingStatus && dragOverEvent(event)", + 'x-on:dragleave.prevent.throttle.500ms' => "currentlyReorderingStatus && dragLeaveEvent(event)", + ':draggable' => "currentlyReorderingStatus", + 'wire:key' => $this->getTableName()."-tablerow-tr-".$row->{$this->getPrimaryKey()}, + ]; + + if($this->hasDisplayLoadingPlaceholder()) + { + $default['wire:loading.class.add'] = "hidden d-none"; + } + else + { + $default['wire:loading.class.delay'] = "opacity-50 dark:bg-gray-900 dark:opacity-60"; + } + + return new ComponentAttributeBag(array_merge($default, $this->getTrAttributes($row, $index))); + } + #[Computed] public function getTdAttributes(Column $column, Model $row, int $colIndex, int $rowIndex): array { return isset($this->tdAttributesCallback) ? call_user_func($this->tdAttributesCallback, $column, $row, $colIndex, $rowIndex) : ['default' => true]; } + #[Computed] + public function getTdAttributesBag(Column $column, Model $row, int $colIndex, int $rowIndex): ComponentAttributeBag + { + $default = [ + 'wire:key' => $this->getTableName() . '-table-td-'.$row->{$this->getPrimaryKey()}.'-'.$column->getSlug(), + 'default' => true, + 'default-colors' => true, + 'default-styling' => true, + ]; + if($column->isClickable()) + { + if($this->getTableRowUrlTarget($row) === 'navigate') { + $default['wire:navigate'] = ''; + $default['href'] = $this->getTableRowUrl($row); + } + else + { + $target = $this->getTableRowUrlTarget($row) ?? '_self'; + $default['onclick'] = "window.open('".$this->getTableRowUrl($row)."', '".$target."')"; + } + } + return new ComponentAttributeBag(array_merge($default, $this->getTdAttributes($column, $row, $colIndex, $rowIndex))); + } + + public function hasTableRowUrl(): bool { return isset($this->trUrlCallback); diff --git a/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php b/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php index adc3cea89..b2e150fee 100644 --- a/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php +++ b/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php @@ -3,6 +3,7 @@ namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers; use Illuminate\View\ComponentAttributeBag; +use Illuminate\Database\Eloquent\Model; use Livewire\Attributes\Computed; trait BulkActionStylingHelpers @@ -79,11 +80,26 @@ public function getBulkActionsThCheckboxAttributes(): array * * @return array */ + public function getBulkActionsTdAttributesNew(string $rowPrimaryKey): array + { + $default = [ + 'wire:key' => $this->getTableName() ."-tbody-td-bulk-actions-".$rowPrimaryKey, + ':displayMinimisedOnReorder' => "true", + ]; + return array_merge($default, $this->getBulkActionsTdAttributes()); + } + + /** + * Used to get attributes for the Bulk Actions TD + * + * @return array + */ public function getBulkActionsTdAttributes(): array { return $this->getCustomAttributes('bulkActionsTdAttributes'); } + /** * Used to get attributes for the Bulk Actions TD * @@ -91,10 +107,30 @@ public function getBulkActionsTdAttributes(): array */ public function getBulkActionsTdCheckboxAttributes(): array { + + return $this->getCustomAttributes('bulkActionsTdCheckboxAttributes'); } + public function getBulkActionsTdCheckboxAttributesNew(string $rowPrimaryKey): array + { + $default = [ + 'x-cloak' => '', + 'x-show' => "!currentlyReorderingStatus", + 'x-model' => "selectedItems", + 'wire:key' => $this->getTableName()."-selectedItems-".$rowPrimaryKey, + 'id' => $this->getTableName()."-row-bac-".$rowPrimaryKey, + 'value' => $rowPrimaryKey, + 'wire:loading.attr.delay' => "disabled", + 'type' => "checkbox", + ]; + + return array_merge($default, $this->getBulkActionsTdCheckboxAttributes()); + + } + + /** * Used to get attributes for the Bulk Actions Row Buttons * diff --git a/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php b/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php index 019c13d22..da5cafb68 100644 --- a/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php +++ b/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php @@ -133,4 +133,63 @@ public function test_bulk_actions_th_checkbox_attributes_returns_default_true_if { $this->assertSame(['default' => true, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getBulkActionsThCheckboxAttributes()); } + + public function test_can_set_bulk_actions_checkbox_attributes(): void + { + $this->assertSame([ + 'x-cloak' => '', + 'x-show' => '!currentlyReorderingStatus', + 'x-model' => 'selectedItems', + 'wire:key' => 'table-selectedItems-5', + 'id' => 'table-row-bac-5', + 'value' => '5', + 'wire:loading.attr.delay' => 'disabled', + 'type' => 'checkbox', + 'default' => true, + 'default-colors' => false, + 'default-styling' => false + ], + $this->basicTable->getBulkActionsTdCheckboxAttributesNew(5)); + + $this->assertSame([ + 'x-cloak' => '', + 'x-show' => '!currentlyReorderingStatus', + 'x-model' => 'selectedItems', + 'wire:key' => 'table-selectedItems-14', + 'id' => 'table-row-bac-14', + 'value' => '14', + 'wire:loading.attr.delay' => 'disabled', + 'type' => 'checkbox', + 'default' => true, + 'default-colors' => false, + 'default-styling' => false + ], + $this->basicTable->getBulkActionsTdCheckboxAttributesNew(14)); + + } + + + public function test_can_set_bulk_actions_td_attributes(): void + { + $this->assertSame([ + 'wire:key' => 'table-tbody-td-bulk-actions-5', + ':displayMinimisedOnReorder' => 'true', + 'default' => true, + 'default-colors' => false, + 'default-styling' => false + ], + $this->basicTable->getBulkActionsTdAttributesNew(5)); + + $this->assertSame([ + 'wire:key' => 'table-tbody-td-bulk-actions-14', + ':displayMinimisedOnReorder' => 'true', + 'default' => true, + 'default-colors' => false, + 'default-styling' => false + ], + $this->basicTable->getBulkActionsTdAttributesNew(14)); + + } + + } From 300929b8bbfe0bab87b781fb6c794602caa4b26c Mon Sep 17 00:00:00 2001 From: lrljoe Date: Sun, 29 Dec 2024 04:50:13 +0000 Subject: [PATCH 2/3] Fix styling --- src/Traits/Helpers/TableAttributeHelpers.php | 42 ++++++++---------- .../Helpers/BulkActionStylingHelpers.php | 24 +++++------ .../BulkActionsStylingConfigurationTest.php | 43 +++++++++---------- 3 files changed, 49 insertions(+), 60 deletions(-) diff --git a/src/Traits/Helpers/TableAttributeHelpers.php b/src/Traits/Helpers/TableAttributeHelpers.php index 15d95aa7e..4f041d22b 100644 --- a/src/Traits/Helpers/TableAttributeHelpers.php +++ b/src/Traits/Helpers/TableAttributeHelpers.php @@ -103,24 +103,21 @@ public function getTrAttributes(Model $row, int $index): array public function getTrAttributesBag(Model $row, int $index): ComponentAttributeBag { $default = [ - 'id' => $this->getTableName()."-row-".$row->{$this->getPrimaryKey()}, + 'id' => $this->getTableName().'-row-'.$row->{$this->getPrimaryKey()}, 'loopType' => $index % 2 === 0 ? 'even' : 'odd', 'rowpk' => $row->{$this->getPrimaryKey()}, - 'x-on:dragstart.self' => "currentlyReorderingStatus && dragStart(event)", - 'x-on:drop.prevent' => "currentlyReorderingStatus && dropEvent(event)", - 'x-on:dragover.prevent.throttle.500ms' => "currentlyReorderingStatus && dragOverEvent(event)", - 'x-on:dragleave.prevent.throttle.500ms' => "currentlyReorderingStatus && dragLeaveEvent(event)", - ':draggable' => "currentlyReorderingStatus", - 'wire:key' => $this->getTableName()."-tablerow-tr-".$row->{$this->getPrimaryKey()}, + 'x-on:dragstart.self' => 'currentlyReorderingStatus && dragStart(event)', + 'x-on:drop.prevent' => 'currentlyReorderingStatus && dropEvent(event)', + 'x-on:dragover.prevent.throttle.500ms' => 'currentlyReorderingStatus && dragOverEvent(event)', + 'x-on:dragleave.prevent.throttle.500ms' => 'currentlyReorderingStatus && dragLeaveEvent(event)', + ':draggable' => 'currentlyReorderingStatus', + 'wire:key' => $this->getTableName().'-tablerow-tr-'.$row->{$this->getPrimaryKey()}, ]; - if($this->hasDisplayLoadingPlaceholder()) - { - $default['wire:loading.class.add'] = "hidden d-none"; - } - else - { - $default['wire:loading.class.delay'] = "opacity-50 dark:bg-gray-900 dark:opacity-60"; + if ($this->hasDisplayLoadingPlaceholder()) { + $default['wire:loading.class.add'] = 'hidden d-none'; + } else { + $default['wire:loading.class.delay'] = 'opacity-50 dark:bg-gray-900 dark:opacity-60'; } return new ComponentAttributeBag(array_merge($default, $this->getTrAttributes($row, $index))); @@ -135,28 +132,25 @@ public function getTdAttributes(Column $column, Model $row, int $colIndex, int $ #[Computed] public function getTdAttributesBag(Column $column, Model $row, int $colIndex, int $rowIndex): ComponentAttributeBag { - $default = [ - 'wire:key' => $this->getTableName() . '-table-td-'.$row->{$this->getPrimaryKey()}.'-'.$column->getSlug(), + $default = [ + 'wire:key' => $this->getTableName().'-table-td-'.$row->{$this->getPrimaryKey()}.'-'.$column->getSlug(), 'default' => true, 'default-colors' => true, 'default-styling' => true, ]; - if($column->isClickable()) - { - if($this->getTableRowUrlTarget($row) === 'navigate') { + if ($column->isClickable()) { + if ($this->getTableRowUrlTarget($row) === 'navigate') { $default['wire:navigate'] = ''; $default['href'] = $this->getTableRowUrl($row); - } - else - { + } else { $target = $this->getTableRowUrlTarget($row) ?? '_self'; $default['onclick'] = "window.open('".$this->getTableRowUrl($row)."', '".$target."')"; - } + } } + return new ComponentAttributeBag(array_merge($default, $this->getTdAttributes($column, $row, $colIndex, $rowIndex))); } - public function hasTableRowUrl(): bool { return isset($this->trUrlCallback); diff --git a/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php b/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php index b2e150fee..a734b8e74 100644 --- a/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php +++ b/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php @@ -2,8 +2,8 @@ namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers; -use Illuminate\View\ComponentAttributeBag; use Illuminate\Database\Eloquent\Model; +use Illuminate\View\ComponentAttributeBag; use Livewire\Attributes\Computed; trait BulkActionStylingHelpers @@ -83,13 +83,14 @@ public function getBulkActionsThCheckboxAttributes(): array public function getBulkActionsTdAttributesNew(string $rowPrimaryKey): array { $default = [ - 'wire:key' => $this->getTableName() ."-tbody-td-bulk-actions-".$rowPrimaryKey, - ':displayMinimisedOnReorder' => "true", + 'wire:key' => $this->getTableName().'-tbody-td-bulk-actions-'.$rowPrimaryKey, + ':displayMinimisedOnReorder' => 'true', ]; + return array_merge($default, $this->getBulkActionsTdAttributes()); } - /** + /** * Used to get attributes for the Bulk Actions TD * * @return array @@ -99,7 +100,6 @@ public function getBulkActionsTdAttributes(): array return $this->getCustomAttributes('bulkActionsTdAttributes'); } - /** * Used to get attributes for the Bulk Actions TD * @@ -108,7 +108,6 @@ public function getBulkActionsTdAttributes(): array public function getBulkActionsTdCheckboxAttributes(): array { - return $this->getCustomAttributes('bulkActionsTdCheckboxAttributes'); } @@ -117,20 +116,19 @@ public function getBulkActionsTdCheckboxAttributesNew(string $rowPrimaryKey): ar { $default = [ 'x-cloak' => '', - 'x-show' => "!currentlyReorderingStatus", - 'x-model' => "selectedItems", - 'wire:key' => $this->getTableName()."-selectedItems-".$rowPrimaryKey, - 'id' => $this->getTableName()."-row-bac-".$rowPrimaryKey, + 'x-show' => '!currentlyReorderingStatus', + 'x-model' => 'selectedItems', + 'wire:key' => $this->getTableName().'-selectedItems-'.$rowPrimaryKey, + 'id' => $this->getTableName().'-row-bac-'.$rowPrimaryKey, 'value' => $rowPrimaryKey, - 'wire:loading.attr.delay' => "disabled", - 'type' => "checkbox", + 'wire:loading.attr.delay' => 'disabled', + 'type' => 'checkbox', ]; return array_merge($default, $this->getBulkActionsTdCheckboxAttributes()); } - /** * Used to get attributes for the Bulk Actions Row Buttons * diff --git a/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php b/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php index da5cafb68..4ebfa4fae 100644 --- a/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php +++ b/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php @@ -145,11 +145,11 @@ public function test_can_set_bulk_actions_checkbox_attributes(): void 'value' => '5', 'wire:loading.attr.delay' => 'disabled', 'type' => 'checkbox', - 'default' => true, - 'default-colors' => false, - 'default-styling' => false - ], - $this->basicTable->getBulkActionsTdCheckboxAttributesNew(5)); + 'default' => true, + 'default-colors' => false, + 'default-styling' => false, + ], + $this->basicTable->getBulkActionsTdCheckboxAttributesNew(5)); $this->assertSame([ 'x-cloak' => '', @@ -160,36 +160,33 @@ public function test_can_set_bulk_actions_checkbox_attributes(): void 'value' => '14', 'wire:loading.attr.delay' => 'disabled', 'type' => 'checkbox', - 'default' => true, - 'default-colors' => false, - 'default-styling' => false - ], - $this->basicTable->getBulkActionsTdCheckboxAttributesNew(14)); + 'default' => true, + 'default-colors' => false, + 'default-styling' => false, + ], + $this->basicTable->getBulkActionsTdCheckboxAttributesNew(14)); } - public function test_can_set_bulk_actions_td_attributes(): void { $this->assertSame([ 'wire:key' => 'table-tbody-td-bulk-actions-5', ':displayMinimisedOnReorder' => 'true', - 'default' => true, - 'default-colors' => false, - 'default-styling' => false - ], - $this->basicTable->getBulkActionsTdAttributesNew(5)); + 'default' => true, + 'default-colors' => false, + 'default-styling' => false, + ], + $this->basicTable->getBulkActionsTdAttributesNew(5)); $this->assertSame([ 'wire:key' => 'table-tbody-td-bulk-actions-14', ':displayMinimisedOnReorder' => 'true', - 'default' => true, - 'default-colors' => false, - 'default-styling' => false - ], - $this->basicTable->getBulkActionsTdAttributesNew(14)); + 'default' => true, + 'default-colors' => false, + 'default-styling' => false, + ], + $this->basicTable->getBulkActionsTdAttributesNew(14)); } - - } From df1ebce1b89f0a893bf438ee7efecabc626debf6 Mon Sep 17 00:00:00 2001 From: LRLJoe Date: Sun, 29 Dec 2024 05:04:13 +0000 Subject: [PATCH 3/3] Tidy CollapsedColumns --- .../table/td/collapsed-columns.blade.php | 112 ++++++------------ 1 file changed, 38 insertions(+), 74 deletions(-) diff --git a/resources/views/components/table/td/collapsed-columns.blade.php b/resources/views/components/table/td/collapsed-columns.blade.php index d836e32bd..92654b1fc 100644 --- a/resources/views/components/table/td/collapsed-columns.blade.php +++ b/resources/views/components/table/td/collapsed-columns.blade.php @@ -2,80 +2,44 @@ @props(['rowIndex', 'hidden' => false]) @if ($this->collapsingColumnsAreEnabled() && $this->hasCollapsedColumns()) - @if ($isTailwind) - merge() - ->class(['p-3 table-cell text-center' => $this->isTailwind]) - ->class(['sm:hidden' => $this->isTailwind && !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet()]) - ->class(['md:hidden' => $this->isTailwind && !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet() && $this->shouldCollapseOnMobile()]) - ->class(['lg:hidden' => $this->isTailwind && !$this->shouldCollapseAlways() && ($this->shouldCollapseOnTablet() || $this->shouldCollapseOnMobile())]) - ->class(['d-sm-none' => $this->isBootstrap && !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet()]) - ->class(['d-md-none' => $this->isBootstrap && !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet() && $this->shouldCollapseOnMobile()]) - ->class(['d-lg-none' => $this->isBootstrap && !$this->shouldCollapseAlways() && ($this->shouldCollapseOnTablet() || $this->shouldCollapseOnMobile())]) + merge() + ->class(['p-3 table-cell text-center' => $this->isTailwind]) + ->class(['sm:hidden' => $this->isTailwind && !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet()]) + ->class(['md:hidden' => $this->isTailwind && !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet() && $this->shouldCollapseOnMobile()]) + ->class(['lg:hidden' => $this->isTailwind && !$this->shouldCollapseAlways() && ($this->shouldCollapseOnTablet() || $this->shouldCollapseOnMobile())]) + ->class(['d-sm-none' => $this->isBootstrap && !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet()]) + ->class(['d-md-none' => $this->isBootstrap && !$this->shouldCollapseAlways() && !$this->shouldCollapseOnTablet() && $this->shouldCollapseOnMobile()]) + ->class(['d-lg-none' => $this->isBootstrap && !$this->shouldCollapseAlways() && ($this->shouldCollapseOnTablet() || $this->shouldCollapseOnMobile())]) - }} - :class="currentlyReorderingStatus ? 'laravel-livewire-tables-reorderingMinimised' : ''" - > - @if (! $hidden) - - @endif - - @elseif ($isBootstrap) - + @if (! $hidden) + - @endif - - @endif + ]) + ->except(['default','default-styling','default-colors']) + }} /> + + @endif + @endif