Skip to content

Commit b0217ba

Browse files
committed
Added checkbox selector to the grid-view component
1 parent 48c3db7 commit b0217ba

File tree

13 files changed

+75
-67
lines changed

13 files changed

+75
-67
lines changed

doc/grid-view.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,14 @@ Name|Description|Type|Value
9999
model|Model instance for this card|||
100100
actions|Actions defined in this view class|Array
101101
hasDefaultAction|Checks if the Grid View has defined a `onCardClick` method|Boolean|true,false
102+
selected|Defines if the item was selected when the grid view has bulk actions|Boolean|true,false
102103

103-
With all this data you can build your own card component as you need, remember to include the `actions` component.
104+
With all this data you can build your own card component as you need, remember to include an `actions` component.
104105

105106
```html
106107
<x-lv-actions :actions="$actions" :model="$model" />
108+
<!-- Or -->
109+
<x-lv-actions.drop-down :actions="$actions" :model="$model" />
107110
```
108111

109112

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@props(['actions' => [], 'model' => null])
2+
3+
<x-lv-drop-down>
4+
<x-slot name="trigger">
5+
<x-lv-icon-button icon="more-horizontal" size="sm"/>
6+
</x-slot>
7+
<x-lv-actions.icon-and-title :actions="$actions" :model="$model" />
8+
</x-lv-drop-down>

resources/views/components/actions/actions.blade.php renamed to resources/views/components/actions/responsive.blade.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
@props(['actions', 'model'])
1+
@props(['actions' => [], 'model' => null])
22

33
<div>
44
@if (count($actions))
55
{{-- Mobile actions dropdown --}}
66
<div class="lg:hidden text-right relative">
7-
<x-lv-drop-down>
8-
<x-slot name="trigger">
9-
<x-lv-icon-button icon="more-horizontal" size="sm" />
10-
</x-slot>
11-
12-
<x-lv-actions.icon-and-title :actions="$actions" :model="$model" />
13-
</x-lv-drop-down>
7+
<x-lv-actions.drop-down :actions="$actions" :model="$model" />
148
</div>
159

