alfasix / alfakit-tree
Drag-and-drop, keyboard-accessible tree pages and widgets for hierarchical Eloquent models in AlfaKit panels.
Requires
- php: ^8.4
- alfasix/alfakit: ^0.2|@dev
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
by Alfa Six
This is a read-only split of the AlfaKit monorepo. Please open issues and pull requests there.
Hierarchical records as a drag-and-drop, keyboard-accessible tree in AlfaKit panels: a resource page, a dashboard widget and a model trait. The API follows solution-forest/filament-tree.
Installation
composer require alfasix/alfakit-tree
The tree component is built into @alfakit/react, @alfakit/vue and @alfakit/svelte.
Register
use AlfaSix\AlfakitTree\TreePlugin; $panel->plugin(TreePlugin::make());
Usage
The model needs a nullable parent_id and an integer order column:
use AlfaSix\AlfakitTree\Concerns\HasTreeStructure; class Category extends Model { use HasTreeStructure; }
A tree page for a resource:
use AlfaSix\AlfakitTree\Pages\TreePage; class CategoryTree extends TreePage { protected static string $resource = CategoryResource::class; protected static ?int $maxDepth = 3; } // CategoryResource::getPages() 'index' => CategoryTree::route('/'),
Or a widget:
use AlfaSix\AlfakitTree\Widgets\TreeWidget; class MenuTree extends TreeWidget { protected static ?string $model = MenuItem::class; protected ?string $heading = 'Menu'; }
Users drag nodes, use the move buttons or Alt + arrow keys, then save the new structure in one request; the server checks the reorder ability, the tenant and the structure (no cycles, no duplicates, at most maxDepth levels).
See the documentation for every option.
License
MIT. See LICENSE.md.