diff --git a/.github/workflows/run-phpstan.yml b/.github/workflows/run-phpstan.yml index c8163e5ac..c286d1e80 100644 --- a/.github/workflows/run-phpstan.yml +++ b/.github/workflows/run-phpstan.yml @@ -20,7 +20,7 @@ jobs: matrix: os: [ubuntu-latest] php: [8.3] - laravel: [10] + laravel: [11] stability: [prefer-dist] name: PHPStan - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/.github/workflows/run-tests-pcov-pull.yml b/.github/workflows/run-tests-pcov-pull.yml index 00cd4b1e5..840cd8ee9 100644 --- a/.github/workflows/run-tests-pcov-pull.yml +++ b/.github/workflows/run-tests-pcov-pull.yml @@ -88,7 +88,7 @@ jobs: run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run Unit Tests - run: php ./vendor/bin/paratest --cache-directory=".phpunit.cache/code-coverage" --strict-coverage --coverage-clover ./coverage.xml --processes=4 + run: php ./vendor/bin/paratest --cache-directory=".phpunit.cache/code-coverage" --strict-coverage --coverage-clover ./coverage.xml - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4 diff --git a/.github/workflows/run-tests-pull.yml b/.github/workflows/run-tests-pull.yml index a0193d19e..583d5d20f 100644 --- a/.github/workflows/run-tests-pull.yml +++ b/.github/workflows/run-tests-pull.yml @@ -163,4 +163,4 @@ jobs: run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run Unit Tests - run: php ./vendor/bin/paratest --no-coverage --processes=4 + run: php ./vendor/bin/paratest --no-coverage diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index f24fec995..bcb0d7031 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -85,7 +85,7 @@ jobs: run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run Unit Tests - run: php ./vendor/bin/paratest --no-coverage --processes=4 + run: php ./vendor/bin/phpunit --no-coverage test-laravel11: @@ -164,4 +164,4 @@ jobs: run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run Unit Tests - run: php ./vendor/bin/paratest --no-coverage --processes=4 + run: php ./vendor/bin/paratest --no-coverage diff --git a/docs/columns/available-methods.md b/docs/columns/available-methods.md index 5c6eaa9b6..18f840b5d 100644 --- a/docs/columns/available-methods.md +++ b/docs/columns/available-methods.md @@ -302,3 +302,7 @@ Labels are visible by default, but should you wish to override a previous "hideC Column::make('Name') ->setColumnLabelStatusEnabled() ``` + +## See Also +[Column Styling](./styling) + diff --git a/docs/columns/styling.md b/docs/columns/styling.md new file mode 100644 index 000000000..f7db2a4bd --- /dev/null +++ b/docs/columns/styling.md @@ -0,0 +1,292 @@ +--- +title: Styling +weight: 10 +--- + +## Keeping Defaults +To allow simpler customisation on a per-table basis, there are numerous methods available to over-ride the default CSS classes. +Historically, this was provided by a simple toggleable "default" flag. However - in many cases, the original "default" has been expanded to include: + +### Keep Default Colors And Default Styles +- set default flag to true +or +- set default-colors flag to true +- set default-styling flag to true + +### Keep Default Colors Only +- set default flag to false +- set default-colors flag to true +- set default-styling flag to false + +### Keep Default Styling Only +- set default flag to false +- set default-colors flag to false +- set default-styling flag to true + +## Styling The Column Label + +The Column itself provides the capability to style the Label shown in the "th" element. You can set custom attributes to pass to the Column Label on a per-Column basis: + +For example: +```php +Column::make('Name') + ->setLabelAttributes(['class' => 'text-2xl']) +``` +By default, this replaces the default classes on the label, if you would like to keep them, set the default/default-styling/default-colors flags to true as appropriate. + +## Styling Table Elements + +It is important to note that you can also customise the parent TH and TD elements, customising both classes and attributes for each Column's header (using setThAttributes) and each row of that Column (using setTdAttributes), these are available in the configure() method of the table. +This allows you to customise attributes based on the value of the table as well! + +Below is a copy of the relevant sections from [datatable styling](../datatable/styling) to ensure visibility of the options. More are documented on the main datatable styling page. + +## setThAttributes + +Set a list of attributes to override on the th elements. + +```php +public function configure(): void +{ + // Takes a callback that gives you the current column. + $this->setThAttributes(function(Column $column) { + if ($column->isField('name')) { + return [ + 'class' => 'bg-green-500', + ]; + } + + return []; + }); +} +``` + +### Keeping Default Colors and Default Styling +```php +public function configure(): void +{ + $this->setThAttributes(function(Column $column) { + if ($column->isField('name')) { + return [ + 'default' => true, + 'class' => 'bg-green-500', + ]; + } + + return ['default' => true]; + }); +} +``` + +### Keeping Default Styling Only For the "Name" Column +```php +public function configure(): void +{ + $this->setThAttributes(function(Column $column) { + if ($column->isField('name')) { + return [ + 'default' => false, + 'default-styling' => true, + 'class' => 'text-black bg-green-500 dark:text-white dark:bg-green-900', + ]; + } + + return ['default' => true]; + }); +} +``` + +### Reorder Column +Note: If you are using Reorder, then the th for Reorder can be [styled separately](../reordering/available-methods). However this is now replaced with the following to ensure consistent behaviour. The separate method will be supported until at least v3.6 + +You can also use the "title" of the Column, which will be "reorder" for the "reorder" Column: +```php +public function configure(): void +{ + $this->setThAttributes(function(Column $column) { + if ($column->getTitle() == 'reorder') + { + return [ + 'class' => 'bg-green-500 dark:bg-green-800', + 'default' => false, + 'default-colors' => false, + ]; + + } + + return ['default' => true]; + }); +} +``` + +### Bulk Actions Column +Note: If you are using Bulk Actions, then the th for Bulk Actions can be [styled separately](../bulk-actions/customisations). However this is now replaced with the following to ensure consistent behaviour. The separate method will be supported until at least v3.6 + +You can also use the "title" of the Column, which will be "bulkactions" for the "Bulk Actions" Column: +```php +public function configure(): void +{ + $this->setThAttributes(function(Column $column) { + if ($column->getTitle() == 'bulkactions') + { + return [ + 'class' => 'bg-yellow-500 dark:bg-yellow-800', + 'default' => false, + 'default-colors' => false, + ]; + + } + + return ['default' => true]; + }); +} +``` + +## setThSortButtonAttributes + +Set a list of attributes to override on the th sort button elements + +```php +public function configure(): void +{ + // Takes a callback that gives you the current column. + $this->setThSortButtonAttributes(function(Column $column) { + if ($column->isField('name')) { + return [ + 'class' => 'bg-green-500', + ]; + } + + return []; + }); +} +``` + +## setTrAttributes + +Set a list of attributes to override on the tr elements + +```php +public function configure(): void +{ + // Takes a callback that gives you the current row and its index + $this->setTrAttributes(function($row, $index) { + if ($index % 2 === 0) { + return [ + 'class' => 'bg-gray-200', + ]; + } + + return []; + }); +} +``` + +By default, this replaces the default classes on the tr, if you would like to keep them, set the appropriate default flag (see above) + +```php +public function configure(): void +{ + $this->setTrAttributes(function($row, $index) { + if ($index % 2 === 0) { + return [ + 'default' => true, + 'class' => 'bg-gray-200', + ]; + } + + return ['default' => true]; + }); +} +``` + +## setTdAttributes + +Set a list of attributes to override on the td elements. For example, changing the background color between red/green based on whether the "total" field is over or under 1000. + +```php +public function configure(): void +{ + // Takes a callback that gives you the current column, row, column index, and row index + $this->setTdAttributes(function(Column $column, $row, $columnIndex, $rowIndex) { + if ($column->isField('total') && $row->total < 1000) { + return [ + 'class' => 'bg-red-500 text-white', + ]; + } + elseif ($column->isField('total') && $row->total >= 1000) { + return [ + 'class' => 'bg-green-500 text-white', + ]; + } + + return []; + }); +} +``` + +By default, this replaces the default classes on the td, if you would like to keep them, set the appropriate default flag (see above). + +```php +public function configure(): void +{ + // Takes a callback that gives you the current column, row, column index, and row index + $this->setTdAttributes(function(Column $column, $row, $columnIndex, $rowIndex) { + if ($column->isField('total') && $row->total < 1000) { + return [ + 'default' => true, + 'class' => 'bg-red-500 text-white', + ]; + } + + return ['default' => true]; + }); +} + +``` + +### Reorder Column +Note: If you are using Reorder, then the td for Reorder can be [styled separately](../reordering/available-methods). However this is now replaced with the following to ensure consistent behaviour. The separate method will be supported until at least v3.6 + +You can use the "title" of the Column, which will be "reorder" for the "reorder" Column: +```php +public function configure(): void +{ + $this->setTdAttributes(function(Column $column) { + if ($column->getTitle() == 'reorder') + { + return [ + 'class' => 'bg-green-500 dark:bg-green-800', + 'default' => false, + 'default-colors' => false, + ]; + + } + + return ['default' => true]; + }); +} +``` + +### Bulk Actions Column +Note: If you are using Bulk Actions, then the td for Bulk Actions can be [styled separately](../bulk-actions/customisations). However this is now replaced with the following to ensure consistent behaviour. The separate method will be supported until at least v3.6 + +You can use the "title" of the Column, which will be "bulkactions" for the "Bulk Actions" Column: +```php +public function configure(): void +{ + $this->setTdAttributes(function(Column $column) { + if ($column->getTitle() == 'bulkactions') + { + return [ + 'class' => 'bg-yellow-500 dark:bg-yellow-800', + 'default' => false, + 'default-colors' => false, + ]; + + } + + return ['default' => true]; + }); +} +``` diff --git a/docs/datatable/styling.md b/docs/datatable/styling.md index 38055dbd9..b460371bf 100644 --- a/docs/datatable/styling.md +++ b/docs/datatable/styling.md @@ -5,6 +5,27 @@ weight: 5 The package offers significant opportunities to customise the look & feel of the core table, as well as other elements (which are documented in the relevant sections). +## Keeping Defaults +To allow simpler customisation on a per-table basis, there are numerous methods available to over-ride the default CSS classes. +Historically, this was provided by a simple toggleable "default" flag. However - in many cases, the original "default" has been expanded to include: + +### Keep Default Colors And Default Styles +- set default flag to true +or +- set default-colors flag to true +- set default-styling flag to true + +### Keep Default Colors Only +- set default flag to false +- set default-colors flag to true +- set default-styling flag to false + +### Keep Default Styling Only +- set default flag to false +- set default-colors flag to false +- set default-styling flag to true + + ## Attributes ### setComponentWrapperAttributes @@ -129,9 +150,6 @@ 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 { @@ -148,8 +166,7 @@ public function configure(): void } ``` -By default, this replaces the default classes on the th, if you would like to keep them, set the default flag to true. - +#### Keeping Default Colors and Default Styling ```php public function configure(): void { @@ -166,6 +183,72 @@ public function configure(): void } ``` +#### Keeping Default Styling Only For the "Name" Column +```php +public function configure(): void +{ + $this->setThAttributes(function(Column $column) { + if ($column->isField('name')) { + return [ + 'default' => false, + 'default-styling' => true, + 'class' => 'text-black bg-green-500 dark:text-white dark:bg-green-900', + ]; + } + + return ['default' => true]; + }); +} +``` + +#### Reorder Column +Note: If you are using Reorder, then the th for Reorder can be [styled separately](../reordering/available-methods). However this is now replaced with the following to ensure consistent behaviour. The separate method will be supported until at least v3.6 + +You can also use the "title" of the Column, which will be "reorder" for the "reorder" Column: +```php +public function configure(): void +{ + $this->setThAttributes(function(Column $column) { + if ($column->getTitle() == 'reorder') + { + return [ + 'class' => 'bg-green-500 dark:bg-green-800', + 'default' => false, + 'default-colors' => false, + ]; + + } + + return ['default' => true]; + }); +} +``` +#### Bulk Actions Column +Note: If you are using Bulk Actions, then the th for Bulk Actions can be [styled separately](../bulk-actions/customisations). However this is now replaced with the following to ensure consistent behaviour. The separate method will be supported until at least v3.6 + +You can also use the "title" of the Column, which will be "bulkactions" for the "Bulk Actions" Column: +```php +public function configure(): void +{ + $this->setThAttributes(function(Column $column) { + if ($column->getTitle() == 'bulkactions') + { + return [ + 'class' => 'bg-yellow-500 dark:bg-yellow-800', + 'default' => false, + 'default-colors' => false, + ]; + + } + + return ['default' => true]; + }); +} +``` + + + + ### setThSortButtonAttributes Set a list of attributes to override on the th sort button elements diff --git a/resources/views/components/includes/actions.blade.php b/resources/views/components/includes/actions.blade.php index 2c354e7ba..db8925279 100644 --- a/resources/views/components/includes/actions.blade.php +++ b/resources/views/components/includes/actions.blade.php @@ -9,7 +9,7 @@ ->class(['justify-end' => $this->getActionsPosition == 'right']) ->class(['pl-2' => $this->showActionsInToolbar && $this->getActionsPosition == 'left']) ->class(['pr-2' => $this->showActionsInToolbar && $this->getActionsPosition == 'right']) - ->except(['default-styling','default-colors']) + ->except(['default','default-styling','default-colors']) }} > @foreach($this->getActions as $action) {{ $action->render() }} diff --git a/resources/views/components/includes/loading.blade.php b/resources/views/components/includes/loading.blade.php index b60d41016..c07d9cb19 100644 --- a/resources/views/components/includes/loading.blade.php +++ b/resources/views/components/includes/loading.blade.php @@ -24,7 +24,7 @@ $attributes->merge($customAttributes['loader-icon']) ->class(['lds-hourglass' => $isTailwind && ($customAttributes['loader-icon']['default'] ?? true)]) ->class(['lds-hourglass' => $isBootstrap && ($customAttributes['loader-icon']['default'] ?? true)]) - ->except('default'); + ->except(['default','default-styling','default-colors']); }} >
{{ $this->getLoadingPlaceholderContent() }}
diff --git a/resources/views/components/table.blade.php b/resources/views/components/table.blade.php index 4a8f14985..297548694 100644 --- a/resources/views/components/table.blade.php +++ b/resources/views/components/table.blade.php @@ -14,19 +14,19 @@ wire:key="{{ $tableName }}-twrap" {{ $attributes->merge($customAttributes['wrapper']) ->class(['shadow overflow-y-auto border-b border-gray-200 dark:border-gray-700 sm:rounded-lg' => $customAttributes['wrapper']['default'] ?? true]) - ->except('default') }} + ->except(['default','default-styling','default-colors']) }} > merge($customAttributes['table']) ->class(['min-w-full divide-y divide-gray-200 dark:divide-none' => $customAttributes['table']['default'] ?? true]) - ->except('default') }} + ->except(['default','default-styling','default-colors']) }} > merge($customAttributes['thead']) ->class(['bg-gray-50 dark:bg-gray-800' => $customAttributes['thead']['default'] ?? true]) - ->except('default') }} + ->except(['default','default-styling','default-colors']) }} > {{ $thead }} @@ -38,7 +38,7 @@ id="{{ $tableName }}-tbody" {{ $attributes->merge($customAttributes['tbody']) ->class(['bg-white divide-y divide-gray-200 dark:bg-gray-800 dark:divide-none' => $customAttributes['tbody']['default'] ?? true]) - ->except('default') }} + ->except(['default','default-styling','default-colors']) }} > {{ $slot }} @@ -54,20 +54,20 @@
merge($customAttributes['wrapper']) ->class(['table-responsive' => $customAttributes['wrapper']['default'] ?? true]) - ->except('default') }} + ->except(['default','default-styling','default-colors']) }} >
merge($customAttributes['table']) ->class(['laravel-livewire-table table' => $customAttributes['table']['default'] ?? true]) - ->except('default') + ->except(['default','default-styling','default-colors']) }} > merge($customAttributes['thead']) ->class(['' => $customAttributes['thead']['default'] ?? true]) - ->except('default') }} + ->except(['default','default-styling','default-colors']) }} > {{ $thead }} @@ -79,7 +79,7 @@ id="{{ $tableName }}-tbody" {{ $attributes->merge($customAttributes['tbody']) ->class(['' => $customAttributes['tbody']['default'] ?? true]) - ->except('default') }} + ->except(['default','default-styling','default-colors']) }} > {{ $slot }} diff --git a/resources/views/components/table/collapsed-columns.blade.php b/resources/views/components/table/collapsed-columns.blade.php index ba21ee2ba..44bb45d9f 100644 --- a/resources/views/components/table/collapsed-columns.blade.php +++ b/resources/views/components/table/collapsed-columns.blade.php @@ -38,7 +38,7 @@ ->class(['hidden bg-gray-50 dark:bg-gray-800 dark:text-white rappasoft-striped-row' => ($isTailwind && ($customAttributes['default'] ?? true) && $rowIndex % 2 !== 0)]) ->class(['d-none bg-light rappasoft-striped-row' => ($isBootstrap && $rowIndex % 2 === 0 && ($customAttributes['default'] ?? true))]) ->class(['d-none bg-white rappasoft-striped-row' => ($isBootstrap && $rowIndex % 2 !== 0 && ($customAttributes['default'] ?? true))]) - ->except(['default']) + ->except(['default','default-styling','default-colors']) }} > diff --git a/resources/views/components/table/td.blade.php b/resources/views/components/table/td.blade.php index 926cd3ae2..0ba2f050d 100644 --- a/resources/views/components/table/td.blade.php +++ b/resources/views/components/table/td.blade.php @@ -22,7 +22,7 @@ ->class(['d-none d-md-table-cell' => $isBootstrap && $column && $column->shouldCollapseOnMobile()]) ->class(['d-none d-lg-table-cell' => $isBootstrap && $column && $column->shouldCollapseOnTablet()]) ->class(['laravel-livewire-tables-cursor' => $isBootstrap && $column && $column->isClickable()]) - ->except('default') + ->except(['default','default-styling','default-colors']) }} > {{ $slot }} diff --git a/resources/views/components/table/td/bulk-actions.blade.php b/resources/views/components/table/td/bulk-actions.blade.php index 341ad650c..918743395 100644 --- a/resources/views/components/table/td/bulk-actions.blade.php +++ b/resources/views/components/table/td/bulk-actions.blade.php @@ -24,8 +24,7 @@ $attributes->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), - 'except' => 'default', - ]) + ])->except(['default','default-styling','default-colors']) }} /> diff --git a/resources/views/components/table/td/collapsed-columns.blade.php b/resources/views/components/table/td/collapsed-columns.blade.php index 29cb50feb..166a62138 100644 --- a/resources/views/components/table/td/collapsed-columns.blade.php +++ b/resources/views/components/table/td/collapsed-columns.blade.php @@ -25,7 +25,7 @@ 'h-6 w-6' => $this->getCollapsingColumnButtonExpandAttributes['default-styling'] ?? true, 'text-green-600' => $this->getCollapsingColumnButtonExpandAttributes['default-colors'] ?? true, ]) - ->except('default') + ->except(['default','default-styling','default-colors']) }} /> $this->getCollapsingColumnButtonCollapseAttributes['default-styling'] ?? true, 'text-yellow-600' => $this->getCollapsingColumnButtonCollapseAttributes['default-colors'] ?? true, ]) - ->except('default') + ->except(['default','default-styling','default-colors']) }} /> @@ -63,7 +63,7 @@ class="border-0 bg-transparent p-0" ->class([ 'laravel-livewire-tables-btn-lg text-success' => $this->getCollapsingColumnButtonExpandAttributes['default-colors'] ?? true, ]) - ->except('default') + ->except(['default','default-styling','default-colors']) }} /> class([ 'laravel-livewire-tables-btn-lg text-warning' => $this->getCollapsingColumnButtonExpandAttributes['default-colors'] ?? true, ]) - ->except('default') + ->except(['default','default-styling','default-colors']) }} /> diff --git a/resources/views/components/table/td/plain.blade.php b/resources/views/components/table/td/plain.blade.php index 54c9efc67..d2e9ffb6f 100644 --- a/resources/views/components/table/td/plain.blade.php +++ b/resources/views/components/table/td/plain.blade.php @@ -8,7 +8,7 @@ ->class(['hidden' => $column && $column->shouldCollapseAlways()]) ->class(['hidden md:table-cell' => $column && $column->shouldCollapseOnMobile()]) ->class(['hidden lg:table-cell' => $column && $column->shouldCollapseOnTablet()]) - ->except('default') + ->except(['default','default-styling','default-colors']) }} @if($hideUntilReorder) x-show="reorderDisplayColumn" @endif > {{ $slot }} @@ -19,7 +19,7 @@ ->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') + ->except(['default','default-styling','default-colors']) }}> {{ $slot }} diff --git a/resources/views/components/table/th.blade.php b/resources/views/components/table/th.blade.php index 10436241f..b12366dc7 100644 --- a/resources/views/components/table/th.blade.php +++ b/resources/views/components/table/th.blade.php @@ -3,86 +3,86 @@ @php $attributes = $attributes->merge(['wire:key' => $tableName . '-header-col-'.$column->getSlug()]); - $customAttributes = $this->getThAttributes($column); - $customSortButtonAttributes = $this->getThSortButtonAttributes($column); + $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 ; @endphp @if ($isTailwind) @elseif ($isBootstrap)
merge($customAttributes) - ->class(['px-6 py-3 text-left text-xs font-medium whitespace-nowrap text-gray-500 uppercase tracking-wider dark:bg-gray-800 dark:text-gray-400' => $customAttributes['default'] ?? true]) + $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') + ->except(['default', 'default-colors', 'default-styling']) }} > @if($column->getColumnLabelStatus()) @unless ($this->sortingIsEnabled() && ($column->isSortable() || $column->getSortCallback())) - {{ $column->getTitle() }} + except(['default', 'default-colors', 'default-styling']) }}>{{ $column->getTitle() }} @else - @endunless @endif merge($customAttributes) - ->class(['' => $customAttributes['default'] ?? true]) + $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') + ->except(['default','default-styling','default-colors']) }} > @if($column->getColumnLabelStatus()) @unless ($this->sortingIsEnabled() && ($column->isSortable() || $column->getSortCallback())) - {{ $column->getTitle() }} + except(['default', 'default-colors', 'default-styling']) }}>{{ $column->getTitle() }} @else
merge($customSortButtonAttributes) + ->class(['' => ($customSortButtonAttributes['default-styling'] ?? true || $customSortButtonAttributes['default'] ?? true)]) + ->except(['default', 'default-colors', 'default-styling', 'wire:key']) + }} > - {{ $column->getTitle() }} + except(['default', 'default-colors', 'default-styling']) }}>{{ $column->getTitle() }} - - @if ($direction === 'asc') - - @elseif ($direction === 'desc') - - @else - - @endif - + merge($customSortButtonAttributes) + ->class(['' => ($customSortButtonAttributes['default-colors'] ?? true || $customSortButtonAttributes['default'] ?? true)]) + ->except(['default', 'default-colors', 'default-styling', 'wire:key']) + }} + />
@endunless @endif diff --git a/resources/views/components/table/th/bulk-actions.blade.php b/resources/views/components/table/th/bulk-actions.blade.php index b07a67f09..c5c6d3e6c 100644 --- a/resources/views/components/table/th/bulk-actions.blade.php +++ b/resources/views/components/table/th/bulk-actions.blade.php @@ -1,6 +1,7 @@ @aware(['component', 'tableName']) @php - $customAttributes = $this->getBulkActionsThAttributes(); + $customAttributes = $this->hasBulkActionsThAttributes ? $this->getBulkActionsThAttributes : $this->getAllThAttributes($this->getBulkActionsColumn())['customAttributes']; + $bulkActionsThCheckboxAttributes = $this->getBulkActionsThCheckboxAttributes(); $theme = $this->getTheme(); @endphp @@ -25,8 +26,7 @@ $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), - 'except' => 'default', - ]) + ])->except(['default','default-styling','default-colors']) }} /> diff --git a/resources/views/components/table/th/plain.blade.php b/resources/views/components/table/th/plain.blade.php index c8d36ad32..4f5837f34 100644 --- a/resources/views/components/table/th/plain.blade.php +++ b/resources/views/components/table/th/plain.blade.php @@ -4,8 +4,8 @@
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'] ?? true), - 'laravel-livewire-tables-reorderingMinimised' => ($isBootstrap) && ($customAttributes['default'] ?? true), + '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 diff --git a/resources/views/components/table/th/reorder.blade.php b/resources/views/components/table/th/reorder.blade.php index b0dc73845..5ba02d959 100644 --- a/resources/views/components/table/th/reorder.blade.php +++ b/resources/views/components/table/th/reorder.blade.php @@ -1,10 +1,14 @@ @aware(['tableName','isTailwind','isBootstrap']) +@php + $customThAttributes = $this->hasReorderThAttributes() ? $this->getReorderThAttributes() : $this->getAllThAttributes($this->getReorderColumn())['customAttributes']; +@endphp -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' => ($isTailwind) && ($this->getReorderThAttributes['default'] ?? true), - 'laravel-livewire-tables-reorderingMinimised' => ($isBootstrap) && ($this->getReorderThAttributes['default'] ?? true), - ]) +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)]) }} >
diff --git a/resources/views/components/table/th/sort-icons.blade.php b/resources/views/components/table/th/sort-icons.blade.php new file mode 100644 index 000000000..b26b7d964 --- /dev/null +++ b/resources/views/components/table/th/sort-icons.blade.php @@ -0,0 +1,32 @@ +@props(['direction']) +class([ + 'relative flex items-center' => $this->isTailwind, + 'relative d-flex align-items-center' => $this->isBootstrap + ]) }} +> + @if($this->isTailwind) + @switch($direction) + @case('asc') + + + @break + @case('desc') + + + @break + @default + + @endswitch + @else + @switch($direction) + @case('asc') + + @break + @case('desc') + + @break + @default + + @endswitch + @endif + diff --git a/resources/views/components/table/tr.blade.php b/resources/views/components/table/tr.blade.php index f043fbf8a..4a3f84ece 100644 --- a/resources/views/components/table/tr.blade.php +++ b/resources/views/components/table/tr.blade.php @@ -27,7 +27,7 @@ ->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']) + ->except(['default','default-styling','default-colors']) }} > diff --git a/resources/views/components/table/tr/plain.blade.php b/resources/views/components/table/tr/plain.blade.php index 5cd34cfef..d04879c87 100644 --- a/resources/views/components/table/tr/plain.blade.php +++ b/resources/views/components/table/tr/plain.blade.php @@ -6,7 +6,7 @@ ->merge($customAttributes) ->class(['bg-white dark:bg-gray-700 dark:text-white' => $customAttributes['default'] ?? true]) ->class(['laravel-livewire-tables-reorderingMinimised']) - ->except('default') + ->except(['default','default-styling','default-colors']) }} > {{ $slot }} @@ -16,7 +16,7 @@ ->merge($customAttributes) ->class(['' => $customAttributes['default'] ?? true]) ->class(['laravel-livewire-tables-reorderingMinimised']) - ->except('default') + ->except(['default','default-styling','default-colors']) }} > {{ $slot }} diff --git a/resources/views/components/tools/filter-label.blade.php b/resources/views/components/tools/filter-label.blade.php index 6ac6196ae..6fc9022dc 100644 --- a/resources/views/components/tools/filter-label.blade.php +++ b/resources/views/components/tools/filter-label.blade.php @@ -2,20 +2,21 @@ @props(['filter', 'filterLayout' => 'popover', 'tableName' => 'table', 'isTailwind' => false, 'isBootstrap' => false, 'isBootstrap4' => false, 'isBootstrap5' => false, 'for' => null]) @php - $customLabelAttributes = $filter->getFilterLabelAttributes(); -@endphp + $filterLabelAttributes = $filter->getFilterLabelAttributes(); + $customLabelAttributes = $filter->getLabelAttributes(); +@endphp @if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition()) @include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName, 'isTailwind' => $isTailwind, 'isBootstrap' => $isBootstrap, 'isBootstrap4' => $isBootstrap4, 'isBootstrap5' => $isBootstrap5, 'customLabelAttributes' => $customLabelAttributes]) @elseif(!$filter->hasCustomPosition())
for Bulk Actions - */ - public function setBulkActionsThAttributes(array $bulkActionsThAttributes): self - { - $this->bulkActionsThAttributes = [...$this->bulkActionsThAttributes, ...$bulkActionsThAttributes]; - - return $this; - } - - /** - * Used to set attributes for the Bulk Actions Checkbox in the - */ - public function setBulkActionsThCheckboxAttributes(array $bulkActionsThCheckboxAttributes): self - { - $this->bulkActionsThCheckboxAttributes = [...$this->bulkActionsThCheckboxAttributes, ...$bulkActionsThCheckboxAttributes]; - - return $this; - } - - /** - * Used to set attributes for the Bulk Actions TD in the Row - */ - public function setBulkActionsTdAttributes(array $bulkActionsTdAttributes): self - { - $this->bulkActionsTdAttributes = [...$this->bulkActionsTdAttributes, ...$bulkActionsTdAttributes]; - - return $this; - } - - /** - * Used to set attributes for the Bulk Actions Checkbox in the Row - */ - public function setBulkActionsTdCheckboxAttributes(array $bulkActionsTdCheckboxAttributes): self - { - $this->bulkActionsTdCheckboxAttributes = [...$this->bulkActionsTdCheckboxAttributes, ...$bulkActionsTdCheckboxAttributes]; - - return $this; - } - public function setShouldAlwaysHideBulkActionsDropdownOption(bool $status = false): self { $this->alwaysHideBulkActionsDropdownOption = $status; @@ -214,27 +174,6 @@ public function setClearSelectedOnFilterDisabled(): self return $this; } - public function setBulkActionsButtonAttributes(array $bulkActionsButtonAttributes): self - { - $this->bulkActionsButtonAttributes = [...$this->bulkActionsButtonAttributes, ...$bulkActionsButtonAttributes]; - - return $this; - } - - public function setBulkActionsMenuAttributes(array $bulkActionsMenuAttributes): self - { - $this->bulkActionsMenuAttributes = [...$this->bulkActionsMenuAttributes, ...$bulkActionsMenuAttributes]; - - return $this; - } - - public function setBulkActionsMenuItemAttributes(array $bulkActionsMenuItemAttributes): self - { - $this->bulkActionsMenuItemAttributes = [...$this->bulkActionsMenuItemAttributes, ...$bulkActionsMenuItemAttributes]; - - return $this; - } - public function setDelaySelectAllStatus(bool $status): self { $this->delaySelectAll = $status; diff --git a/src/Traits/Configuration/SearchConfiguration.php b/src/Traits/Configuration/SearchConfiguration.php index a5e06634a..c746ef609 100644 --- a/src/Traits/Configuration/SearchConfiguration.php +++ b/src/Traits/Configuration/SearchConfiguration.php @@ -156,7 +156,7 @@ public function setSearchPlaceholder(string $placeholder): self public function setSearchFieldAttributes(array $attributes = []): self { - $this->searchFieldAttributes = $attributes; + $this->setCustomAttributes('searchFieldAttributes', $attributes); return $this; } diff --git a/src/Traits/Configuration/TableAttributeConfiguration.php b/src/Traits/Configuration/TableAttributeConfiguration.php index c1bb681e9..2053d50d7 100644 --- a/src/Traits/Configuration/TableAttributeConfiguration.php +++ b/src/Traits/Configuration/TableAttributeConfiguration.php @@ -85,6 +85,16 @@ public function setThSortButtonAttributes(\Closure $callback): self return $this; } + /** + * Set a list of attributes to override on the th sort icon elements + */ + public function setThSortIconAttributes(\Closure $callback): self + { + $this->thSortIconAttributesCallback = $callback; + + return $this; + } + /** * Set a list of attributes to override on the td elements */ diff --git a/src/Traits/Core/HasCustomAttributes.php b/src/Traits/Core/HasCustomAttributes.php new file mode 100644 index 000000000..99afeb4c4 --- /dev/null +++ b/src/Traits/Core/HasCustomAttributes.php @@ -0,0 +1,49 @@ +{$propertyName}); + } + + public function getCustomAttributes(string $propertyName, bool $default = false, bool $classicMode = true): array + { + if ($classicMode) { + if ($this->hasCustomAttributes($propertyName)) { + $vals = array_merge(['default' => $default, 'default-colors' => $default, 'default-styling' => $default], $this->{$propertyName}); + ksort($vals); + + return $vals; + } + + return ['default' => $default, 'default-colors' => $default, 'default-styling' => $default]; + } else { + if ($this->hasCustomAttributes($propertyName)) { + $vals = array_merge(['default-colors' => $default, 'default-styling' => $default], $this->{$propertyName}); + ksort($vals); + + return $vals; + } + + return ['default-colors' => $default, 'default-styling' => $default]; + + } + } + + public function getCustomAttributesBag(string $propertyName): ComponentAttributeBag + { + return new ComponentAttributeBag($this->getCustomAttributes($propertyName)); + } + + public function setCustomAttributes(string $propertyName, array $customAttributes): self + { + $this->{$propertyName} = $customAttributes; + + return $this; + } +} diff --git a/src/Traits/HasAllTraits.php b/src/Traits/HasAllTraits.php index 8877bc69d..70ddd3eb5 100644 --- a/src/Traits/HasAllTraits.php +++ b/src/Traits/HasAllTraits.php @@ -2,6 +2,7 @@ namespace Rappasoft\LaravelLivewireTables\Traits; +use Rappasoft\LaravelLivewireTables\Traits\Core\HasCustomAttributes; use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasTheme; trait HasAllTraits @@ -18,6 +19,7 @@ trait HasAllTraits WithSearch, WithPagination; use WithBulkActions, + HasCustomAttributes, WithCollapsingColumns, WithColumnSelect, WithConfigurableAreas, diff --git a/src/Traits/Helpers/BulkActionsHelpers.php b/src/Traits/Helpers/BulkActionsHelpers.php index efe9e69a4..d07e9fdc6 100644 --- a/src/Traits/Helpers/BulkActionsHelpers.php +++ b/src/Traits/Helpers/BulkActionsHelpers.php @@ -3,6 +3,7 @@ namespace Rappasoft\LaravelLivewireTables\Traits\Helpers; use Livewire\Attributes\Computed; +use Rappasoft\LaravelLivewireTables\Views\Column; trait BulkActionsHelpers { @@ -183,46 +184,6 @@ public function getBulkActionDefaultConfirmationMessage(): string return isset($this->bulkActionConfirmDefaultMessage) ? $this->bulkActionConfirmDefaultMessage : __('Bulk Actions Confirm'); } - /** - * Used to get attributes for the for Bulk Actions - * - * @return array - */ - public function getBulkActionsThAttributes(): array - { - return $this->bulkActionsThAttributes ?? ['default' => true]; - } - - /** - * Used to get attributes for the Checkbox for Bulk Actions TH - * - * @return array - */ - public function getBulkActionsThCheckboxAttributes(): array - { - return $this->bulkActionsThCheckboxAttributes ?? ['default' => true]; - } - - /** - * Used to get attributes for the Bulk Actions TD - * - * @return array - */ - public function getBulkActionsTdAttributes(): array - { - return $this->bulkActionsTdAttributes ?? ['default' => true]; - } - - /** - * Used to get attributes for the Bulk Actions TD - * - * @return array - */ - public function getBulkActionsTdCheckboxAttributes(): array - { - return $this->bulkActionsTdCheckboxAttributes ?? ['default' => true]; - } - #[Computed] public function shouldAlwaysHideBulkActionsDropdownOption(): bool { @@ -239,25 +200,6 @@ public function getClearSelectedOnFilter(): bool return $this->clearSelectedOnFilter ?? true; } - #[Computed] - public function getBulkActionsButtonAttributes(): array - { - return array_merge(['default-colors' => true, 'default-styling' => true], $this->bulkActionsButtonAttributes); - - } - - #[Computed] - public function getBulkActionsMenuAttributes(): array - { - return array_merge(['default-colors' => true, 'default-styling' => true], $this->bulkActionsMenuAttributes); - } - - #[Computed] - public function getBulkActionsMenuItemAttributes(): array - { - return array_merge(['default-colors' => true, 'default-styling' => true], $this->bulkActionsMenuItemAttributes); - } - public function getSelectedRows(): array { if ($this->getDelaySelectAllStatus() && $this->selectAllIsEnabled()) { @@ -271,4 +213,9 @@ public function getDelaySelectAllStatus(): bool { return $this->delaySelectAll ?? false; } + + public function getBulkActionsColumn(): Column + { + return Column::make('bulkactions')->label(fn () => null); + } } diff --git a/src/Traits/Helpers/ReorderingHelpers.php b/src/Traits/Helpers/ReorderingHelpers.php index 3dc694b0a..c6ad8bd9a 100644 --- a/src/Traits/Helpers/ReorderingHelpers.php +++ b/src/Traits/Helpers/ReorderingHelpers.php @@ -3,6 +3,7 @@ namespace Rappasoft\LaravelLivewireTables\Traits\Helpers; use Livewire\Attributes\Computed; +use Rappasoft\LaravelLivewireTables\Views\Column; trait ReorderingHelpers { @@ -102,4 +103,15 @@ public function getReorderThAttributes(): array { return $this->reorderThAttributes ?? ['default' => true]; } + + #[Computed] + public function hasReorderThAttributes(): bool + { + return $this->getReorderThAttributes() != ['default' => true]; + } + + public function getReorderColumn(): Column + { + return Column::make('reorder')->label(fn () => null); + } } diff --git a/src/Traits/Helpers/SearchHelpers.php b/src/Traits/Helpers/SearchHelpers.php index 4cde87290..1547414a2 100644 --- a/src/Traits/Helpers/SearchHelpers.php +++ b/src/Traits/Helpers/SearchHelpers.php @@ -137,7 +137,7 @@ public function hasSearchPlaceholder(): bool public function getSearchFieldAttributes(): array { - return count($this->searchFieldAttributes) ? $this->searchFieldAttributes : ['default' => true]; + return $this->getCustomAttributes('searchFieldAttributes'); } public function shouldTrimSearchString(): bool diff --git a/src/Traits/Helpers/TableAttributeHelpers.php b/src/Traits/Helpers/TableAttributeHelpers.php index 4d82a5393..5c8125fa9 100644 --- a/src/Traits/Helpers/TableAttributeHelpers.php +++ b/src/Traits/Helpers/TableAttributeHelpers.php @@ -39,16 +39,58 @@ public function getTbodyAttributes(): array return count($this->tbodyAttributes) ? $this->tbodyAttributes : ['default' => true]; } + /** + * Used in resources/views/components/table/th.blade.php + */ #[Computed] public function getThAttributes(Column $column): array { - return isset($this->thAttributesCallback) ? call_user_func($this->thAttributesCallback, $column) : ['default' => true]; + + if (isset($this->thAttributesCallback)) { + return array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], call_user_func($this->thAttributesCallback, $column)); + } + + return ['default' => true, 'default-colors' => true, 'default-styling' => true]; } + /** + * Used in resources/views/components/table/th.blade.php + */ #[Computed] public function getThSortButtonAttributes(Column $column): array { - return isset($this->thSortButtonAttributesCallback) ? call_user_func($this->thSortButtonAttributesCallback, $column) : ['default' => true]; + if (isset($this->thSortButtonAttributesCallback)) { + return array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], call_user_func($this->thSortButtonAttributesCallback, $column)); + } + + return ['default' => true, 'default-colors' => true, 'default-styling' => true]; + } + + /** + * Used in resources/views/components/table/th.blade.php + */ + #[Computed] + public function getThSortIconAttributes(Column $column): array + { + if (isset($this->thSortIconAttributesCallback)) { + return array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], call_user_func($this->thSortIconAttributesCallback, $column)); + } + + return ['default' => true, 'default-colors' => true, 'default-styling' => true]; + } + + /** + * Used in resources/views/components/table/th.blade.php + */ + #[Computed] + public function getAllThAttributes(Column $column): array + { + return [ + 'customAttributes' => $this->getThAttributes($column), + 'labelAttributes' => $column->getLabelAttributesBag(), + 'sortButtonAttributes' => $this->getThSortButtonAttributes($column), + 'sortIconAttributes' => $this->getThSortIconAttributes($column), + ]; } #[Computed] diff --git a/src/Traits/Styling/Configuration/BulkActionStylingConfiguration.php b/src/Traits/Styling/Configuration/BulkActionStylingConfiguration.php new file mode 100644 index 000000000..9c61f9eba --- /dev/null +++ b/src/Traits/Styling/Configuration/BulkActionStylingConfiguration.php @@ -0,0 +1,76 @@ +setCustomAttributes('bulkActionsButtonAttributes', $bulkActionsButtonAttributes); + + return $this; + } + + /** + * Used to set attributes for the Bulk Actions Menu + */ + public function setBulkActionsMenuAttributes(array $bulkActionsMenuAttributes): self + { + $this->setCustomAttributes('bulkActionsMenuAttributes', $bulkActionsMenuAttributes); + + return $this; + } + + /** + * Used to set attributes for the Bulk Actions Menu Items + */ + public function setBulkActionsMenuItemAttributes(array $bulkActionsMenuItemAttributes): self + { + $this->setCustomAttributes('bulkActionsMenuItemAttributes', $bulkActionsMenuItemAttributes); + + return $this; + } + + /** + * Used to set attributes for the Bulk Actions TD in the Row + */ + public function setBulkActionsTdAttributes(array $bulkActionsTdAttributes): self + { + $this->setCustomAttributes('bulkActionsTdAttributes', $bulkActionsTdAttributes); + + return $this; + } + + /** + * Used to set attributes for the Bulk Actions Checkbox in the Row + */ + public function setBulkActionsTdCheckboxAttributes(array $bulkActionsTdCheckboxAttributes): self + { + $this->setCustomAttributes('bulkActionsTdCheckboxAttributes', $bulkActionsTdCheckboxAttributes); + + return $this; + } + + /** + * Used to set attributes for the for Bulk Actions + */ + public function setBulkActionsThAttributes(array $bulkActionsThAttributes): self + { + $this->setCustomAttributes('bulkActionsThAttributes', $bulkActionsThAttributes); + + return $this; + } + + /** + * Used to set attributes for the Bulk Actions Checkbox in the + */ + public function setBulkActionsThCheckboxAttributes(array $bulkActionsThCheckboxAttributes): self + { + $this->setCustomAttributes('bulkActionsThCheckboxAttributes', $bulkActionsThCheckboxAttributes); + + return $this; + } +} diff --git a/src/Traits/Styling/HasBulkActionsStyling.php b/src/Traits/Styling/HasBulkActionsStyling.php new file mode 100644 index 000000000..c1f1b1aca --- /dev/null +++ b/src/Traits/Styling/HasBulkActionsStyling.php @@ -0,0 +1,28 @@ + true]; + + protected array $bulkActionsThCheckboxAttributes = ['default' => true]; + + protected array $bulkActionsTdAttributes = ['default' => true]; + + protected array $bulkActionsTdCheckboxAttributes = ['default' => true]; + + protected array $bulkActionsButtonAttributes = ['default-colors' => true, 'default-styling' => true]; + + protected array $bulkActionsMenuAttributes = ['default-colors' => true, 'default-styling' => true]; + + protected array $bulkActionsMenuItemAttributes = ['default-colors' => true, 'default-styling' => true]; +} diff --git a/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php b/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php new file mode 100644 index 000000000..6c100c345 --- /dev/null +++ b/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php @@ -0,0 +1,96 @@ + + */ + #[Computed] + public function getBulkActionsButtonAttributes(): array + { + return $this->getCustomAttributes('bulkActionsButtonAttributes', true); + + } + + /** + * Used to get attributes for the Bulk Actions Menu (Dropdown) + * + * @return array + */ + #[Computed] + public function getBulkActionsMenuAttributes(): array + { + return $this->getCustomAttributes('bulkActionsMenuAttributes', true, false); + + } + + /** + * Used to get attributes for the items in the Bulk Actions Menu (Dropdown) + * + * @return array + */ + #[Computed] + public function getBulkActionsMenuItemAttributes(): array + { + return $this->getCustomAttributes('bulkActionsMenuItemAttributes', true, false); + + } + + /** + * Used to get attributes for the for Bulk Actions + * + * @return array + */ + #[Computed] + public function getBulkActionsThAttributes(): array + { + return $this->getCustomAttributes('bulkActionsThAttributes'); + + } + + /** + * Used to check if the Bulk Actions TH has any attributes (supports historic approach) + */ + #[Computed] + public function hasBulkActionsThAttributes(): bool + { + return $this->getBulkActionsThAttributes() != ['default' => true, 'default-colors' => false, 'default-styling' => false]; + } + + /** + * Used to get attributes for the Checkbox for Bulk Actions TH + * + * @return array + */ + public function getBulkActionsThCheckboxAttributes(): array + { + return $this->getCustomAttributes('bulkActionsThCheckboxAttributes'); + } + + /** + * 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 + * + * @return array + */ + public function getBulkActionsTdCheckboxAttributes(): array + { + return $this->getCustomAttributes('bulkActionsTdCheckboxAttributes'); + + } +} diff --git a/src/Traits/WithBulkActions.php b/src/Traits/WithBulkActions.php index c36b87bb4..17c4fdcea 100644 --- a/src/Traits/WithBulkActions.php +++ b/src/Traits/WithBulkActions.php @@ -4,11 +4,13 @@ use Rappasoft\LaravelLivewireTables\Traits\Configuration\BulkActionsConfiguration; use Rappasoft\LaravelLivewireTables\Traits\Helpers\BulkActionsHelpers; +use Rappasoft\LaravelLivewireTables\Traits\Styling\HasBulkActionsStyling; trait WithBulkActions { use BulkActionsConfiguration, - BulkActionsHelpers; + BulkActionsHelpers, + HasBulkActionsStyling; public bool $bulkActionsStatus = true; @@ -27,28 +29,12 @@ trait WithBulkActions public ?string $bulkActionConfirmDefaultMessage; - protected array $bulkActionsCheckboxAttributes = []; - - protected array $bulkActionsThAttributes = ['default' => true]; - - protected array $bulkActionsThCheckboxAttributes = ['default' => true]; - - protected array $bulkActionsTdAttributes = ['default' => true]; - - protected array $bulkActionsTdCheckboxAttributes = ['default' => true]; - protected bool $alwaysHideBulkActionsDropdownOption = false; protected bool $clearSelectedOnSearch = true; protected bool $clearSelectedOnFilter = true; - protected array $bulkActionsButtonAttributes = ['default-colors' => true, 'default-styling' => true]; - - protected array $bulkActionsMenuAttributes = ['default-colors' => true, 'default-styling' => true]; - - protected array $bulkActionsMenuItemAttributes = ['default-colors' => true, 'default-styling' => true]; - // Entangled in JS public bool $delaySelectAll = false; diff --git a/src/Traits/WithTableAttributes.php b/src/Traits/WithTableAttributes.php index f87edea61..a0ce12c44 100644 --- a/src/Traits/WithTableAttributes.php +++ b/src/Traits/WithTableAttributes.php @@ -26,6 +26,8 @@ trait WithTableAttributes protected ?\Closure $thSortButtonAttributesCallback; + protected ?\Closure $thSortIconAttributesCallback; + protected ?\Closure $trAttributesCallback; protected ?\Closure $tdAttributesCallback; diff --git a/src/Views/Traits/Columns/IsSortable.php b/src/Views/Traits/Columns/IsSortable.php index b627ac334..5af058650 100644 --- a/src/Views/Traits/Columns/IsSortable.php +++ b/src/Views/Traits/Columns/IsSortable.php @@ -42,11 +42,19 @@ public function setSortingPillDirections(string $asc, string $desc): self return $this; } + /** + * Used internally + * Used in resources/views/components/table/th.blade.php + */ public function getSortCallback(): ?callable { return $this->sortCallback; } + /** + * Used internally + * Used in resources/views/components/table/th.blade.php + */ public function isSortable(): bool { return $this->hasField() && $this->sortable === true; @@ -102,4 +110,12 @@ public function getSortingPillDirection(DataTableComponent $component, string $d return $direction === 'asc' ? $component->getDefaultSortingLabelAsc() : $component->getDefaultSortingLabelDesc(); } + + /** + * Used in resources/views/components/table/th.blade.php + */ + public function getColumnSortKey(): string + { + return $this->isSortable() ? $this->getColumnSelectName() : $this->getSlug(); + } } diff --git a/src/Views/Traits/Core/HasLabelAttributes.php b/src/Views/Traits/Core/HasLabelAttributes.php new file mode 100644 index 000000000..ba1ec4f9b --- /dev/null +++ b/src/Views/Traits/Core/HasLabelAttributes.php @@ -0,0 +1,41 @@ +hasCustomAttributes('labelAttributesArray'); + } + + /** + * Used in resources/views/components/table/th.blade.php + */ + public function getLabelAttributes(): array + { + return $this->getCustomAttributes('labelAttributesArray'); + } + + public function getLabelAttributesBag(): ComponentAttributeBag + { + return new ComponentAttributeBag($this->getLabelAttributes()); + } + + /** + * Set a list of attributes to override on the th label + */ + public function setLabelAttributes(array $labelAttributes): self + { + $this->setCustomAttributes('labelAttributesArray', $labelAttributes); + + return $this; + } +} diff --git a/src/Views/Traits/IsColumn.php b/src/Views/Traits/IsColumn.php index 42bbfb5b4..4dc6e4eef 100644 --- a/src/Views/Traits/IsColumn.php +++ b/src/Views/Traits/IsColumn.php @@ -5,7 +5,7 @@ use Rappasoft\LaravelLivewireTables\DataTableComponent; use Rappasoft\LaravelLivewireTables\Views\Traits\Columns\{HasVisibility, IsCollapsible, IsSearchable, IsSelectable, IsSortable}; use Rappasoft\LaravelLivewireTables\Views\Traits\Configuration\ColumnConfiguration; -use Rappasoft\LaravelLivewireTables\Views\Traits\Core\{HasAttributes,HasFooter,HasSecondaryHeader,HasTheme,HasView}; +use Rappasoft\LaravelLivewireTables\Views\Traits\Core\{HasAttributes,HasFooter,HasLabelAttributes,HasSecondaryHeader,HasTheme,HasView}; use Rappasoft\LaravelLivewireTables\Views\Traits\Helpers\{ColumnHelpers,RelationshipHelpers}; trait IsColumn @@ -19,6 +19,7 @@ trait IsColumn IsSortable, HasAttributes, HasFooter, + HasLabelAttributes, HasSecondaryHeader, HasTheme, HasView, diff --git a/src/Views/Traits/IsFilter.php b/src/Views/Traits/IsFilter.php index 13af1e3af..9896e8bd3 100644 --- a/src/Views/Traits/IsFilter.php +++ b/src/Views/Traits/IsFilter.php @@ -3,7 +3,7 @@ namespace Rappasoft\LaravelLivewireTables\Views\Traits; use Rappasoft\LaravelLivewireTables\Views\Traits\Configuration\FilterConfiguration; -use Rappasoft\LaravelLivewireTables\Views\Traits\Core\{HasConfig,HasView}; +use Rappasoft\LaravelLivewireTables\Views\Traits\Core\{HasConfig,HasLabelAttributes,HasView}; use Rappasoft\LaravelLivewireTables\Views\Traits\Filters\{HasCustomPosition,HasVisibility}; use Rappasoft\LaravelLivewireTables\Views\Traits\Helpers\FilterHelpers; @@ -13,6 +13,7 @@ trait IsFilter FilterHelpers, HasConfig, HasCustomPosition, + HasLabelAttributes, HasVisibility, HasView; diff --git a/tests/Traits/Configuration/BulkActionsConfigurationTest.php b/tests/Traits/Configuration/BulkActionsConfigurationTest.php index af9773618..de113419f 100644 --- a/tests/Traits/Configuration/BulkActionsConfigurationTest.php +++ b/tests/Traits/Configuration/BulkActionsConfigurationTest.php @@ -2,10 +2,25 @@ namespace Rappasoft\LaravelLivewireTables\Tests\Traits\Configuration; +use PHPUnit\Framework\Attributes\DataProvider; use Rappasoft\LaravelLivewireTables\Tests\TestCase; final class BulkActionsConfigurationTest extends TestCase { + public static function attributeStatusProvider(): array + { + return [ + [false, false, false], + [true, false, false], + [true, true, false], + [true, true, true], + [true, false, true], + [false, true, false], + [false, true, true], + [false, false, true], + ]; + } + public function test_variables_are_correct_types(): void { $this->assertIsBool($this->basicTable->bulkActionsStatus); @@ -142,107 +157,6 @@ public function test_can_set_bulk_action_default_confirmation_message(): void } - public function test_can_set_bulk_actions_td_attributes(): void - { - $this->assertSame(['default' => true], $this->basicTable->getBulkActionsTdAttributes()); - - $this->basicTable->setBulkActionsTdAttributes(['class' => 'bg-blue-500']); - - $this->assertSame(['default' => true, 'class' => 'bg-blue-500'], $this->basicTable->getBulkActionsTdAttributes()); - - $this->basicTable->setBulkActionsTdAttributes(['class' => 'bg-blue-500', 'default' => false]); - - $this->assertSame(['default' => false, 'class' => 'bg-blue-500'], $this->basicTable->getBulkActionsTdAttributes()); - } - - public function test_can_set_bulk_actions_td_checkbox_attributes(): void - { - $this->assertSame(['default' => true], $this->basicTable->getBulkActionsTdCheckboxAttributes()); - - $this->basicTable->setBulkActionsTdCheckboxAttributes(['class' => 'bg-gray-500']); - - $this->assertSame(['default' => true, 'class' => 'bg-gray-500'], $this->basicTable->getBulkActionsTdCheckboxAttributes()); - - $this->basicTable->setBulkActionsTdCheckboxAttributes(['class' => 'bg-gray-500', 'default' => false]); - - $this->assertSame(['default' => false, 'class' => 'bg-gray-500'], $this->basicTable->getBulkActionsTdCheckboxAttributes()); - } - - public function test_can_set_bulk_actions_th_attributes(): void - { - $this->assertSame(['default' => true], $this->basicTable->getBulkActionsThAttributes()); - - $this->basicTable->setBulkActionsThAttributes(['class' => 'bg-red-500']); - - $this->assertSame(['default' => true, 'class' => 'bg-red-500'], $this->basicTable->getBulkActionsThAttributes()); - - $this->basicTable->setBulkActionsThAttributes(['class' => 'bg-red-500', 'default' => false]); - - $this->assertSame(['default' => false, 'class' => 'bg-red-500'], $this->basicTable->getBulkActionsThAttributes()); - } - - public function test_can_set_bulk_actions_th_checkbox_attributes(): void - { - $this->assertSame(['default' => true], $this->basicTable->getBulkActionsThCheckboxAttributes()); - - $this->basicTable->setBulkActionsThCheckboxAttributes(['class' => 'bg-green-500']); - - $this->assertSame(['default' => true, 'class' => 'bg-green-500'], $this->basicTable->getBulkActionsThCheckboxAttributes()); - - $this->basicTable->setBulkActionsThCheckboxAttributes(['class' => 'bg-green-500', 'default' => false]); - - $this->assertSame(['default' => false, 'class' => 'bg-green-500'], $this->basicTable->getBulkActionsThCheckboxAttributes()); - } - - public function test_can_set_bulk_actions_button_attributes(): void - { - $this->assertSame(['default-colors' => true, 'default-styling' => true], $this->basicTable->getBulkActionsButtonAttributes()); - $this->assertSame(['default-colors' => true, 'default-styling' => true], $this->basicTable->getBulkActionsMenuAttributes()); - - $this->basicTable->setBulkActionsButtonAttributes(['default-colors' => false, 'class' => 'bg-green-500']); - - $this->assertSame(['default-colors' => false, 'default-styling' => true, 'class' => 'bg-green-500'], $this->basicTable->getBulkActionsButtonAttributes()); - $this->assertSame(['default-colors' => true, 'default-styling' => true], $this->basicTable->getBulkActionsMenuAttributes()); - - $this->basicTable->setBulkActionsButtonAttributes(['class' => 'bg-green-500', 'default-colors' => false]); - - $this->assertSame(['default-colors' => false, 'default-styling' => true, 'class' => 'bg-green-500'], $this->basicTable->getBulkActionsButtonAttributes()); - $this->assertSame(['default-colors' => true, 'default-styling' => true], $this->basicTable->getBulkActionsMenuAttributes()); - } - - public function test_can_set_bulk_actions_menu_attributes(): void - { - $this->assertSame(['default-colors' => true, 'default-styling' => true], $this->basicTable->getBulkActionsMenuAttributes()); - $this->assertSame(['default-colors' => true, 'default-styling' => true], $this->basicTable->getBulkActionsButtonAttributes()); - - $this->basicTable->setBulkActionsMenuAttributes(['class' => 'bg-blue-500']); - - $this->assertSame(['default-colors' => true, 'default-styling' => true, 'class' => 'bg-blue-500'], $this->basicTable->getBulkActionsMenuAttributes()); - $this->assertSame(['default-colors' => true, 'default-styling' => true], $this->basicTable->getBulkActionsButtonAttributes()); - - $this->basicTable->setBulkActionsMenuAttributes(['class' => 'bg-blue-500', 'default-colors' => false]); - - $this->assertSame(['default-colors' => false, 'default-styling' => true, 'class' => 'bg-blue-500'], $this->basicTable->getBulkActionsMenuAttributes()); - $this->assertSame(['default-colors' => true, 'default-styling' => true], $this->basicTable->getBulkActionsButtonAttributes()); - } - - public function test_can_set_bulk_actions_menu_item_attributes(): void - { - $this->assertSame(['default-colors' => true, 'default-styling' => true], $this->basicTable->getBulkActionsMenuAttributes()); - $this->assertSame(['default-colors' => true, 'default-styling' => true], $this->basicTable->getBulkActionsMenuItemAttributes()); - - $this->basicTable->setBulkActionsMenuItemAttributes(['class' => 'bg-red-500']); - - $this->assertSame(['default-colors' => true, 'default-styling' => true, 'class' => 'bg-red-500'], $this->basicTable->getBulkActionsMenuItemAttributes()); - $this->assertSame(['default-colors' => true, 'default-styling' => true], $this->basicTable->getBulkActionsMenuAttributes()); - - $this->basicTable->setBulkActionsMenuItemAttributes(['class' => 'bg-amber-500', 'default-colors' => false]); - - $this->assertSame(['default-colors' => false, 'default-styling' => true, 'class' => 'bg-amber-500'], $this->basicTable->getBulkActionsMenuItemAttributes()); - $this->assertSame(['default-colors' => true, 'default-styling' => true], $this->basicTable->getBulkActionsMenuAttributes()); - - } - public function test_can_set_bulk_actions_delay_select_all_status(): void { $this->assertFalse($this->basicTable->getDelaySelectAllStatus()); diff --git a/tests/Traits/Configuration/BulkActionsStylingConfigurationTest.php b/tests/Traits/Configuration/BulkActionsStylingConfigurationTest.php new file mode 100644 index 000000000..e93674466 --- /dev/null +++ b/tests/Traits/Configuration/BulkActionsStylingConfigurationTest.php @@ -0,0 +1,135 @@ + [false, false, false, 'bg-blue-500', 'bg-red-300'], + 'tff' => [true, false, false, 'bg-red-500', 'bg-yellow-300'], + 'ttf' => [true, true, false, 'bg-green-500', 'bg-gray-300'], + 'ttt' => [true, true, true, 'bg-yellow-500', 'bg-green-300'], + 'tft' => [true, false, true, 'bg-red-500', 'bg-blue-300'], + 'ftf' => [false, true, false, 'bg-green-500', 'bg-amber-300'], + 'ftt' => [false, true, true, 'bg-gray-500', 'bg-blue-300'], + 'fff' => [false, false, true, 'bg-blue-500', 'bg-yellow-300'], + ]; + } + + public static function providesBulkActionMethodsToTest(): array + { + return [ + 'BulkActionsButtonAttributes', + 'BulkActionsMenuAttributes', + 'BulkActionsMenuItemAttributes', + 'BulkActionsThAttributes', + 'BulkActionsThCheckboxAttributes', + 'BulkActionsTdAttributes', + 'BulkActionsTdCheckboxAttributes', + ]; + } + + public static function mergesMethodsWithAttributes(array $methodsToTest, array $dataSetItems): array + { + $allItems = []; + + foreach ($methodsToTest as $methodToTest) { + $lcFirst = lcfirst($methodToTest); + $getMethod = 'get'.$methodToTest; + $setMethod = 'set'.$methodToTest; + $lower = strtolower($methodToTest); + + foreach ($dataSetItems as $index => $dataSetItem) { + $allItems[$lower.'_'.$index] = [$setMethod, $getMethod, $lcFirst, $dataSetItem[0], $dataSetItem[1], $dataSetItem[2], $dataSetItem[3], $dataSetItem[4]]; + } + } + + return $allItems; + } + + public static function bulkActionAttributesProvider(): array + { + $dataSetItems = self::providesAttributeDataSet(); + $methodsToTest = self::providesBulkActionMethodsToTest(); + + return self::mergesMethodsWithAttributes($methodsToTest, $dataSetItems); + + } + + #[DataProvider('bulkActionAttributesProvider')] + public function test_can_set_bulk_actions_attributes_via_provider(string $setMethod, string $getMethod, string $propertyName, bool $default, bool $defaultColors, bool $defaultStyling, string $class1, string $class2): void + { + $this->basicTable->{$setMethod}([ + 'default' => $default, + 'default-colors' => $defaultColors, + 'class' => $class1, + 'default-styling' => $defaultStyling, + ]); + + $this->assertSame([ + 'class' => $class1, + 'default' => $default, + 'default-colors' => $defaultColors, + 'default-styling' => $defaultStyling, + ], $this->basicTable->{$getMethod}()); + + $this->basicTable->{$setMethod}([ + 'default' => $default, + 'class' => $class2, + 'default-colors' => ! $defaultColors, + 'default-styling' => $defaultStyling, + ]); + + $this->assertSame([ + 'class' => $class2, + 'default' => $default, + 'default-colors' => ! $defaultColors, + 'default-styling' => $defaultStyling, + ], $this->basicTable->{$getMethod}()); + } + + #[DataProvider('bulkActionAttributesProvider')] + public function test_can_get_bulk_actions_attributes_bag_via_provider(string $setMethod, string $getMethod, string $propertyName, bool $default, bool $defaultColors, bool $defaultStyling, string $class1, string $class2): void + { + $data = [ + 'class' => $class1, + 'default' => $default, + 'default-colors' => $defaultColors, + 'default-styling' => $defaultStyling, + ]; + + $this->basicTable->{$setMethod}($data); + + $this->assertSame($data, $this->basicTable->{$getMethod}()); + + $attributeBag = new ComponentAttributeBag($data); + + $this->assertSame($attributeBag->getAttributes(), $this->basicTable->getCustomAttributesBag($propertyName)->getAttributes()); + } + + public function test_bulk_actions_td_attributes_returns_default_true_if_not_set(): void + { + $this->assertSame(['default' => true, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getBulkActionsTdAttributes()); + } + + public function test_bulk_actions_td_checkbox_attributes_returns_default_true_if_not_set(): void + { + $this->assertSame(['default' => true, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getBulkActionsTdCheckboxAttributes()); + } + + public function test_bulk_actions_th_attributes_returns_default_true_if_not_set(): void + { + $this->assertSame(['default' => true, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getBulkActionsThAttributes()); + } + + public function test_bulk_actions_th_checkbox_attributes_returns_default_true_if_not_set(): void + { + $this->assertSame(['default' => true, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getBulkActionsThCheckboxAttributes()); + } +} diff --git a/tests/Traits/Configuration/ComponentConfigurationTest.php b/tests/Traits/Configuration/ComponentConfigurationTest.php index 3892083a5..d853d09c1 100644 --- a/tests/Traits/Configuration/ComponentConfigurationTest.php +++ b/tests/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, 'this' => 'that']); - $this->assertSame($this->basicTable->getThAttributes($this->basicTable->columns()[1]), ['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']); } public function test_can_set_th_sort_button_attributes(): void @@ -87,8 +87,22 @@ public function test_can_set_th_sort_button_attributes(): void return ['default' => true, 'here' => 'there']; }); - $this->assertSame($this->basicTable->getThSortButtonAttributes($this->basicTable->columns()[0]), ['default' => false, 'this' => 'that']); - $this->assertSame($this->basicTable->getThSortButtonAttributes($this->basicTable->columns()[1]), ['default' => true, 'here' => 'there']); + $this->assertSame($this->basicTable->getThSortButtonAttributes($this->basicTable->columns()[0]), ['default' => false, 'default-colors' => false, 'default-styling' => false, 'this' => 'that']); + $this->assertSame($this->basicTable->getThSortButtonAttributes($this->basicTable->columns()[1]), ['default' => true, 'default-colors' => false, 'default-styling' => false, 'here' => 'there']); + } + + public function test_can_set_th_sort_icon_attributes(): void + { + $this->basicTable->setThSortIconAttributes(function (Column $column) { + if ($column->isField('id')) { + return ['default' => false, 'this' => 'that']; + } + + return ['default' => true, 'here' => 'there']; + }); + + $this->assertSame($this->basicTable->getThSortIconAttributes($this->basicTable->columns()[0]), ['default' => false, 'default-colors' => false, 'default-styling' => false, 'this' => 'that']); + $this->assertSame($this->basicTable->getThSortIconAttributes($this->basicTable->columns()[1]), ['default' => true, 'default-colors' => false, 'default-styling' => false, 'here' => 'there']); } public function test_can_set_tr_attributes(): void @@ -441,4 +455,13 @@ public function test_can_set_collapsing_column_button_expand_attributes(): void $this->assertSame(['default-styling' => true, 'default-colors' => true], $this->basicTable->getCollapsingColumnButtonCollapseAttributes()); } + + public function test_can_get_set_should_be_displayed(): void + { + $this->assertTrue($this->basicTable->getShouldBeDisplayed()); + $this->basicTable->setShouldBeHidden(); + $this->assertFalse($this->basicTable->getShouldBeDisplayed()); + $this->basicTable->setShouldBeDisplayed(); + $this->assertTrue($this->basicTable->getShouldBeDisplayed()); + } } diff --git a/tests/Traits/Configuration/SearchConfigurationTest.php b/tests/Traits/Configuration/SearchConfigurationTest.php index b89461e15..caeaf19e5 100644 --- a/tests/Traits/Configuration/SearchConfigurationTest.php +++ b/tests/Traits/Configuration/SearchConfigurationTest.php @@ -180,11 +180,11 @@ public function test_can_set_search_placeholder(): void public function test_can_set_search_field_attributes(): void { - $this->assertSame(['default' => true], $this->basicTable->getSearchFieldAttributes()); + $this->assertSame(['default' => false, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getSearchFieldAttributes()); $this->basicTable->setSearchFieldAttributes(['class' => 'bg-blue', 'style' => 'font-size: 3em;']); - $this->assertSame(['class' => 'bg-blue', 'style' => 'font-size: 3em;'], $this->basicTable->getSearchFieldAttributes()); + $this->assertSame(['class' => 'bg-blue', 'default' => false, 'default-colors' => false, 'default-styling' => false, 'style' => 'font-size: 3em;'], $this->basicTable->getSearchFieldAttributes()); } } diff --git a/tests/Traits/Core/CustomAttributesTest.php b/tests/Traits/Core/CustomAttributesTest.php new file mode 100644 index 000000000..cfe3478eb --- /dev/null +++ b/tests/Traits/Core/CustomAttributesTest.php @@ -0,0 +1,97 @@ +setDataTableFingerprint('test'); + } + }; + + $mock->configure(); + $mock->boot(); + + $this->assertSame([ + 'default' => false, + 'default-colors' => false, + 'default-styling' => false, + ], $mock->getCustomAttributes('testAttributesArray', false, true)); + } + + public function test_can_get_custom_attribute_defaults_false_classic_mode(): void + { + $mock = new class extends PetsTable + { + public ?array $testAttributesArray; + + public function configure(): void + { + $this->setDataTableFingerprint('test'); + } + }; + + $mock->configure(); + $mock->boot(); + + $this->assertSame([ + 'default-colors' => false, + 'default-styling' => false, + ], $mock->getCustomAttributes('testAttributesArray', false, false)); + } + + public function test_can_get_custom_attribute_defaults_true_standard_mode(): void + { + $mock = new class extends PetsTable + { + public ?array $testAttributesArray; + + public function configure(): void + { + $this->setDataTableFingerprint('test'); + } + }; + + $mock->configure(); + $mock->boot(); + + $this->assertSame([ + 'default' => true, + 'default-colors' => true, + 'default-styling' => true, + ], $mock->getCustomAttributes('testAttributesArray', true, true)); + } + + public function test_can_get_custom_attribute_defaults_true_classic_mode(): void + { + $mock = new class extends PetsTable + { + public ?array $testAttributesArray; + + public function configure(): void + { + $this->setDataTableFingerprint('test'); + } + }; + + $mock->configure(); + $mock->boot(); + + $this->assertSame([ + 'default-colors' => true, + 'default-styling' => true, + ], $mock->getCustomAttributes('testAttributesArray', true, false)); + } +} diff --git a/tests/Traits/Helpers/BulkActionsHelpersTest.php b/tests/Traits/Helpers/BulkActionsHelpersTest.php index 5506fcb4b..78283a5d9 100644 --- a/tests/Traits/Helpers/BulkActionsHelpersTest.php +++ b/tests/Traits/Helpers/BulkActionsHelpersTest.php @@ -188,26 +188,6 @@ public function test_can_get_bulk_action_default_confirmation_message(): void $this->assertSame('Are you sure?', $this->basicTable->getBulkActionDefaultConfirmationMessage()); } - public function test_bulk_actions_td_attributes_returns_default_true_if_not_set(): void - { - $this->assertSame(['default' => true], $this->basicTable->getBulkActionsTdAttributes()); - } - - public function test_bulk_actions_td_checkbox_attributes_returns_default_true_if_not_set(): void - { - $this->assertSame(['default' => true], $this->basicTable->getBulkActionsTdCheckboxAttributes()); - } - - public function test_bulk_actions_th_attributes_returns_default_true_if_not_set(): void - { - $this->assertSame(['default' => true], $this->basicTable->getBulkActionsThAttributes()); - } - - public function test_bulk_actions_th_checkbox_attributes_returns_default_true_if_not_set(): void - { - $this->assertSame(['default' => true], $this->basicTable->getBulkActionsThCheckboxAttributes()); - } - public function test_select_clears_by_default(): void { $this->basicTable->setSelected([1, 2, 3, 4, 5]); diff --git a/tests/Traits/Helpers/ColumnHelpersTest.php b/tests/Traits/Helpers/ColumnHelpersTest.php index a135ac86c..a295b721e 100644 --- a/tests/Traits/Helpers/ColumnHelpersTest.php +++ b/tests/Traits/Helpers/ColumnHelpersTest.php @@ -342,4 +342,22 @@ public function test_can_check_if_column_label_should_be_shown(): void $this->assertTrue($column3->getColumnLabelStatus()); $this->assertFalse($column2->getColumnLabelStatus()); } + + public function test_can_check_if_column_label_has_attributes(): void + { + $column = Column::make('ID', 'id'); + + $this->assertFalse($column->hasLabelAttributes()); + + $column->setLabelAttributes(['class' => 'text-xl']); + + $this->assertTrue($column->hasLabelAttributes()); + + $this->assertSame(['class' => 'text-xl', 'default' => false, 'default-colors' => false, 'default-styling' => false], $column->getLabelAttributes()); + + $column->setLabelAttributes(['class' => 'text-xl', 'default' => true]); + + $this->assertSame(['class' => 'text-xl', 'default' => true, 'default-colors' => false, 'default-styling' => false], $column->getLabelAttributes()); + + } } diff --git a/tests/Traits/Visuals/BulkActionsVisualsTest.php b/tests/Traits/Visuals/BulkActionsVisualsTest.php index 91f73c177..1e61b1940 100644 --- a/tests/Traits/Visuals/BulkActionsVisualsTest.php +++ b/tests/Traits/Visuals/BulkActionsVisualsTest.php @@ -189,4 +189,37 @@ public function exportBulk($items) } })->assertDontSee('Bulk Actions'); } + + public function test_bulk_dropdown_can_have_customised_classes(): 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="bg-yellow-500 dark:bg-yellow-800"', + 'wire:key="table-thead-bulk-actions"', + ]); + } } diff --git a/tests/Traits/Visuals/SortingVisualsTest.php b/tests/Traits/Visuals/SortingVisualsTest.php index 6419f2643..c74999eb0 100644 --- a/tests/Traits/Visuals/SortingVisualsTest.php +++ b/tests/Traits/Visuals/SortingVisualsTest.php @@ -35,7 +35,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 text-gray-500 uppercase tracking-wider group focus:outline-none dark:text-gray-400"', + '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"', ]); } @@ -45,8 +45,25 @@ public function test_th_headers_are_not_buttons_with_sorting_disabled(): void ->call('setSortingDisabled') ->assertDontSeeHtml('