Skip to content

Commit eacb719

Browse files
committed
Init filament v4
1 parent 2f1c001 commit eacb719

21 files changed

+314
-227
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323
"php": "^8.2",
2424
"baspa/laravel-timezones": "^1.2",
2525
"filament/filament": "^3.3.10",
26-
"saade/filament-adjacency-list": "^3.2.2",
26+
"saade/filament-adjacency-list": "dev-release/filament-v4",
2727
"spatie/laravel-package-tools": "^1.15.0",
2828
"staudenmeir/laravel-adjacency-list": "^1.0"
2929
},
3030
"require-dev": {
3131
"laravel/pint": "^1.14",
3232
"nunomaduro/collision": "^8.1.1||^7.10.0",
33-
"nunomaduro/larastan": "^2.0.1",
33+
"nunomaduro/larastan": "^3.0",
3434
"orchestra/testbench": "^9.0.0||^8.22.0",
3535
"pestphp/pest": "^2.34",
3636
"pestphp/pest-plugin-arch": "^2.0",
3737
"pestphp/pest-plugin-laravel": "^2.0",
3838
"phpstan/extension-installer": "^1.1",
39-
"phpstan/phpstan-deprecation-rules": "^1.0",
40-
"phpstan/phpstan-phpunit": "^1.0"
39+
"phpstan/phpstan-deprecation-rules": "^2.0",
40+
"phpstan/phpstan-phpunit": "^2.0"
4141
},
4242
"autoload": {
4343
"psr-4": {
@@ -80,6 +80,6 @@
8080
"url": "[email protected]:backstagephp/filament-adjacency-list.git"
8181
}
8282
},
83-
"minimum-stability": "dev",
83+
"minimum-stability": "beta",
8484
"prefer-stable": true
8585
}

src/Concerns/HasAffixes.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
namespace Backstage\Fields\Concerns;
44

5+
use Filament\Schemas\Components\Fieldset;
6+
use Filament\Schemas\Components\Grid;
7+
use Filament\Forms\Components\TextInput;
8+
use Filament\Forms\Components\ColorPicker;
59
use Filament\Forms;
6-
use Filament\Forms\Components\Fieldset;
710
use Filament\Support\Colors\Color;
811

912
trait HasAffixes
@@ -16,11 +19,11 @@ public static function addAffixesToInput(mixed $input, mixed $field): mixed
1619
->suffixIcon($field->config['suffixIcon'] ?? self::getDefaultConfig()['suffixIcon']);
1720

1821
if (isset($field->config['prefixIconColor']) && $field->config['prefixIconColor']) {
19-
$input->prefixIconColor(Color::hex($field->config['prefixIconColor']));
22+
$input->prefixIconColor(Color::generateV3Palette($field->config['prefixIconColor']));
2023
}
2124

2225
if (isset($field->config['suffixIconColor']) && $field->config['suffixIconColor']) {
23-
$input->suffixIconColor(Color::hex($field->config['suffixIconColor']));
26+
$input->suffixIconColor(Color::generateV3Palette($field->config['suffixIconColor']));
2427
}
2528

2629
return $input;
@@ -40,25 +43,25 @@ public static function getAffixesConfig(): array
4043

4144
public function affixFormFields(): Fieldset
4245
{
43-
return Forms\Components\Fieldset::make('Affixes')
46+
return Fieldset::make('Affixes')
4447
->columnSpanFull()
4548
->label(__('Affixes'))
4649
->schema([
47-
Forms\Components\Grid::make(3)
50+
Grid::make(3)
4851
->schema([
49-
Forms\Components\TextInput::make('config.prefix')
52+
TextInput::make('config.prefix')
5053
->label(__('Prefix')),
51-
Forms\Components\TextInput::make('config.prefixIcon')
54+
TextInput::make('config.prefixIcon')
5255
->placeholder('heroicon-m-')
5356
->label(__('Prefix icon')),
54-
Forms\Components\ColorPicker::make('config.prefixIconColor')
57+
ColorPicker::make('config.prefixIconColor')
5558
->label(__('Prefix color')),
56-
Forms\Components\TextInput::make('config.suffix')
59+
TextInput::make('config.suffix')
5760
->label(__('Suffix')),
58-
Forms\Components\TextInput::make('config.suffixIcon')
61+
TextInput::make('config.suffixIcon')
5962
->placeholder('heroicon-m-')
6063
->label(__('Suffix icon')),
61-
Forms\Components\ColorPicker::make('config.suffixIconColor')
64+
ColorPicker::make('config.suffixIconColor')
6265
->label(__('Suffix color')),
6366
]),
6467
]);

src/Concerns/HasDatalist.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Backstage\Fields\Concerns;
44

5+
use Filament\Schemas\Components\Fieldset;
56
use Filament\Forms\Components\TagsInput;
67

78
trait HasDatalist
@@ -25,7 +26,7 @@ public static function getDatalistConfig(): array
2526
]);
2627
}
2728

