Skip to content

Commit

Permalink
Merge pull request #336 from holmesadam/layout-options
Browse files Browse the repository at this point in the history
Allow sections to be styled as a Grid component instead of a Section
  • Loading branch information
atmonshi authored Jan 5, 2025
2 parents e3c69a4 + 5ca0ad4 commit 67147c1
Show file tree
Hide file tree
Showing 24 changed files with 294 additions and 239 deletions.
394 changes: 195 additions & 199 deletions composer.lock

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions database/migrations/add_borderless_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(config('zeus-bolt.table-prefix').'sections', function (Blueprint $table) {
$table->boolean('borderless')->default(0);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table(config('zeus-bolt.table-prefix').'sections', function (Blueprint $table) {
$table->dropColumn('borderless');
});
}
};
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('borderless')->default(0);
$table->timestamps();
$table->softDeletes();
});
Expand Down
4 changes: 3 additions & 1 deletion resources/lang/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,7 @@
"View Form": "عرض",
"Thanks": "شكرا لك",
"New Submission in": "لديك سجل جديد في النموذج",
"Form Links": "روابط النموذج"
"Form Links": "روابط النموذج",
"Borderless Section": "عرض بدون اطار",
"Show the section without borders": "عرض القسم بدون اطار"
}
4 changes: 3 additions & 1 deletion resources/lang/ckb.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@
"Hint Color" :"ڕەنگی ئاماژە",
"Textarea": "ناوچەی دەق",
"Paragraph": "پەرەگراف",
"Color Picker": "ڕەنگ هەڵبژاردە"
"Color Picker": "ڕەنگ هەڵبژاردە",
"Borderless Section": "Borderless Section",
"Show the section without borders": "Show the section with borders"
}

4 changes: 3 additions & 1 deletion resources/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,7 @@
"Hint Color" :"Hint Color",
"Textarea": "Textarea",
"Paragraph": "Paragraph",
"Color Picker": "Color Picker"
"Color Picker": "Color Picker",
"Borderless Section": "Borderless Section",
"Show the section without borders": "Show the section with borders"
}
6 changes: 4 additions & 2 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"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",
"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 Expand Up @@ -205,5 +205,7 @@
"View Form": "View Form",
"Thanks": "Thanks",
"New Submission in": "New Submission in",
"Form Links": "Form Links"
"Form Links": "Form Links",
"Borderless Section": "Borderless Section",
"Show the section without borders": "Show the section with borders"
}
4 changes: 3 additions & 1 deletion resources/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,7 @@
"View Form": "Ver Formulario",
"Thanks": "Gracias",
"New Submission in": "Nueva Presentación en",
"Form Links": "Enlaces de Formulario"
"Form Links": "Enlaces de Formulario",
"Borderless Section": "Borderless Section",
"Show the section without borders": "Show the section with borders"
}
4 changes: 3 additions & 1 deletion resources/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,7 @@
"Hint Color" :"Hint Color",
"Textarea": "Textarea",
"Paragraph": "Paragraph",
"Color Picker": "Color Picker"
"Color Picker": "Color Picker",
"Borderless Section": "Borderless Section",
"Show the section without borders": "Show the section with borders"
}
1 change: 1 addition & 0 deletions src/BoltServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ protected function getMigrations(): array
'add_options_to_section',
'add_grade_to_response',
'add_grade_to_field_response',
'add_borderless_to_section',
];
}
}
12 changes: 5 additions & 7 deletions src/Concerns/Designer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LaraZeus\Bolt\Concerns;

use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\Tabs\Tab;
Expand Down Expand Up @@ -36,7 +37,7 @@ public static function ui(Form $zeusForm, bool $inline = false): array
return [
Wizard::make($sections)
->live(condition: $hasSectionVisibility),
//->skippable() // todo still not working
// ->skippable() // todo still not working
];
}

Expand Down Expand Up @@ -97,20 +98,19 @@ 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)
// ->live()
->icon($section->icon ?? null);
} elseif (optional($zeusForm->options)['show-as'] === 'wizard') {
$component = Step::make($section->name)
// ->live()
->description($section->description)
->icon($section->icon ?? null);
} elseif ((bool) $section->borderless === true) {
$component = Grid::make($section->name);
} else {
$component = Section::make($section->name)
// ->live()
->description($section->description)
->aside(fn () => $section->aside)
->compact(fn () => $section->compact)
Expand Down Expand Up @@ -139,9 +139,7 @@ private static function drawSections(Form $zeusForm, ZeusSection $section, array
});

