Skip to content

Commit 4f44616

Browse files
committed
Update README.md
(cherry picked from commit 6bea472)
1 parent 5076efd commit 4f44616

File tree

1 file changed

+142
-6
lines changed

1 file changed

+142
-6
lines changed

README.md

Lines changed: 142 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Demo password : 12345678
1818
Auto Reset every hour.
1919

2020
## Supported Filament versions
21+
2122
| Filament Version | Plugin Version |
22-
|------------------|----------------|
23+
| ---------------- | -------------- |
2324
| v3 | 2.x.x |
2425
| v4 | 3.x.x |
2526

@@ -47,7 +48,7 @@ Add the plugin's views and css to your `theme.css` file.
4748
@import '<path-to-vendor>/solution-forest/filament-tree/resources/css/jquery.nestable.css';
4849
@import '<path-to-vendor>/solution-forest/filament-tree/resources/css/button.css';
4950
@import '<path-to-vendor>/solution-forest/filament-tree/resources/css/custom-nestable-item.css';
50-
@source '<path-to-vendor>/solution-forest/filament-tree/resources/**/*.blade.php'
51+
@source '<path-to-vendor>/solution-forest/filament-tree/resources/**/*.blade.php';
5152
```
5253

5354
Then, publish the config file using:
@@ -325,14 +326,16 @@ The `getActions()` method defines actions that are displayed next to the page's
325326
The `getTreeActions()` method defines the actions that are displayed for each record in the tree. For example:
326327

327328
```php
328-
use Filament\Pages\Actions\Action;
329+
use SolutionForest\FilamentTree\Actions\DeleteAction;
330+
use SolutionForest\FilamentTree\Actions\EditAction;
331+
use SolutionForest\FilamentTree\Actions\ViewAction;
329332

330333
protected function getTreeActions(): array
331334
{
332335
return [
333-
Actions\ViewAction::make(),
334-
Actions\EditAction::make(),
335-
Actions\DeleteAction::make(),
336+
ViewAction::make(),
337+
EditAction::make(),
338+
DeleteAction::make(),
336339
];
337340
}
338341

@@ -408,6 +411,139 @@ public function getTreeRecordTitle(?\Illuminate\Database\Eloquent\Model $record
408411
}
409412
```
410413

414+
#### Configuring Tree Item Actions
415+
416+
You can customize the behavior and appearance of tree item actions (Delete, Edit, and View) by overriding the configuration methods in your widget or page class. Each action type has its own configuration method:
417+
418+
##### Configure Delete Action
419+
420+
Override the `configureDeleteAction()` method to customize the delete action:
421+
422+
```php
423+
protected function configureDeleteAction(DeleteAction $action): DeleteAction
424+
{
425+
$action
426+
->label('Remove Item')
427+
->icon('heroicon-o-trash')
428+
->color('danger')
429+
->requiresConfirmation()
430+
->modalHeading('Delete Category')
431+
->modalDescription('Are you sure you want to delete this category? This action cannot be undone.')
432+
->modalSubmitActionLabel('Yes, delete it');
433+
434+
return $action;
435+
}
436+
```
437+
438+
##### Configure Edit Action
439+
440+
Override the `configureEditAction()` method to customize the edit action:
441+
442+
```php
443+
protected function configureEditAction(EditAction $action): EditAction
444+
{
445+
$action
446+
->label('Edit Item')
447+
->icon('heroicon-o-pencil')
448+
->color('primary')
449+
->modalHeading('Edit Category')
450+
->modalSubmitActionLabel('Save Changes')
451+
->slideOver();
452+
453+
return $action;
454+
}
455+
```
456+
457+
##### Configure View Action
458+
459+
Override the `configureViewAction()` method to customize the view action:
460+
461+
```php
462+
protected function configureViewAction(ViewAction $action): ViewAction
463+
{
464+
$action
465+
->label('View Details')
466+
->icon('heroicon-o-eye')
467+
->color('secondary')
468+
->modalHeading('Category Details')
469+
->modalWidth('2xl')
470+
->slideOver();
471+
472+
return $action;
473+
}
474+
```
475+
476+
##### Example: Complete Action Configuration
477+
478+
Here's a complete example showing how to configure all three actions in a tree widget:
479+
480+
```php
481+
<?php
482+
483+
namespace App\Filament\Widgets;
484+
485+
use App\Models\ProductCategory;
486+
use Filament\Forms\Components\TextInput;
487+
use SolutionForest\FilamentTree\Actions\DeleteAction;
488+
use SolutionForest\FilamentTree\Actions\EditAction;
489+
use SolutionForest\FilamentTree\Actions\ViewAction;
490+
use SolutionForest\FilamentTree\Widgets\Tree as BaseWidget;
491+
492+
class ProductCategoryWidget extends BaseWidget
493+
{
494+
protected static string $model = ProductCategory::class;
495+
496+
protected function getFormSchema(): array
497+
{
498+
return [
499+
TextInput::make('title')->required(),
500+
];
501+
}
502+
503+
protected function hasDeleteAction(): bool
504+
{
505+
return true;
506+
}
507+
508+
protected function hasEditAction(): bool
509+
{
510+
return true;
511+
}
512+
513+
protected function hasViewAction(): bool
514+
{
515+
return true;
516+
}
517+
518+
protected function configureDeleteAction(DeleteAction $action): DeleteAction
519+
{
520+
$action
521+
->requiresConfirmation()
522+
->modalDescription('This will permanently delete the category and all its subcategories.');
523+
524+
return $action;
525+
}
526+
527+
protected function configureEditAction(EditAction $action): EditAction
528+
{
529+
$action
530+
->slideOver()
531+
->modalWidth('md');
532+
533+
return $action;
534+
}
535+
536+
protected function configureViewAction(ViewAction $action): ViewAction
537+
{
538+
$action
539+
->slideOver()
540+
->disabled(fn ($record) => $record->parent_id === -1); // Disable for root items
541+
542+
return $action;
543+
}
544+
}
545+
```
546+
411547
### Pages
412548

413549
This plugin enables you to create tree pages in the admin panel. To create a tree page for a model, use the `make:filament-tree-page` command. For example, to create a tree page for the ProductCategory model, you can run:

0 commit comments

Comments
 (0)