Skip to content

Commit

Permalink
add hideChildLabel and Modify Child Placeholder using Label
Browse files Browse the repository at this point in the history
  • Loading branch information
rupadana committed Oct 2, 2023
1 parent c00f43c commit 5b1a658
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
60 changes: 58 additions & 2 deletions src/Components/InputGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Check failure on line 37 in src/Components/InputGroup.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Rupadana\FilamentCustomForms\Components\InputGroup::$isHideChildLabel.

return $this;
}

/**
* @return array<Component>
*/
public function getChildComponents(): array

Check failure on line 45 in src/Components/InputGroup.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Rupadana\FilamentCustomForms\Components\InputGroup::getChildComponents() has invalid return type Rupadana\FilamentCustomForms\Components\Component.
{

$components = $this->childComponents;

if ($this->isHideChildLabel) {

Check failure on line 50 in src/Components/InputGroup.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Rupadana\FilamentCustomForms\Components\InputGroup::$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<Component>
// */
// 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
{
}
}

0 comments on commit 5b1a658

Please sign in to comment.