return $component
//->id(str($section->name)->slug() . '-' . $section->id)
->schema($fields)
//->live()
->columns($section->columns);
}
}
16 changes: 13 additions & 3 deletions src/Concerns/Schemata.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ protected static function sectionOptionsFormSchema(array $formOptions, array $al
{
return [
TextInput::make('description')
->hidden(fn (Get $get) => $get('borderless') === true)
->nullable()
->live()
->visible($formOptions['show-as'] !== 'tabs')
->label(__('Section Description')),

Expand All @@ -79,15 +81,22 @@ protected static function sectionOptionsFormSchema(array $formOptions, array $al
'lg' => 3,
'2xl' => 5,
])
->visible(fn (Get $get) => $formOptions['show-as'] === 'page' && $get('borderless') === false)
->label(__('Section icon')),
Toggle::make('aside')
->default(false)
->visible($formOptions['show-as'] === 'page')
->visible(fn (Get $get) => $formOptions['show-as'] === 'page' && $get('borderless') === false)
->label(__('show as aside')),
Toggle::make('compact')
Toggle::make('borderless')
->live()
->default(false)
->visible($formOptions['show-as'] === 'page')
->label(__('compact section')),
->label(__('Borderless Section'))
->helperText('Show the section without borders'),
Toggle::make('compact')
->default(false)
->visible(fn (Get $get) => $formOptions['show-as'] === 'page' && $get('borderless') === false)
->label(__('Compact section')),
]),
self::visibility($allSections),
Bolt::getCustomSchema('section') ?? [],
Expand Down Expand Up @@ -439,6 +448,7 @@ public static function getSectionsSchema(): array

