diff --git a/CHANGELOG.md b/CHANGELOG.md index 97813a7..a290b2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,5 +4,9 @@ All notable changes to `filament-custom-forms` will be documented in this file. ## 3.0.0 - 2023-10-02 -- initial release -- add InputGroup Component +- Initial release +- Add InputGroup Component + +## 3.0.1 - 2023-10-02 +- Add hideChildLabel +- Modify Child Placeholder using Label diff --git a/README.md b/README.md index 3385ca5..9650dce 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,25 @@ composer require rupadana/filament-custom-forms InputGroup::make(3) ->label('Input Group') ->schema([ - TextInput::make('first')->hiddenLabel()->placeholder("first"), - Select::make('second')->placeholder("second")->hiddenLabel(), - ColorPicker::make('third')->placeholder("third")->hiddenLabel(), + TextInput::make('first'), + Select::make('second'), + ColorPicker::make('third'), ]) ``` + +Show child Label + +```php +InputGroup::make(3) + ->showChildLabel() + ->schema([ + TextInput::make('first'), + Select::make('second'), + ColorPicker::make('third'), + ]) +``` + ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. diff --git a/src/Components/InputGroup.php b/src/Components/InputGroup.php index da53297..bb880a4 100644 --- a/src/Components/InputGroup.php +++ b/src/Components/InputGroup.php @@ -4,11 +4,12 @@ use Filament\Forms\Components\Concerns\HasLabel; use Filament\Forms\Components\Grid; +use Closure; +use Filament\Forms\Components\Field; class InputGroup extends Grid { use HasLabel; - protected string $view = 'filament-custom-forms::components.grid'; public static function make(array | int | string | null $columns = 2): static @@ -18,7 +19,62 @@ public static function make(array | int | string | null $columns = 2): static $static->extraAttributes(['class' => 'filament-input-group gap-y-2 grid']); $static->columnSpan(1); - + return $static; } + + + public function schema(array | Closure $components): static + { + $this->childComponents($components); + + return $this; + } + + public function showChildLabel(bool $condition = true) + { + + $this->isHideChildLabel = !$condition; + + return $this; + } + + /** + * @return array + */ + public function getChildComponents(): array + { + + $components = $this->childComponents; + + if ($this->isHideChildLabel) { + $components = collect($components)->map(function (Field $component) { + if (method_exists($component, 'placeholder')) { + $component = $component->placeholder($component->getLabel()); + } + return $component->hiddenLabel(); + })->toArray(); + } + + return $this->evaluate($components); + } + // /** + // * @return array + // */ + // public function getChildComponents(): array + // { + // $components = $this->getChildComponents(); + + // if ($this->isHideChildLabel) { + // $components = collect($components)->map(function (Field $component) { + // return $component->hiddenLabel(); + // })->toArray(); + // } + + // return $this->evaluate($components); + // } + + protected function setUp(): void + { + } }