Skip to content

Commit 0fbd225

Browse files
authored
Merge pull request #758 from rappasoft/develop
v2.6
2 parents 04e0177 + d60300b commit 0fbd225

File tree

12 files changed

+276
-12
lines changed

12 files changed

+276
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Added functionality to display BooleanColumn as Yes/No instead of icons.
10+
- Added ButtonGroupColumn for multiple LinkColumns in one group. Pretty much built in action buttons support.
11+
- Added bulk action export example to docs.
12+
713
## [2.5.0] - 2022-05-03
814

915
### Added

docs/columns/other-column-types.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ BooleanColumn::make('Active')
7171
}),
7272
```
7373

74+
### Different types of boolean display
75+
76+
By default, the BooleanColumn displays icons.
77+
78+
If you would like the BooleanColumn to display a plain Yes/No, you can set:
79+
80+
```php
81+
BooleanColumn::make('Active')
82+
->yesNo()
83+
```
84+
7485
## Image Columns
7586

7687
Image columns provide a way to display images in your table without having to use `format()` or partial views:
@@ -115,4 +126,36 @@ LinkColumn::make('Action')
115126
'class' => 'rounded-full',
116127
'alt' => $row->name . ' Avatar',
117128
]),
129+
```
130+
131+
## Button Group Columns
132+
133+
Button group columns let you provide an array of LinkColumns to display in a single cell.
134+
135+
```php
136+
ButtonGroupColumn::make('Actions')
137+
->attributes(function($row) {
138+
return [
139+
'class' => 'space-x-2',
140+
];
141+
})
142+
->buttons([
143+
LinkColumn::make('View')
144+
->title(fn($row) => 'View ' . $row->name)
145+
->location(fn($row) => route('user.show', $row)),
146+
->attributes(function($row) {
147+
return [
148+
'class' => 'underline text-blue-500 hover:no-underline',
149+
];
150+
}),
151+
LinkColumn::make('Edit ' . $row->name)
152+
->title(fn($row) => 'Edit')
153+
->location(fn($row) => route('user.edit', $row)),
154+
->attributes(function($row) {
155+
return [
156+
'target' => '_blank',
157+
'class' => 'underline text-blue-500 hover:no-underline',
158+
];
159+
}),
160+
]),
118161
```

docs/examples/bulk-action-export.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: Bulk Action Export
3+
weight: 3
4+
---
5+
6+
Here's an example on exporting your data from a bulk action using [Laravel Excel](https://laravel-excel.com):
7+
8+
```php
9+
use App\Exports\UsersExport;
10+
use Maatwebsite\Excel\Facades\Excel;
11+
12+
public function bulkActions(): array
13+
{
14+
return [
15+
'export' => 'Export',
16+
];
17+
}
18+
19+
public function export()
20+
{
21+
$users = $this->getSelected();
22+
23+
$this->clearSelected();
24+
25+
return Excel::download(new UsersExport($users), 'users.xlsx');
26+
}
27+
```
28+
29+
The `UsersExport` class is a simple example of how to export data from a bulk action:
30+
31+
```php
32+
<?php
33+
34+
namespace App\Exports;
35+
36+
use App\Models\User;
37+
use Maatwebsite\Excel\Concerns\FromCollection;
38+
39+
class UsersExport implements FromCollection
40+
{
41+
public $users;
42+
43+
public function __construct($users) {
44+
$this->users = $users;
45+
}
46+
47+
public function collection()
48+
{
49+
return User::whereIn('id', $this->users)->get();
50+
}
51+
}
52+
```

resources/views/includes/columns/boolean.blade.php

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,54 @@
44

