Skip to content

Commit ebd4637

Browse files
authored
Merge pull request #87 from solutionforest/feature/add_toolbar_actions
Feature/add toolbar actions
2 parents a534833 + 707db9b commit ebd4637

31 files changed

+442
-692
lines changed

.github/copilot-instructions.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ public function getTreeRecordIcon(?Model $record = null): ?string
119119
}
120120
```
121121

122+
**Toolbar Actions**: Add global actions displayed above the tree:
123+
124+
```php
125+
protected function getTreeToolbarActions(): array
126+
{
127+
return [
128+
CreateAction::make(),
129+
ExportAction::make(),
130+
ImportAction::make(),
131+
];
132+
}
133+
```
134+
135+
> **Note**: Toolbar actions are only supported in version 3.1.0 and later.
136+
122137
## Key File Locations
123138

124139
- Models: Add `ModelTree` trait to any hierarchical model

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
> [!IMPORTANT]
2-
> Please note that we will only be updating to version 2.x or 3.x, excluding any bug fixes.
2+
> Please note that we will only be updating to version 3.x, excluding any bug fixes.
33
44
# Filament Tree
55

@@ -544,6 +544,34 @@ class ProductCategoryWidget extends BaseWidget
544544
}
545545
```
546546

547+
#### Toolbar Actions
548+
549+
You can add global actions that appear in the toolbar above the tree by implementing the `getTreeToolbarActions()` method. These actions are displayed alongside the default expand/collapse and save buttons:
550+
551+
```php
552+
protected function getTreeToolbarActions(): array
553+
{
554+
return [
555+
\SolutionForest\FilamentTree\Actions\CreateAction::make()
556+
->label('Add Category')
557+
->icon('heroicon-o-plus')
558+
->color('primary'),
559+
\Filament\Actions\ExportAction::make()
560+
->label('Export Tree')
561+
->icon('heroicon-o-document-arrow-down'),
562+
\Filament\Actions\ImportAction::make()
563+
->label('Import Tree')
564+
->icon('heroicon-o-document-arrow-up'),
565+
];
566+
}
567+
```
568+
569+
![Tree toolbar actions](https://github.com/user-attachments/assets/6d2e29c0-caa3-432c-8a7f-00ae7d7265ba)
570+
571+
The toolbar actions are automatically generated by the Artisan command and include a `CreateAction` by default for tree widgets, but return an empty array for tree pages. You can customize this method to add any actions you need.
572+
573+
> **Note**: Toolbar actions are only supported in version 3.1.0 and later.
574+
547575
### Pages
548576

549577
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:

resources/css/custom-nestable-item.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,15 @@
106106
}
107107

108108
.filament-tree-component .nestable-menu {
109-
@apply flex gap-2 mb-4;
109+
@apply mb-4;
110+
}
111+
.filament-tree-component .nestable-menu,
112+
.filament-tree-component .nestable-menu .toolbar-btns {
113+
@apply flex items-center gap-2;
114+
}
115+
.filament-tree-component .nestable-menu {
116+
@apply justify-between;
117+
}
118+
.filament-tree-component .nestable-menu .toolbar-btns.main {
119+
@apply flex-1;
110120
}

resources/dist/filament-tree.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1 @@
1-
<x-filament-tree::actions.action
2-
:action="$action"
3-
dynamic-component="filament::button"
4-
:outlined="$isOutlined()"
5-
:labeled-from="$getLabeledFromBreakpoint()"
6-
:icon-position="$getIconPosition()"
7-
:icon-size="$getIconSize()"
8-
class="filament-tree-button-action"
9-
>
10-
{{ $getLabel() }}
11-
</x-filament-tree::actions.action>
12-
1+
{{-- Deprecated with filament v4 --}}
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
<x-filament-actions::group
2-
:actions="$getActions()"
3-
:dark-mode="config('filament.dark_mode')"
4-
:color="$getColor()"
5-
:icon="$getIcon()"
6-
:label="$getLabel()"
7-
:size="$getSize()"
8-
:tooltip="$getTooltip()"
9-
/>
1+
{{-- Deprecated with filament v4 --}}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
<x-filament-tree::actions.action
2-
:action="$action"
3-
dynamic-component="filament::dropdown.list.item"
4-
:icon="$getGroupedIcon()"
5-
class="filament-grouped-action"
6-
>
7-
{{ $getLabel() }}
8-
</x-filament-tree::actions.action>
1+
{{-- Deprecated with filament v4 --}}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
<x-filament-tree::actions.action
2-
:action="$action"
3-
:label="$getLabel()"
4-
dynamic-component="filament::icon-button"
5-
class="filament-tree-icon-button-action"
6-
/>
1+
{{-- Deprecated with filament v4 --}}
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
<x-filament-tree::actions.action
2-
:action="$action"
3-
dynamic-component="filament::link"
4-
:icon-position="$getIconPosition()"
5-
:icon-size="$getIconSize()"
6-
class="filament-tree-link-action"
7-
>
8-
{{ $getLabel() }}
9-
</x-filament-tree::actions.action>
1+
{{-- Deprecated with filament v4 --}}

0 commit comments

Comments
 (0)