Skip to content

Commit 5b1a658

Browse files
committed
add hideChildLabel and Modify Child Placeholder using Label
1 parent c00f43c commit 5b1a658

File tree

3 files changed

+80
-7
lines changed

3 files changed

+80
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ All notable changes to `filament-custom-forms` will be documented in this file.
44

55
## 3.0.0 - 2023-10-02
66

7-
- initial release
8-
- add InputGroup Component
7+
- Initial release
8+
- Add InputGroup Component
9+
10+
## 3.0.1 - 2023-10-02
11+
- Add hideChildLabel
12+
- Modify Child Placeholder using Label

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,25 @@ composer require rupadana/filament-custom-forms
2121
InputGroup::make(3)
2222
->label('Input Group')
2323
->schema([
24-
TextInput::make('first')->hiddenLabel()->placeholder("first"),
25-
Select::make('second')->placeholder("second")->hiddenLabel(),
26-
ColorPicker::make('third')->placeholder("third")->hiddenLabel(),
24+
TextInput::make('first'),
25+
Select::make('second'),
26+
ColorPicker::make('third'),
2727
])
2828
```
2929

30+
31+
Show child Label
32+
33+
```php
34+
InputGroup::make(3)
35+
->showChildLabel()
36+
->schema([
37+
TextInput::make('first'),
38+
Select::make('second'),
39+
ColorPicker::make('third'),
40+
])
41+
```
42+
3043
## Changelog
3144

3245
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

src/Components/InputGroup.php

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
use Filament\Forms\Components\Concerns\HasLabel;
66
use Filament\Forms\Components\Grid;
7+
use Closure;
8+
use Filament\Forms\Components\Field;
79

810
class InputGroup extends Grid
911
{
1012
use HasLabel;
11-
1213
protected string $view = 'filament-custom-forms::components.grid';
1314

1415
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
1819
$static->extraAttributes(['class' => 'filament-input-group gap-y-2 grid']);
1920

2021
$static->columnSpan(1);
21-
22+
2223
return $static;
2324
}
25+
26+
27+
public function schema(array | Closure $components): static
28+
{
29+
$this->childComponents($components);
30+
31+
return $this;
32+
}
33+
34+
public function showChildLabel(bool $condition = true)
35+
{
36+
37+
$this->isHideChildLabel = !$condition;
38+
39+
return $this;
40+
}
41+
42+
/**
43+
* @return array<Component>
44+
*/
45+
public function getChildComponents(): array
46+
{
47+
48+
$components = $this->childComponents;
49+
50+
if ($this->isHideChildLabel) {
51+
$components = collect($components)->map(function (Field $component) {
52+
if (method_exists($component, 'placeholder')) {
53+
$component = $component->placeholder($component->getLabel());
54+
}
55+
return $component->hiddenLabel();
56+
})->toArray();
57+
}
58+
59+
return $this->evaluate($components);
60+
}
61+
// /**
62+
// * @return array<Component>
63+
// */
64+
// public function getChildComponents(): array
65+
// {
66+
// $components = $this->getChildComponents();
67+
68+
// if ($this->isHideChildLabel) {
69+
// $components = collect($components)->map(function (Field $component) {
70+
// return $component->hiddenLabel();
71+
// })->toArray();
72+
// }
73+
74+
// return $this->evaluate($components);
75+
// }
76+
77+
protected function setUp(): void
78+
{
79+
}
2480
}

0 commit comments

Comments
 (0)