Skip to content

Commit da165d1

Browse files
committed
refactor tabs
1 parent 92d5e97 commit da165d1

8 files changed

Lines changed: 83 additions & 146 deletions

File tree

app/Concerns/TabbedLayout.php

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,60 @@
55
namespace App\Concerns;
66

77
use App\Contracts\Pages\WithTabs;
8+
use App\Filament\Schemas\Components\Tabs;
89
use Filament\Resources\Pages\CreateRecord;
910
use Filament\Resources\Pages\EditRecord;
1011
use Filament\Resources\Pages\ListRecords;
1112
use Filament\Resources\Pages\ViewRecord;
13+
use Filament\Schemas\Components\EmbeddedTable;
14+
use Filament\Schemas\Components\RenderHook;
15+
use Filament\Schemas\Schema;
16+
use Filament\View\PanelsRenderHook;
1217

1318
trait TabbedLayout
1419
{
15-
public function bootedTabbedLayout(): void
20+
public function content(Schema $schema): Schema
1621
{
1722
if (! $this instanceof WithTabs) {
18-
return;
23+
return parent::content($schema);
1924
}
2025

21-
$this->view = match (true) {
22-
$this instanceof ListRecords => 'filament.tabs.list-records',
23-
$this instanceof CreateRecord => 'filament.tabs.create-record',
24-
$this instanceof ViewRecord => 'filament.tabs.view-record',
25-
$this instanceof EditRecord => 'filament.tabs.edit-record',
26-
default => $this->view,
27-
};
26+
$components = [
27+
Tabs::make()
28+
->tabs($this->getTabsNavigation())
29+
->components(function (Schema $schema): array {
30+
if ($this instanceof ListRecords) {
31+
return [
32+
RenderHook::make(PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_BEFORE),
33+
EmbeddedTable::make(),
34+
RenderHook::make(PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_AFTER),
35+
];
36+
}
37+
38+
if ($this instanceof ViewRecord) {
39+
if ($this->hasInfolist()) {
40+
return [$this->getInfolistContentComponent()];
41+
}
42+
43+
return [$this->getFormContentComponent()];
44+
}
45+
46+
if (
47+
$this instanceof CreateRecord ||
48+
$this instanceof EditRecord
49+
) {
50+
return [$this->getFormContentComponent()];
51+
}
52+
53+
return parent::content($schema);
54+
}),
55+
];
56+
57+
if (method_exists($this, 'getRelationManagersContentComponent')) {
58+
$components[] = $this->getRelationManagersContentComponent();
59+
}
60+
61+
return $schema
62+
->components($components);
2863
}
2964
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Schemas\Components;
6+
7+
use Closure;
8+
use Filament\Schemas\Components\Component;
9+
10+
class Tabs extends Component
11+
{
12+
protected string $view = 'filament.schemas.components.tabs';
13+
14+
protected array | Closure $tabs = [];
15+
16+
public static function make(): static
17+
{
18+
$static = app(static::class);
19+
$static->configure();
20+
21+
return $static;
22+
}
23+
24+
public function tabs(array | Closure $tabs): static
25+
{
26+
$this->tabs = $tabs;
27+
28+
return $this;
29+
}
30+
31+
public function getTabs(): array
32+
{
33+
return $this->evaluate($this->tabs) ?? [];
34+
}
35+
}

resources/views/components/tabs.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
])
55

66
<div class="fi-tabs-component">
7-
<nav class="flex overflow-y-auto fi-tabs-component-header gap-x-[2px]">
7+
<nav class="flex overflow-y-auto fi-tabs-component-header gap-x-0.5">
88
@foreach ($tabs as $tab)
99
@if ($tab->isHidden())
1010
@continue
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<x-tabs :tabs="$getTabs()">
2+
{{ $getChildSchema() }}
3+
</x-tabs>

resources/views/filament/tabs/create-record.blade.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

resources/views/filament/tabs/edit-record.blade.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

resources/views/filament/tabs/list-records.blade.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

resources/views/filament/tabs/view-record.blade.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)