diff --git a/resources/views/components/table/th.blade.php b/resources/views/components/table/th.blade.php index 525833fe7..f587600eb 100644 --- a/resources/views/components/table/th.blade.php +++ b/resources/views/components/table/th.blade.php @@ -1,90 +1,58 @@ -@aware([ 'tableName','isTailwind','isBootstrap']) @props(['column', 'index']) @php - $attributes = $attributes->merge(['wire:key' => $tableName . '-header-col-'.$column->getSlug()]); $allThAttributes = $this->getAllThAttributes($column); - $customThAttributes = $allThAttributes['customAttributes']; $customSortButtonAttributes = $allThAttributes['sortButtonAttributes']; - $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 ; + $customIconAttributes = $this->getThSortIconAttributes($column); + $direction = $column->hasField() ? $this->getSort($column->getColumnSelectName()) : $this->getSort($column->getSlug()) ?? null; @endphp -@if ($isTailwind) - <th scope="col" {{ - $attributes->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())) - <span {{ $customLabelAttributes->except(['default', 'default-colors', 'default-styling']) }}>{{ $column->getTitle() }}</span> - @else - <button wire:click="sortBy('{{ $column->getColumnSortKey() }}')" - {{ +<th {{ + $attributes->merge($customThAttributes) + ->class([ + 'text-gray-500 dark:bg-gray-800 dark:text-gray-400' => $this->isTailwind && (($customThAttributes['default-colors'] ?? true) || ($customThAttributes['default'] ?? true)), + 'px-6 py-3 text-left text-xs font-medium whitespace-nowrap uppercase tracking-wider' => $this->isTailwind && (($customThAttributes['default-styling'] ?? true) || ($customThAttributes['default'] ?? true)), + 'hidden' => $this->isTailwind && $column->shouldCollapseAlways(), + 'hidden md:table-cell' => $this->isTailwind && $column->shouldCollapseOnMobile(), + 'hidden lg:table-cell' => $this->isTailwind && $column->shouldCollapseOnTablet(), + '' => $this->isBootstrap && ($customThAttributes['default'] ?? true), + 'd-none' => $this->isBootstrap && $column->shouldCollapseAlways(), + 'd-none d-md-table-cell' => $this->isBootstrap && $column->shouldCollapseOnMobile(), + 'd-none d-lg-table-cell' => $this->isBootstrap && $column->shouldCollapseOnTablet(), + ]) + ->except(['default', 'default-colors', 'default-styling']) +}}> + @if($column->getColumnLabelStatus()) + @unless ($this->sortingIsEnabled() && ($column->isSortable() || $column->getSortCallback())) + <x-livewire-tables::table.th.label :$customLabelAttributes :columnTitle="$column->getTitle()" /> + @else + @if ($this->isTailwind) + + <button wire:click="sortBy('{{ $column->getColumnSortKey() }}')" {{ $attributes->merge($customSortButtonAttributes) - ->class(['text-gray-500 dark:text-gray-400' => (($customSortButtonAttributes['default-colors'] ?? true) || ($customSortButtonAttributes['default'] ?? true))]) - ->class(['flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none' => (($customSortButtonAttributes['default-styling'] ?? true) || ($customSortButtonAttributes['default'] ?? true))]) - ->except(['default', 'default-colors', 'default-styling', 'wire:key']) - }} - > - <span {{ $customLabelAttributes->except(['default', 'default-colors', 'default-styling']) }}>{{ $column->getTitle() }}</span> - <x-livewire-tables::table.th.sort-icons :$direction - {{ - $attributes->merge($customSortIconAttributes) + ->class([ + 'text-gray-500 dark:text-gray-400' => (($customSortButtonAttributes['default-colors'] ?? true) || ($customSortButtonAttributes['default'] ?? true)), + 'flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none' => (($customSortButtonAttributes['default-styling'] ?? true) || ($customSortButtonAttributes['default'] ?? true)), + ]) ->except(['default', 'default-colors', 'default-styling', 'wire:key']) - }} - /> - + }}> + <x-livewire-tables::table.th.label :$customLabelAttributes :columnTitle="$column->getTitle()" /> + <x-livewire-tables::table.th.sort-icons :$direction :$customIconAttributes /> </button> - @endunless - @endif - </th> -@elseif ($isBootstrap) - <th scope="col" {{ - $attributes->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())) - <span {{ $customLabelAttributes->except(['default', 'default-colors', 'default-styling']) }}>{{ $column->getTitle() }}</span> - @else - <div - class="d-flex align-items-center laravel-livewire-tables-cursor" - wire:click="sortBy('{{ $column->getColumnSortKey() }}')" - {{ + @elseif ($this->isBootstrap) + <div wire:click="sortBy('{{ $column->getColumnSortKey() }}')" {{ $attributes->merge($customSortButtonAttributes) - ->class(['' => (($customSortButtonAttributes['default-styling'] ?? true) || ($customSortButtonAttributes['default'] ?? true))]) + ->class(['d-flex align-items-center laravel-livewire-tables-cursor' => (($customSortButtonAttributes['default-styling'] ?? true) || ($customSortButtonAttributes['default'] ?? true))]) ->except(['default', 'default-colors', 'default-styling', 'wire:key']) - }} - > - <span {{ $customLabelAttributes->except(['default', 'default-colors', 'default-styling']) }}>{{ $column->getTitle() }}</span> + }}> + <x-livewire-tables::table.th.label :$customLabelAttributes :columnTitle="$column->getTitle()" /> + <x-livewire-tables::table.th.sort-icons :$direction :$customIconAttributes /> - <x-livewire-tables::table.th.sort-icons :$direction {{ - $attributes->merge($customSortButtonAttributes) - ->class(['' => (($customSortButtonAttributes['default-colors'] ?? true) || ($customSortButtonAttributes['default'] ?? true))]) - ->except(['default', 'default-colors', 'default-styling', 'wire:key']) - }} - /> </div> - @endunless - @endif - </th> -@endif + @endif + + @endunless + @endif +</th> diff --git a/resources/views/components/table/th/bulk-actions.blade.php b/resources/views/components/table/th/bulk-actions.blade.php index d15f5a728..e99199e2f 100644 --- a/resources/views/components/table/th/bulk-actions.blade.php +++ b/resources/views/components/table/th/bulk-actions.blade.php @@ -1,20 +1,17 @@ -@aware([ 'tableName']) @php $customAttributes = $this->hasBulkActionsThAttributes ? $this->getBulkActionsThAttributes : $this->getAllThAttributes($this->getBulkActionsColumn())['customAttributes']; - $bulkActionsThCheckboxAttributes = $this->getBulkActionsThCheckboxAttributes(); - $theme = $this->getTheme(); @endphp @if ($this->bulkActionsAreEnabled() && $this->hasBulkActions()) - <x-livewire-tables::table.th.plain wire:key="{{ $tableName }}-thead-bulk-actions" :displayMinimisedOnReorder="true" :$customAttributes> + <x-livewire-tables::table.th.plain :displayMinimisedOnReorder="true" wire:key="{{ $this->getTableName }}-thead-bulk-actions" :$customAttributes> <div x-data="{newSelectCount: 0, indeterminateCheckbox: false, bulkActionHeaderChecked: false}" x-init="$watch('selectedItems', value => indeterminateCheckbox = (value.length > 0 && value.length < paginationTotalItemCount))" x-cloak x-show="currentlyReorderingStatus !== true" @class([ - 'inline-flex rounded-md shadow-sm' => $theme === 'tailwind', - 'form-check' => $theme === 'bootstrap-5', + 'inline-flex rounded-md shadow-sm' => $this->isTailwind, + 'form-check' => $this->isBootstrap, ]) > <input @@ -24,8 +21,9 @@ :checked="selectedItems.length == paginationTotalItemCount" {{ $attributes->merge($bulkActionsThCheckboxAttributes)->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') && ($bulkActionsThCheckboxAttributes['default'] ?? true), - 'form-check-input' => ($theme === 'bootstrap-5') && ($bulkActionsThCheckboxAttributes['default'] ?? 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 && (($bulkActionsThCheckboxAttributes['default'] ?? true) || ($bulkActionsThCheckboxAttributes['default-colors'] ?? true)), + 'rounded shadow-sm transition duration-150 ease-in-out focus:ring focus:ring-opacity-50 ' => $this->isTailwind && (($bulkActionsThCheckboxAttributes['default'] ?? true) || ($bulkActionsThCheckboxAttributes['default-styling'] ?? true)), + 'form-check-input' => $this->isBootstrap && ($bulkActionsThCheckboxAttributes['default'] ?? true), ])->except(['default','default-styling','default-colors']) }} /> diff --git a/resources/views/components/table/th/collapsed-columns.blade.php b/resources/views/components/table/th/collapsed-columns.blade.php index eebc53e70..ad8a1860d 100644 --- a/resources/views/components/table/th/collapsed-columns.blade.php +++ b/resources/views/components/table/th/collapsed-columns.blade.php @@ -1,29 +1,15 @@ -@aware([ 'tableName','isTailwind','isBootstrap']) - -@if ($this->collapsingColumnsAreEnabled() && $this->hasCollapsedColumns()) - @if ($isTailwind) - <th - scope="col" - {{ - $attributes - ->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 }" - ></th> - @elseif ($isBootstrap) - <th - scope="col" - {{ - $attributes - ->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 }" - ></th> - @endif +@if ($this->collapsingColumnsAreEnabled && $this->hasCollapsedColumns) + <th scope="col" :class="{ 'laravel-livewire-tables-reorderingMinimised': ! currentlyReorderingStatus }" {{ + $attributes->merge() + ->class([ + 'table-cell dark:bg-gray-800 laravel-livewire-tables-reorderingMinimised' => $this->isTailwind, + 'sm:hidden' => $this->isTailwind && !$this->shouldCollapseOnTablet && !$this->shouldCollapseAlways, + 'md:hidden' => $this->isTailwind && !$this->shouldCollapseOnMobile && !$this->shouldCollapseOnTablet && !$this->shouldCollapseAlways, + 'lg:hidden' => $this->isTailwind && !$this->shouldCollapseAlways, + 'd-table-cell laravel-livewire-tables-reorderingMinimised' => $this->isBootstrap, + 'd-sm-none' => $this->isBootstrap && !$this->shouldCollapseOnTablet && !$this->shouldCollapseAlways, + 'd-md-none' => $this->isBootstrap && !$this->shouldCollapseOnMobile && !$this->shouldCollapseOnTablet && !$this->shouldCollapseAlways, + 'd-lg-none' => $this->isBootstrap && !$this->shouldCollapseAlways, + ]) + }}></th> @endif diff --git a/resources/views/components/table/th/label.blade.php b/resources/views/components/table/th/label.blade.php new file mode 100644 index 000000000..bafe25fdb --- /dev/null +++ b/resources/views/components/table/th/label.blade.php @@ -0,0 +1,4 @@ +@props(['columnTitle' => '', 'customLabelAttributes' => ['default' => true]]) +<span {{ $customLabelAttributes->except(['default', 'default-colors', 'default-styling']) }}> + {{ $columnTitle }} +</span> diff --git a/resources/views/components/table/th/plain.blade.php b/resources/views/components/table/th/plain.blade.php index 0b9c8326e..b15d56d0f 100644 --- a/resources/views/components/table/th/plain.blade.php +++ b/resources/views/components/table/th/plain.blade.php @@ -1,14 +1,11 @@ -@aware(['isTailwind','isBootstrap']) @props(['displayMinimisedOnReorder' => false, 'hideUntilReorder' => false, 'customAttributes' => ['default' => true]]) -<th x-cloak {{ $attributes }} scope="col" - {{ +<th x-cloak scope="col" @if($hideUntilReorder) :class="!reorderDisplayColumn && 'w-0 p-0 hidden'" @endif {{ $attributes->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 -> + 'table-cell px-3 py-2 md:px-6 md:py-3 text-center md:text-left laravel-livewire-tables-reorderingMinimised' => $this->isTailwind && (($customAttributes['default-styling'] ?? true) || ($customAttributes['default'] ?? true)), + 'bg-gray-50 dark:bg-gray-800' => $this->isTailwind && (($customAttributes['default-colors'] ?? true) || ($customAttributes['default'] ?? true)), + 'laravel-livewire-tables-reorderingMinimised' => $this->isBootstrap && (($customAttributes['default-colors'] ?? true) || ($customAttributes['default'] ?? true)), + ])->except(['default','default-styling','default-colors']) +}}> {{ $slot }} </th> diff --git a/resources/views/components/table/th/reorder.blade.php b/resources/views/components/table/th/reorder.blade.php index e4fe7cecb..a3b1f7e86 100644 --- a/resources/views/components/table/th/reorder.blade.php +++ b/resources/views/components/table/th/reorder.blade.php @@ -1,14 +1,16 @@ -@aware(['tableName','isTailwind','isBootstrap']) @php $customThAttributes = $this->hasReorderThAttributes() ? $this->getReorderThAttributes() : $this->getAllThAttributes($this->getReorderColumn())['customAttributes']; @endphp -<x-livewire-tables::table.th.plain x-cloak x-show="currentlyReorderingStatus" wire:key="{{ $tableName }}-thead-reorder" :displayMinimisedOnReorder="false" +<x-livewire-tables::table.th.plain x-cloak x-show="currentlyReorderingStatus" wire:key="{{ $this->getTableName }}-thead-reorder" :displayMinimisedOnReorder="false" {{ $attributes->merge($customThAttributes) - ->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)]) + ->class([ + 'table-cell px-6 py-3 text-left text-xs font-medium whitespace-nowrap uppercase tracking-wider' => $this->isTailwind && (($customThAttributes['default-styling'] ?? true) || ($customThAttributes['default'] ?? true)), + 'text-gray-500 dark:bg-gray-800 dark:text-gray-400' => $this->isTailwind && (($customThAttributes['default-colors'] ?? true) || ($customThAttributes['default'] ?? true)), + 'laravel-livewire-tables-reorderingMinimised' => $this->isBootstrap && ($customThAttributes['default'] ?? true), + ]) + ->except(['default','default-styling','default-colors']) }} > <div x-cloak x-show="currentlyReorderingStatus"></div> diff --git a/resources/views/components/table/th/sort-icons.blade.php b/resources/views/components/table/th/sort-icons.blade.php index b26b7d964..f08cd3473 100644 --- a/resources/views/components/table/th/sort-icons.blade.php +++ b/resources/views/components/table/th/sort-icons.blade.php @@ -1,32 +1,79 @@ -@props(['direction']) -<span {{ $attributes->class([ +@props(['direction' => 'none', 'customIconAttributes']) +<span @class([ 'relative flex items-center' => $this->isTailwind, 'relative d-flex align-items-center' => $this->isBootstrap - ]) }} + ]) > + @if($this->isTailwind) @switch($direction) @case('asc') - <x-heroicon-o-chevron-up class="w-3 h-3 group-hover:opacity-0" /> - <x-heroicon-o-chevron-down class="w-3 h-3 opacity-0 group-hover:opacity-100 absolute"/> - @break + <x-heroicon-o-chevron-up {{ $attributes->merge($customIconAttributes) + ->class([ + 'w-3 h-3' => $customIconAttributes['default-styling'] ?? ($customIconAttributes['default'] ?? true), + 'absolute opacity-100 group-hover:opacity-0', + ]) + ->except(['default', 'default-colors', 'default-styling', 'wire:key']) }} /> + <x-heroicon-o-chevron-down {{ $attributes->merge($customIconAttributes) + ->class([ + 'w-3 h-3' => $customIconAttributes['default-styling'] ?? ($customIconAttributes['default'] ?? true), + 'absolute opacity-0 group-hover:opacity-100', + ]) + ->except(['default', 'default-colors', 'default-styling', 'wire:key']) }} /> + @break @case('desc') - <x-heroicon-o-chevron-down class="w-3 h-3 group-hover:opacity-0" /> - <x-heroicon-o-x-circle class="w-3 h-3 opacity-0 group-hover:opacity-100 absolute"/> - @break + <x-heroicon-o-chevron-down {{ $attributes->merge($customIconAttributes) + ->class([ + 'w-3 h-3' => $customIconAttributes['default-styling'] ?? ($customIconAttributes['default'] ?? true), + 'absolute opacity-100 group-hover:opacity-0', + ]) + ->except(['default', 'default-colors', 'default-styling', 'wire:key']) }} /> + <x-heroicon-o-x-circle {{ $attributes->merge($customIconAttributes) + ->class([ + 'w-3 h-3' => $customIconAttributes['default-styling'] ?? ($customIconAttributes['default'] ?? true), + 'absolute opacity-0 group-hover:opacity-100', + ]) + ->except(['default', 'default-colors', 'default-styling', 'wire:key']) }} /> + + @break @default - <x-heroicon-o-chevron-up class="w-3 h-3 opacity-0 group-hover:opacity-100 transition-opacity duration-300" /> - @endswitch + <x-heroicon-o-chevron-up-down {{ $attributes->merge($customIconAttributes) + ->class([ + 'w-3 h-3' => $customIconAttributes['default-styling'] ?? ($customIconAttributes['default'] ?? true), + 'absolute opacity-100 group-hover:opacity-0', + ]) + ->except(['default', 'default-colors', 'default-styling', 'wire:key']) }} /> + <x-heroicon-o-chevron-up {{ $attributes->merge($customIconAttributes) + ->class([ + 'w-3 h-3' => $customIconAttributes['default-styling'] ?? ($customIconAttributes['default'] ?? true), + 'absolute opacity-0 group-hover:opacity-100', + ]) + ->except(['default', 'default-colors', 'default-styling', 'wire:key']) }} /> + @endswitch + + @else @switch($direction) @case('asc') - <x-heroicon-o-chevron-up class="laravel-livewire-tables-btn-smaller ms-1 " /> + <x-heroicon-o-chevron-up {{ $attributes->merge($customIconAttributes) + ->class([ + 'laravel-livewire-tables-btn-smaller ms-1' => $customIconAttributes['default-styling'] ?? ($customIconAttributes['default'] ?? true), + ]) + ->except(['default', 'default-colors', 'default-styling', 'wire:key']) }} /> @break @case('desc') - <x-heroicon-o-chevron-down class="laravel-livewire-tables-btn-smaller ms-1" /> + <x-heroicon-o-chevron-down {{ $attributes->merge($customIconAttributes) + ->class([ + 'laravel-livewire-tables-btn-smaller ms-1' => $customIconAttributes['default-styling'] ?? ($customIconAttributes['default'] ?? true), + ]) + ->except(['default', 'default-colors', 'default-styling', 'wire:key']) }} /> @break @default - <x-heroicon-o-chevron-up-down class="laravel-livewire-tables-btn-smaller ms-1" /> + <x-heroicon-o-chevron-up-down {{ $attributes->merge($customIconAttributes) + ->class([ + 'laravel-livewire-tables-btn-smaller ms-1' => $customIconAttributes['default-styling'] ?? ($customIconAttributes['default'] ?? true), + ]) + ->except(['default', 'default-colors', 'default-styling', 'wire:key']) }} /> @endswitch @endif </span> diff --git a/resources/views/datatable.blade.php b/resources/views/datatable.blade.php index 7b90b7734..4b4feab5a 100644 --- a/resources/views/datatable.blade.php +++ b/resources/views/datatable.blade.php @@ -68,7 +68,7 @@ @endif @foreach($this->selectedVisibleColumns as $index => $column) - <x-livewire-tables::table.th wire:key="{{ $tableName.'-table-head-'.$index }}" :column="$column" :index="$index" /> + <x-livewire-tables::table.th wire:key="{{ $tableName.'-table-head-'.$index }}" :$column :$index /> @endforeach </x-slot> @@ -84,19 +84,19 @@ @endif @forelse ($this->getRows as $rowIndex => $row) - <x-livewire-tables::table.tr wire:key="{{ $tableName }}-row-wrap-{{ $row->{$primaryKey} }}" :row="$row" :rowIndex="$rowIndex"> + <x-livewire-tables::table.tr wire:key="{{ $tableName }}-row-wrap-{{ $row->{$primaryKey} }}" :$row :$rowIndex> @if($this->getCurrentlyReorderingStatus) - <x-livewire-tables::table.td.reorder x-cloak x-show="currentlyReorderingStatus" wire:key="{{ $tableName }}-row-reorder-{{ $row->{$primaryKey} }}" :rowID="$tableName.'-'.$row->{$this->getPrimaryKey()}" :rowIndex="$rowIndex" /> + <x-livewire-tables::table.td.reorder x-cloak x-show="currentlyReorderingStatus" wire:key="{{ $tableName }}-row-reorder-{{ $row->{$primaryKey} }}" :rowID="$tableName.'-'.$row->{$this->getPrimaryKey()}" :$rowIndex /> @endif @if($this->showBulkActionsSections) - <x-livewire-tables::table.td.bulk-actions wire:key="{{ $tableName }}-row-bulk-act-{{ $row->{$primaryKey} }}" :row="$row" :rowIndex="$rowIndex"/> + <x-livewire-tables::table.td.bulk-actions wire:key="{{ $tableName }}-row-bulk-act-{{ $row->{$primaryKey} }}" :$row :$rowIndex /> @endif @if ($this->showCollapsingColumnSections) - <x-livewire-tables::table.td.collapsed-columns wire:key="{{ $tableName }}-row-collapsed-{{ $row->{$primaryKey} }}" :rowIndex="$rowIndex" /> + <x-livewire-tables::table.td.collapsed-columns wire:key="{{ $tableName }}-row-collapsed-{{ $row->{$primaryKey} }}" :$rowIndex /> @endif @foreach($this->selectedVisibleColumns as $colIndex => $column) - <x-livewire-tables::table.td wire:key="{{ $tableName . '-' . $row->{$primaryKey} . '-datatable-td-' . $column->getSlug() }}" :column="$column" :colIndex="$colIndex"> + <x-livewire-tables::table.td wire:key="{{ $tableName . '-' . $row->{$primaryKey} . '-datatable-td-' . $column->getSlug() }}" :$column :$colIndex> @if($column->isHtml()) {!! $column->setIndexes($rowIndex, $colIndex)->renderContents($row) !!} @else @@ -107,7 +107,7 @@ </x-livewire-tables::table.tr> @if ($this->showCollapsingColumnSections) - <x-livewire-tables::table.collapsed-columns :row="$row" :rowIndex="$rowIndex" /> + <x-livewire-tables::table.collapsed-columns :$row :$rowIndex /> @endif @empty <x-livewire-tables::table.empty /> diff --git a/src/Commands/MakeCommand.php b/src/Commands/MakeCommand.php index bf06570ae..cc974885f 100644 --- a/src/Commands/MakeCommand.php +++ b/src/Commands/MakeCommand.php @@ -126,7 +126,7 @@ public function getModelImport(): string if (isset($this->modelPath)) { $filename = rtrim($this->modelPath, '/').'/'.$this->model.'.php'; if (File::exists($filename)) { - //In case the file has more than one class which is highly unlikely but still possible + // In case the file has more than one class which is highly unlikely but still possible $classes = array_filter($this->getClassesList($filename), function ($class) { return substr($class, strrpos($class, '\\') + 1) == $this->model; }); diff --git a/src/Traits/Helpers/CollapsingColumnHelpers.php b/src/Traits/Helpers/CollapsingColumnHelpers.php index 131e43b65..e80e9da64 100644 --- a/src/Traits/Helpers/CollapsingColumnHelpers.php +++ b/src/Traits/Helpers/CollapsingColumnHelpers.php @@ -11,11 +11,13 @@ public function getCollapsingColumnsStatus(): bool return $this->collapsingColumnsStatus; } + #[Computed] public function hasCollapsingColumns(): bool { return $this->getCollapsingColumnsStatus() === true; } + #[Computed] public function collapsingColumnsAreEnabled(): bool { return $this->getCollapsingColumnsStatus() === true; diff --git a/src/Traits/Helpers/ColumnHelpers.php b/src/Traits/Helpers/ColumnHelpers.php index 487bcb879..830756a0c 100644 --- a/src/Traits/Helpers/ColumnHelpers.php +++ b/src/Traits/Helpers/ColumnHelpers.php @@ -3,6 +3,7 @@ namespace Rappasoft\LaravelLivewireTables\Traits\Helpers; use Illuminate\Support\Collection; +use Livewire\Attributes\Computed; use Rappasoft\LaravelLivewireTables\Views\Column; use Rappasoft\LaravelLivewireTables\Views\Columns\AggregateColumn; @@ -133,6 +134,7 @@ public function hasCollapsedColumns(): bool return false; } + #[Computed] public function shouldCollapseOnMobile(): bool { @@ -170,6 +172,7 @@ public function getVisibleMobileColumnsCount(): int return $this->getVisibleMobileColumns()->count(); } + #[Computed] public function shouldCollapseOnTablet(): bool { if (! isset($this->shouldTabletCollapse)) { @@ -235,6 +238,7 @@ public function getCollapsedAlwaysColumnsCount(): int return $this->getCollapsedAlwaysColumns()->count(); } + #[Computed] public function shouldCollapseAlways(): bool { if (! isset($this->shouldAlwaysCollapse)) { diff --git a/src/Traits/Helpers/TableAttributeHelpers.php b/src/Traits/Helpers/TableAttributeHelpers.php index 5c8125fa9..36971ab3e 100644 --- a/src/Traits/Helpers/TableAttributeHelpers.php +++ b/src/Traits/Helpers/TableAttributeHelpers.php @@ -47,7 +47,7 @@ public function getThAttributes(Column $column): array { if (isset($this->thAttributesCallback)) { - return array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], call_user_func($this->thAttributesCallback, $column)); + return array_merge(['scope' => 'col', 'default' => false, 'default-colors' => false, 'default-styling' => false], call_user_func($this->thAttributesCallback, $column)); } return ['default' => true, 'default-colors' => true, 'default-styling' => true]; diff --git a/src/Traits/WithData.php b/src/Traits/WithData.php index b2d191031..e7b52518a 100644 --- a/src/Traits/WithData.php +++ b/src/Traits/WithData.php @@ -21,7 +21,7 @@ trait WithData */ public function bootedWithData(): void { - //Sets up the Builder Instance + // Sets up the Builder Instance $this->setBuilder($this->builder()); } diff --git a/src/Traits/WithReordering.php b/src/Traits/WithReordering.php index 49d36f78f..ae5be34cb 100644 --- a/src/Traits/WithReordering.php +++ b/src/Traits/WithReordering.php @@ -51,13 +51,10 @@ public function enablePaginatedReordering(): void {} public function enableReordering(): void { - //$this->enablePaginatedReordering(); - $this->setReorderingSession(); $this->setReorderingBackup(); $this->resetReorderFields(); $this->reorderStatus = $this->currentlyReorderingStatus = $this->reorderDisplayColumn = true; - } public function disableReordering(): void diff --git a/src/Views/Traits/Filters/HasCustomPosition.php b/src/Views/Traits/Filters/HasCustomPosition.php index 443baf749..4bdb670ee 100644 --- a/src/Views/Traits/Filters/HasCustomPosition.php +++ b/src/Views/Traits/Filters/HasCustomPosition.php @@ -67,7 +67,6 @@ public function hasFilterSlidedownColspan(): bool public function setFilterSlidedownRow(string $filterSlidedownRow): self { - //$this->filterSlidedownRow = (is_int($filterSlidedownRow) ? $filterSlidedownRow : intval($filterSlidedownRow)); $this->filterSlidedownRow = intval($filterSlidedownRow); return $this; @@ -75,7 +74,6 @@ public function setFilterSlidedownRow(string $filterSlidedownRow): self public function setFilterSlidedownColspan(string $filterSlidedownColspan): self { - //$this->filterSlidedownColspan = (is_int($filterSlidedownColspan) ? $filterSlidedownColspan : intval($filterSlidedownColspan)); $this->filterSlidedownColspan = intval($filterSlidedownColspan); return $this; diff --git a/tests/DataTableComponentTest.php b/tests/DataTableComponentTest.php index 8237e8411..e0849463c 100644 --- a/tests/DataTableComponentTest.php +++ b/tests/DataTableComponentTest.php @@ -2,7 +2,6 @@ namespace Rappasoft\LaravelLivewireTables\Tests; -use Livewire\Livewire; use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\FailingTables\NoColumnsTable; use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\FailingTables\NoPrimaryKeyTable; use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable; @@ -27,13 +26,6 @@ public function test_primary_key_can_be_checked_for_existence(): void $this->assertFalse($this->basicTable->hasPrimaryKey()); } - public function test_primary_key_has_to_be_set(): void - { - $this->expectException(\Illuminate\View\ViewException::class); - Livewire::test(NoPrimaryKeyTable::class) - ->call('setSearch', 'abcd'); - } - public function test_default_fingerprint_will_always_be_the_same_for_same_datatable(): void { $this->assertSame( diff --git a/tests/Localisations/BaseLocalisationCase.php b/tests/Localisations/BaseLocalisationCase.php index 595c019e7..e3ae15093 100644 --- a/tests/Localisations/BaseLocalisationCase.php +++ b/tests/Localisations/BaseLocalisationCase.php @@ -57,10 +57,10 @@ public static function localisationProvider(): array 'tw', 'uk', ]; - //return $availableLocales; + // return $availableLocales; foreach ($availableLocales as $availableLocale) { - //$array = require($baseDir.$availableLocale.'/core.php'); + // $array = require($baseDir.$availableLocale.'/core.php'); $localisations[] = [ 'locale' => $availableLocale, // 'localisationStrings' => $array, diff --git a/tests/Unit/Traits/Configuration/ComponentConfigurationTest.php b/tests/Unit/Traits/Configuration/ComponentConfigurationTest.php index a477cf06c..bd593eeab 100644 --- a/tests/Unit/Traits/Configuration/ComponentConfigurationTest.php +++ b/tests/Unit/Traits/Configuration/ComponentConfigurationTest.php @@ -73,8 +73,8 @@ public function test_can_set_th_attributes(): void return ['default' => true, 'here' => 'there']; }); - $this->assertSame($this->basicTable->getThAttributes($this->basicTable->columns()[0]), ['default' => false, 'default-colors' => false, 'default-styling' => false, 'this' => 'that']); - $this->assertSame($this->basicTable->getThAttributes($this->basicTable->columns()[1]), ['default' => true, 'default-colors' => false, 'default-styling' => false, 'here' => 'there']); + $this->assertSame($this->basicTable->getThAttributes($this->basicTable->columns()[0]), ['scope' => 'col', 'default' => false, 'default-colors' => false, 'default-styling' => false, 'this' => 'that']); + $this->assertSame($this->basicTable->getThAttributes($this->basicTable->columns()[1]), ['scope' => 'col', 'default' => true, 'default-colors' => false, 'default-styling' => false, 'here' => 'there']); } public function test_can_set_th_sort_button_attributes(): void diff --git a/tests/Unit/Traits/Helpers/ColumnHelpersTest.php b/tests/Unit/Traits/Helpers/ColumnHelpersTest.php index cfebce832..ec4f3814b 100644 --- a/tests/Unit/Traits/Helpers/ColumnHelpersTest.php +++ b/tests/Unit/Traits/Helpers/ColumnHelpersTest.php @@ -205,7 +205,7 @@ public function test_can_get_visible_tablet_columns_count(): void $this->assertSame(7, $this->basicTable->getVisibleTabletColumnsCount()); } - /// *** ** // + // / *** ** // public function test_can_tell_if_columns_should_collapse_always(): void { @@ -299,7 +299,7 @@ public function test_can_check_if_column_has_secondary_header_filter(): void $this->assertTrue($column->hasSecondaryHeaderCallback()); $contents = $column->getSecondaryHeaderFilter($this->basicTable->getFilterByKey($column->getSecondaryHeaderCallback()), $this->basicTable->getFilterGenericData()); - //$contents = $column->getSecondaryHeaderFilter($this->basicTable->getFilterByKey('breed')); + // $contents = $column->getSecondaryHeaderFilter($this->basicTable->getFilterByKey('breed')); $this->assertStringContainsString('id="table-filter-breed-8-header"', $contents); } diff --git a/tests/Unit/Traits/Helpers/ComponentHelpersTest.php b/tests/Unit/Traits/Helpers/ComponentHelpersTest.php index 6fbbf6364..d9deb58f4 100644 --- a/tests/Unit/Traits/Helpers/ComponentHelpersTest.php +++ b/tests/Unit/Traits/Helpers/ComponentHelpersTest.php @@ -244,7 +244,7 @@ public function test_can_get_hide_configurable_areas_when_reordering_status(): v // Exists in DataTableComponentTest // public function test_can_get_dataTable_fingerprint(): void - //{ + // { // $this->assertSame($this->defaultFingerPrintingAlgo($this->basicTable::class), $this->basicTable->getDataTableFingerprint()); // } diff --git a/tests/Unit/Traits/WithCustomisationsTest.php b/tests/Unit/Traits/WithCustomisationsTest.php index 64ccf4d36..e5101454f 100644 --- a/tests/Unit/Traits/WithCustomisationsTest.php +++ b/tests/Unit/Traits/WithCustomisationsTest.php @@ -2,43 +2,12 @@ namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits; -use Livewire\Component; use Livewire\Features\SupportPageComponents\PageComponentConfig; -use Livewire\Livewire; use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable; use Rappasoft\LaravelLivewireTables\Tests\TestCase; final class WithCustomisationsTest extends TestCase { - public function test_can_use_as_nested(): void - { - $test = Livewire::test([new class extends Component - { - public function render() - { - return <<<'HTML' - <div> - <div>ParentComponentTest</div> - <div> <livewire:child /></div> - </div> - HTML; - } - }, - 'child' => new class extends PetsTable - { - public function configure(): void - { - parent::configure(); - $this->setLayout('livewire-tables::tests.layout1'); - - } - }, - ]) - ->assertSee('ParentComponentTest') - ->assertSee('Cartman'); - - } - public function test_can_use_as_full_page(): void { $temp = new class extends PetsTable diff --git a/tests/Unit/Views/Columns/DateColumnTest.php b/tests/Unit/Views/Columns/DateColumnTest.php index 1b3e96a94..876bb9bda 100644 --- a/tests/Unit/Views/Columns/DateColumnTest.php +++ b/tests/Unit/Views/Columns/DateColumnTest.php @@ -2,7 +2,7 @@ namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Views\Columns; -//use Illuminate\Support\Facades\Exceptions; +// use Illuminate\Support\Facades\Exceptions; use Rappasoft\LaravelLivewireTables\Tests\Models\Pet; use Rappasoft\LaravelLivewireTables\Tests\TestCase; use Rappasoft\LaravelLivewireTables\Views\Columns\DateColumn; diff --git a/tests/Unit/Views/Columns/IconColumnTest.php b/tests/Unit/Views/Columns/IconColumnTest.php index 3696bbc67..a6a609939 100644 --- a/tests/Unit/Views/Columns/IconColumnTest.php +++ b/tests/Unit/Views/Columns/IconColumnTest.php @@ -2,7 +2,7 @@ namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Views\Columns; -//use Illuminate\Support\Facades\Exceptions; +// use Illuminate\Support\Facades\Exceptions; use Rappasoft\LaravelLivewireTables\Tests\Models\Pet; use Rappasoft\LaravelLivewireTables\Tests\TestCase; use Rappasoft\LaravelLivewireTables\Views\Columns\IconColumn; diff --git a/tests/Unit/Visuals/BulkActionsVisualsTest.php b/tests/Unit/Visuals/BulkActionsVisualsTest.php index 32f0a57cc..59570f3cd 100644 --- a/tests/Unit/Visuals/BulkActionsVisualsTest.php +++ b/tests/Unit/Visuals/BulkActionsVisualsTest.php @@ -192,7 +192,7 @@ public function exportBulk($items) })->assertDontSee('Bulk Actions'); } - public function test_bulk_dropdown_can_have_customised_classes(): void + public function test_bulk_dropdown_can_have_customised_classes_with_no_defaults(): void { Livewire::test(new class extends PetsTable { @@ -202,7 +202,7 @@ public function configure(): void $this->setBulkActionsThAttributes([ 'class' => 'bg-yellow-500 dark:bg-yellow-800', 'default' => false, - 'default-styling' => true, + 'default-styling' => false, 'default-colors' => false, ]); @@ -224,4 +224,103 @@ public function exportBulk($items) 'wire:key="table-thead-bulk-actions"', ]); } + + public function test_bulk_dropdown_can_have_customised_classes_with_default_styling(): void + { + Livewire::test(new class extends PetsTable + { + public function configure(): void + { + $this->setPrimaryKey('id'); + $this->setBulkActionsThAttributes([ + 'class' => 'bg-yellow-500 dark:bg-yellow-800', + 'default' => false, + 'default-styling' => true, + 'default-colors' => false, + ]); + + } + + public function bulkActions(): array + { + return ['exportBulk' => 'exportBulk']; + } + + public function exportBulk($items) + { + return $items; + } + })->assertSee('Bulk Actions') + ->assertSeeHtmlInOrder([ + 'scope="col"', + 'class="table-cell px-3 py-2 md:px-6 md:py-3 text-center md:text-left laravel-livewire-tables-reorderingMinimised bg-yellow-500 dark:bg-yellow-800"', + 'wire:key="table-thead-bulk-actions"', + ]); + } + + public function test_bulk_dropdown_can_have_customised_classes_with_default_colors(): void + { + Livewire::test(new class extends PetsTable + { + public function configure(): void + { + $this->setPrimaryKey('id'); + $this->setBulkActionsThAttributes([ + 'class' => 'text-lg', + 'default' => false, + 'default-styling' => false, + 'default-colors' => true, + ]); + + } + + public function bulkActions(): array + { + return ['exportBulk' => 'exportBulk']; + } + + public function exportBulk($items) + { + return $items; + } + })->assertSee('Bulk Actions') + ->assertSeeHtmlInOrder([ + 'scope="col"', + 'class="bg-gray-50 dark:bg-gray-800 text-lg"', + 'wire:key="table-thead-bulk-actions"', + ]); + } + + public function test_bulk_dropdown_can_have_customised_classes_with_defaults(): void + { + Livewire::test(new class extends PetsTable + { + public function configure(): void + { + $this->setPrimaryKey('id'); + $this->setBulkActionsThAttributes([ + 'class' => 'text-lg', + 'default' => true, + 'default-styling' => true, + 'default-colors' => true, + ]); + + } + + public function bulkActions(): array + { + return ['exportBulk' => 'exportBulk']; + } + + public function exportBulk($items) + { + return $items; + } + })->assertSee('Bulk Actions') + ->assertSeeHtmlInOrder([ + 'scope="col"', + 'class="table-cell px-3 py-2 md:px-6 md:py-3 text-center md:text-left laravel-livewire-tables-reorderingMinimised bg-gray-50 dark:bg-gray-800 text-lg"', + 'wire:key="table-thead-bulk-actions"', + ]); + } } diff --git a/tests/Unit/Visuals/CustomisationsVisualsTest.php b/tests/Unit/Visuals/CustomisationsVisualsTest.php new file mode 100644 index 000000000..55a6da4e1 --- /dev/null +++ b/tests/Unit/Visuals/CustomisationsVisualsTest.php @@ -0,0 +1,46 @@ +<?php + +namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Visuals; + +use Exception; +use Illuminate\View\ViewException; +use Livewire\Component; +use Livewire\Livewire; +use PHPUnit\Framework\Attributes\Group; +use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException; +use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\FailingTables\{BrokenSecondaryHeaderTable, NoBuildMethodTable, NoPrimaryKeyTable}; +use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\{PetsTable,PetsTableAttributes}; +use Rappasoft\LaravelLivewireTables\Tests\TestCase; + +#[Group('Visuals')] +final class CustomisationsVisualsTest extends TestCase +{ + public function test_can_use_as_nested(): void + { + $test = Livewire::test([new class extends Component + { + public function render() + { + return <<<'HTML' + <div> + <div>ParentComponentTest</div> + <div> <livewire:child /></div> + </div> + HTML; + } + }, + 'child' => new class extends PetsTable + { + public function configure(): void + { + parent::configure(); + $this->setLayout('livewire-tables::tests.layout1'); + + } + }, + ]) + ->assertSee('ParentComponentTest') + ->assertSee('Cartman'); + + } +} diff --git a/tests/Unit/Visuals/DataTableComponentVisualsTest.php b/tests/Unit/Visuals/DataTableComponentVisualsTest.php new file mode 100644 index 000000000..29fd9f01e --- /dev/null +++ b/tests/Unit/Visuals/DataTableComponentVisualsTest.php @@ -0,0 +1,24 @@ +<?php + +namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Visuals; + +use Exception; +use Illuminate\View\ViewException; +use Livewire\Component; +use Livewire\Livewire; +use PHPUnit\Framework\Attributes\Group; +use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException; +use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\FailingTables\{BrokenSecondaryHeaderTable, NoBuildMethodTable, NoPrimaryKeyTable}; +use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\{PetsTable,PetsTableAttributes}; +use Rappasoft\LaravelLivewireTables\Tests\TestCase; + +#[Group('Visuals')] +final class DataTableComponentVisualsTest extends TestCase +{ + public function test_primary_key_has_to_be_set(): void + { + $this->expectException(\Illuminate\View\ViewException::class); + Livewire::test(NoPrimaryKeyTable::class) + ->call('setSearch', 'abcd'); + } +} diff --git a/tests/Unit/Visuals/SortingVisualsTest.php b/tests/Unit/Visuals/SortingVisualsTest.php index 6a6333445..6a9df4714 100644 --- a/tests/Unit/Visuals/SortingVisualsTest.php +++ b/tests/Unit/Visuals/SortingVisualsTest.php @@ -37,7 +37,7 @@ public function test_th_headers_are_buttons_with_sorting_enabled(): void Livewire::test(PetsTable::class) ->assertSeeHtmlInOrder([ 'wire:click="sortBy(\'id\')"', - 'class="flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none text-gray-500 dark:text-gray-400"', + 'class="text-gray-500 dark:text-gray-400 flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none"', ]); } @@ -58,12 +58,12 @@ public function test_th_headers_are_not_buttons_until_sorting_enabled(): void ->call('setSortingDisabled') ->assertDontSeeHtml('<button wire:click="sortBy(\'id\')" - class="flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none text-gray-500 dark:text-gray-400" + class="text-gray-500 dark:text-gray-400 flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none" >') ->call('setSortingEnabled') ->assertSeeHtmlInOrder([ 'wire:click="sortBy(\'id\')"', - 'class="flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none text-gray-500 dark:text-gray-400"', + 'class="text-gray-500 dark:text-gray-400 flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none"', ]); }