diff --git a/src/Filament/Config/FilamentLayout.php b/src/Filament/Config/FilamentLayout.php index 89cb2a1..48de540 100644 --- a/src/Filament/Config/FilamentLayout.php +++ b/src/Filament/Config/FilamentLayout.php @@ -2,11 +2,10 @@ namespace Kiwilan\Steward\Filament\Config; -use Filament\Forms\Components\Section; +use Filament\Forms\Components\Component; use Filament\Forms\Form; -use Kiwilan\Steward\Filament\Config\FilamentLayout\FilamentLayoutCard; use Kiwilan\Steward\Filament\Config\FilamentLayout\FilamentLayoutColumn; -use Kiwilan\Steward\Filament\Config\FilamentLayout\FilamentLayoutSettings; +use Kiwilan\Steward\Filament\Config\FilamentLayout\FilamentLayoutSection; class FilamentLayout { @@ -29,41 +28,39 @@ public static function make(Form $form, array $schema = [], int $width = 3): For } /** - * @param array>|array $fields + * @param FilamentLayoutSection[] $sections */ - public static function column(array $fields = [], int $width = 2): \Filament\Forms\Components\Group + public static function column(array $sections = [], int $width = 2): \Filament\Forms\Components\Group { - return FilamentLayoutColumn::make($fields) + return FilamentLayoutColumn::make($sections) ->width($width) ->get() ; } - public static function card(array $fields = [], string $title = null, int $width = 2): Section - { - return FilamentLayoutCard::make($fields, $title, $width); - } - - public static function setting(array $fields = [], int $width = 2, string $title = null): \Filament\Forms\Components\Group + /** + * @param Component[] $fields + */ + public static function section(array $fields = []): FilamentLayoutSection { - return FilamentLayoutSettings::make($fields, $width, $title); + return FilamentLayoutSection::make($fields); } - public function width(int $width = 3): self + protected function width(int $width = 3): self { $this->width = $width; return $this; } - public function schema(array $schema = []): self + protected function schema(array $schema = []): self { $this->schema = $schema; return $this; } - public function get(): Form + protected function get(): Form { return $this->form ->schema($this->schema) diff --git a/src/Filament/Config/FilamentLayout/FilamentLayoutColumn.php b/src/Filament/Config/FilamentLayout/FilamentLayoutColumn.php index 16f478c..1286af3 100644 --- a/src/Filament/Config/FilamentLayout/FilamentLayoutColumn.php +++ b/src/Filament/Config/FilamentLayout/FilamentLayoutColumn.php @@ -4,26 +4,26 @@ use Closure; use Filament\Forms; -use Illuminate\Support\Str; class FilamentLayoutColumn { + /** + * @param FilamentLayoutSection[]|mixed[] $sections + */ public function __construct( - protected array $fields = [], + protected array $sections = [], protected int $width = 2, protected bool|Closure $hidden = false, - protected bool $card = true, - protected array $titles = [], ) { } /** - * @param array>|array $fields + * @param FilamentLayoutSection[] $sections */ - public static function make(array $fields = []): self + public static function make(array $sections = []): self { $column = new FilamentLayoutColumn(); - $column->fields = $fields; + $column->sections = $sections; return $column; } @@ -35,13 +35,6 @@ public function width(int $width = 2): self return $this; } - public function disableCard(): self - { - $this->card = false; - - return $this; - } - public function hidden(bool|Closure $condition = true): self { $this->hidden = $condition; @@ -49,13 +42,6 @@ public function hidden(bool|Closure $condition = true): self return $this; } - public function titles(string|array $titles = []): self - { - $this->titles = is_array($titles) ? $titles : [$titles]; - - return $this; - } - public function get() { $fields = $this->setFields(); @@ -74,38 +60,16 @@ private function setFields(): array { $fields = []; - foreach ($this->fields as $key => $field) { - if (! is_array($field)) { - $field = [$field]; - } - - $title = null; - - if (array_key_exists($key, $this->titles)) { - $title = $this->titles[$key]; - } - - $group = []; - - if ($title) { - $group[] = Forms\Components\Placeholder::make(Str::slug($title)) - ->label($title) - ->columnSpan($this->width) - ; - } - $group = array_merge($group, $field); - $component = $this->card ? Forms\Components\Section::make() : Forms\Components\Group::make(); + foreach ($this->sections as $key => $section) { + $component = Forms\Components\Section::make(); + $schema = $section instanceof FilamentLayoutSection ? $section->get() : $section; - if (! empty($group)) { - $fields[] = $component - ->schema($group) - ->columns([ - 'sm' => $this->width, - ]) - ; - } else { - $fields[] = Forms\Components\Group::make(); - } + $fields[] = $component + ->schema($schema) + ->columns([ + 'sm' => $this->width, + ]) + ; } return $fields; diff --git a/src/Filament/Config/FilamentLayout/FilamentLayoutSection.php b/src/Filament/Config/FilamentLayout/FilamentLayoutSection.php new file mode 100644 index 0000000..36d319e --- /dev/null +++ b/src/Filament/Config/FilamentLayout/FilamentLayoutSection.php @@ -0,0 +1,29 @@ +fields = $fields; + + return $column; + } + + public function get(): array + { + return $this->fields; + } +} diff --git a/src/Filament/Config/FilamentLayout/FilamentLayoutSettings.php b/src/Filament/Config/FilamentLayout/FilamentLayoutSettings.php deleted file mode 100644 index 571eb71..0000000 --- a/src/Filament/Config/FilamentLayout/FilamentLayoutSettings.php +++ /dev/null @@ -1,31 +0,0 @@ -schema([ - FilamentLayout::card($self->fields, $self->title), - ]) - ->columnSpan([ - 'sm' => 1, - 'lg' => $self->width, - ]) - ; - } -}