Skip to content

Commit ecf1fee

Browse files
authored
v3.4.14 (rappasoft#1890)
## [v3.4.14] - 2024-08-25 ### New Features - Migrate Action to Helper/Configuration and Set Action Position (Left/Center/Right) and Set Actions in Toolbar by @lrljoe in rappasoft#1889
1 parent ed00338 commit ecf1fee

File tree

12 files changed

+380
-62
lines changed

12 files changed

+380
-62
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## [v3.4.14] - 2024-08-25
6+
### New Features
7+
- Set Action Position (Left/Center/Right) and Set Actions in Toolbar by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1889
8+
59
## [v3.4.13] - 2024-08-25
610
### Bug Fixes
711
- Fix for Action Button with no icon by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1887

docs/misc/actions.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,61 @@ This is used to set attributes for the "div" that wraps all defined Action Butto
2121
}
2222
```
2323

24+
### setActionsInToolbarEnabled
25+
26+
Displays the Actions within the Toolbar. Default is displaying above the Toolbar.
27+
28+
```php
29+
public function configure(): void
30+
{
31+
$this->setActionsInToolbarEnabled();
32+
}
33+
```
34+
35+
### setActionsInToolbarDisabled
36+
37+
Displays the Actions above the Toolbar, default behaviour
38+
```php
39+
public function configure(): void
40+
{
41+
$this->setActionsInToolbarDisabled();
42+
}
43+
```
44+
45+
46+
### setActionsLeft
47+
48+
Displays the Actions justified to the left
49+
50+
```php
51+
public function configure(): void
52+
{
53+
$this->setActionsLeft();
54+
}
55+
```
56+
57+
### setActionsCenter
58+
59+
Displays the Actions justified to the center
60+
61+
```php
62+
public function configure(): void
63+
{
64+
$this->setActionsCenter();
65+
}
66+
```
67+
68+
### setActionsRight
69+
70+
Displays the Actions justified to the right
71+
72+
```php
73+
public function configure(): void
74+
{
75+
$this->setActionsRight();
76+
}
77+
```
78+
2479
### actions()
2580

2681
Define your actions using the actions() method:

resources/views/components/includes/actions.blade.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<div {{ $attributes
2-
->merge($this->getActionWrapperAttributes())
3-
->class(['flex flex-cols justify-center' => $this->isTailwind && $this->getActionWrapperAttributes()['default-styling'] ?? true])
4-
->class(['' => $this->isTailwind && $this->getActionWrapperAttributes()['default-colors'] ?? true])
5-
->class(['d-flex flex-cols justify-center' => $this->isBootstrap && $this->getActionWrapperAttributes()['default-styling'] ?? true])
6-
->class(['' => $this->isBootstrap && $this->getActionWrapperAttributes()['default-colors'] ?? true])
2+
->merge($this->getActionWrapperAttributes)
3+
->class(['flex flex-cols py-2 space-x-2' => $this->isTailwind && $this->getActionWrapperAttributes['default-styling'] ?? true])
4+
->class(['' => $this->isTailwind && $this->getActionWrapperAttributes['default-colors'] ?? true])
5+
->class(['d-flex flex-cols py-2 space-x-2' => $this->isBootstrap && $this->getActionWrapperAttributes['default-styling'] ?? true])
6+
->class(['' => $this->isBootstrap && $this->getActionWrapperAttributes['default-colors'] ?? true])
7+
->class(['justify-start' => $this->getActionsPosition == 'left'])
8+
->class(['justify-center' => $this->getActionsPosition == 'center'])
9+
->class(['justify-end' => $this->getActionsPosition == 'right'])
10+
->class(['pl-2' => $this->showActionsInToolbar && $this->getActionsPosition == 'left'])
11+
->class(['pr-2' => $this->showActionsInToolbar && $this->getActionsPosition == 'right'])
712
->except(['default-styling','default-colors'])
813
}} >
914
@foreach($this->getActions as $action)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<x-livewire-tables::tools.toolbar.items.filter-button />
3737
@endif
3838

39+
@if($this->hasActions && $this->showActionsInToolbar && $this->getActionsPosition == 'left')
40+
<x-livewire-tables::includes.actions/>
41+
@endif
42+
3943
@if ($this->hasConfigurableAreaFor('toolbar-left-end'))
4044
<div x-cloak x-show="!currentlyReorderingStatus" @class([
4145
'mb-3 mb-md-0 input-group' => $this->isBootstrap,
@@ -56,6 +60,10 @@
5660
@include($this->getConfigurableAreaFor('toolbar-right-start'), $this->getParametersForConfigurableArea('toolbar-right-start'))
5761
@endif
5862

63+
@if($this->hasActions && $this->showActionsInToolbar && $this->getActionsPosition == 'right')
64+
<x-livewire-tables::includes.actions/>
65+
@endif
66+
5967
@if ($this->showBulkActionsDropdownAlpine() && $this->shouldAlwaysHideBulkActionsDropdownOption != true)
6068
<x-livewire-tables::tools.toolbar.items.bulk-actions />
6169
@endif

resources/views/datatable.blade.php

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

99
<div x-data="laravellivewiretable($wire, '{{ $this->showBulkActionsDropdownAlpine() }}', '{{ $tableId }}', '{{ $primaryKey }}')">
1010
<x-livewire-tables::wrapper :component="$this" :tableName="$tableName" :$primaryKey :$isTailwind :$isBootstrap :$isBootstrap4 :$isBootstrap5>
11-
@if(method_exists($this,'hasActions') && $this->hasActions())
11+
@if($this->hasActions && !$this->showActionsInToolbar)
1212
<x-livewire-tables::includes.actions/>
1313
@endif
1414

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Configuration;
4+
5+
trait ActionsConfiguration
6+
{
7+
public function setActionWrapperAttributes(array $actionWrapperAttributes): self
8+
{
9+
$this->actionWrapperAttributes = [...$this->actionWrapperAttributes, ...$actionWrapperAttributes];
10+
11+
return $this;
12+
}
13+
14+
public function setActionsInToolbar(bool $status): self
15+
{
16+
$this->displayActionsInToolbar = $status;
17+
18+
return $this;
19+
}
20+
21+
public function setActionsInToolbarEnabled(): self
22+
{
23+
return $this->setActionsInToolbar(true);
24+
}
25+
26+
public function setActionsInToolbarDisabled(): self
27+
{
28+
return $this->setActionsInToolbar(false);
29+
}
30+
31+
protected function setActionsPosition(string $position): self
32+
{
33+
$this->actionsPosition = ($position == 'left' || $position == 'center' || $position == 'right') ? $position : 'right';
34+
35+
return $this;
36+
}
37+
38+
public function setActionsLeft(): self
39+
{
40+
return $this->setActionsPosition('left');
41+
}
42+
43+
public function setActionsCenter(): self
44+
{
45+
return $this->setActionsPosition('center');
46+
}
47+
48+
public function setActionsRight(): self
49+
{
50+
return $this->setActionsPosition('right');
51+
}
52+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Helpers;
4+
5+
use Illuminate\Support\Collection;
6+
use Livewire\Attributes\Computed;
7+
use Rappasoft\LaravelLivewireTables\Views\Action;
8+
9+
trait ActionsHelpers
10+
{
11+
#[Computed]
12+
public function showActionsInToolbar(): bool
13+
{
14+
return $this->displayActionsInToolbar ?? false;
15+
}
16+
17+
#[Computed]
18+
public function getActionsPosition(): string
19+
{
20+
return $this->actionsPosition ?? 'right';
21+
}
22+
23+
#[Computed]
24+
public function getActionWrapperAttributes(): array
25+
{
26+
return [...['class' => '', 'default-styling' => true, 'default-colors' => true], ...$this->actionWrapperAttributes];
27+
}
28+
29+
#[Computed]
30+
public function hasActions(): bool
31+
{
32+
return (new Collection($this->actions()))
33+
->filter(fn ($action) => $action instanceof Action)->count() > 0;
34+
}
35+
36+
#[Computed]
37+
public function getActions(): Collection
38+
{
39+
return (new Collection($this->actions()))
40+
->filter(fn ($action) => $action instanceof Action)
41+
->each(function (Action $action, int $key) {
42+
$action->setTheme($this->getTheme());
43+
});
44+
45+
}
46+
}

src/Traits/WithActions.php

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,22 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Traits;
44

5-
use Illuminate\Support\Collection;
6-
use Livewire\Attributes\Computed;
7-
use Rappasoft\LaravelLivewireTables\Views\Action;
5+
use Rappasoft\LaravelLivewireTables\Traits\Configuration\ActionsConfiguration;
6+
use Rappasoft\LaravelLivewireTables\Traits\Helpers\ActionsHelpers;
87

98
trait WithActions
109
{
11-
protected array $actionWrapperAttributes = ['default-styling' => true, 'default-colors' => true];
10+
use ActionsConfiguration,
11+
ActionsHelpers;
1212

13-
protected function actions(): array
14-
{
15-
return [];
16-
}
13+
protected array $actionWrapperAttributes = ['class' => '', 'default-styling' => true, 'default-colors' => true];
1714

18-
public function setActionWrapperAttributes(array $actionWrapperAttributes): self
19-
{
20-
$this->actionWrapperAttributes = [...['default-styling' => true, 'default-colors' => true], ...$actionWrapperAttributes];
15+
protected bool $displayActionsInToolbar = false;
2116

22-
return $this;
23-
}
17+
protected string $actionsPosition = 'right';
2418

25-
#[Computed]
26-
public function getActionWrapperAttributes(): array
27-
{
28-
return [...['default-styling' => true, 'default-colors' => true], ...$this->actionWrapperAttributes];
29-
}
30-
31-
#[Computed]
32-
public function hasActions(): bool
33-
{
34-
return (new Collection($this->actions()))
35-
->filter(fn ($action) => $action instanceof Action)->count() > 0;
36-
}
37-
38-
#[Computed]
39-
public function getActions(): Collection
19+
protected function actions(): array
4020
{
41-
return (new Collection($this->actions()))
42-
->filter(fn ($action) => $action instanceof Action)
43-
->each(function (Action $action, int $key) {
44-
$action->setTheme($this->getTheme());
45-
});
46-
21+
return [];
4722
}
4823
}

src/Views/Traits/Actions/HasActionAttributes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66

77
trait HasActionAttributes
88
{
9-
protected array $actionAttributes = ['default-styling' => true, 'default-colors' => true];
9+
protected array $actionAttributes = ['class' => '', 'default-styling' => true, 'default-colors' => true];
1010

1111
public function setActionAttributes(array $actionAttributes): self
1212
{
13-
$this->actionAttributes = [...['default-styling' => true, 'default-colors' => true], ...$actionAttributes];
13+
$this->actionAttributes = [...$this->actionAttributes, ...$actionAttributes];
1414

1515
return $this;
1616
}
1717

1818
public function getActionAttributes(): ComponentAttributeBag
1919
{
20-
$actionAttributes = [...['default-styling' => true, 'default-colors' => true], ...$this->actionAttributes];
20+
$actionAttributes = [...['class' => '', 'default-styling' => true, 'default-colors' => true], ...$this->actionAttributes];
2121

2222
if (! $this->hasWireAction() && method_exists($this, 'getRoute')) {
2323
$actionAttributes['href'] = $this->getRoute();

src/Views/Traits/Core/HasIcon.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait HasIcon
99
{
1010
public ?string $icon;
1111

12-
public array $iconAttributes = ['default-styling' => true];
12+
public array $iconAttributes = ['class' => '', 'default-styling' => true];
1313

1414
public bool $iconRight = true;
1515

@@ -32,14 +32,14 @@ public function getIcon(): string
3232

3333
public function setIconAttributes(array $iconAttributes): self
3434
{
35-
$this->iconAttributes = [...['default-styling' => true], ...$iconAttributes];
35+
$this->iconAttributes = [...$this->iconAttributes, ...$iconAttributes];
3636

3737
return $this;
3838
}
3939

4040
public function getIconAttributes(): ComponentAttributeBag
4141
{
42-
return new ComponentAttributeBag([...['default-styling' => true], ...$this->iconAttributes]);
42+
return new ComponentAttributeBag([...['class' => '', 'default-styling' => true], ...$this->iconAttributes]);
4343
}
4444

4545
public function getIconRight(): bool

0 commit comments

Comments
 (0)