22
33namespace Backstage \Fields \Fields ;
44
5- use Backstage \Fields \Concerns \HasConfigurableFields ;
6- use Backstage \Fields \Concerns \HasFieldTypeResolver ;
7- use Backstage \Fields \Concerns \HasOptions ;
8- use Backstage \Fields \Contracts \FieldContract ;
9- use Backstage \Fields \Enums \Field as FieldEnum ;
10- use Backstage \Fields \Facades \Fields ;
5+ use Illuminate \Support \Str ;
116use Backstage \Fields \Models \Field ;
7+ use Illuminate \Support \Collection ;
8+ use Backstage \Fields \Facades \Fields ;
129use Filament \Forms \Components \Hidden ;
13- use Filament \Forms \Components \Repeater as Input ;
1410use Filament \Forms \Components \Select ;
15- use Filament \Forms \Components \TextInput ;
1611use Filament \Forms \Components \Toggle ;
1712use Filament \Schemas \Components \Grid ;
18- use Filament \Schemas \Components \Section ;
1913use Filament \Schemas \Components \Tabs ;
14+ use Filament \Tables \Columns \TextColumn ;
15+ use Filament \Forms \Components \TextInput ;
16+ use Filament \Schemas \Components \Section ;
17+ use Backstage \Fields \Concerns \HasOptions ;
2018use Filament \Schemas \Components \Tabs \Tab ;
19+ use Filament \Tables \Columns \SelectColumn ;
20+ use Filament \Tables \Columns \ToggleColumn ;
21+ use Backstage \Fields \Contracts \FieldContract ;
22+ use Backstage \Fields \Enums \Field as FieldEnum ;
2123use Filament \Schemas \Components \Utilities \Get ;
2224use Filament \Schemas \Components \Utilities \Set ;
23- use Illuminate \Support \Collection ;
24- use Illuminate \Support \Str ;
25+ use Filament \Forms \Components \Repeater as Input ;
26+ use Backstage \Fields \Concerns \HasFieldTypeResolver ;
27+ use Filament \Forms \Components \Repeater \TableColumn ;
28+ use Backstage \Fields \Concerns \HasConfigurableFields ;
2529use Saade \FilamentAdjacencyList \Forms \Components \AdjacencyList ;
2630
2731class Repeater extends Base implements FieldContract
@@ -49,6 +53,8 @@ public static function getDefaultConfig(): array
4953 'cloneable ' => false ,
5054 'columns ' => 1 ,
5155 'form ' => [],
56+ 'table ' => false ,
57+ 'compact ' => false ,
5258 ];
5359 }
5460
@@ -65,6 +71,10 @@ public static function make(string $name, ?Field $field = null): Input
6571 ->cloneable ($ field ->config ['cloneable ' ] ?? self ::getDefaultConfig ()['cloneable ' ])
6672 ->columns ($ field ->config ['columns ' ] ?? self ::getDefaultConfig ()['columns ' ]);
6773
74+ if ($ field ->config ['compact ' ] ?? self ::getDefaultConfig ()['compact ' ]) {
75+ $ input = $ input ->compact ();
76+ }
77+
6878 if ($ field ->config ['reorderableWithButtons ' ] ?? self ::getDefaultConfig ()['reorderableWithButtons ' ]) {
6979 $ input = $ input ->reorderableWithButtons ();
7080 }
@@ -74,7 +84,15 @@ public static function make(string $name, ?Field $field = null): Input
7484 }
7585
7686 if ($ field && $ field ->children ->count () > 0 ) {
77- $ input = $ input ->schema (self ::generateSchemaFromChildren ($ field ->children ));
87+ $ isTableMode = $ field ->config ['table ' ] ?? self ::getDefaultConfig ()['table ' ];
88+
89+ if ($ isTableMode ) {
90+ $ input = $ input
91+ ->table (self ::generateTableColumns ($ field ->children ))
92+ ->schema (self ::generateSchemaFromChildren ($ field ->children , false ));
93+ } else {
94+ $ input = $ input ->schema (self ::generateSchemaFromChildren ($ field ->children , false ));
95+ }
7896 }
7997
8098 return $ input ;
@@ -91,13 +109,13 @@ public function getForm(): array
91109 Tab::make ('Field specific ' )
92110 ->label (__ ('Field specific ' ))
93111 ->schema ([
94- Toggle ::make (' config.addable ' )
95- -> label ( __ ( ' Addable ' ) )
96- -> inline ( false ),
97- Toggle:: make ( ' config.deletable ' )
98- -> label ( __ ( ' Deletable ' ) )
99- -> inline ( false ),
100- Grid:: make ( 2 )-> schema ([
112+ Grid ::make (3 )-> schema ([
113+ Toggle:: make ( ' config.addable ' )
114+ -> label ( __ ( ' Addable ' ))
115+ -> inline ( false ),
116+ Toggle:: make ( ' config.deletable ' )
117+ -> label ( __ ( ' Deletable ' ))
118+ -> inline ( false ),
101119 Toggle::make ('config.reorderable ' )
102120 ->label (__ ('Reorderable ' ))
103121 ->live ()
@@ -107,23 +125,33 @@ public function getForm(): array
107125 ->dehydrated ()
108126 ->disabled (fn (Get $ get ): bool => $ get ('config.reorderable ' ) === false )
109127 ->inline (false ),
128+ Toggle::make ('config.collapsible ' )
129+ ->label (__ ('Collapsible ' ))
130+ ->inline (false ),
131+ Toggle::make ('config.collapsed ' )
132+ ->label (__ ('Collapsed ' ))
133+ ->visible (fn (Get $ get ): bool => $ get ('config.collapsible ' ) === true )
134+ ->inline (false ),
135+ Toggle::make ('config.cloneable ' )
136+ ->label (__ ('Cloneable ' ))
137+ ->inline (false ),
138+ ]),
139+ Grid::make (2 )->schema ([
140+ TextInput::make ('config.addActionLabel ' )
141+ ->label (__ ('Add action label ' )),
142+ TextInput::make ('config.columns ' )
143+ ->label (__ ('Columns ' ))
144+ ->default (1 )
145+ ->numeric (),
146+ Toggle::make ('config.table ' )
147+ ->label (__ ('Table repeater ' ))
148+ ->inline (false ),
149+ Toggle::make ('config.compact ' )
150+ ->label (__ ('Compact table ' ))
151+ ->inline (false )
152+ ->live ()
153+ ->visible (fn (Get $ get ): bool => $ get ('config.table ' ) === true ),
110154 ]),
111- Toggle::make ('config.collapsible ' )
112- ->label (__ ('Collapsible ' ))
113- ->inline (false ),
114- Toggle::make ('config.collapsed ' )
115- ->label (__ ('Collapsed ' ))
116- ->visible (fn (Get $ get ): bool => $ get ('config.collapsible ' ) === true )
117- ->inline (false ),
118- Toggle::make ('config.cloneable ' )
119- ->label (__ ('Cloneable ' ))
120- ->inline (false ),
121- TextInput::make ('config.addActionLabel ' )
122- ->label (__ ('Add action label ' )),
123- TextInput::make ('config.columns ' )
124- ->label (__ ('Columns ' ))
125- ->default (1 )
126- ->numeric (),
127155 AdjacencyList::make ('config.form ' )
128156 ->columnSpanFull ()
129157 ->label (__ ('Fields ' ))
@@ -197,7 +225,7 @@ function () {
197225 ))
198226 ->visible (fn (Get $ get ) => filled ($ get ('field_type ' ))),
199227 ]),
200- ])-> columns ( 2 ) ,
228+ ]),
201229 ])->columnSpanFull (),
202230 ];
203231 }
@@ -207,7 +235,21 @@ protected function excludeFromBaseSchema(): array
207235 return ['defaultValue ' ];
208236 }
209237
210- private static function generateSchemaFromChildren (Collection $ children ): array
238+ private static function generateTableColumns (Collection $ children ): array
239+ {
240+ $ columns = [];
241+
242+ $ children = $ children ->sortBy ('position ' );
243+
244+ foreach ($ children as $ child ) {
245+ $ columns [] = TableColumn::make ($ child ['slug ' ])
246+ ->label ($ child ['name ' ] ?? $ child ['slug ' ]);
247+ }
248+
249+ return $ columns ;
250+ }
251+
252+ private static function generateSchemaFromChildren (Collection $ children , bool $ isTableMode = false ): array
211253 {
212254 $ schema = [];
213255
0 commit comments