Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sections to be styled as a Grid component instead of a Section #336

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions database/migrations/create_sections_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ return new class extends Migration
$table->text('description')->nullable();
$table->string('icon')->nullable();
$table->boolean('aside')->default(0);
$table->boolean('grid')->default(0);
$table->timestamps();
$table->softDeletes();
});
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
"From 1-12": "Von 1-12",
"Section icon": "Abschnittssymbol",
"show as aside": "Als Beilage anzeigen",
"Use Grid": "Raster verwenden",
"Use a Grid instead of a Section": "Ein Grid statt einem Abschnitt verwenden",
"Show As Tabs": "Als Tabs anzeigen",
"Show the Form as Tabs": "Das Formular als Tabs anzeigen",
"Show the form as": "Formular anzeigen als",
Expand Down
4 changes: 3 additions & 1 deletion resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@
"Section Details": "Section Details",
"From 1-12": "From 1-12",
"Section icon": "Section icon",
"show as aside": "show as aside",
"show as aside": "Show as aside",
"Use Grid": "Use Grid",
"Use a Grid instead of a Section": "Use a Grid instead of a Section",
"Show As Tabs": "Show As Tabs",
"Show the Form as Tabs": "Show the Form as Tabs",
"Show the form as": "Show the form as",
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
"From 1-12": "De 1-12",
"Section icon": "Ícono de la Sección",
"show as aside": "mostrar al lado",
"Use Grid": "Usar Grilla",
"Use a Grid instead of a Section": "Utilice una cuadrícula en lugar de una sección",
"Show As Tabs": "Mostrar como Pestañas",
"Show the Form as Tabs": "Mostrar el Formulario como Pestañas",
"Show the form as": "Mostrar el formulario como",
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
"From 1-12": "De 1 à 12",
"Section icon": "Icône de la section",
"show as aside": "afficher comme une barre latérale",
"Use Grid": "Utiliser la grille",
"Use a Grid instead of a Section": "Utiliser une Grille au lieu d'une Section",
"Show As Tabs": "Afficher comme des onglets",
"Show the Form as Tabs": "Afficher le formulaire sous forme d'onglets",
"Show the form as": "Afficher le formulaire comme",
Expand Down
17 changes: 10 additions & 7 deletions src/Concerns/Designer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace LaraZeus\Bolt\Concerns;

use Filament\Forms\Components\Section;
use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\Tabs\Tab;
use Filament\Forms\Components\Wizard;
use Filament\Forms\Components\Wizard\Step;
use Filament\Forms\Get;
use LaraZeus\Bolt\Models\Form;
use LaraZeus\Bolt\Facades\Bolt;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\Wizard;
use LaraZeus\Bolt\Facades\Extensions;
use LaraZeus\Bolt\Models\Form;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Tabs\Tab;
use Filament\Forms\Components\Wizard\Step;
use LaraZeus\Bolt\Models\Section as ZeusSection;

trait Designer
Expand Down Expand Up @@ -97,7 +98,7 @@ private static function drawFields(ZeusSection $section, bool $inline, bool $has
return $fields;
}

private static function drawSections(Form $zeusForm, ZeusSection $section, array $fields): Tab | Step | Section
private static function drawSections(Form $zeusForm, ZeusSection $section, array $fields): Tab | Step | Section | Grid
{
if (optional($zeusForm->options)['show-as'] === 'tabs') {
$component = Tab::make($section->name)
Expand All @@ -108,6 +109,8 @@ private static function drawSections(Form $zeusForm, ZeusSection $section, array
// ->live()
->description($section->description)
->icon($section->icon ?? null);
} elseif ($section->grid == true) {
$component = Grid::make($section->name);
} else {
$component = Section::make($section->name)
// ->live()
Expand Down
14 changes: 11 additions & 3 deletions src/Concerns/Schemata.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,22 @@ protected static function sectionOptionsFormSchema(array $formOptions, array $al
'lg' => 3,
'2xl' => 5,
])
->visible(fn (Get $get) => $formOptions['show-as'] === 'page' && $get('grid') === false)
->label(__('Section icon')),
Toggle::make('aside')
->default(false)
->visible($formOptions['show-as'] === 'page')
->visible(fn (Get $get) => $formOptions['show-as'] === 'page' && $get('grid') === false)
->label(__('show as aside')),
Toggle::make('compact')
Toggle::make('grid')
->live()
->default(false)
->visible($formOptions['show-as'] === 'page')
->label(__('compact section')),
->label(__('Use Grid'))
->hint('Use a Grid instead of a Section'),
Toggle::make('compact')
->default(false)
->visible(fn (Get $get) => $formOptions['show-as'] === 'page' && $get('grid') === false)
->label(__('Compact section')),
]),
self::visibility($allSections),
Bolt::getCustomSchema('section') ?? [],
Expand Down Expand Up @@ -439,6 +446,7 @@ public static function getSectionsSchema(): array

Hidden::make('compact')->default(0)->nullable(),
Hidden::make('aside')->default(0)->nullable(),
Hidden::make('grid')->default(0)->nullable(),
Hidden::make('icon')->nullable(),
Hidden::make('columns')->default(1)->nullable(),
Hidden::make('description')->nullable(),
Expand Down
1 change: 1 addition & 0 deletions src/Models/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @property string $columns
* @property string $description
* @property bool $aside
* @property bool $grid
* @property bool $compact
* @property mixed $fields
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/FormsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
'name' => 'sdf',
'columns' => 2,
'aside' => 0,
'grid' => 0,
'fields' => [
[
'name' => 'sdf',
Expand Down Expand Up @@ -176,6 +177,7 @@
]),
'columns' => 2,
'aside' => 0,
'grid' => 0,
]);

assertDatabaseHas(Field::class, [
Expand Down Expand Up @@ -244,6 +246,7 @@
'name' => 'sdf',
'columns' => 2,
'aside' => 0,
'grid' => 0,
'compact' => 0,
'fields' => [
[
Expand Down
1 change: 1 addition & 0 deletions tests/migrations/004_create_sections_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function up()
$table->text('description')->nullable();
$table->string('icon')->nullable();
$table->boolean('aside')->default(0);
$table->boolean('grid')->default(0);
$table->boolean('compact')->default(0);
$table->text('options')->nullable();
$table->timestamps();
Expand Down