Skip to content

Commit ae1cee2

Browse files
committed
docs: add CardFlex, events, filter options, override patterns, enum support
1 parent 9b08f88 commit ae1cee2

File tree

4 files changed

+187
-3
lines changed

4 files changed

+187
-3
lines changed

docs/content/2.essentials/1.integration-patterns.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,62 @@ public static function getPages(): array
153153
}
154154
```
155155

156-
**Use when:** Adding Kanban views to existing Filament resources
156+
**Use when:** Adding Kanban views to existing Filament resources
157157
**Benefits:** Inherits resource permissions, policies, and global scopes automatically
158+
159+
## Extending Board Behavior
160+
161+
Override these methods to customize board behavior for your specific needs.
162+
163+
### Custom Card Movement Logic
164+
165+
Override `moveCard()` to add custom logic when cards are moved:
166+
167+
```php
168+
public function moveCard(
169+
string $cardId,
170+
string $targetColumnId,
171+
?string $afterCardId = null,
172+
?string $beforeCardId = null
173+
): void {
174+
// Call parent to handle the actual move
175+
parent::moveCard($cardId, $targetColumnId, $afterCardId, $beforeCardId);
176+
177+
// Add custom logic
178+
$task = Task::find($cardId);
179+
180+
if ($targetColumnId === 'completed') {
181+
$task->update(['completed_at' => now()]);
182+
$task->assignee->notify(new TaskCompletedNotification($task));
183+
}
184+
}
185+
```
186+
187+
### Custom Record Fetching
188+
189+
Override `getBoardRecords()` for complex filtering logic:
190+
191+
```php
192+
public function getBoardRecords(string $columnId): \Illuminate\Support\Collection
193+
{
194+
return $this->getEloquentQuery()
195+
->where($this->getBoard()->getColumnIdentifier(), $columnId)
196+
->where('team_id', auth()->user()->current_team_id) // Custom filter
197+
->with(['assignee', 'priority', 'labels']) // Eager loading
198+
->orderBy($this->getBoard()->getPositionIdentifier())
199+
->get();
200+
}
201+
```
202+
203+
### Custom Count Logic
204+
205+
Override `getBoardRecordCount()` if you need custom counting:
206+
207+
```php
208+
public function getBoardRecordCount(string $columnId): int
209+
{
210+
return $this->getEloquentQuery()
211+
->where($this->getBoard()->getColumnIdentifier(), $columnId)
212+
->where('is_archived', false) // Exclude archived from count
213+
->count();
214+
}

docs/content/2.essentials/2.customization.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,61 @@ public function board(Board $board): Board
3131
}
3232
```
3333

34+
## CardFlex Layout
35+
36+
Use `CardFlex` to arrange multiple elements in a flexible row with intelligent wrapping:
37+
38+
```php
39+
use Filament\Infolists\Components\TextEntry;
40+
use Filament\Infolists\Components\ImageEntry;
41+
use Relaticle\Flowforge\Components\CardFlex;
42+
43+
->cardSchema(fn (Schema $schema) => $schema->components([
44+
TextEntry::make('title')->weight('bold'),
45+
CardFlex::make([
46+
TextEntry::make('priority')->badge(),
47+
TextEntry::make('due_date')->icon('heroicon-o-calendar'),
48+
ImageEntry::make('assignee.avatar_url')->circular()->size(24),
49+
])
50+
->wrap() // Enable wrapping on small screens
51+
->justify('between') // Horizontal: 'start', 'end', 'between', 'center'
52+
->align('center'), // Vertical: 'start', 'end', 'center'
53+
]))
54+
```
55+
56+
### CardFlex Options
57+
58+
| Method | Description | Default |
59+
|--------|-------------|---------|
60+
| `wrap(bool $wrap = true)` | Enable/disable wrapping | `false` |
61+
| `justify(string $justify)` | Horizontal alignment | `'start'` |
62+
| `align(string $align)` | Vertical alignment | `'start'` |
63+
64+
### Real-World Example
65+
66+
```php
67+
->cardSchema(fn (Schema $schema) => $schema->components([
68+
TextEntry::make('title')
69+
->weight('bold')
70+
->size('lg'),
71+
TextEntry::make('description')
72+
->limit(100)
73+
->color('gray'),
74+
CardFlex::make([
75+
TextEntry::make('priority')
76+
->badge()
77+
->icon('heroicon-o-flag'),
78+
TextEntry::make('due_date')
79+
->badge()
80+
->date()
81+
->icon('heroicon-o-calendar'),
82+
TextEntry::make('assignedTo.name')
83+
->badge()
84+
->icon('heroicon-o-user'),
85+
])->wrap()->justify('start'),
86+
]))
87+
```
88+
3489
## Column Actions
3590

3691
Add actions to column headers for creating new cards or bulk operations:

docs/content/2.essentials/3.database-schema.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,37 @@ Schema::create('tasks', function (Blueprint $table) {
1919
});
2020
```
2121

