Skip to content

Commit b09c351

Browse files
committed
Add initial commit with basic tests
1 parent 51f998a commit b09c351

File tree

5 files changed

+115
-123
lines changed

5 files changed

+115
-123
lines changed
Lines changed: 83 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@aware([ 'tableName','isTailwind','isBootstrap'])
1+
@aware([ 'tableName'])
22

33
@if ($this->bulkActionsAreEnabled() && $this->hasBulkActions())
44
@php
@@ -7,134 +7,94 @@
77
$simplePagination = $this->isPaginationMethod('simple');
88
@endphp
99

10-
@if ($isTailwind)
11-
<x-livewire-tables::table.tr.plain
12-
x-cloak x-show="selectedItems.length > 0 && !currentlyReorderingStatus"
13-
wire:key="{{ $tableName }}-bulk-select-message"
14-
class="bg-indigo-50 dark:bg-gray-900 dark:text-white"
15-
>
16-
<x-livewire-tables::table.td.plain :colspan="$colspan">
17-
<template x-if="selectedItems.length == paginationTotalItemCount || selectAllStatus">
18-
<div wire:key="{{ $tableName }}-all-selected">
19-
<span>
20-
{{ __($this->getLocalisationPath.'You are currently selecting all') }}
21-
@if(!$simplePagination) <strong><span x-text="paginationTotalItemCount"></span></strong> @endif
22-
{{ __($this->getLocalisationPath.'rows') }}.
23-
</span>
24-
25-
<button
26-
x-on:click="clearSelected"
27-
wire:loading.attr="disabled"
28-
type="button"
29-
class="ml-1 text-blue-600 underline text-gray-700 text-sm leading-5 font-medium focus:outline-none focus:text-gray-800 focus:underline transition duration-150 ease-in-out dark:text-white dark:hover:text-gray-400"
30-
>
31-
{{ __($this->getLocalisationPath.'Deselect All') }}
32-
</button>
33-
</div>
34-
</template>
35-
36-
<template x-if="selectedItems.length !== paginationTotalItemCount && !selectAllStatus">
37-
<div wire:key="{{ $tableName }}-some-selected">
38-
<span>
39-
{{ __($this->getLocalisationPath.'You have selected') }}
40-
<strong><span x-text="selectedItems.length"></span></strong>
41-
{{ __($this->getLocalisationPath.'rows, do you want to select all') }}
42-
@if(!$simplePagination) <strong><span x-text="paginationTotalItemCount"></span></strong> @endif
43-
</span>
44-
45-
<button
46-
x-on:click="selectAllOnPage()"
47-
wire:loading.attr="disabled"
48-
type="button"
49-
class="ml-1 text-blue-600 underline text-gray-700 text-sm leading-5 font-medium focus:outline-none focus:text-gray-800 focus:underline transition duration-150 ease-in-out dark:text-white dark:hover:text-gray-400"
50-
>{{ __($this->getLocalisationPath.'Select All On Page') }}
51-
</button>&nbsp;
52-
53-
<button
54-
x-on:click="setAllSelected()"
55-
wire:loading.attr="disabled"
56-
type="button"
57-
class="ml-1 text-blue-600 underline text-gray-700 text-sm leading-5 font-medium focus:outline-none focus:text-gray-800 focus:underline transition duration-150 ease-in-out dark:text-white dark:hover:text-gray-400"
58-
>
59-
{{ __($this->getLocalisationPath.'Select All') }}
60-
</button>
61-
62-
<button
63-
x-on:click="clearSelected"
64-
wire:loading.attr="disabled"
65-
type="button"
66-
class="ml-1 text-blue-600 underline text-gray-700 text-sm leading-5 font-medium focus:outline-none focus:text-gray-800 focus:underline transition duration-150 ease-in-out dark:text-white dark:hover:text-gray-400"
67-
>
68-
{{ __($this->getLocalisationPath.'Deselect All') }}
69-
</button>
70-
</div>
71-
</template>
72-
</x-livewire-tables::table.td.plain>
73-
</x-livewire-tables::table.tr.plain>
74-
@elseif ($isBootstrap)
75-
<x-livewire-tables::table.tr.plain
76-
x-cloak x-show="selectedItems.length > 0 && !currentlyReorderingStatus"
77-
wire:key="{{ $tableName }}-bulk-select-message"
78-
>
79-
<x-livewire-tables::table.td.plain :colspan="$colspan">
80-
<template x-if="selectedItems.length == paginationTotalItemCount || selectAllStatus">
81-
<div wire:key="{{ $tableName }}-all-selected">
82-
<span>
10+
<x-livewire-tables::table.tr.plain
11+
x-cloak x-show="selectedItems.length > 0 && !currentlyReorderingStatus"
12+
wire:key="{{ $tableName }}-bulk-select-message"
13+
@class([
14+
'bg-indigo-50 dark:bg-gray-900 dark:text-white' => $this->isTailwind,
15+
])
16+
>
17+
<x-livewire-tables::table.td.plain :colspan="$colspan">
18+
<template x-if="selectedItems.length == paginationTotalItemCount || selectAllStatus">
19+
<div wire:key="{{ $tableName }}-all-selected">
20+
<span>
8321
{{ __($this->getLocalisationPath.'You are currently selecting all') }}
8422
@if(!$simplePagination) <strong><span x-text="paginationTotalItemCount"></span></strong> @endif
85-
{{ __($this->getLocalisationPath.'rows') }}.
23+
{{ __($this->getLocalisationPath.'rows') }}.
24+
</span>
8625