28-
public function datalistFormFields(): \Filament\Forms\Components\Fieldset
29+
public function datalistFormFields(): Fieldset
2930
{
3031
return $this->selectableValuesFormFields(
3132
type: 'datalistType',

src/Concerns/HasOptions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Backstage\Fields\Concerns;
44

5+
use Filament\Schemas\Components\Fieldset;
56
use Filament\Forms\Components\KeyValue;
67

78
trait HasOptions
@@ -25,7 +26,7 @@ public static function getOptionsConfig(): array
2526
]);
2627
}
2728

28-
public function optionFormFields(): \Filament\Forms\Components\Fieldset
29+
public function optionFormFields(): Fieldset
2930
{
3031
return $this->selectableValuesFormFields(
3132
type: 'optionType',

src/Concerns/HasSelectableValues.php

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
namespace Backstage\Fields\Concerns;
44

5+
use Filament\Schemas\Components\Fieldset;
6+
use Filament\Schemas\Components\Grid;
7+
use Filament\Forms\Components\Select;
8+
use Filament\Schemas\Components\Utilities\Get;
9+
use Filament\Schemas\Components\Utilities\Set;
10+
use Filament\Forms\Components\Hidden;
11+
use Filament\Forms\Components\TextInput;
512
use Filament\Forms;
6-
use Filament\Forms\Components\Fieldset;
7-
use Filament\Forms\Components\Grid;
813
use Filament\Forms\Components\Repeater;
914
use Illuminate\Support\Facades\Schema;
1015
use Illuminate\Support\Str;
@@ -101,13 +106,13 @@ protected static function getSelectableValuesConfig(): array
101106

102107
protected function selectableValuesFormFields(string $type, string $label, string $arrayComponent): Fieldset
103108
{
104-
return Forms\Components\Fieldset::make($label)
109+
return Fieldset::make($label)
105110
->columnSpanFull()
106111
->label(__($label))
107112
->schema([
108-
Forms\Components\Grid::make(2)
113+
Grid::make(2)
109114
->schema([
110-
Forms\Components\Select::make("config.{$type}")
115+
Select::make("config.{$type}")
111116
->options([
112117
'array' => __('Array'),
113118
'relationship' => __('Relationship'),
@@ -120,22 +125,22 @@ protected function selectableValuesFormFields(string $type, string $label, strin
120125
$arrayComponent::make('config.options')
121126
->label(__('Options'))
122127
->columnSpanFull()
123-
->visible(fn (Forms\Get $get): bool => $get("config.{$type}") == 'array')
124-
->required(fn (Forms\Get $get): bool => $get("config.{$type}") == 'array'),
128+
->visible(fn (Get $get): bool => $get("config.{$type}") == 'array')
129+
->required(fn (Get $get): bool => $get("config.{$type}") == 'array'),
125130
// Relationship options
126131
Repeater::make('config.relations')
127132
->label(__('Relations'))
128133
->schema([
129134
Grid::make()
130135
->columns(2)
131136
->schema([
132-
Forms\Components\Select::make('resource')
137+
Select::make('resource')
133138
->label(__('Resource'))
134139
->searchable()
135140
->preload()
136141
->columnSpanFull()
137142
->live(debounce: 250)
138-
->afterStateUpdated(function (Forms\Set $set, ?string $state) {
143+
->afterStateUpdated(function (Set $set, ?string $state) {
139144
$model = static::resolveResourceModel($state);
140145

141146
if (! $model) {
@@ -169,32 +174,32 @@ protected function selectableValuesFormFields(string $type, string $label, strin
169174
->toArray();
170175
})
171176
->noSearchResultsMessage(__('No types found'))
172-
->required(fn (Forms\Get $get): bool => $get("config.{$type}") == 'relationship'),
173-
Forms\Components\Select::make('relationValue')
177+
->required(fn (Get $get): bool => $get("config.{$type}") == 'relationship'),
178+
Select::make('relationValue')
174179
->label(__('Column'))
175180
->helperText(__('The column to use as name for the options'))
176-
->options(fn (Forms\Get $get) => $get('relationValue_options') ?? [])
181+
->options(fn (Get $get) => $get('relationValue_options') ?? [])
177182
->searchable()
178-
->visible(fn (Forms\Get $get): bool => ! empty($get('resource')))
179-
->required(fn (Forms\Get $get): bool => ! empty($get('resource'))),
180-
Forms\Components\Hidden::make('relationKey')
183+
->visible(fn (Get $get): bool => ! empty($get('resource')))
184+
->required(fn (Get $get): bool => ! empty($get('resource'))),
185+
Hidden::make('relationKey')
181186
->default('ulid')
182187
->label(__('Key'))
183-
->required(fn (Forms\Get $get): bool => $get("config.{$type}") == 'relationship'),
184-
Forms\Components\Repeater::make('relationValue_filters')
188+
->required(fn (Get $get): bool => $get("config.{$type}") == 'relationship'),
189+
Repeater::make('relationValue_filters')
185190
->label(__('Filters'))
186-
->visible(fn (Forms\Get $get): bool => ! empty($get('resource')))
191+
->visible(fn (Get $get): bool => ! empty($get('resource')))
187192
->schema([
188-
Forms\Components\Grid::make(3)
193+
Grid::make(3)
189194
->schema([
190-
Forms\Components\Select::make('column')
191-
->options(fn (\Filament\Forms\Get $get) => $get('../../relationValue_options') ?? [
195+
Select::make('column')
196+
->options(fn (Get $get) => $get('../../relationValue_options') ?? [
192197
'slug' => __('Slug'),
193198
'name' => __('Name'),
194199
])
195200
->live()
196201
->label(__('Column')),
197-
Forms\Components\Select::make('operator')
202+
Select::make('operator')
198203
->options([
199204
'=' => __('Equal'),
200205
'!=' => __('Not equal'),
@@ -206,8 +211,8 @@ protected function selectableValuesFormFields(string $type, string $label, strin
206211
'NOT LIKE' => __('Not like'),
207212
])
208213
->label(__('Operator')),
209-
Forms\Components\TextInput::make('value')
210-
->datalist(function (Forms\Get $get) {
214+
TextInput::make('value')
215+
->datalist(function (Get $get) {
211216
$resource = $get('../../resource');
212217
$column = $get('column');
213218

@@ -233,7 +238,7 @@ protected function selectableValuesFormFields(string $type, string $label, strin
233238
->columnSpanFull(),
234239
]),
235240
])
236-
->visible(fn (Forms\Get $get): bool => $get("config.{$type}") == 'relationship')
241+
->visible(fn (Get $get): bool => $get("config.{$type}") == 'relationship')
237242
->columnSpanFull(),
238243
]),
239244
]);

src/Fields/Base.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Backstage\Fields\Fields;
44

5+
use Filament\Schemas\Components\Grid;
6+
use Filament\Forms\Components\Toggle;
7+
use Filament\Forms\Components\TextInput;
8+
use Filament\Forms\Components\ColorPicker;
9+
use Filament\Schemas\Components\Utilities\Get;
510
use Backstage\Fields\Contracts\FieldContract;
611
use Backstage\Fields\Models\Field;
712
use Filament\Forms;
@@ -12,37 +17,37 @@ abstract class Base implements FieldContract
1217
public function getForm(): array
1318
{
1419
return [
15-
Forms\Components\Grid::make(3)
20+
Grid::make(3)
1621
->schema([
17-
Forms\Components\Toggle::make('config.required')
22+
Toggle::make('config.required')
1823
->label(__('Required'))
1924
->inline(false),
20-
Forms\Components\Toggle::make('config.disabled')
25+
Toggle::make('config.disabled')
2126
->label(__('Disabled'))
2227
->inline(false),
23-
Forms\Components\Toggle::make('config.hidden')
28+
Toggle::make('config.hidden')
2429
->label(__('Hidden'))
2530
->inline(false),
2631
]),
27-
Forms\Components\Grid::make(2)
32+
Grid::make(2)
2833
->schema([
29-
Forms\Components\TextInput::make('config.helperText')
34+
TextInput::make('config.helperText')
3035
->live(onBlur: true)
3136
->label(__('Helper text')),
32-
Forms\Components\TextInput::make('config.hint')
37+
TextInput::make('config.hint')
3338
->live(onBlur: true)
3439
->label(__('Hint')),
35-
Forms\Components\ColorPicker::make('config.hintColor')
40+
ColorPicker::make('config.hintColor')
3641
->label(__('Hint color'))
37-
->visible(function (Forms\Get $get): bool {
42+
->visible(function (Get $get): bool {
3843
$hint = $get('config.hint');
3944

4045
return ! empty(trim($hint));
4146
}),
42-
Forms\Components\TextInput::make('config.hintIcon')
47+
TextInput::make('config.hintIcon')
4348
->label(__('Hint icon'))
4449
->placeholder('heroicon-m-')
45-
->visible(function (Forms\Get $get): bool {
50+
->visible(function (Get $get): bool {
4651
$hint = $get('config.hint');
4752

4853
return ! empty(trim($hint));
@@ -75,7 +80,7 @@ public static function applyDefaultSettings($input, ?Field $field = null)
7580
->hintIcon($field->config['hintIcon'] ?? self::getDefaultConfig()['hintIcon']);
7681

7782
if (isset($field->config['hintColor']) && $field->config['hintColor']) {
78-
$input->hintColor(Color::hex($field->config['hintColor']));
83+
$input->hintColor(Color::generateV3Palette($field->config['hintColor']));
7984
}
8085

8186
return $input;

src/Fields/Checkbox.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace Backstage\Fields\Fields;
44

5+
use Filament\Schemas\Components\Tabs;
6+
use Filament\Schemas\Components\Tabs\Tab;
7+
use Filament\Schemas\Components\Grid;
8+
use Filament\Forms\Components\Toggle;
59
use Backstage\Fields\Contracts\FieldContract;
610
use Backstage\Fields\Models\Field;
711
use Filament\Forms;
@@ -40,26 +44,26 @@ public static function make(string $name, Field $field): Input
4044
public function getForm(): array
4145
{
4246
return [
43-
Forms\Components\Tabs::make()
47+
Tabs::make()
4448
->schema([
45-
Forms\Components\Tabs\Tab::make('General')
49+
Tab::make('General')
4650
->label(__('General'))
4751
->schema([
4852
...parent::getForm(),
4953
]),
50-
Forms\Components\Tabs\Tab::make('Field specific')
54+
Tab::make('Field specific')
5155
->label(__('Field specific'))
5256
->schema([
53-
Forms\Components\Grid::make(2)->schema([
57+
Grid::make(2)->schema([
5458

55-
Forms\Components\Toggle::make('config.inline')
59+
Toggle::make('config.inline')
5660
->label(__('Inline'))
5761
->inline(false),
58-
Forms\Components\Toggle::make('config.accepted')
62+
Toggle::make('config.accepted')
5963
->label(__('Accepted'))
6064
->helperText(__('Requires the checkbox to be checked'))
6165
->inline(false),
62-
Forms\Components\Toggle::make('config.declined')
66+
Toggle::make('config.declined')
6367
->label(__('Declined'))
6468
->helperText(__('Requires the checkbox to be unchecked'))
6569
->inline(false),

0 commit comments

Comments
 (0)