Skip to content

Commit d140f39

Browse files
authored
v3.4.15 (#1893)
## [v3.4.15] - 2024-08-25 ### New Features - BooleanColumn - Toggleable Callback by @lrljoe in #1892 ### Tweaks - Doc Type Fixes by @lrljoe in #1891
1 parent ecf1fee commit d140f39

26 files changed

+221
-97
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to `laravel-livewire-tables` will be documented in this file
44

5+
## [v3.4.15] - 2024-08-25
6+
### New Features
7+
- BooleanColumn - Toggleable Callback by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1892
8+
9+
### Tweaks
10+
- Doc Type Fixes by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1891
11+
512
## [v3.4.14] - 2024-08-25
613
### New Features
714
- Set Action Position (Left/Center/Right) and Set Actions in Toolbar by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1889

docs/column-types/boolean_columns.md

+40
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,46 @@ BooleanColumn::make('Active')
8080
->yesNo()
8181
```
8282

83+
### Toggleable
84+
85+
You may call a defined public function, which should live within your Table Component, to allow "toggling" against your database:
86+
87+
```php
88+
BooleanColumn::make('Active', 'status')
89+
->toggleable('changeStatus'),
90+
```
91+
92+
Then your "changeStatus" method may look like
93+
```php
94+
public function changeStatus(int $id)
95+
{
96+
$item = $this->model::find($id);
97+
$item->status = !$item->status;
98+
$item->save();
99+
}
100+
```
101+
102+
### Toggleable Confirmation Message
103+
104+
You may define a confirmation message prior to executing your toggleable() method. The method will only be executed upon confirming.
105+
```php
106+
BooleanColumn::make('Active', 'status')
107+
->confirmMessage('Are you sure that you want to change the status?')
108+
->toggleable('changeStatus'),
109+
```
110+
111+
Then your "changeStatus" method may look like
112+
```php
113+
public function changeStatus(int $id)
114+
{
115+
$item = $this->model::find($id);
116+
$item->status = !$item->status;
117+
$item->save();
118+
}
119+
```
120+
121+
122+
### Additional Methods
83123
Please also see the following for other available methods:
84124
<ul>
85125
<li>
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,27 @@
1-
@if ($isTailwind)
2-
@if ($status)
3-
@if ($type === 'icons')
4-
@if ($successValue === true)
5-
<x-heroicon-o-check-circle class="inline-block h-5 w-5 text-green-500" />
6-
@else
7-
<x-heroicon-o-check-circle class="inline-block h-5 w-5 text-red-500" />
8-
@endif
9-
@elseif ($type === 'yes-no')
10-
@if ($successValue === true)
11-
<span>Yes</span>
12-
@else
13-
<span>No</span>
14-
@endif
15-
@endif
16-
@else
17-
@if ($type === 'icons')
18-
@if ($successValue === false)
19-
<x-heroicon-o-x-circle class="inline-block h-5 w-5 text-green-500" />
20-
@else
21-
<x-heroicon-o-x-circle class="inline-block h-5 w-5 text-red-500" />
22-
@endif
23-
@elseif ($type === 'yes-no')
24-
@if ($successValue === false)
25-
<span>Yes</span>
26-
@else
27-
<span>No</span>
28-
@endif
29-
@endif
30-
@endif
31-
@elseif ($isBootstrap)
1+
@if($isToggleable && $toggleMethod != '')
2+
<button wire:click="{{ $toggleMethod }}('{{ $rowPrimaryKey }}')"
3+
@if($hasConfirmMessage) wire:confirm="{{ $confirmMessage }}" @endif
4+
>
5+
@endif
326
@if ($status)
337
@if ($type === 'icons')
348
@if ($successValue === true)
35-
<x-heroicon-o-check-circle class="d-inline-block text-success laravel-livewire-tables-btn-small" />
36-
@else
37-
<x-heroicon-o-check-circle class="d-inline-block text-danger laravel-livewire-tables-btn-small" />
9+
<x-heroicon-o-check-circle
10+
@class(
11+
[
12+
"inline-block h-5 w-5 text-green-500" => $isTailwind,
13+
"d-inline-block text-success laravel-livewire-tables-btn-small" => $isBootstrap
14+
]
15+
)
16+
/>
17+
@else
18+
<x-heroicon-o-check-circle @class(
19+
[
20+
"inline-block h-5 w-5 text-red-500" => $isTailwind,
21+
"d-inline-block text-danger laravel-livewire-tables-btn-small" => $isBootstrap
22+
]
23+
)
24+
/>
3825
@endif
3926
@elseif ($type === 'yes-no')
4027
@if ($successValue === true)
@@ -46,9 +33,21 @@
4633
@else
4734
@if ($type === 'icons')
4835
@if ($successValue === false)
49-
<x-heroicon-o-x-circle class="d-inline-block text-success laravel-livewire-tables-btn-small" />
50-
@else
51-
<x-heroicon-o-x-circle class="d-inline-block text-danger laravel-livewire-tables-btn-small" />
36+
<x-heroicon-o-x-circle @class(
37+
[
38+
"inline-block h-5 w-5 text-green-500" => $isTailwind,
39+
"d-inline-block text-success laravel-livewire-tables-btn-small" => $isBootstrap
40+
]
41+
)
42+
/>
43+
@else
44+
<x-heroicon-o-x-circle @class(
45+
[
46+
"inline-block h-5 w-5 text-red-500" => $isTailwind,
47+
"d-inline-block text-danger laravel-livewire-tables-btn-small" => $isBootstrap
48+
]
49+
)
50+
/>
5251
@endif
5352
@elseif ($type === 'yes-no')
5453
@if ($successValue === false)
@@ -58,4 +57,6 @@
5857
@endif
5958
@endif
6059
@endif
60+
@if($isToggleable && $toggleMethod != '')
61+
</button>
6162
@endif

src/Traits/Configuration/FooterConfiguration.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ public function setUseHeaderAsFooterDisabled(): self
4646
return $this;
4747
}
4848

49-
public function setFooterTrAttributes(callable $callback): self
49+
public function setFooterTrAttributes(\Closure $callback): self
5050
{
5151
$this->footerTrAttributesCallback = $callback;
5252

5353
return $this;
5454
}
5555

56-
public function setFooterTdAttributes(callable $callback): self
56+
public function setFooterTdAttributes(\Closure $callback): self
5757
{
5858
$this->footerTdAttributesCallback = $callback;
5959

src/Traits/Configuration/SecondaryHeaderConfiguration.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public function setSecondaryHeaderDisabled(): self
2525
return $this;
2626
}
2727

28-
public function setSecondaryHeaderTrAttributes(callable $callback): self
28+
public function setSecondaryHeaderTrAttributes(\Closure $callback): self
2929
{
3030
$this->secondaryHeaderTrAttributesCallback = $callback;
3131

3232
return $this;
3333
}
3434

35-
public function setSecondaryHeaderTdAttributes(callable $callback): self
35+
public function setSecondaryHeaderTdAttributes(\Closure $callback): self
3636
{
3737
$this->secondaryHeaderTdAttributesCallback = $callback;
3838

src/Traits/Configuration/TableAttributeConfiguration.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function setTbodyAttributes(array $attributes = []): self
6868
/**
6969
* Set a list of attributes to override on the th elements
7070
*/
71-
public function setThAttributes(callable $callback): self
71+
public function setThAttributes(\Closure $callback): self
7272
{
7373
$this->thAttributesCallback = $callback;
7474

@@ -78,7 +78,7 @@ public function setThAttributes(callable $callback): self
7878
/**
7979
* Set a list of attributes to override on the th sort button elements
8080
*/
81-
public function setThSortButtonAttributes(callable $callback): self
81+
public function setThSortButtonAttributes(\Closure $callback): self
8282
{
8383
$this->thSortButtonAttributesCallback = $callback;
8484

@@ -88,7 +88,7 @@ public function setThSortButtonAttributes(callable $callback): self
8888
/**
8989
* Set a list of attributes to override on the td elements
9090
*/
91-
public function setTrAttributes(callable $callback): self
91+
public function setTrAttributes(\Closure $callback): self
9292
{
9393
$this->trAttributesCallback = $callback;
9494

@@ -98,21 +98,21 @@ public function setTrAttributes(callable $callback): self
9898
/**
9999
* Set a list of attributes to override on the td elements
100100
*/
101-
public function setTdAttributes(callable $callback): self
101+
public function setTdAttributes(\Closure $callback): self
102102
{
103103
$this->tdAttributesCallback = $callback;
104104

105105
return $this;
106106
}
107107

108-
public function setTableRowUrl(callable $callback): self
108+
public function setTableRowUrl(\Closure $callback): self
109109
{
110110
$this->trUrlCallback = $callback;
111111

112112
return $this;
113113
}
114114

115-
public function setTableRowUrlTarget(callable $callback): self
115+
public function setTableRowUrlTarget(\Closure $callback): self
116116
{
117117
$this->trUrlTargetCallback = $callback;
118118

src/Traits/Helpers/ConfigurableAreasHelpers.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ public function hasConfigurableAreaFor(string $area): bool
2121
return isset($this->configurableAreas[$area]) && $this->getConfigurableAreaFor($area) !== null;
2222
}
2323

24-
/**
25-
* @param string|array<mixed> $area
26-
*/
27-
public function getConfigurableAreaFor($area): ?string
24+
public function getConfigurableAreaFor(string $area): ?string
2825
{
29-
$area = $this->configurableAreas[$area] ?? null;
26+
$area = array_key_exists($area, $this->configurableAreas) ? $this->configurableAreas[$area] : null;
3027

3128
if (is_array($area)) {
3229
return $area[0];
@@ -35,13 +32,9 @@ public function getConfigurableAreaFor($area): ?string
3532
return $area;
3633
}
3734

38-
/**
39-
* @param string|array<mixed> $area
40-
* @return array<mixed>
41-
*/
42-
public function getParametersForConfigurableArea($area): array
35+
public function getParametersForConfigurableArea(string $area): array
4336
{
44-
$area = $this->configurableAreas[$area] ?? null;
37+
$area = array_key_exists($area, $this->configurableAreas) ? $this->configurableAreas[$area] : null;
4538

4639
if (is_array($area) && isset($area[1]) && is_array($area[1])) {
4740
return $area[1];

src/Traits/Helpers/SearchHelpers.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ public function getSearchOptions(): string
123123

124124
public function getSearchPlaceholder(): string
125125
{
126-
return $this->hasSearchPlaceholder() ? $this->searchPlaceholder : __('Search');
126+
if ($this->hasSearchPlaceholder()) {
127+
return $this->searchPlaceholder;
128+
}
129+
130+
return __('Search');
127131
}
128132

129133
public function hasSearchPlaceholder(): bool

src/Traits/WithFooter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ trait WithFooter
1616

1717
protected bool $columnsWithFooter = false;
1818

19-
protected ?object $footerTrAttributesCallback;
19+
protected ?\Closure $footerTrAttributesCallback;
2020

21-
protected ?object $footerTdAttributesCallback;
21+
protected ?\Closure $footerTdAttributesCallback;
2222

2323
public function setupFooter(): void
2424
{

src/Traits/WithSecondaryHeader.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ trait WithSecondaryHeader
1414

1515
protected bool $columnsWithSecondaryHeader = false;
1616

17-
protected ?object $secondaryHeaderTrAttributesCallback;
17+
protected ?\Closure $secondaryHeaderTrAttributesCallback;
1818

19-
protected ?object $secondaryHeaderTdAttributesCallback;
19+
protected ?\Closure $secondaryHeaderTdAttributesCallback;
2020

2121
public function bootedWithSecondaryHeader(): void
2222
{

src/Traits/WithTableAttributes.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ trait WithTableAttributes
2121

2222
protected array $tbodyAttributes = [];
2323

24-
protected ?object $thAttributesCallback;
24+
protected ?\Closure $thAttributesCallback;
2525

26-
protected ?object $thSortButtonAttributesCallback;
26+
protected ?\Closure $thSortButtonAttributesCallback;
2727

28-
protected ?object $trAttributesCallback;
28+
protected ?\Closure $trAttributesCallback;
2929

30-
protected ?object $tdAttributesCallback;
30+
protected ?\Closure $tdAttributesCallback;
3131

32-
protected ?object $trUrlCallback;
32+
protected ?\Closure $trUrlCallback;
3333

34-
protected ?object $trUrlTargetCallback;
34+
protected ?\Closure $trUrlTargetCallback;
3535
}

src/Views/Columns/BooleanColumn.php

+11
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
use Rappasoft\LaravelLivewireTables\Views\Column;
88
use Rappasoft\LaravelLivewireTables\Views\Traits\Configuration\BooleanColumnConfiguration;
99
use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasCallback;
10+
use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasConfirmation;
1011
use Rappasoft\LaravelLivewireTables\Views\Traits\Helpers\BooleanColumnHelpers;
1112

1213
class BooleanColumn extends Column
1314
{
1415
use BooleanColumnConfiguration,
1516
BooleanColumnHelpers,
17+
HasConfirmation,
1618
HasCallback;
1719

1820
protected string $type = 'icons';
@@ -21,6 +23,10 @@ class BooleanColumn extends Column
2123

2224
protected string $view = 'livewire-tables::includes.columns.boolean';
2325

26+
protected bool $isToggleable = false;
27+
28+
protected ?string $toggleMethod;
29+
2430
public function getContents(Model $row): null|string|\Illuminate\Support\HtmlString|DataTableConfigurationException|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
2531
{
2632
if ($this->isLabel()) {
@@ -30,6 +36,11 @@ public function getContents(Model $row): null|string|\Illuminate\Support\HtmlStr
3036
$value = $this->getValue($row);
3137

3238
return view($this->getView())
39+
->withRowPrimaryKey($row->{$row->getKeyName()})
40+
->withIsToggleable($this->getIsToggleable())
41+
->withToggleMethod($this->getIsToggleable() ? $this->getToggleMethod() : '')
42+
->withHasConfirmMessage($this->hasConfirmMessage())
43+
->withConfirmMessage($this->hasConfirmMessage() ? $this->getConfirmMessage() : '')
3344
->withIsTailwind($this->isTailwind())
3445
->withIsBootstrap($this->isBootstrap())
3546
->withSuccessValue($this->getSuccessValue())

src/Views/Columns/ColorColumn.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ColorColumn extends Column
1717
ColorColumnHelpers;
1818
use HasDefaultStringValue;
1919

20-
public ?object $colorCallback = null;
20+
public ?\Closure $colorCallback;
2121

2222
protected string $view = 'livewire-tables::includes.columns.color';
2323

0 commit comments

Comments
 (0)