87-
</span>
88-
89-
<button
90-
x-on:click="clearSelected"
91-
wire:loading.attr="disabled"
92-
type="button"
93-
class="btn btn-primary btn-sm"
94-
>
26+
<button
27+
x-on:click="clearSelected"
28+
wire:loading.attr="disabled"
29+
type="button"
30+
{{
31+
$attributes->merge($this->getBulkActionsRowButtonAttributes)->class([
32+
'ml-1 underline text-sm leading-5 font-medium focus:outline-none focus:underline transition duration-150 ease-in-out' => $this->isTailwind && ($this->getBulkActionsRowButtonAttributes['default-styling'] ?? true),
33+
'text-blue-600 text-gray-700 focus:text-gray-800 dark:text-white dark:hover:text-gray-400' => $this->isTailwind && ($this->getBulkActionsRowButtonAttributes['default-colors'] ?? true),
34+
'btn btn-primary btn-sm' => $this->isBootstrap && ($this->getBulkActionsRowButtonAttributes['default-styling'] ?? true)
35+
])
36+
}}
37+
>
9538
{{ __($this->getLocalisationPath.'Deselect All') }}
96-
</button>
97-
</div>
98-
</template>
39+
</button>
40+
</div>
41+
</template>
42+
43+
<template x-if="selectedItems.length !== paginationTotalItemCount && !selectAllStatus">
44+
<div wire:key="{{ $tableName }}-some-selected">
45+
<span>
46+
{{ __($this->getLocalisationPath.'You have selected') }}
47+
<strong><span x-text="selectedItems.length"></span></strong>
48+
{{ __($this->getLocalisationPath.'rows, do you want to select all') }}
49+
@if(!$simplePagination) <strong><span x-text="paginationTotalItemCount"></span></strong> @endif
50+
</span>
9951

100-
<template x-if="selectedItems.length !== paginationTotalItemCount && !selectAllStatus">
101-
<div wire:key="{{ $tableName }}-some-selected">
102-
<span>
103-
{{ __($this->getLocalisationPath.'You have selected') }}
104-
<strong><span x-text="selectedItems.length"></span></strong>
105-
{{ __($this->getLocalisationPath.'rows, do you want to select all') }}
106-
@if(!$simplePagination) <strong><span x-text="paginationTotalItemCount"></span></strong> @endif
107-
</span>
52+
<button
53+
x-on:click="selectAllOnPage()"
54+
wire:loading.attr="disabled"
55+
type="button"
56+
{{
57+
$attributes->merge($this->getBulkActionsRowButtonAttributes)->class([
58+
'ml-1 underline text-sm leading-5 font-medium focus:outline-none focus:underline transition duration-150 ease-in-out' => $this->isTailwind && ($this->getBulkActionsRowButtonAttributes['default-styling'] ?? true),
59+
'text-blue-600 text-gray-700 focus:text-gray-800 dark:text-white dark:hover:text-gray-400' => $this->isTailwind && ($this->getBulkActionsRowButtonAttributes['default-colors'] ?? true),
60+
'btn btn-primary btn-sm' => $this->isBootstrap && ($this->getBulkActionsRowButtonAttributes['default-styling'] ?? true)
61+
])
62+
}}
10863

109-
<button
110-
x-on:click="selectAllOnPage"
111-
wire:loading.attr="disabled"
112-
type="button"
113-
class="btn btn-primary btn-sm"
114-
>
115-
{{ __($this->getLocalisationPath.'Select All On Page') }}
116-
</button>&nbsp;
64+
>{{ __($this->getLocalisationPath.'Select All On Page') }}
65+
</button>&nbsp;
11766

