Skip to content

Commit

Permalink
Merge pull request #186 from lara-zeus/compact-section
Browse files Browse the repository at this point in the history
Compact section
  • Loading branch information
atmonshi authored Oct 10, 2023
2 parents 423aaad + 4f8b305 commit 8464646
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 24 deletions.
32 changes: 32 additions & 0 deletions database/migrations/add_compact_to_section.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('sections', function (Blueprint $table) {
$table->boolean('compact')->default(0);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('sections', function (Blueprint $table) {
$table->dropColumn('compact');
});
}
};
1 change: 1 addition & 0 deletions src/BoltServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected function getMigrations(): array
'add_extensions_to_forms',
'add_extension_item_responses',
'alter_tables_constraints',
'add_compact_to_section',
];
}
}
20 changes: 5 additions & 15 deletions src/Concerns/Schemata.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@

trait Schemata
{
public static function getMainFormSchemaForView(): array
{
return [
Hidden::make('user_id')->default(auth()->user()->id ?? null),

Section::make()
->schema([
TextInput::make('name')
->maxLength(255)
->live(onBlur: true)
->label(__('Form Name')),
]),
];
}

public static function getMainFormSchema(): array
{
return [
Expand Down Expand Up @@ -280,6 +265,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')),
]),
]),
]),
Expand Down
24 changes: 16 additions & 8 deletions src/Facades/Bolt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -130,14 +131,21 @@ public static function prepareFieldsAndSectionToRender(Form $zeusForm, bool $inl
Grid::make()->columns($section->columns)->schema($fields),
]);
} else {
$sections[] = Section::make($section->name)
->id($sectionId)
->icon($section->icon ?? null)
->schema($fields)
->collapsible()
->aside(fn () => $section->aside)
->description($section->description)
->columns($section->columns);
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)
->collapsible()
->aside(fn () => $section->aside)
->description($section->description)
->columns($section->columns);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Models/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
* @property string $name
* @property string $columns
* @property string $description
* @property string $aside
* @property bool $aside
* @property bool $compact
*/
class Section extends Model
{
Expand Down

0 comments on commit 8464646

Please sign in to comment.