22+
## Enum Support
23+
24+
Flowforge automatically handles PHP `BackedEnum` for status fields. No manual conversion needed:
25+
26+
```php
27+
// Define your enum
28+
enum TaskStatus: string
29+
{
30+
case Todo = 'todo';
31+
case InProgress = 'in_progress';
32+
case Done = 'done';
33+
}
34+
35+
// Cast in your model
36+
class Task extends Model
37+
{
38+
protected $casts = [
39+
'status' => TaskStatus::class,
40+
];
41+
}
42+
43+
// Flowforge automatically converts column IDs to enum values
44+
Column::make('todo') // → TaskStatus::Todo
45+
Column::make('in_progress') // → TaskStatus::InProgress
46+
Column::make('done') // → TaskStatus::Done
47+
```
48+
49+
::callout{type="info"}
50+
When a card moves between columns, Flowforge detects the `BackedEnum` cast and converts the column identifier to the appropriate enum value automatically.
51+
::
52+
2253
## Position Column
2354

2455
The `flowforgePositionColumn()` method creates a `DECIMAL(20,10)` column for drag-and-drop functionality:

docs/content/2.essentials/4.api-reference.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ navigation:
2020
| `searchable(array)` | Enable search on specified fields | |
2121
| `filters(array)` | Add filtering capabilities | |
2222
| `cardAction(string)` | Make cards clickable with action | |
23+
| `cardsPerColumn(int)` | Cards to load per column (pagination) | |
24+
| `filtersFormWidth(Width)` | Filter panel width | |
25+
| `filtersFormColumns(int)` | Columns in filter form | |
2326

2427
## Board Methods
2528

@@ -125,7 +128,45 @@ $this->getBoardPositionInColumn(string $columnId): string
125128
## Performance Features
126129

127130
- **Intelligent Pagination**: Efficiently handles 100+ cards per column
128-
- **Infinite Scroll**: Smooth loading with 80% scroll threshold
131+
- **Infinite Scroll**: Smooth loading with 80% scroll threshold
129132
- **Optimistic UI**: Immediate feedback with rollback on errors
130133
- **Fractional Ranking**: Prevents database locks during reordering
131-
- **Query Optimization**: Cursor-based pagination with eager loading
134+
- **Query Optimization**: Cursor-based pagination with eager loading
135+
136+
## Livewire Events
137+
138+
Flowforge dispatches these events for frontend integration and custom logic:
139+
140+
| Event | Payload | When Fired |
141+
|-------|---------|------------|
142+
| `kanban-card-moved` | `cardId`, `columnId`, `position` | After a card is moved |
143+
| `kanban-items-loaded` | `columnId`, `loadedCount`, `totalCount`, `isFullyLoaded` | After pagination loads more cards |
144+
| `kanban-all-items-loaded` | `columnId`, `totalCount` | After "Load All" completes |
145+
146+
### Listening to Events
147+
148+
```php
149+
use Livewire\Attributes\On;
150+
151+
#[On('kanban-card-moved')]
152+
public function onCardMoved(string $cardId, string $columnId, string $position): void
153+
{
154+
// Custom logic when a card moves (e.g., send notification, update analytics)
155+
}
156+
157+
#[On('kanban-items-loaded')]
158+
public function onItemsLoaded(string $columnId, int $loadedCount, int $totalCount, bool $isFullyLoaded): void
159+
{
160+
// Track loading progress
161+
}
162+
```
163+
164+
### JavaScript Listeners
165+
166+
```javascript
167+
document.addEventListener('livewire:init', () => {
168+
Livewire.on('kanban-card-moved', ({ cardId, columnId }) => {
169+
console.log(`Card ${cardId} moved to ${columnId}`);
170+
});
171+
});
172+
```

0 commit comments

Comments
 (0)