Skip to content

Commit 43b1de0

Browse files
authored
Tweaks for BulkActions
1 parent c5b63fc commit 43b1de0

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@
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
}}
2824
/>
2925
</div>
3026
</x-livewire-tables::table.td.plain>
31-
@endif
27+
@endif

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

Lines changed: 3 additions & 3 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))"
@@ -30,4 +30,4 @@
3030
/>
3131
</div>
3232
</x-livewire-tables::table.th.plain>
33-
@endif
33+
@endif

src/Traits/Styling/HasBulkActionsStyling.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait HasBulkActionsStyling
1515

1616
protected array $bulkActionsTdAttributes = ['default' => true];
1717

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

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

@@ -110,9 +110,23 @@ public function getBulkActionsTdAttributes(): array
110110
public function getBulkActionsTdCheckboxAttributes(): array
111111
{
112112
return $this->getCustomAttributes('bulkActionsTdCheckboxAttributes');
113+
$array = array_merge(
114+
[
115+
'x-cloak',
116+
'x-show' => '!currentlyReorderingStatus',
117+
'x-model' => 'selectedItems',
118+
'wire:loading.attr.delay' => 'disabled',
119+
'type' => 'checkbox',
120+
],
121+
$this->getCustomAttributes('bulkActionsTdCheckboxAttributes')
122+
);
123+
ksort($array);
124+
125+
return $array;
113126

114127
}
115128

129+
116130
/**
117131
* Used to get attributes for the Bulk Actions Row Buttons
118132
*

tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function test_can_set_bulk_actions_attributes_via_provider(string $setMet
7878
'default' => $default,
7979
'default-colors' => $defaultColors,
8080
'default-styling' => $defaultStyling,
81-
], $this->basicTable->{$getMethod}());
81+
], collect($this->basicTable->{$getMethod}())->only(['class', 'default', 'default-colors', 'default-styling'])->toArray());
8282

8383
$this->basicTable->{$setMethod}([
8484
'default' => $default,
@@ -92,7 +92,7 @@ public function test_can_set_bulk_actions_attributes_via_provider(string $setMet
9292
'default' => $default,
9393
'default-colors' => ! $defaultColors,
9494
'default-styling' => $defaultStyling,
95-
], $this->basicTable->{$getMethod}());
95+
], collect($this->basicTable->{$getMethod}())->only(['class', 'default', 'default-colors', 'default-styling'])->toArray());
9696
}
9797

9898
#[DataProvider('bulkActionAttributesProvider')]
@@ -107,7 +107,7 @@ public function test_can_get_bulk_actions_attributes_bag_via_provider(string $se
107107

108108
$this->basicTable->{$setMethod}($data);
109109

110-
$this->assertSame($data, $this->basicTable->{$getMethod}());
110+
$this->assertSame($data, collect($this->basicTable->{$getMethod}())->only(['class', 'default', 'default-colors', 'default-styling'])->toArray());
111111

112112
$attributeBag = new ComponentAttributeBag($data);
113113

@@ -121,16 +121,31 @@ public function test_bulk_actions_td_attributes_returns_default_true_if_not_set(
121121

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

127141
public function test_bulk_actions_th_attributes_returns_default_true_if_not_set(): void
128142
{
143+
129144
$this->assertSame(['default' => true, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getBulkActionsThAttributes());
130145
}
131146

132147
public function test_bulk_actions_th_checkbox_attributes_returns_default_true_if_not_set(): void
133148
{
134149
$this->assertSame(['default' => true, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getBulkActionsThCheckboxAttributes());
135150
}
136-
}
151+
}

0 commit comments

Comments
 (0)