Skip to content

Commit f8a37b5

Browse files
committed
Added checkbox selector to the list-view component
1 parent b0217ba commit f8a37b5

File tree

10 files changed

+46
-27
lines changed

10 files changed

+46
-27
lines changed

resources/views/components/buttons/select.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
class="border border-transparent hover:border-gray-300 focus:border-gray-300 focus:outline-none flex items-center gap-1 text-xs px-3 py-2 rounded hover:shadow-sm font-medium"
1515
>
1616
{{ $slot }}
17-
<i data-feather="{{ $icon }}" class="w-4 h-4"></i>
17+
@if ($icon)
18+
<i data-feather="{{ $icon }}" class="w-4 h-4"></i>
19+
@endif
1820
</button>

resources/views/components/form/input-group.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{{ $label ?? '' }}
2020
</label>
2121
<input
22-
class="appearance-none w-full bg-white border-gray-300 hover:border-gray-500 px-4 py-2 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-blue-400 focus:border-2 border"
22+
class="appearance-none w-full bg-white border-gray-300 hover:border-gray-500 px-3 py-2 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500 focus:border-2 border"
2323
type="text"
2424
name="{{ $name ?? '' }}"
2525
placeholder="{{ $placeholder ?? ''}}"
@@ -30,7 +30,7 @@ class="appearance-none w-full bg-white border-gray-300 hover:border-gray-500 px-
3030
wire:model="{{ $model ?? '' }}"
3131
>
3232
<div class="absolute right-0 top-0 mt-2 mr-4 text-purple-lighter">
33-
<a wire:click="{{ $onClick ?? '' }}" href="#" class="text-gray-400 hover:text-blue-600">
33+
<a wire:click.prevent="{{ $onClick ?? '' }}" href="#" class="text-gray-400 hover:text-blue-600">
3434
<i data-feather="{{ $icon }}" class="w-4"></i>
3535
</a>
3636
</div>

resources/views/components/table.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<thead class="border-b border-t border-gray-200 bg-gray-100 text-xs leading-4 font-semibold uppercase tracking-wider text-left">
1414
<tr>
1515
@if ($this->hasBulkActions)
16-
<th class="px-3 pr-0">
16+
<th class="pl-3">
1717
<span class="flex items-center justify-center">
1818
<x-lv-checkbox wire:model="allSelected" />
1919
</span>
@@ -53,7 +53,7 @@
5353
@foreach ($items as $item)
5454
<tr class="border-b border-gray-200 text-sm" wire:key="{{ $item->getKey() }}">
5555
@if ($this->hasBulkActions)
56-
<td class="pr-0 px-3">
56+
<td class="pl-3">
5757
<span class="flex items-center justify-center">
5858
<x-lv-checkbox value="{{ $item->getKey() }}" wire:model="selected" />
5959
</span>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="flex space-x-1">
2+
@if (count($selected) > 0)
3+
<x-lv-drop-down label='Actions'>
4+
<x-lv-drop-down.header label='{{ count($selected) }} Selected' />
5+
<x-lv-actions.icon-and-title :actions="$this->bulkActions" />
6+
</x-lv-drop-down>
7+
@endif
8+
9+
@if ($this->hasBulkActions && isset($headers) <= 0)
10+
<button
11+
wire:click="$set('allSelected', {{ !$allSelected }})"
12+
class="border border-transparent hover:border-gray-300 focus:border-gray-300 focus:outline-none flex items-center gap-1 text-xs px-3 py-2 rounded hover:shadow-sm font-medium"
13+
>
14+
{{ __($allSelected ? 'Unselect all' : 'Select all') }}
15+
</button>
16+
@endif
17+
</div>

resources/views/components/toolbar/toolbar.blade.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@
1313
</div>
1414

1515
{{-- Actions on the left --}}
16-
<div class="flex gap-2 flex-1 justify-end items-center mb-4">
16+
<div class="flex space-x-1 flex-1 justify-end items-center mb-4">
1717
{{-- Bulk actions --}}
18-
@if (count($selected) > 0)
19-
<div>
20-
<x-lv-drop-down label='Actions'>
21-
<x-lv-drop-down.header label='{{ count($selected) }} Selected' />
22-
<x-lv-actions.icon-and-title :actions="$this->bulkActions" />
23-
</x-lv-drop-down>
24-
</div>
25-
@endif
18+
<div>
19+
@include('laravel-views::components.toolbar.bulk-actions')
20+
</div>
2621

2722
{{-- Sorting --}}
2823
@if (isset($sortableBy) && $sortableBy->isNotEmpty())

