Skip to content

Commit

Permalink
update fields options
Browse files Browse the repository at this point in the history
  • Loading branch information
atmonshi committed Jan 8, 2024
1 parent d2f7292 commit 93deb9f
Show file tree
Hide file tree
Showing 17 changed files with 233 additions and 167 deletions.
76 changes: 3 additions & 73 deletions src/Concerns/HasHiddenOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@

namespace LaraZeus\Bolt\Concerns;

use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Get;
use Filament\Forms\Set;
use LaraZeus\Bolt\BoltPlugin;
use LaraZeus\Bolt\Facades\Bolt;

trait HasHiddenOptions
{
Expand Down Expand Up @@ -50,70 +41,9 @@ public static function hiddenColumnSpanFull(): array

public static function hiddenDataSource(): array
{
$dataSources = BoltPlugin::getModel('Collection')::get()
->mapWithKeys(function ($item, $key) {
return [
$key => [
'title' => $item['name'],
'class' => $item['id'],
],
];
})
->merge(
Bolt::availableDataSource()
->mapWithKeys(function ($item, $key) {
return [
$key => [
'title' => $item['title'],
'class' => $item['class'],
],
];
})
)
->pluck('title', 'class');

return Grid::make()
->schema([
Select::make('options.dataSource')
->required()
->createOptionForm([
TextInput::make('name')
->live(onBlur: true)
->label(__('Collections Name'))->required()->maxLength(255)->columnSpan(2),
Repeater::make('values')
->grid([
'default' => 1,
'md' => 2,
'lg' => 3,
])
->label(__('Collections Values'))
->columnSpan(2)
->columns(1)
->schema([
TextInput::make('itemValue')
->live(onBlur: true)
->afterStateUpdated(function (Set $set, Get $get, string $operation) {
$set('itemKey', $get('itemValue'));
})
->required()->label(__('Value'))->hint(__('what the user will see')),
TextInput::make('itemKey')
->live(onBlur: true)
->required()->label(__('Key'))->hint(__('what store in the form')),
Toggle::make('itemIsDefault')->label(__('selected by default')),
]),
])
->createOptionUsing(function (array $data) {
$collectionModel = BoltPlugin::getModel('Collection');
$collection = new $collectionModel;
$collection->fill($data);
$collection->save();

return $collection->id;
})
->options($dataSources)
->label(__('Data Source')),
])
->columns(1);
return [
Hidden::make('options.dataSource'),
];
}

public static function hiddenHtmlID(): array
Expand Down
6 changes: 4 additions & 2 deletions src/Concerns/Schemata.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Filament\Forms\Set;
use Guava\FilamentIconPicker\Forms\IconPicker;
use Illuminate\Support\Str;
use LaraZeus\Accordion\Forms\Accordions;
use LaraZeus\Bolt\BoltPlugin;
use LaraZeus\Bolt\Facades\Bolt;
use LaraZeus\Bolt\Models\Category;
Expand Down Expand Up @@ -89,9 +88,11 @@ public static function getMainFormSchema(): array
])
->label(__('Section icon')),
Toggle::make('aside')
->default(false)
->visible($formOptions['show-as'] === 'page')
->label(__('show as aside')),
Toggle::make('compact')
->default(false)
->visible($formOptions['show-as'] === 'page')
->label(__('compact section')),
self::visibility($get('sections')),
Expand Down Expand Up @@ -341,7 +342,7 @@ public static function getSectionsSchema(): array
Action::make('fields options')
->slideOver()
->color('warning')
->tooltip('more section options')
->tooltip('more field options')
->icon('heroicon-m-cog')
->modalIcon('heroicon-m-cog')
->modalDescription(__('advanced fields settings'))
Expand Down Expand Up @@ -413,6 +414,7 @@ public static function getFieldsSchema(): array
if (class_exists($class)) {
$newClass = (new $class);
if ($newClass->hasOptions()) {
// @phpstan-ignore-next-line
return collect($newClass->getOptionsHidden())->flatten()->toArray();
}
}
Expand Down
20 changes: 15 additions & 5 deletions src/Fields/Classes/CheckboxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace LaraZeus\Bolt\Fields\Classes;

use LaraZeus\Accordion\Forms\Accordion;
use LaraZeus\Accordion\Forms\Accordions;
use LaraZeus\Bolt\Fields\FieldsContract;
use LaraZeus\Bolt\Models\Field;
use LaraZeus\Bolt\Models\FieldResponse;
Expand All @@ -21,11 +23,19 @@ public static function getOptions(?array $sections = null): array
{
return [
self::dataSource(),
self::htmlID(),
self::hintOptions(),
self::required(),
self::columnSpanFull(),
self::visibility($sections),
Accordions::make('check-list-options')
->accordions([
Accordion::make('general-options')
->label(__('General Options'))
->icon('iconpark-checklist-o')
->schema([
self::required(),
self::columnSpanFull(),
self::htmlID(),
]),
self::hintOptions(),
self::visibility($sections),
]),
];
}

Expand Down
32 changes: 21 additions & 11 deletions src/Fields/Classes/ColorPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Filament\Forms\Components\ColorPicker as ColorPickerAlias;
use Filament\Forms\Components\Hidden;
use LaraZeus\Accordion\Forms\Accordion;
use LaraZeus\Accordion\Forms\Accordions;
use LaraZeus\Bolt\Fields\FieldsContract;