Hidden::make('compact')->default(0)->nullable(),
Hidden::make('aside')->default(0)->nullable(),
Hidden::make('borderless')->default(0)->nullable(),
Hidden::make('icon')->nullable(),
Hidden::make('columns')->default(1)->nullable(),
Hidden::make('description')->nullable(),
Expand Down
2 changes: 1 addition & 1 deletion src/Fields/Classes/CheckboxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function appendFilamentComponentsOptions($component, $zeusField, bool $ha
if (request()->filled($zeusField->options['htmlId'])) {
$component = $component->default(request($zeusField->options['htmlId']));

//todo set default items for datasources
// todo set default items for datasources
} elseif ($selected = $options->where('itemIsDefault', true)->pluck('itemKey')->isNotEmpty()) {
$component = $component->default($selected);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fields/Classes/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function appendFilamentComponentsOptions($component, $zeusField, bool $ha

if (request()->filled($zeusField->options['htmlId'])) {
$component = $component->default(request($zeusField->options['htmlId']));
//todo set default items for datasources
// todo set default items for datasources
} elseif ($selected = $options->where('itemIsDefault', true)->pluck('itemKey')->isNotEmpty()) {
$component = $component->default($selected);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fields/Classes/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function appendFilamentComponentsOptions($component, $zeusField, bool $ha

if (request()->filled($zeusField->options['htmlId'])) {
$component = $component->default(request($zeusField->options['htmlId']));
//todo set default items for datasources
// todo set default items for datasources
} elseif ($selected = $options->where('itemIsDefault', true)->pluck('itemKey')->isNotEmpty()) {
$component = $component->default($selected);
}
Expand Down
22 changes: 11 additions & 11 deletions src/Fields/FieldsContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function appendFilamentComponentsOptions($component, $zeusField, bool $ha
return null;
}

//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
if (! $zeusField instanceof FieldPreset && $zeusField->section->form->extensions !== 'LaraZeus\\BoltPro\\Extensions\\Grades') {
return null;
}
Expand Down Expand Up @@ -206,7 +206,7 @@ public function getCollectionsValuesForResponse(Field $field, FieldResponse $res
return (is_array($response)) ? implode(', ', $response) : $response;
}

//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
public static function getFieldCollectionItemsList(Field | FieldPreset | array $zeusField): Collection | array
{
if (is_array($zeusField)) {
Expand All @@ -215,28 +215,28 @@ public static function getFieldCollectionItemsList(Field | FieldPreset | array $

$getCollection = collect();

//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
if (optional($zeusField->options)['dataSource'] === null) {
return $getCollection;
}

//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
if ($zeusField instanceof FieldPreset && is_string($zeusField->options)) {
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
$zeusField->options = json_decode($zeusField->options, true);
}

// to not braking old dataSource structure
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
if ((int) $zeusField->options['dataSource'] !== 0) {
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
if ($zeusField instanceof FieldPreset) {
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
$getCollection = \LaraZeus\BoltPro\Models\Collection::query()
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
->find($zeusField->options['dataSource'] ?? 0)
->values;
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
$getCollection = collect(json_decode($getCollection, true))
->pluck('itemValue', 'itemKey');
} else {
Expand All @@ -250,7 +250,7 @@ public static function getFieldCollectionItemsList(Field | FieldPreset | array $
}
} else {
if (class_exists($zeusField->options['dataSource'])) {
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
$dataSourceClass = new $zeusField->options['dataSource'];
$getCollection = $dataSourceClass->getQuery()->pluck(
$dataSourceClass->getValuesUsing(),
Expand Down
2 changes: 1 addition & 1 deletion src/Filament/Exports/ResponseExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ResponseExporter extends Exporter
public static function getColumns(): array
{
$record = \Livewire\Livewire::current()->getRecord();
//todo refactor with v4
// todo refactor with v4
$userModel = BoltPlugin::getModel('User') ?? config('auth.providers.users.model');
$getUserModel = $userModel::getBoltUserFullNameAttribute();
$mainColumns = [
Expand Down
10 changes: 5 additions & 5 deletions src/Filament/Resources/FormResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ public static function getPages(): array
];

if (Bolt::hasPro()) {
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
$pages['prefilled'] = \LaraZeus\BoltPro\Livewire\PrefilledForm::route('/{record}/prefilled');
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
$pages['share'] = \LaraZeus\BoltPro\Livewire\ShareForm::route('/{record}/share');
}

Expand All @@ -224,7 +224,7 @@ public static function getWidgets(): array
];

if (Bolt::hasPro()) {
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
$widgets[] = \LaraZeus\BoltPro\Widgets\ResponsesPerCollection::class;
}

Expand Down Expand Up @@ -264,7 +264,7 @@ public static function getActions(): array
}

if (class_exists(\LaraZeus\Helen\HelenServiceProvider::class)) {
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
$advancedActions[] = \LaraZeus\Helen\Actions\ShortUrlAction::make('get-link')
->label(__('Short Link'))
->distUrl(fn (ZeusForm $record) => route(BoltPlugin::get()->getRouteNamePrefix() . 'bolt.form.show', $record));
Expand All @@ -283,7 +283,7 @@ public static function getRecordSubNavigation(Page $page): array
];

if (Bolt::hasPro()) {
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
$formNavs[] = \LaraZeus\BoltPro\Livewire\ShareForm::class;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Filament/Resources/FormResource/Pages/ListForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function getHeaderActions(): array
];

if (Bolt::hasPro()) {
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
$actions[] = \LaraZeus\BoltPro\Actions\PresetAction::make('new from preset')
->visible(config('zeus-bolt.show_presets'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ManageResponses extends ManageRelatedRecords

public function table(Table $table): Table
{
//todo refactor with v4
// todo refactor with v4
$userModel = BoltPlugin::getModel('User') ?? config('auth.providers.users.model');
$getUserModel = $userModel::getBoltUserFullNameAttribute();

Expand Down
2 changes: 1 addition & 1 deletion src/Filament/Resources/FormResource/Pages/ViewForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function getFooterWidgets(): array
];

if (Bolt::hasPro()) {
//@phpstan-ignore-next-line
// @phpstan-ignore-next-line
$widgets[] = \LaraZeus\BoltPro\Widgets\ResponsesCharts::class;
}

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 $borderless
* @property bool $compact
* @property mixed $fields
*/
Expand Down
Loading

0 comments on commit 67147c1

Please sign in to comment.