Skip to content

Commit 1a31977

Browse files
committed
Allow custom display title and description
1 parent 86f468e commit 1a31977

File tree

5 files changed

+54
-13
lines changed

5 files changed

+54
-13
lines changed

resources/dist/filament-tree.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@props(['title', 'icon', 'description', 'record'])
2+
@php
3+
use Illuminate\Support\HtmlString;
4+
@endphp
5+
6+
<div
7+
{{
8+
$attributes->merge([
9+
'class' => 'flex items-center flex-1 gap-1'
10+
])
11+
}}>
12+
@if ($icon)
13+
<div class="w-4">
14+
<x-dynamic-component :component="$icon" class="w-4 h-4"/>
15+
</div>
16+
@endif
17+
18+
<div @class([
19+
'ml-4 rtl:mr-4' => !$icon,
20+
'flex-1',
21+
])>
22+
<span @class([
23+
'font-semibold',
24+
])>
25+
{{ str($title)->sanitizeHtml()->toHtmlString() }}
26+
</span>
27+
28+
@if ($description && (is_string($description) || $description instanceof HtmlString))
29+
@if (is_string($description))
30+
<span class="text-gray-500 dark:text-gray-400 text-sm truncate">
31+
{{ str($description)->sanitizeHtml()->toHtmlString() }}
32+
</span>
33+
34+
@else
35+
{!! $description->toHtml() !!}
36+
@endif
37+
38+
@endif
39+
</div>
40+
41+
</div>

resources/views/components/tree/item.blade.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@php use Illuminate\Database\Eloquent\Model; @endphp
22
@php use Filament\Facades\Filament; @endphp
33
@php use SolutionForest\FilamentTree\Components\Tree; @endphp
4-
@props(['record', 'containerKey', 'tree', 'title' => null, 'icon' => null])
4+
@props(['record', 'containerKey', 'tree', 'title' => null, 'icon' => null, 'description' => null])
55
@php
66
/** @var $record Model */
77
/** @var $containerKey string */
@@ -36,18 +36,11 @@
3636
</button>
3737

3838
<div class="dd-content dd-nodrag flex gap-1">
39-
@if ($icon)
40-
<div class="w-4">
41-
<x-dynamic-component :component="$icon" class="w-4 h-4"/>
42-
</div>
43-
@endif
4439

45-
<span @class([
46-
'ml-4 rtl:mr-4' => !$icon,
47-
'font-semibold'
48-
])>
49-
{{ $title }}
50-
</span>
40+
<x-filament-tree::tree.item-display
41+
class="ml-1 rtl:mr-1"
42+
:record="$record" :title="$title" :icon="$icon" :description="$description"
43+
/>
5144

5245
<div @class(['dd-item-btns', 'hidden' => !count($children), 'flex items-center justify-center pl-3'])>
5346
<button data-action="expand" @class(['hidden' => !$collapsed])>

resources/views/components/tree/list.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
:containerKey="$containerKey"
2020
:tree="$tree"
2121
:title="$title"
22+
:description="$this->getTreeRecordDescription($record)"
2223
:icon="$icon"
2324
/>
2425
@endforeach

src/Concern/InteractWithTree.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Closure;
66
use Filament\Notifications\Notification;
77
use Illuminate\Database\Eloquent\Model;
8+
use Illuminate\Support\HtmlString;
89
use SolutionForest\FilamentTree\Components\Tree;
910
use SolutionForest\FilamentTree\Concern\HasActions;
1011
use SolutionForest\FilamentTree\Concern\HasRecords;
@@ -65,6 +66,11 @@ public function getTreeRecordTitle(?Model $record = null): string
6566
return $record->{(method_exists($record, 'determineTitleColumnName') ? $record->determineTitleColumnName() : 'title')};
6667
}
6768

69+
public function getTreeRecordDescription(?Model $record = null): string|HtmlString|null
70+
{
71+
return null;
72+
}
73+
6874
public function getTreeRecordIcon(?Model $record = null): ?string
6975
{
7076
if (! $record) {

0 commit comments

Comments
 (0)