class ColorPicker extends FieldsContract
Expand All @@ -20,18 +22,26 @@ public function title(): string
public static function getOptions(?array $sections = null): array
{
return [
\Filament\Forms\Components\Select::make('options.colorType')
->label(__('Color Type'))
->options([
'hsl' => 'hsl',
'rgb' => 'rgb',
'rgba' => 'rgba',
Accordions::make('check-list-options')
->accordions([
Accordion::make('general-options')
->label(__('General Options'))
->icon('iconpark-checklist-o')
->schema([
\Filament\Forms\Components\Select::make('options.colorType')
->label(__('Color Type'))
->options([
'hsl' => 'hsl',
'rgb' => 'rgb',
'rgba' => 'rgba',
]),
self::required(),
self::columnSpanFull(),
self::htmlID(),
]),
self::hintOptions(),
self::visibility($sections),
]),
self::htmlID(),
self::hintOptions(),
self::required(),
self::columnSpanFull(),
self::visibility($sections),
];
}

Expand Down
20 changes: 15 additions & 5 deletions src/Fields/Classes/DatePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace LaraZeus\Bolt\Fields\Classes;

use LaraZeus\Accordion\Forms\Accordion;
use LaraZeus\Accordion\Forms\Accordions;
use LaraZeus\Bolt\Fields\FieldsContract;

class DatePicker extends FieldsContract
Expand All @@ -18,11 +20,19 @@ public function title(): string
public static function getOptions(?array $sections = null): array
{
return [
self::htmlID(),
self::hintOptions(),
self::required(),
self::columnSpanFull(),
self::visibility($sections),
Accordions::make('check-list-options')
->accordions([
Accordion::make('general-options')
->label(__('General Options'))
->icon('iconpark-checklist-o')
->schema([
self::required(),
self::columnSpanFull(),
self::htmlID(),
]),
self::hintOptions(),
self::visibility($sections),
]),
];
}

Expand Down
22 changes: 16 additions & 6 deletions src/Fields/Classes/DateTimePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace LaraZeus\Bolt\Fields\Classes;

use LaraZeus\Accordion\Forms\Accordion;
use LaraZeus\Accordion\Forms\Accordions;
use LaraZeus\Bolt\Fields\FieldsContract;

class DateTimePicker extends FieldsContract
Expand All @@ -15,14 +17,22 @@ public function title(): string
return __('Date Time Picker');
}

public static function getOptions(): array
public static function getOptions(?array $sections = null): array
{
return [
self::htmlID(),
self::hintOptions(),
self::required(),
self::columnSpanFull(),
self::visibility(),
Accordions::make('check-list-options')
->accordions([
Accordion::make('general-options')
->label(__('General Options'))
->icon('iconpark-checklist-o')
->schema([
self::required(),
self::columnSpanFull(),
self::htmlID(),
]),
self::hintOptions(),
self::visibility($sections),
]),
];
}

Expand Down
22 changes: 16 additions & 6 deletions src/Fields/Classes/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace LaraZeus\Bolt\Fields\Classes;

use Filament\Forms\Components\Hidden;
use LaraZeus\Accordion\Forms\Accordion;
use LaraZeus\Accordion\Forms\Accordions;
use LaraZeus\Bolt\Facades\Bolt;
use LaraZeus\Bolt\Fields\FieldsContract;
use LaraZeus\Bolt\Models\Field;
Expand All @@ -22,12 +24,20 @@ public function title(): string
public static function getOptions(?array $sections = null): array
{
return [
\Filament\Forms\Components\Toggle::make('options.allow_multiple')->label(__('Allow Multiple')),
self::htmlID(),
self::hintOptions(),
self::required(),
self::columnSpanFull(),
self::visibility($sections),
Accordions::make('check-list-options')
->accordions([
Accordion::make('general-options')
->label(__('General Options'))
->icon('iconpark-checklist-o')
->schema([
\Filament\Forms\Components\Toggle::make('options.allow_multiple')->label(__('Allow Multiple')),
self::required(),
self::columnSpanFull(),
self::htmlID(),
]),
self::hintOptions(),
self::visibility($sections),
]),
];
}

Expand Down
15 changes: 13 additions & 2 deletions src/Fields/Classes/Paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace LaraZeus\Bolt\Fields\Classes;

use Filament\Forms\Components\Placeholder;
use LaraZeus\Accordion\Forms\Accordion;
use LaraZeus\Accordion\Forms\Accordions;
use LaraZeus\Bolt\Fields\FieldsContract;

class Paragraph extends FieldsContract
Expand All @@ -19,8 +21,17 @@ public function title(): string
public static function getOptions(): array
{
return [
self::hintOptions(),
self::columnSpanFull(),
Accordions::make('check-list-options')
->accordions([
Accordion::make('general-options')
->label(__('General Options'))
->icon('iconpark-checklist-o')
->schema([
self::columnSpanFull(),
self::hintOptions(),
]),

]),
];
}

Expand Down
22 changes: 16 additions & 6 deletions src/Fields/Classes/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Toggle;
use LaraZeus\Accordion\Forms\Accordion;
use LaraZeus\Accordion\Forms\Accordions;
use LaraZeus\Bolt\Fields\FieldsContract;
use LaraZeus\Bolt\Models\Field;
use LaraZeus\Bolt\Models\FieldResponse;
Expand All @@ -23,12 +25,20 @@ public static function getOptions(?array $sections = null): array
{
return [
self::dataSource(),
self::htmlID(),
self::hintOptions(),
Toggle::make('options.is_inline')->label(__('Is inline')),
self::required(),
self::columnSpanFull(),
self::visibility($sections),
Accordions::make('check-list-options')
->accordions([
Accordion::make('general-options')
->label(__('General Options'))
->icon('iconpark-checklist-o')
->schema([
self::required(),
Toggle::make('options.is_inline')->label(__('Is inline')),
self::columnSpanFull(),
self::htmlID(),
]),
self::hintOptions(),
self::visibility($sections),
]),
];
}

Expand Down
Loading

0 comments on commit 93deb9f

Please sign in to comment.