diff --git a/composer.json b/composer.json index 529bab7c..ab0873e9 100644 --- a/composer.json +++ b/composer.json @@ -31,8 +31,9 @@ "php": "^8.1", "alperenersoy/filament-export": "dev-fix-there", "codeat3/blade-clarity-icons": "^1.7", - "guava/filament-icon-picker": "^2.0", "flowframe/laravel-trend": "^0.1.5", + "guava/filament-icon-picker": "^2.0", + "lara-zeus/accordion": "^1.0", "lara-zeus/core": "^3.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 603fac8c..4a37e264 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b61d0fb103846cd7ce174d0b45e4f046", + "content-hash": "d129f56fbbd7e588ed7ef053d0decec6", "packages": [ { "name": "alperenersoy/filament-export", @@ -2439,6 +2439,90 @@ }, "time": "2023-12-07T10:44:41+00:00" }, + { + "name": "lara-zeus/accordion", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/lara-zeus/accordion.git", + "reference": "206caace18bc09ddd63f19ec439b823ef8282a33" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/lara-zeus/accordion/zipball/206caace18bc09ddd63f19ec439b823ef8282a33", + "reference": "206caace18bc09ddd63f19ec439b823ef8282a33", + "shasum": "" + }, + "require": { + "filament/filament": "^3.0", + "php": "^8.1", + "spatie/laravel-package-tools": "^1.16" + }, + "require-dev": { + "laravel/pint": "^1.0", + "nunomaduro/collision": "^7.0", + "nunomaduro/larastan": "^2.0.1", + "nunomaduro/phpinsights": "^2.8", + "orchestra/testbench": "^8.0", + "phpstan/extension-installer": "^1.1" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "LaraZeus\\Accordion\\AccordionServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "LaraZeus\\Accordion\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "php coder", + "email": "info@larazeus.com", + "role": "Owner" + } + ], + "description": "Zeus Accordion is filamentphp layout component to group components", + "homepage": "https://larazeus.com/accordion", + "keywords": [ + "accordion", + "code", + "coulmn", + "design", + "field", + "filamentphp", + "generator", + "input", + "lara-zeus", + "laravel", + "tippy", + "tooltip", + "ui" + ], + "support": { + "issues": "https://github.com/lara-zeus/accordion/issues", + "source": "https://github.com/lara-zeus/accordion" + }, + "funding": [ + { + "url": "https://www.buymeacoffee.com/larazeus", + "type": "custom" + }, + { + "url": "https://github.com/atmonshi", + "type": "github" + } + ], + "time": "2024-01-07T23:21:38+00:00" + }, { "name": "lara-zeus/core", "version": "v3.0.15", diff --git a/src/Concerns/HasHiddenOptions.php b/src/Concerns/HasHiddenOptions.php index f3ec82ad..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 { @@ -37,6 +28,7 @@ public static function hiddenHintOptions(): array Hidden::make('options.hint.text'), Hidden::make('options.hint.icon'), Hidden::make('options.hint.color'), + Hidden::make('options.hint.icon-tooltip'), ]; } @@ -49,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/HasOptions.php b/src/Concerns/HasOptions.php index 4b733ce2..ce2d025e 100644 --- a/src/Concerns/HasOptions.php +++ b/src/Concerns/HasOptions.php @@ -11,43 +11,45 @@ use Filament\Forms\Get; use Filament\Forms\Set; use Guava\FilamentIconPicker\Forms\IconPicker; +use LaraZeus\Accordion\Forms\Accordion; use LaraZeus\Bolt\BoltPlugin; use LaraZeus\Bolt\Facades\Bolt; use LaraZeus\Bolt\Fields\FieldsContract; trait HasOptions { - public static function visibility(string $type = 'field', ?array $getFields = null): Grid + public static function visibility(?array $getFields = []): Accordion { - $fieldsList = []; if (filled($getFields)) { - $fieldsList = collect($getFields) + $getFields = collect($getFields) ->pluck('fields') ->mapWithKeys(function (array $item) { return $item; }); } - return Grid::make() + return Accordion::make('visibility-options') + ->label('Conditional Visibility') + ->icon('iconpark-eyes') ->schema([ Toggle::make('options.visibility.active') ->live() - ->label(__('Conditional Visibility')), + ->label(__('Enable Conditional Visibility')), Select::make('options.visibility.fieldID') ->label(__('show when the field:')) ->live() ->visible(fn (Get $get): bool => ! empty($get('options.visibility.active'))) ->required(fn (Get $get): bool => ! empty($get('options.visibility.active'))) - ->options(optional($fieldsList)->pluck('name', 'id')), + ->options(optional($getFields)->pluck('name', 'id')), Select::make('options.visibility.values') ->label(__('has the value:')) ->live() ->required(fn (Get $get): bool => ! empty($get('options.visibility.fieldID'))) ->visible(fn (Get $get): bool => ! empty($get('options.visibility.fieldID'))) - ->options(function (Get $get) use ($fieldsList) { - $getRelated = $fieldsList->where('id', $get('options.visibility.fieldID'))->first(); + ->options(function (Get $get) use ($getFields) { + $getRelated = $getFields->where('id', $get('options.visibility.fieldID'))->first(); if ($get('options.visibility.fieldID') === null) { return []; @@ -66,8 +68,7 @@ public static function visibility(string $type = 'field', ?array $getFields = nu return FieldsContract::getFieldCollectionItemsList($getRelated); }), - ]) - ->columns(1); + ]); } public static function required(): Grid @@ -79,12 +80,18 @@ public static function required(): Grid ->columns(1); } - public static function hintOptions(): Grid + public static function hintOptions(): Accordion { - return Grid::make() + return Accordion::make('hint-options') + ->columns() + ->label('Hint Options') + ->icon('heroicon-o-light-bulb') ->schema([ TextInput::make('options.hint.text') ->label(__('Hint Text')), + TextInput::make('options.hint.icon-tooltip') + ->label(__('Hint Icon tooltip')), + ColorPicker::make('options.hint.color')->label(__('Hint Color')), IconPicker::make('options.hint.icon') ->columns([ 'default' => 1, @@ -92,9 +99,7 @@ public static function hintOptions(): Grid '2xl' => 5, ]) ->label(__('Hint Icon')), - ColorPicker::make('options.hint.color')->label(__('Hint Color')), - ]) - ->columns(1); + ]); } public static function columnSpanFull(): Grid diff --git a/src/Concerns/Schemata.php b/src/Concerns/Schemata.php index 7cfb1c46..8b0a87d6 100644 --- a/src/Concerns/Schemata.php +++ b/src/Concerns/Schemata.php @@ -53,7 +53,7 @@ public static function getMainFormSchema(): array ->addActionLabel(__('Add Section')) ->cloneable() ->collapsible() - ->collapsed(fn (string $operation) => $operation === 'edit') + //->collapsed(fn (string $operation) => $operation === 'edit') ->minItems(1) ->extraItemActions([ Action::make('options') @@ -88,12 +88,14 @@ 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('section', $get('sections')), + self::visibility($get('sections')), ]; }) ->action(function (array $data, array $arguments, Repeater $component): void { @@ -326,7 +328,7 @@ public static function getSectionsSchema(): array ->cloneable() ->minItems(1) ->collapsible() - ->collapsed(fn (string $operation) => $operation === 'edit') + //->collapsed(fn (string $operation) => $operation === 'edit') ->grid([ 'default' => 1, 'md' => 2, @@ -337,11 +339,13 @@ public static function getSectionsSchema(): array ->itemLabel(fn (array $state): ?string => $state['name'] ?? null) ->addActionLabel(__('Add field')) ->extraItemActions([ - Action::make('options') + 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')) ->fillForm(fn ( $state, array $arguments, @@ -410,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 a27a8607..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('field', $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 693a82a7..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('field', $sections), ]; } diff --git a/src/Fields/Classes/DatePicker.php b/src/Fields/Classes/DatePicker.php index 2bba4c9d..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('field', $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 9ba70cb3..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,6 +17,25 @@ public function title(): string return __('Date Time Picker'); } + public static function getOptions(?array $sections = null): array + { + return [ + 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), + ]), + ]; + } + public static function getOptionsHidden(): array { return [ diff --git a/src/Fields/Classes/FileUpload.php b/src/Fields/Classes/FileUpload.php index ffeadc97..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('field', $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 ac07b2b8..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('field', $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 f12bf446..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('field', $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 0e14b477..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('field', $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 0ab5b30e..c2774556 100644 --- a/src/Fields/Classes/TextInput.php +++ b/src/Fields/Classes/TextInput.php @@ -2,10 +2,15 @@ namespace LaraZeus\Bolt\Fields\Classes; +use Filament\Forms\Components\ColorPicker; use Filament\Forms\Components\Hidden; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput as TextInputAlias; use Filament\Forms\Get; +use Filament\Support\Colors\Color; +use Guava\FilamentIconPicker\Forms\IconPicker; +use LaraZeus\Accordion\Forms\Accordion; +use LaraZeus\Accordion\Forms\Accordions; use LaraZeus\Bolt\Fields\FieldsContract; class TextInput extends FieldsContract @@ -22,47 +27,83 @@ public function title(): string public static function getOptions(?array $sections = null): array { return [ - Select::make('options.dateType') - ->label(__('Data type')) - ->required() - ->options([ - 'string' => __('text'), - 'email' => __('email'), - 'numeric' => __('numeric'), - 'password' => __('password'), - 'tel' => __('tel'), - 'url' => __('url'), - 'activeUrl' => __('active url'), - 'alpha' => __('alpha'), - 'alphaDash' => __('alpha dash'), - 'alphaNum' => __('alpha num'), - 'ip' => __('ip'), - 'ipv4' => __('ip v4'), - 'ipv6' => __('ip v6'), - 'macAddress' => __('mac address'), - ]) - ->default('string') - ->live(), - - TextInputAlias::make('options.prefix') - ->label(__('prefix')), - - TextInputAlias::make('options.suffix') - ->label(__('suffix')), - - TextInputAlias::make('options.minValue') - ->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') - ->label(__('max value')), - - self::htmlID(), - self::hintOptions(), - self::required(), - self::columnSpanFull(), - self::visibility('field', $sections), + Accordions::make('options') + ->accordions([ + Accordion::make('validation-options') + ->label(__('Validation Options')) + ->icon('iconpark-checkcorrect-o') + ->columns() + ->schema([ + Select::make('options.dateType') + ->label(__('Data type')) + ->required() + ->options([ + 'string' => __('text'), + 'email' => __('email'), + 'numeric' => __('numeric'), + 'password' => __('password'), + 'tel' => __('tel'), + 'url' => __('url'), + 'activeUrl' => __('active url'), + 'alpha' => __('alpha'), + 'alphaDash' => __('alpha dash'), + 'alphaNum' => __('alpha num'), + 'ip' => __('ip'), + 'ipv4' => __('ip v4'), + 'ipv6' => __('ip v6'), + 'macAddress' => __('mac address'), + ]) + ->default('string') + ->columnSpanFull() + ->live(), + + TextInputAlias::make('options.minValue') + ->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') + ->label(__('max value')), + + self::required(), + ]), + + Accordion::make('visual-options') + ->label(__('Visual Options')) + ->columns() + ->icon('iconpark-viewgriddetail-o') + ->schema([ + TextInputAlias::make('options.prefix') + ->label(__('prefix')), + TextInputAlias::make('options.suffix') + ->label(__('suffix')), + + IconPicker::make('options.prefix-icon') + ->columns([ + 'default' => 1, + 'lg' => 3, + '2xl' => 5, + ]) + ->label(__('Prefix Icon')), + IconPicker::make('options.suffix-icon') + ->columns([ + 'default' => 1, + 'lg' => 3, + '2xl' => 5, + ]) + ->label(__('Suffix Icon')), + + ColorPicker::make('options.prefix-icon-color') + ->label(__('Prefix Icon Color')), + ColorPicker::make('options.suffix-icon-color') + ->label(__('Suffix Icon Color')), + + self::columnSpanFull(), + self::htmlID(), + ]), + self::hintOptions(), + self::visibility($sections), + ]), ]; } @@ -74,11 +115,19 @@ public static function getOptionsHidden(): array self::hiddenHintOptions(), self::hiddenRequired(), self::hiddenColumnSpanFull(), + Hidden::make('options.dateType'), - Hidden::make('options.prefix'), - Hidden::make('options.suffix'), + Hidden::make('options.minValue'), Hidden::make('options.maxValue'), + + Hidden::make('options.suffix'), + Hidden::make('options.suffix-icon'), + Hidden::make('options.suffix-icon-color'), + + Hidden::make('options.prefix'), + Hidden::make('options.prefix-icon'), + Hidden::make('options.prefix-icon-color'), ]; } @@ -91,6 +140,20 @@ public function appendFilamentComponentsOptions($component, $zeusField) call_user_func([$component, $zeusField['options']['dateType']]); } + if (isset($zeusField->options['prefix']) && $zeusField->options['prefix'] !== null) { + $component = $component + ->prefixIcon($zeusField->options['prefix-icon'] ?? null) + ->prefixIconColor(Color::hex($zeusField->options['prefix-icon-color'] ?? '#000000')) + ->prefix($zeusField->options['prefix']); + } + + if (isset($zeusField->options['suffix']) && $zeusField->options['suffix'] !== null) { + $component = $component + ->suffixIcon($zeusField->options['suffix-icon'] ?? null) + ->suffixIconColor(Color::hex($zeusField->options['suffix-icon-color'] ?? '#000000')) + ->suffix($zeusField->options['suffix']); + } + return $component; } } diff --git a/src/Fields/Classes/Textarea.php b/src/Fields/Classes/Textarea.php index b3722dbb..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('field', $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 d63022f4..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('field', $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 1769adeb..e0b9b47d 100644 --- a/src/Fields/Classes/Toggle.php +++ b/src/Fields/Classes/Toggle.php @@ -2,6 +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 @@ -18,11 +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('field', $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.off-icon') + ->columns([ + 'default' => 1, + 'lg' => 3, + '2xl' => 5, + ]) + ->label(__('Off Icon')), + ]), + self::required(), + self::columnSpanFull(), + self::htmlID(), + ]), + self::hintOptions(), + self::visibility($sections), + ]), ]; } @@ -34,6 +66,8 @@ public static function getOptionsHidden(): array self::hiddenHintOptions(), self::hiddenRequired(), self::hiddenColumnSpanFull(), + Hidden::make('options.on-icon'), + Hidden::make('options.off-icon'), ]; } @@ -42,6 +76,14 @@ public function appendFilamentComponentsOptions($component, $zeusField) { parent::appendFilamentComponentsOptions($component, $zeusField); + if (optional($zeusField->options)['on-icon']) { + $component = $component->onIcon($zeusField->options['on-icon']); + } + + if (optional($zeusField->options)['off-icon']) { + $component = $component->offIcon($zeusField->options['off-icon']); + } + return $component->live(); } } diff --git a/src/Fields/FieldsContract.php b/src/Fields/FieldsContract.php index 118d6bb4..ebc1f3de 100644 --- a/src/Fields/FieldsContract.php +++ b/src/Fields/FieldsContract.php @@ -74,14 +74,6 @@ public function appendFilamentComponentsOptions($component, $zeusField) ->id($htmlId) ->helperText($zeusField->description); - if (isset($zeusField->options['prefix']) && $zeusField->options['prefix'] !== null) { - $component = $component->prefix($zeusField->options['prefix']); - } - - if (isset($zeusField->options['suffix']) && $zeusField->options['suffix'] !== null) { - $component = $component->suffix($zeusField->options['suffix']); - } - if (optional($zeusField->options)['is_required']) { $component = $component->required(); } @@ -99,7 +91,7 @@ public function appendFilamentComponentsOptions($component, $zeusField) $component = $component->hint($zeusField->options['hint']['text']); } if (optional($zeusField->options)['hint']['icon']) { - $component = $component->hintIcon($zeusField->options['hint']['icon'], tooltip: $zeusField->options['hint']['text']); + $component = $component->hintIcon($zeusField->options['hint']['icon'], tooltip: $zeusField->options['hint']['icon-tooltip'] ?? $zeusField->options['hint']['text']); } if (optional($zeusField->options)['hint']['color']) { $component = $component->hintColor(fn () => Color::hex($zeusField->options['hint']['color'])); @@ -171,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',