diff --git a/src/Concerns/HasHiddenOptions.php b/src/Concerns/HasHiddenOptions.php index 1c014493..6ca7348b 100644 --- a/src/Concerns/HasHiddenOptions.php +++ b/src/Concerns/HasHiddenOptions.php @@ -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 { @@ -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 diff --git a/src/Concerns/Schemata.php b/src/Concerns/Schemata.php index a2839382..bad01d50 100644 --- a/src/Concerns/Schemata.php +++ b/src/Concerns/Schemata.php @@ -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; @@ -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')), @@ -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')) @@ -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(); } } diff --git a/src/Fields/Classes/CheckboxList.php b/src/Fields/Classes/CheckboxList.php index f489c3ba..54ada6e2 100644 --- a/src/Fields/Classes/CheckboxList.php +++ b/src/Fields/Classes/CheckboxList.php @@ -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; @@ -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), + ]), ]; } diff --git a/src/Fields/Classes/ColorPicker.php b/src/Fields/Classes/ColorPicker.php index 462ef116..03a5b219 100644 --- a/src/Fields/Classes/ColorPicker.php +++ b/src/Fields/Classes/ColorPicker.php @@ -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 @@ -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), ]; } diff --git a/src/Fields/Classes/DatePicker.php b/src/Fields/Classes/DatePicker.php index 43baa9a1..09590c15 100644 --- a/src/Fields/Classes/DatePicker.php +++ b/src/Fields/Classes/DatePicker.php @@ -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 @@ -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), + ]), ]; } diff --git a/src/Fields/Classes/DateTimePicker.php b/src/Fields/Classes/DateTimePicker.php index 6fe8d7f0..90f77d58 100644 --- a/src/Fields/Classes/DateTimePicker.php +++ b/src/Fields/Classes/DateTimePicker.php @@ -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 @@ -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), + ]), ]; } diff --git a/src/Fields/Classes/FileUpload.php b/src/Fields/Classes/FileUpload.php index 71daf559..9594aa6f 100644 --- a/src/Fields/Classes/FileUpload.php +++ b/src/Fields/Classes/FileUpload.php @@ -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; @@ -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), + ]), ]; } diff --git a/src/Fields/Classes/Paragraph.php b/src/Fields/Classes/Paragraph.php index 4b02750c..65a63c54 100644 --- a/src/Fields/Classes/Paragraph.php +++ b/src/Fields/Classes/Paragraph.php @@ -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 @@ -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(), + ]), + + ]), ]; } diff --git a/src/Fields/Classes/Radio.php b/src/Fields/Classes/Radio.php index 4b9b4e1e..2c49bf35 100644 --- a/src/Fields/Classes/Radio.php +++ b/src/Fields/Classes/Radio.php @@ -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; @@ -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), + ]), ]; } diff --git a/src/Fields/Classes/RichEditor.php b/src/Fields/Classes/RichEditor.php index 4a6dadea..7427e31d 100644 --- a/src/Fields/Classes/RichEditor.php +++ b/src/Fields/Classes/RichEditor.php @@ -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 RichEditor extends FieldsContract @@ -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), + ]), ]; } diff --git a/src/Fields/Classes/Select.php b/src/Fields/Classes/Select.php index 5712ffb6..bacc9d94 100644 --- a/src/Fields/Classes/Select.php +++ b/src/Fields/Classes/Select.php @@ -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; @@ -23,12 +25,22 @@ public static function getOptions(?array $sections = null): array { return [ self::dataSource(), - self::htmlID(), - self::hintOptions(), Toggle::make('options.allow_multiple')->label(__('Allow Multiple')), - self::required(), - self::columnSpanFull(), - self::visibility($sections), + Accordions::make('options') + ->activeAccordion(1) + ->accordions([ + Accordion::make('general-options') + ->label(__('General Options')) + ->icon('iconpark-checklist-o') + ->columns() + ->schema([ + self::required(), + self::columnSpanFull(), + self::htmlID(), + ]), + self::hintOptions(), + self::visibility($sections), + ]), ]; } diff --git a/src/Fields/Classes/TextInput.php b/src/Fields/Classes/TextInput.php index 43c7f5b2..c2774556 100644 --- a/src/Fields/Classes/TextInput.php +++ b/src/Fields/Classes/TextInput.php @@ -58,11 +58,11 @@ public static function getOptions(?array $sections = null): array ->live(), TextInputAlias::make('options.minValue') - ->visible(fn(Get $get): bool => $get('options.dateType') === 'numeric') + ->visible(fn (Get $get): bool => $get('options.dateType') === 'numeric') ->label(__('min value')), TextInputAlias::make('options.maxValue') - ->visible(fn(Get $get): bool => $get('options.dateType') === 'numeric') + ->visible(fn (Get $get): bool => $get('options.dateType') === 'numeric') ->label(__('max value')), self::required(), @@ -136,7 +136,7 @@ public function appendFilamentComponentsOptions($component, $zeusField) { parent::appendFilamentComponentsOptions($component, $zeusField); - if (!empty($zeusField['options']['dateType'])) { + if (! empty($zeusField['options']['dateType'])) { call_user_func([$component, $zeusField['options']['dateType']]); } diff --git a/src/Fields/Classes/Textarea.php b/src/Fields/Classes/Textarea.php index b788233f..ae78ad01 100644 --- a/src/Fields/Classes/Textarea.php +++ b/src/Fields/Classes/Textarea.php @@ -5,6 +5,8 @@ use Filament\Forms\Components\Hidden; use Filament\Forms\Components\Textarea as TextareaAlias; use Filament\Forms\Components\TextInput; +use LaraZeus\Accordion\Forms\Accordion; +use LaraZeus\Accordion\Forms\Accordions; use LaraZeus\Bolt\Fields\FieldsContract; class Textarea extends FieldsContract @@ -21,23 +23,32 @@ public function title(): string public static function getOptions(?array $sections = null): array { return [ - TextInput::make('options.rows') - ->label(__('rows')), + Accordions::make('check-list-options') + ->columns() + ->accordions([ + Accordion::make('general-options') + ->label(__('General Options')) + ->icon('iconpark-checklist-o') + ->schema([ + TextInput::make('options.rows') + ->label(__('rows')), - TextInput::make('options.cols') - ->label(__('cols')), + TextInput::make('options.cols') + ->label(__('cols')), - TextInput::make('options.minLength') - ->label(__('min length')), + TextInput::make('options.minLength') + ->label(__('min length')), - TextInput::make('options.maxLength') - ->label(__('max length')), + TextInput::make('options.maxLength') + ->label(__('max length')), - self::htmlID(), - self::hintOptions(), - self::required(), - self::columnSpanFull(), - self::visibility($sections), + self::required(), + self::columnSpanFull(), + self::htmlID(), + ]), + self::hintOptions(), + self::visibility($sections), + ]), ]; } diff --git a/src/Fields/Classes/TimePicker.php b/src/Fields/Classes/TimePicker.php index 593e8ba4..ef9062e3 100644 --- a/src/Fields/Classes/TimePicker.php +++ b/src/Fields/Classes/TimePicker.php @@ -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 TimePicker extends FieldsContract @@ -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), + ]), ]; } diff --git a/src/Fields/Classes/Toggle.php b/src/Fields/Classes/Toggle.php index 3f00ad23..e0b9b47d 100644 --- a/src/Fields/Classes/Toggle.php +++ b/src/Fields/Classes/Toggle.php @@ -2,8 +2,11 @@ namespace LaraZeus\Bolt\Fields\Classes; +use Filament\Forms\Components\Grid; use Filament\Forms\Components\Hidden; use Guava\FilamentIconPicker\Forms\IconPicker; +use LaraZeus\Accordion\Forms\Accordion; +use LaraZeus\Accordion\Forms\Accordions; use LaraZeus\Bolt\Fields\FieldsContract; class Toggle extends FieldsContract @@ -20,27 +23,38 @@ 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([ + Grid::make() + ->columns() + ->schema([ + IconPicker::make('options.on-icon') + ->columns([ + 'default' => 1, + 'lg' => 3, + '2xl' => 5, + ]) + ->label(__('On Icon')), - IconPicker::make('options.on-icon') - ->columns([ - 'default' => 1, - 'lg' => 3, - '2xl' => 5, - ]) - ->label(__('On Icon')), - - IconPicker::make('options.off-icon') - ->columns([ - 'default' => 1, - 'lg' => 3, - '2xl' => 5, - ]) - ->label(__('Off Icon')), + IconPicker::make('options.off-icon') + ->columns([ + 'default' => 1, + 'lg' => 3, + '2xl' => 5, + ]) + ->label(__('Off Icon')), + ]), + self::required(), + self::columnSpanFull(), + self::htmlID(), + ]), + self::hintOptions(), + self::visibility($sections), + ]), ]; } diff --git a/src/Fields/FieldsContract.php b/src/Fields/FieldsContract.php index aa66d045..ebc1f3de 100644 --- a/src/Fields/FieldsContract.php +++ b/src/Fields/FieldsContract.php @@ -163,6 +163,11 @@ public static function getFieldCollectionItemsList(Field | FieldPreset | array $ $getCollection = collect(); + //@phpstan-ignore-next-line + if (optional($zeusField->options)['dataSource'] === null) { + return $getCollection; + } + //@phpstan-ignore-next-line if ($zeusField instanceof FieldPreset && is_string($zeusField->options)) { //@phpstan-ignore-next-line diff --git a/tests/FormsTest.php b/tests/FormsTest.php index d61c7da3..61407703 100644 --- a/tests/FormsTest.php +++ b/tests/FormsTest.php @@ -244,6 +244,7 @@ 'name' => 'sdf', 'columns' => 2, 'aside' => 0, + 'compact' => 0, 'fields' => [ [ 'name' => 'sdf',