Skip to content

Commit d8ec4ce

Browse files
committed
Card actions for improved functionality
1 parent ff4bdba commit d8ec4ce

File tree

6 files changed

+1821
-2
lines changed

6 files changed

+1821
-2
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,44 @@ public function editAction(Action $action): Action
266266

267267
**Note:** If this method is not implemented, cards will be read-only and users won't be able to edit them.
268268

269+
### cardActions() - For adding custom actions to cards
270+
271+
If you want to add custom actions to each card (such as viewing details, archiving, marking as complete, etc.), implement this method:
272+
273+
```php
274+
use Filament\Actions\Action;
275+
use Filament\Actions\ActionGroup;
276+
277+
public function cardActions(ActionGroup $actionGroup): ActionGroup
278+
{
279+
return $actionGroup
280+
->actions([
281+
Action::make('view')
282+
->icon('heroicon-m-eye')
283+
->url(fn (mixed $record): string => route('tasks.show', ['task' => $record])),
284+
285+
Action::make('archive')
286+
->icon('heroicon-m-archive-box')
287+
->requiresConfirmation()
288+
->action(function (mixed $record): void {
289+
$task = $this->getSubject()->find($record);
290+
$task->update(['archived' => true]);
291+
$this->refreshBoard();
292+
}),
293+
294+
Action::make('complete')
295+
->icon('heroicon-m-check-circle')
296+
->action(function (mixed $record): void {
297+
$task = $this->getSubject()->find($record);
298+
$task->update(['status' => 'completed']);
299+
$this->refreshBoard();
300+
}),
301+
]);
302+
}
303+
```
304+
305+
**Note:** If this method is not implemented, no action dropdown will appear on cards. Actions can perform operations on the specific card record and can open modals, execute code, or navigate to other pages.
306+
269307
## 🧩 Optional Configuration
270308

271309
These settings enhance your board but are not required:

resources/dist/flowforge.css

Lines changed: 1729 additions & 1 deletion
Large diffs are not rendered by default.

resources/views/livewire/card.blade.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,22 @@
1313
@endif
1414
>
1515
<div class="ff-card__content">
16-
<h4 class="ff-card__title">{{ $record['title'] }}</h4>
16+
<div class="flex justify-between items-start">
17+
<h4 class="ff-card__title">{{ $record['title'] }}</h4>
18+
19+
@if($this->cardActions() && count($this->cardActions()->getActions()) > 0)
20+
<div class="ff-card__actions" onclick="event.stopPropagation();">
21+
<x-filament-actions::group
22+
:actions="$this->cardActions()->getActions()"
23+
:record="$record['id']"
24+
:action="$this->cardActions()"
25+
:color="$this->cardActions()->getColor()"
26+
:icon="$this->cardActions()->getIcon()"
27+
:size="$this->cardActions()->getSize()"
28+
/>
29+
</div>
30+
@endif
31+
</div>
1732

1833
@if(!empty($record['description']))
1934
<p class="ff-card__description">{{ $record['description'] }}</p>

src/Contracts/KanbanBoardPageInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Relaticle\Flowforge\Contracts;
66

77
use Filament\Actions\Action;
8+
use Filament\Actions\ActionGroup;
89
use Illuminate\Database\Eloquent\Builder;
910

1011
interface KanbanBoardPageInterface
@@ -14,4 +15,12 @@ public function getSubject(): Builder;
1415
// public function createAction(Action $action): Action;
1516
//
1617
// public function editAction(Action $action): Action;
18+
19+
/**
20+
* Define custom actions that will be displayed on each card.
21+
*
22+
* @param ActionGroup $actionGroup The action group to add actions to
23+
* @return ActionGroup The modified action group
24+
*/
25+
public function cardActions(ActionGroup $actionGroup): ActionGroup;
1726
}

src/Filament/Pages/KanbanBoardPage.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Relaticle\Flowforge\Filament\Pages;
66

7+
use Filament\Actions\ActionGroup;
78
use Filament\Pages\Page;
89
use Illuminate\Support\Str;
910
use Relaticle\Flowforge\Adapters\DefaultKanbanAdapter;
@@ -179,6 +180,17 @@ public function pluralCardLabel(string $label): static
179180
return $this;
180181
}
181182

183+
/**
184+
* Define custom actions that will be displayed on each card.
185+
*
186+
* @param ActionGroup $actionGroup The action group to add actions to
187+
* @return ActionGroup The modified action group
188+
*/
189+
public function cardActions(ActionGroup $actionGroup): ActionGroup
190+
{
191+
return $actionGroup;
192+
}
193+
182194
/**
183195
* Get the Kanban adapter.
184196
*

src/Livewire/KanbanBoard.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Relaticle\Flowforge\Livewire;
66

77
use Filament\Actions\Action;
8+
use Filament\Actions\ActionGroup;
89
use Filament\Actions\Concerns\InteractsWithActions;
910
use Filament\Actions\Contracts\HasActions;
1011
use Filament\Forms\Concerns\InteractsWithForms;
@@ -206,6 +207,22 @@ public function createAction(): ?Action
206207
return $boardPage->createAction($action);
207208
}
208209

210+
public function cardActions(): ?ActionGroup
211+
{
212+
$boardPage = app($this->pageClass);
213+
214+
if (! method_exists($boardPage, 'cardActions')) {
215+
return null;
216+
}
217+
218+
$actionGroup = ActionGroup::make([])
219+
->icon('heroicon-m-ellipsis-horizontal')
220+
->size('sm')
221+
->iconButton();
222+
223+
return $boardPage->cardActions($actionGroup);
224+
}
225+
209226
public function editAction(): ?Action
210227
{
211228
$boardPage = app($this->pageClass);

0 commit comments

Comments
 (0)