Skip to content

Commit 4f7e7de

Browse files
committed
Migrate some default attributes into the default checkbox attributes method from blade, to simplify adjustments going forward with published views
1 parent 203d7ad commit 4f7e7de

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

resources/views/components/table/td/bulk-actions.blade.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@
1212
'inline-flex rounded-md shadow-sm' => $isTailwind,
1313
'form-check' => $isBootstrap5,
1414
])>
15-
<input
16-
x-cloak x-show="!currentlyReorderingStatus"
17-
x-model="selectedItems"
18-
wire:key="{{ $tableName . 'selectedItems-'.$row->{$primaryKey} }}"
19-
wire:loading.attr.delay="disabled"
15+
<input wire:key="{{ $tableName . 'selectedItems-'.$row->{$primaryKey} }}"
2016
value="{{ $row->{$primaryKey} }}"
21-
type="checkbox"
2217
{{
2318
$attributes->merge($bulkActionsTdCheckboxAttributes)->class([
24-
'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' => ($isTailwind) && ($bulkActionsTdCheckboxAttributes['default'] ?? true),
19+
'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' => ($isTailwind) && (($bulkActionsTdCheckboxAttributes['default'] ?? true) || ($bulkActionsTdCheckboxAttributes['default-colors'] ?? true)),
20+
'rounded shadow-sm transition duration-150 ease-in-out focus:ring focus:ring-opacity-50' => ($isTailwind) && (($bulkActionsTdCheckboxAttributes['default'] ?? true) || ($bulkActionsTdCheckboxAttributes['default-styling'] ?? true)),
2521
'form-check-input' => ($isBootstrap5) && ($bulkActionsTdCheckboxAttributes['default'] ?? true),
2622
])->except(['default','default-styling','default-colors'])
2723
}}

resources/views/components/table/th/bulk-actions.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
@aware(['isTailwind', 'isBootstrap'])
1+
@aware(['tableName','isTailwind', 'isBootstrap'])
22
@php
33
$customAttributes = $this->hasBulkActionsThAttributes ? $this->getBulkActionsThAttributes : $this->getAllThAttributes($this->getBulkActionsColumn())['customAttributes'];
44
$bulkActionsThCheckboxAttributes = $this->getBulkActionsThCheckboxAttributes();
55
@endphp
66

77
@if ($this->bulkActionsAreEnabled() && $this->hasBulkActions())
8-
<x-livewire-tables::table.th.plain :displayMinimisedOnReorder="true" wire:key="{{ $this->getTableName }}-thead-bulk-actions" :$customAttributes>
8+
<x-livewire-tables::table.th.plain :displayMinimisedOnReorder="true" wire:key="{{ $tableName }}-thead-bulk-actions" :$customAttributes>
99
<div
1010
x-data="{newSelectCount: 0, indeterminateCheckbox: false, bulkActionHeaderChecked: false}"
1111
x-init="$watch('selectedItems', value => indeterminateCheckbox = (value.length > 0 && value.length < paginationTotalItemCount))"

src/Traits/Styling/HasBulkActionsStyling.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait HasBulkActionsStyling
1818

1919
protected array $bulkActionsTdAttributes = ['default' => true];
2020

21-
protected array $bulkActionsTdCheckboxAttributes = ['default' => true];
21+
protected array $bulkActionsTdCheckboxAttributes = ['default' => true, 'default-colors' => false, 'default-styling' => false];
2222

2323
protected array $bulkActionsButtonAttributes = ['default-colors' => true, 'default-styling' => true];
2424

src/Traits/Styling/Helpers/BulkActionStylingHelpers.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,24 @@ public function getBulkActionsTdAttributes(): array
8585
}
8686

8787
/**
88-
* Used to get attributes for the Bulk Actions TD
88+
* Used to get attributes for the Bulk Actions TD Checkbox
8989
*
9090
* @return array<mixed>
9191
*/
9292
public function getBulkActionsTdCheckboxAttributes(): array
9393
{
94-
return $this->getCustomAttributes('bulkActionsTdCheckboxAttributes');
94+
$array = array_merge(
95+
[
96+
'x-cloak',
97+
'x-show' => "!currentlyReorderingStatus",
98+
'x-model' => "selectedItems",
99+
'wire:loading.attr.delay' => "disabled",
100+
'type' => "checkbox",
101+
],
102+
$this->getCustomAttributes('bulkActionsTdCheckboxAttributes')
103+
);
104+
ksort($array);
105+
return $array;
95106

96107
}
97108

tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public static function providesBulkActionMethodsToTest(): array
3131
'BulkActionsThAttributes',
3232
'BulkActionsThCheckboxAttributes',
3333
'BulkActionsTdAttributes',
34-
'BulkActionsTdCheckboxAttributes',
3534
'BulkActionsRowButtonAttributes',
3635
];
3736
}
@@ -121,11 +120,24 @@ public function test_bulk_actions_td_attributes_returns_default_true_if_not_set(
121120

122121
public function test_bulk_actions_td_checkbox_attributes_returns_default_true_if_not_set(): void
123122
{
124-
$this->assertSame(['default' => true, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getBulkActionsTdCheckboxAttributes());
123+
$data = [
124+
'x-cloak',
125+
'x-show' => '!currentlyReorderingStatus',
126+
'x-model' => 'selectedItems',
127+
'wire:loading.attr.delay' => 'disabled',
128+
'type' => 'checkbox',
129+
'default' => true,
130+
'default-colors' => false,
131+
'default-styling' => false
132+
];
133+
ksort($data);
134+
135+
$this->assertSame($data, $this->basicTable->getBulkActionsTdCheckboxAttributes());
125136
}
126137

127138
public function test_bulk_actions_th_attributes_returns_default_true_if_not_set(): void
128139
{
140+
129141
$this->assertSame(['default' => true, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getBulkActionsThAttributes());
130142
}
131143

0 commit comments

Comments
 (0)