118-
<button
119-
x-on:click="setAllSelected()"
120-
wire:loading.attr="disabled"
121-
type="button"
122-
class="btn btn-primary btn-sm"
123-
>
124-
{{ __($this->getLocalisationPath.'Select All') }}
125-
</button>
67+
<button
68+
x-on:click="setAllSelected()"
69+
wire:loading.attr="disabled"
70+
type="button"
71+
{{
72+
$attributes->merge($this->getBulkActionsRowButtonAttributes)->class([
73+
'ml-1 underline text-sm leading-5 font-medium focus:outline-none focus:underline transition duration-150 ease-in-out' => $this->isTailwind && ($this->getBulkActionsRowButtonAttributes['default-styling'] ?? true),
74+
'text-blue-600 text-gray-700 focus:text-gray-800 dark:text-white dark:hover:text-gray-400' => $this->isTailwind && ($this->getBulkActionsRowButtonAttributes['default-colors'] ?? true),
75+
'btn btn-primary btn-sm' => $this->isBootstrap && ($this->getBulkActionsRowButtonAttributes['default-styling'] ?? true)
76+
])
77+
}}
78+
>
79+
{{ __($this->getLocalisationPath.'Select All') }}
80+
</button>
12681

127-
<button
128-
x-on:click="clearSelected"
129-
wire:loading.attr="disabled"
130-
type="button"
131-
class="btn btn-primary btn-sm"
132-
>
133-
{{ __($this->getLocalisationPath.'Deselect All') }}
134-
</button>
135-
</div>
136-
</template>
137-
</x-livewire-tables::table.td.plain>
138-
</x-livewire-tables::table.tr.plain>
139-
@endif
82+
<button
83+
x-on:click="clearSelected"
84+
wire:loading.attr="disabled"
85+
type="button"
86+
{{
87+
$attributes->merge($this->getBulkActionsRowButtonAttributes)->class([
88+
'ml-1 underline text-sm leading-5 font-medium focus:outline-none focus:underline transition duration-150 ease-in-out' => $this->isTailwind && ($this->getBulkActionsRowButtonAttributes['default-styling'] ?? true),
89+
'text-blue-600 text-gray-700 focus:text-gray-800 dark:text-white dark:hover:text-gray-400' => $this->isTailwind && ($this->getBulkActionsRowButtonAttributes['default-colors'] ?? true),
90+
'btn btn-primary btn-sm' => $this->isBootstrap && ($this->getBulkActionsRowButtonAttributes['default-styling'] ?? true)
91+
])
92+
}}
93+
>
94+
{{ __($this->getLocalisationPath.'Deselect All') }}
95+
</button>
96+
</div>
97+
</template>
98+
</x-livewire-tables::table.td.plain>
99+
</x-livewire-tables::table.tr.plain>
140100
@endif

src/Traits/Styling/Configuration/BulkActionStylingConfiguration.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,17 @@ public function setBulkActionsThCheckboxAttributes(array $bulkActionsThCheckboxA
7373

7474
return $this;
7575
}
76+
77+
/**
78+
* Used to set attributes for the Bulk Actions Row Buttons
79+
*
80+
*/
81+
#[Computed]
82+
public function setBulkActionsRowButtonAttributes(array $bulkActionsRowButtonAttributes): self
83+
{
84+
$this->setCustomAttributes('bulkActionsRowButtonAttributes', $bulkActionsRowButtonAttributes);
85+
86+
return $this;
87+
}
88+
7689
}

src/Traits/Styling/HasBulkActionsStyling.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ trait HasBulkActionsStyling
2525
protected array $bulkActionsMenuAttributes = ['default-colors' => true, 'default-styling' => true];
2626

2727
protected array $bulkActionsMenuItemAttributes = ['default-colors' => true, 'default-styling' => true];
28+
29+
protected array $bulkActionsRowButtonAttributes = ['default-colors' => true, 'default-styling' => true];
30+
2831
}

src/Traits/Styling/Helpers/BulkActionStylingHelpers.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers;
44

55
use Livewire\Attributes\Computed;
6+
use Illuminate\View\ComponentAttributeBag;
67

78
trait BulkActionStylingHelpers
89
{
@@ -93,4 +94,18 @@ public function getBulkActionsTdCheckboxAttributes(): array
9394
return $this->getCustomAttributes('bulkActionsTdCheckboxAttributes');
9495

9596
}
97+
98+
/**
99+
* Used to get attributes for the Bulk Actions Row Buttons
100+
*
101+
* @return array<mixed>
102+
*/
103+
#[Computed]
104+
public function getBulkActionsRowButtonAttributes(): array
105+
{
106+
return $this->getCustomAttributes('bulkActionsRowButtonAttributes', true);
107+
108+
}
109+
110+
96111
}

tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static function providesBulkActionMethodsToTest(): array
3232
'BulkActionsThCheckboxAttributes',
3333
'BulkActionsTdAttributes',
3434
'BulkActionsTdCheckboxAttributes',
35+
'BulkActionsRowButtonAttributes',
3536
];
3637
}
3738

0 commit comments

Comments
 (0)