File tree Expand file tree Collapse file tree 8 files changed +75
-46
lines changed Expand file tree Collapse file tree 8 files changed +75
-46
lines changed Original file line number Diff line number Diff line change @@ -32,14 +32,14 @@ You can use the `Sidebar` component to split the form into two distinct sections
32
32
``` php
33
33
use RalphJSmit\Filament\Components\Forms\Sidebar;
34
34
35
- Sidebar::make()->schema( [
35
+ Sidebar::make([
36
36
// Components for the main section here
37
37
],[
38
38
// Components for the sidebar section here
39
- ])->getSchema()[0]
39
+ ])
40
40
```
41
41
42
- If you're using it in the Admin panel, you can directly return the ` Sidebar ` component from the ` form() ` in your resource :
42
+ If you're using it in the Admin panel, you can use the ` Sidebar ` in your ` form() ` method :
43
43
44
44
``` php
45
45
use Filament\Forms\Components\Card;
@@ -50,18 +50,20 @@ use RalphJSmit\Filament\Components\Forms\Sidebar;
50
50
51
51
public static function form(Form $form): Form
52
52
{
53
- return Sidebar::make($form)->schema([
54
- Card::make([
55
- TextInput::make('title')->label('Title'),
53
+ return $form->schema([
54
+ Sidebar::make([
55
+ Card::make([
56
+ TextInput::make('title')->label('Title'),
57
+ // ...
58
+ ]),
56
59
// ...
57
- ]),
58
- // ...
59
- ], [
60
- Card::make([
61
- ...Timestamps::make( ),
60
+ ], [
61
+ Card::make([
62
+ ...Timestamps::make(),
63
+ // ...
64
+ ] ),
62
65
// ...
63
66
]),
64
- // ...
65
67
]);
66
68
}
67
69
```
Original file line number Diff line number Diff line change
1
+ # Upgrade
2
+
3
+ ## From 1.x to 2.x
4
+
5
+ The ` Sidebar::make() ` method's signature was changed. Previously it accepted a ` $form ` parameter and returned a form. Now you can just use the ` Sidebar::make() ` method inside any form schema:
6
+
7
+ ``` diff
8
+ - public static function form(Form $form): Form
9
+ - {
10
+ - return Sidebar::make($form)->schema([
11
+ - // Main components
12
+ - ], [
13
+ - // Sidebar components
14
+ - ]);
15
+ - }
16
+ + public static function form(Form $form): Form
17
+ + {
18
+ + return $form->schema([
19
+ + Sidebar::make([
20
+ + // Main components
21
+ + ], [
22
+ + // Sidebar components
23
+ + ]),
24
+ + ]);
25
+ + }
Original file line number Diff line number Diff line change 2
2
3
3
namespace RalphJSmit \Filament \Components \Forms ;
4
4
5
+ use Closure ;
5
6
use Filament \Forms \Components \Grid ;
6
- use Filament \Forms \Form ;
7
- use Filament \Resources \Form as FormV2 ;
8
7
9
8
class Sidebar
10
9
{
11
10
public function __construct (
12
- public FormV2 |Form $ form ,
11
+ public array |Closure $ mainComponents ,
12
+ public array |Closure $ sidebarComponents
13
13
) {}
14
14
15
- public static function make (FormV2 | Form | null $ form = null ): static
15
+ public static function make (array | Closure $ mainComponents , array | Closure $ sidebarComponents ): Grid
16
16
{
17
- if ( ! $ form ) {
18
- $ form = match ( true ) {
19
- class_exists (FormV2::class) => FormV2::make (),
20
- default => Form::make (),
21
- };
22
- }
23
-
24
- return new static (form: $ form );
25
- }
26
-
27
- public function schema (array $ mainComponents , array $ sidebarComponents ): FormV2 |Form
28
- {
29
- return $ this ->form ->schema ([
30
- Grid::make (['sm ' => 3 ])->schema ([
17
+ return Grid::make (['sm ' => 3 ])->schema ([
31
18
Grid::make ()->schema ($ mainComponents )->columnSpan (['sm ' => 2 ]),
32
19
Grid::make ()->schema ($ sidebarComponents )->columnSpan (['sm ' => 1 ]),
33
- ]),
34
- ]);
20
+ ]);
35
21
}
36
- }
22
+ }
Original file line number Diff line number Diff line change 32
32
testTime ()->freeze ();
33
33
34
34
$ component = Livewire::test (TestableForm::class, [
35
- 'record ' => $ record = Record::factory ()->make (['created_at ' => null ]),
35
+ 'record ' => $ record = Record::factory ()->create (['created_at ' => null ]),
36
36
]);
37
37
38
38
$ component
48
48
testTime ()->freeze ();
49
49
50
50
$ component = Livewire::test (TestableForm::class, [
51
- 'record ' => $ record = Record::factory ()->make (['created_at ' => now ()->subMinutes (10 )]),
51
+ 'record ' => $ record = Record::factory ()->create (['created_at ' => now ()->subMinutes (10 )]),
52
52
]);
53
53
54
54
$ component
55
55
->assertSet ('record.created_at ' , fn (Carbon $ value ) => $ value !== null && $ value ->gt (now ()->subMinutes (10 )->subSecond ()))
56
56
->assertSee ('10 minutes ago ' );
57
- });
57
+ });
Original file line number Diff line number Diff line change 8
8
9
9
it ('can create a sidebar ' , function () {
10
10
TestableForm::$ formSchema = [
11
- Sidebar::make ()-> schema (
11
+ Sidebar::make (
12
12
mainComponents: [
13
13
\Filament \Forms \Components \Placeholder::make ('dummy_placeholder ' ),
14
14
\Filament \Forms \Components \Placeholder::make ('dummy_placeholder_2 ' ),
17
17
Filament \Forms \Components \TextInput::make ('name ' )->label ('Test label for sidebar component ' ),
18
18
Filament \Forms \Components \TextInput::make ('name ' )->label ('Test label 2 for sidebar component ' ),
19
19
]
20
- )-> getSchema ()[ 0 ] ,
20
+ ),
21
21
];
22
22
23
23
testTime ()->freeze ();
29
29
->assertSee ('dummy_placeholder_2 ' )
30
30
->assertSee ('Test label for sidebar component ' )
31
31
->assertSee ('Test label 2 for sidebar component ' );
32
- });
32
+ });
Original file line number Diff line number Diff line change 15
15
testTime ()->freeze ();
16
16
17
17
$ component = Livewire::test (TestableForm::class, [
18
- 'record ' => $ record = Record::factory ()->make (['created_at ' => now ()->subMinutes (10 ), 'updated_at ' => now ()->subMinutes (15 )]),
18
+ 'record ' => $ record = Record::factory ()->create (['created_at ' => now ()->subMinutes (10 ), 'updated_at ' => now ()->subMinutes (15 )]),
19
19
]);
20
20
21
21
$ component
22
22
->assertSet ('record ' , $ record )
23
23
->assertSee ('10 minutes ago ' )
24
24
->assertSee ('15 minutes ago ' );
25
- });
25
+ });
Original file line number Diff line number Diff line change 32
32
testTime ()->freeze ();
33
33
34
34
$ component = Livewire::test (TestableForm::class, [
35
- 'record ' => $ record = Record::factory ()->make (['updated_at ' => null ]),
35
+ 'record ' => $ record = Record::factory ()->create (['updated_at ' => null ]),
36
36
]);
37
37
38
38
$ component
48
48
testTime ()->freeze ();
49
49
50
50
$ component = Livewire::test (TestableForm::class, [
51
- 'record ' => $ record = Record::factory ()->make (['updated_at ' => now ()->subMinutes (10 )]),
51
+ 'record ' => $ record = Record::factory ()->create (['updated_at ' => now ()->subMinutes (10 )]),
52
52
]);
53
53
54
54
$ component
55
55
->assertSet ('record.updated_at ' , fn (Carbon $ value ) => $ value !== null && $ value ->gt (now ()->subMinutes (10 )->subSecond ()))
56
56
->assertSee ('10 minutes ago ' );
57
- });
57
+ });
Original file line number Diff line number Diff line change 4
4
5
5
use Filament \Forms \FormsServiceProvider ;
6
6
use Filament \Support \SupportServiceProvider ;
7
+ use Illuminate \Database \Schema \Blueprint ;
8
+ use Illuminate \Foundation \Testing \RefreshDatabase ;
7
9
use Livewire \LivewireServiceProvider ;
8
10
use Orchestra \Testbench \TestCase as Orchestra ;
9
11
use RalphJSmit \Filament \Components \FilamentComponentsServiceProvider ;
@@ -13,6 +15,8 @@ class TestCase extends Orchestra
13
15
protected function setUp (): void
14
16
{
15
17
parent ::setUp ();
18
+
19
+ $ this ->setUpDatabase ();
16
20
}
17
21
18
22
protected function getPackageProviders (mixed $ app ): array
@@ -27,6 +31,18 @@ protected function getPackageProviders(mixed $app): array
27
31
28
32
public function getEnvironmentSetUp ($ app ): void
29
33
{
30
- //
34
+ $ app ['config ' ]->set ('database.default ' , 'sqlite ' );
35
+ $ app ['config ' ]->set ('database.connections.sqlite ' , [
36
+ 'driver ' => 'sqlite ' ,
37
+ 'database ' => ':memory: ' ,
38
+ 'prefix ' => '' ,
39
+ ]);
40
+ }
41
+
42
+ protected function setUpDatabase ()
43
+ {
44
+ $ this ->app ->get ('db ' )->connection ()->getSchemaBuilder ()->create ('records ' , function (Blueprint $ table ) {
45
+ $ table ->timestamps ();
46
+ });
31
47
}
32
- }
48
+ }
You can’t perform that action at this time.
0 commit comments