From fed199725a08a63f0a6896b59fcb509b9bcf25aa Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Sun, 8 Oct 2023 22:54:19 +0300 Subject: [PATCH] add compact section view --- .../add_compact_to_section.php.stub | 32 +++++++++++++++++++ src/BoltServiceProvider.php | 1 + src/Concerns/Schemata.php | 5 +++ src/Facades/Bolt.php | 10 +++++- src/Models/Section.php | 3 +- 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 database/migrations/add_compact_to_section.php.stub diff --git a/database/migrations/add_compact_to_section.php.stub b/database/migrations/add_compact_to_section.php.stub new file mode 100644 index 00000000..737392f1 --- /dev/null +++ b/database/migrations/add_compact_to_section.php.stub @@ -0,0 +1,32 @@ +boolean('compact')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('sections', function (Blueprint $table) { + $table->dropColumn('compact'); + }); + } +}; diff --git a/src/BoltServiceProvider.php b/src/BoltServiceProvider.php index bda858f4..4c8f38e2 100644 --- a/src/BoltServiceProvider.php +++ b/src/BoltServiceProvider.php @@ -68,6 +68,7 @@ protected function getMigrations(): array 'add_extensions_to_forms', 'add_extension_item_responses', 'alter_tables_constraints', + 'add_compact_to_section', ]; } } diff --git a/src/Concerns/Schemata.php b/src/Concerns/Schemata.php index f368f66b..41b21168 100644 --- a/src/Concerns/Schemata.php +++ b/src/Concerns/Schemata.php @@ -280,6 +280,11 @@ public static function getSectionsSchema(): array ->inline(false) ->visible(fn (Get $get) => $get('../../options.show-as') === 'page') ->label(__('show as aside')), + + Toggle::make('compact') + ->inline(false) + ->visible(fn (Get $get) => $get('../../options.show-as') === 'page') + ->label(__('compact section')), ]), ]), ]), diff --git a/src/Facades/Bolt.php b/src/Facades/Bolt.php index 501ee2c8..39fe85ab 100644 --- a/src/Facades/Bolt.php +++ b/src/Facades/Bolt.php @@ -2,6 +2,7 @@ namespace LaraZeus\Bolt\Facades; +use Filament\Forms\Components\Fieldset; use Filament\Forms\Components\Grid; use Filament\Forms\Components\Placeholder; use Filament\Forms\Components\Section; @@ -131,7 +132,13 @@ public static function prepareFieldsAndSectionToRender(Form $zeusForm, bool $inl Grid::make()->columns($section->columns)->schema($fields), ]); } else { - $sections[] = Section::make($section->name) + if($section->compact){ + $sections[] = Fieldset::make($section->name) + ->id($sectionId) + ->schema($fields) + ->columns($section->columns); + } else { + $sections[] = Section::make($section->name) ->id($sectionId) ->icon($section->icon ?? null) ->schema($fields) @@ -139,6 +146,7 @@ public static function prepareFieldsAndSectionToRender(Form $zeusForm, bool $inl ->aside(fn () => $section->aside) ->description($section->description) ->columns($section->columns); + } } } diff --git a/src/Models/Section.php b/src/Models/Section.php index e7dbe7e8..6c516721 100644 --- a/src/Models/Section.php +++ b/src/Models/Section.php @@ -16,7 +16,8 @@ * @property string $name * @property string $columns * @property string $description - * @property string $aside + * @property boolean $aside + * @property boolean $compact */ class Section extends Model {