1610
{{-- Desktop action buttons --}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<input type="checkbox" {{ $attributes->merge(['class' => 'w-4 h-4 rounded']) }}>

resources/views/components/table.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@if ($this->hasBulkActions)
1616
<th class="px-3 pr-0">
1717
<span class="flex items-center justify-center">
18-
<input type="checkbox" wire:model="allSelected">
18+
<x-lv-checkbox wire:model="allSelected" />
1919
</span>
2020
</th>
2121
@endif
@@ -55,7 +55,7 @@
5555
@if ($this->hasBulkActions)
5656
<td class="pr-0 px-3">
5757
<span class="flex items-center justify-center">
58-
<input wire:model="selected" type="checkbox" value="{{ $item->getKey() }}">
58+
<x-lv-checkbox value="{{ $item->getKey() }}" wire:model="selected" />
5959
</span>
6060
</td>
6161
@endif

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
@props([
2-
'image',
3-
'title',
4-
'subtitle',
5-
'description',
6-
'withBackground',
2+
'image' => '',
3+
'title' => '',
4+
'subtitle' => '',
5+
'description' => '',
6+
'withBackground' => false,
77
'model',
8-
'actions',
9-
'hasDefaultAction'
8+
'actions' => [],
9+
'hasDefaultAction' => false,
10+
'selected' => false
1011
])
1112

1213
<div class="{{ $withBackground ? 'rounded-md shadow-md' : '' }}">
1314
@if ($hasDefaultAction)
1415
<a href="#!" wire:click.prevent="onCardClick({{ $model->id }})">
15-
<img src="{{ $image }}" alt="{{ $image }}" class="hover:shadow-lg cursor-pointer rounded-md h-48 w-full object-cover {{ $withBackground ? 'rounded-b-none' : '' }}">
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" : "" }}">
1617
</a>
1718
@else
18-
<img src="{{ $image }}" alt="{{ $image }}" class="rounded-md h-48 w-full object-cover {{ $withBackground ? 'rounded-b-none' : '' }}">
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" : "" }}">
1920
@endif
2021

2122
<div class="pt-4 {{ $withBackground ? 'bg-white rounded-b-md p-4' : '' }}">
@@ -38,12 +39,7 @@
3839
</div>
3940

4041
<div class="flex justify-end items-center">
41-
<x-lv-drop-down>
42-
<x-slot name="trigger">
43-
<x-lv-icon-button icon="more-horizontal" size="sm"/>
44-
</x-slot>
45-
<x-lv-actions.icon-and-title :actions="$actions" :model="$model" />
46-
</x-lv-drop-down>
42+
<x-lv-actions.drop-down :actions="$actions" :model="$model" />
4743
</div>
4844
</div>
4945

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,23 @@
1515

1616
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-{{ $maxCols }} gap-8 md:gap-8">
1717
@foreach ($items as $item)
18-
<x-lv-dynamic-component
18+
<div class="relative">
19+
@if ($this->hasBulkActions)
20+
<div class="absolute top-0 lef-0 p-2">
21+
<x-lv-checkbox wire:model="selected" value="{{ $item->getKey() }}"/>
22+
</div>
23+
@endif
24+
<x-lv-dynamic-component
1925
:view="$cardComponent"
2026
:data="array_merge($this->card($item), [
2127
'withBackground' => $withBackground,
2228
'model' => $item,
2329
'actions' => $actionsByRow,
24-
'hasDefaultAction' => $this->hasDefaultAction])"
30+
'hasDefaultAction' => $this->hasDefaultAction,
31+
'selected' => in_array($item->getKey(), $selected)
32+
])"
2533
/>
34+
</div>
2635
@endforeach
2736
</div>
2837

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
{{-- Empty data message --}}
2929
<div class="flex justify-center items-center p-4">
30-
<h1>There are no items in this table</h1>
30+
<h3>{{ __('There are no items in this table') }}</h3>
3131
</div>
3232

3333
@endif

src/LaravelViews.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ public function components()
2020
'buttons.button' => 'button',
2121
'dropdown.drop-down' => 'drop-down',
2222
'dropdown.header' => 'drop-down.header',
23-
'actions.actions' => 'actions',
23+
'actions.responsive' => 'actions',
24+
'actions.drop-down' => 'actions.drop-down',
2425
'actions.icon-and-title' => 'actions.icon-and-title',
2526
'actions.icon' => 'actions.icon',
2627
'attributes-list' => 'attributes-list',
2728
'alert' => 'alert',
2829
'alerts-handler' => 'alerts-handler',
2930
'form.input-group' => 'form.input-group',
3031
'icon' => 'icon',
31-
'modal' => 'modal'
32+
'modal' => 'modal',
33+
'form.checkbox' => 'checkbox'
3234
];
3335
}
3436

src/Views/DataView.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace LaravelViews\Views;
44

5-
use LaravelViews\Actions\WithActions;
65
use LaravelViews\Data\Contracts\Filterable;
76
use LaravelViews\Data\Contracts\Searchable;
87
use LaravelViews\Data\Contracts\Sortable;
98
use LaravelViews\Data\QueryStringData;
9+
use LaravelViews\Views\Traits\WithActions;
1010
use Livewire\WithPagination;
1111

1212
abstract class DataView extends View
@@ -131,14 +131,6 @@ public function updatedAllSelected($value)
131131
}) : [];
132132
}
133133

134-
/**
135-
* Computed properties
136-
*/
137-
public function getHasBulkActionsProperty()
138-
{
139-
return method_exists($this, 'bulkActions') && count($this->bulkActions) > 0;
140-
}
141-
142134
/**
143135
* Returns the items from the database regarding to the filters selected by the user
144136
* applies the search query, the filters used and the total of items found

0 commit comments

Comments
 (0)