resources/views/grid-view/grid-view-item.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
<div class="{{ $withBackground ? 'rounded-md shadow-md' : '' }}">
1414
@if ($hasDefaultAction)
1515
<a href="#!" wire:click.prevent="onCardClick({{ $model->id }})">
16-
<img src="{{ $image }}" alt="{{ $image }}" class="hover:shadow-lg cursor-pointer rounded-md h-48 w-full object-cover {{ $withBackground ? 'rounded-b-none' : '' }} {{ $selected ? "border-2 border-blue-500" : "" }}">
16+
<img src="{{ $image }}" alt="{{ $image }}" class="hover:shadow-lg cursor-pointer rounded-md h-48 w-full object-cover {{ $withBackground ? 'rounded-b-none' : '' }} {{ $selected ? variants('gridView.selected') : "" }}">
1717
</a>
1818
@else
19-
<img src="{{ $image }}" alt="{{ $image }}" class="rounded-md h-48 w-full object-cover {{ $withBackground ? 'rounded-b-none' : '' }} {{ $selected ? "border-2 border-blue-500" : "" }}">
19+
<img src="{{ $image }}" alt="{{ $image }}" class="rounded-md h-48 w-full object-cover {{ $withBackground ? 'rounded-b-none' : '' }} {{ $selected ? variants('gridView.selected') : "" }}">
2020
@endif
2121

2222
<div class="pt-4 {{ $withBackground ? 'bg-white rounded-b-md p-4' : '' }}">

resources/views/list-view/list-view.blade.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66

77
<div>
88
@foreach ($items as $item)
9-
<div class="border-b border-gray-200 py-2 px-4">
10-
<x-lv-dynamic-component :view="$itemComponent" :data="array_merge($this->data($item), ['actions' => $actionsByRow, 'model' => $item])" />
9+
<div class="flex items-center border-b border-gray-200 ">
10+
@if ($this->hasBulkActions)
11+
<div class="h-full flex items-center pl-3 md:pl-4">
12+
<x-lv-checkbox wire:model="selected" value="{{ $item->getKey() }}" />
13+
</div>
14+
@endif
15+
<div class="py-2 px-3 md:px-4 flex-1">
16+
<x-lv-dynamic-component :view="$itemComponent" :data="array_merge($this->data($item), ['actions' => $actionsByRow, 'model' => $item])" />
17+
</div>
1118
</div>
1219
@endforeach
1320
</div>

src/Views/DataView.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function updatedAllSelected($value)
128128
{
129129
$this->selected = $value ? $this->query->pluck('id')->map(function ($id) {
130130
return (string)$id;
131-
}) : [];
131+
})->toArray() : [];
132132
}
133133

134134
/**

src/config/laravel-views.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
"primary-light" => "text-blue-700 border border-blue-600 hover:bg-blue-600 hover:text-white focus:bg-blue-600 focus:text-white active:bg-blue-600 active:text-white",
1515
],
1616

17-
"paginator" => [
18-
"primary" => "bg-blue-600 border-blue-600"
19-
],
20-
2117
"alerts" => [
2218
"success" => [
2319
"base" => "bg-green-100 border-green-300 text-green-700",
@@ -57,5 +53,9 @@
5753

5854
'links' => [
5955
'default' => 'hover:text-blue-600 hover:underline'
56+
],
57+
58+
'gridView' => [
59+
'selected' => 'border-2 border-blue-500'
6060
]
6161
];

tests/Feature/BulkActionsTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testSelectUnselectAll()
4141

4242
Livewire::test(MockTableViewWithBulkActions::class)
4343
->set('allSelected', true)
44-
->assertSet('selected', $users->pluck('id'))
44+
->assertSet('selected', $users->pluck('id')->toArray())
4545
->set('allSelected', false)
4646
->assertSet('selected', []);
4747
}
@@ -51,7 +51,7 @@ public function testExecuteActionToSelectedRows()
5151
$users = factory(UserTest::class, 7)->create();
5252

5353
Livewire::test(MockTableViewWithBulkActions::class)
54-
->set('selected', $users->pluck('id'))
54+
->set('allSelected', true)
5555
->call('executeBulkAction', 'test-delete-users-action', true)
5656
->assertEmitted('notify', [
5757
'message' => 'Action was executed successfully',
@@ -87,6 +87,4 @@ public function testExecuteBulkActionsWithConfirmationMessage()
8787
$this->assertDatabaseMissing('users', $user->toArray());
8888
}
8989
}
90-
91-
// Execute bulk actions with confirmation
9290
}

0 commit comments

Comments
 (0)