55
@if ($theme === 'tailwind')
66
@if ($status)
7-
<svg xmlns="http://www.w3.org/2000/svg" class="inline-block h-5 w-5 @if ($successValue === true) text-green-500 @else text-red-500 @endif" fill="none" viewBox="0 0 24 24" stroke="currentColor">
8-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
9-
</svg>
7+
@if ($type === 'icons')
8+
<svg xmlns="http://www.w3.org/2000/svg" class="inline-block h-5 w-5 @if ($successValue === true) text-green-500 @else text-red-500 @endif" fill="none" viewBox="0 0 24 24" stroke="currentColor">
9+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
10+
</svg>
11+
@elseif ($type === 'yes-no')
12+
@if ($successValue === true)
13+
<span>Yes</span>
14+
@else
15+
<span>No</span>
16+
@endif
17+
@endif
1018
@else
11-
<svg xmlns="http://www.w3.org/2000/svg" class="inline-block h-5 w-5 @if ($successValue === false) text-green-500 @else text-red-500 @endif" fill="none" viewBox="0 0 24 24" stroke="currentColor">
12-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
13-
</svg>
19+
@if ($type === 'icons')
20+
<svg xmlns="http://www.w3.org/2000/svg" class="inline-block h-5 w-5 @if ($successValue === false) text-green-500 @else text-red-500 @endif" fill="none" viewBox="0 0 24 24" stroke="currentColor">
21+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
22+
</svg>
23+
@elseif ($type === 'yes-no')
24+
@if ($successValue === false)
25+
<span>Yes</span>
26+
@else
27+
<span>No</span>
28+
@endif
29+
@endif
1430
@endif
1531
@elseif ($theme === 'bootstrap-4' || $theme === 'bootstrap-5')
1632
@if ($status)
17-
<svg xmlns="http://www.w3.org/2000/svg" style="width:1.2em;height:1.2em;" class="d-inline-block @if ($successValue === true) text-success @else text-danger @endif" fill="none" viewBox="0 0 24 24" stroke="currentColor">
18-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
19-
</svg>
33+
@if ($type === 'icons')
34+
<svg xmlns="http://www.w3.org/2000/svg" style="width:1.2em;height:1.2em;" class="d-inline-block @if ($successValue === true) text-success @else text-danger @endif" fill="none" viewBox="0 0 24 24" stroke="currentColor">
35+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
36+
</svg>
37+
@elseif ($type === 'yes-no')
38+
@if ($successValue === true)
39+
<span>Yes</span>
40+
@else
41+
<span>No</span>
42+
@endif
43+
@endif
2044
@else
21-
<svg xmlns="http://www.w3.org/2000/svg" style="width:1.2em;height:1.2em;" class="d-inline-block @if ($successValue === false) text-success @else text-danger @endif" fill="none" viewBox="0 0 24 24" stroke="currentColor">
22-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
23-
</svg>
45+
@if ($type === 'icons')
46+
<svg xmlns="http://www.w3.org/2000/svg" style="width:1.2em;height:1.2em;" class="d-inline-block @if ($successValue === false) text-success @else text-danger @endif" fill="none" viewBox="0 0 24 24" stroke="currentColor">
47+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
48+
</svg>
49+
@elseif ($type === 'yes-no')
50+
@if ($successValue === false)
51+
<span>Yes</span>
52+
@else
53+
<span>No</span>
54+
@endif
55+
@endif
2456
@endif
2557
@endif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div {!! count($attributes) ? $column->arrayToAttributes($attributes) : '' !!}>
2+
@foreach($buttons as $button)
3+
{!! $button->getContents($row) !!}
4+
@endforeach
5+
</div>

src/Views/Columns/BooleanColumn.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class BooleanColumn extends Column
1313
use BooleanColumnConfiguration,
1414
BooleanColumnHelpers;
1515

16+
protected string $type = 'icons';
1617
protected bool $successValue = true;
1718
protected string $view = 'livewire-tables::includes.columns.boolean';
1819
protected $callback;
@@ -28,6 +29,7 @@ public function getContents(Model $row)
2829
return view($this->getView())
2930
->withComponent($this->getComponent())
3031
->withSuccessValue($this->getSuccessValue())
32+
->withType($this->getType())
3133
->withStatus($this->hasCallback() ? call_user_func($this->getCallback(), $value, $row) : (bool)$value === true);
3234
}
3335
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Views\Columns;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Rappasoft\LaravelLivewireTables\Views\Column;
7+
use Rappasoft\LaravelLivewireTables\Views\Traits\Configuration\ButtonGroupColumnConfiguration;
8+
use Rappasoft\LaravelLivewireTables\Views\Traits\Helpers\ButtonGroupColumnHelpers;
9+
10+
class ButtonGroupColumn extends Column
11+
{
12+
use ButtonGroupColumnConfiguration,
13+
ButtonGroupColumnHelpers;
14+
15+
protected array $buttons = [];
16+
protected string $view = 'livewire-tables::includes.columns.button-group';
17+
protected $attributesCallback;
18+
19+
public function __construct(string $title, string $from = null)
20+
{
21+
parent::__construct($title, $from);
22+
23+
$this->label(fn () => null);
24+
}
25+
26+
public function getContents(Model $row)
27+
{
28+
return view($this->getView())
29+
->withColumn($this)
30+
->withRow($row)
31+
->withButtons($this->getButtons())
32+
->withAttributes($this->hasAttributesCallback() ? app()->call($this->getAttributesCallback(), ['row' => $row]) : []);
33+
}
34+
}

src/Views/Traits/Configuration/BooleanColumnConfiguration.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,24 @@ public function setView(string $view): self
4141

4242
return $this;
4343
}
44+
45+
/**
46+
* @return $this
47+
*/
48+
public function icons(): self
49+
{
50+
$this->type = 'icons';
51+
52+
return $this;
53+
}
54+
55+
/**
56+
* @return $this
57+
*/
58+
public function yesNo()
59+
{
60+
$this->type = 'yes-no';
61+
62+
return $this;
63+
}
4464
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Views\Traits\Configuration;
4+
5+
trait ButtonGroupColumnConfiguration
6+
{
7+
public function buttons(array $buttons): self
8+
{
9+
$this->buttons = $buttons;
10+
11+
return $this;
12+
}
13+
14+
public function attributes(callable $callback): self
15+
{
16+
$this->attributesCallback = $callback;
17+
18+
return $this;
19+
}
20+
}

src/Views/Traits/Helpers/BooleanColumnHelpers.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ public function getView(): string
3737
{
3838
return $this->view;
3939
}
40+
41+
/**
42+
* @return string
43+
*/
44+
public function getType(): string
45+
{
46+
return $this->type;
47+
}
4048
}

0 commit comments

Comments
 (0)