@@ -36,7 +36,19 @@ const useFielArrayStyles = makeStyles({
36
36
}
37
37
} ) ;
38
38
39
- const ArrayItem = ( { fields, fieldIndex, name, remove, length, minItems, removeLabel } ) => {
39
+ const ArrayItem = ( {
40
+ fields,
41
+ fieldIndex,
42
+ name,
43
+ remove,
44
+ length,
45
+ minItems,
46
+ removeLabel,
47
+ FieldContainerProps,
48
+ FieldGroupGridProps,
49
+ RemoveButtonGridProps,
50
+ RemoveButtonProps
51
+ } ) => {
40
52
const { renderForm } = useFormApi ( ) ;
41
53
const classes = useFielArrayStyles ( ) ;
42
54
@@ -46,14 +58,14 @@ const ArrayItem = ({ fields, fieldIndex, name, remove, length, minItems, removeL
46
58
} ) ;
47
59
48
60
return (
49
- < Grid container spacing = { 3 } >
50
- < Grid item xs = { 12 } >
61
+ < Grid container spacing = { 3 } { ... FieldContainerProps } >
62
+ < Grid item xs = { 12 } { ... FieldGroupGridProps } >
51
63
< Grid container spacing = { 3 } >
52
64
{ renderForm ( [ editedFields ] ) }
53
65
</ Grid >
54
66
</ Grid >
55
- < Grid item xs = { 12 } className = { classes . buttonsToEnd } >
56
- < Button color = "secondary" onClick = { ( ) => remove ( fieldIndex ) } disabled = { length <= minItems } >
67
+ < Grid item xs = { 12 } className = { classes . buttonsToEnd } { ... RemoveButtonGridProps } >
68
+ < Button color = "secondary" onClick = { ( ) => remove ( fieldIndex ) } disabled = { length <= minItems } { ... RemoveButtonProps } >
57
69
{ removeLabel }
58
70
</ Button >
59
71
</ Grid >
@@ -68,7 +80,18 @@ ArrayItem.propTypes = {
68
80
remove : PropTypes . func . isRequired ,
69
81
length : PropTypes . number ,
70
82
minItems : PropTypes . number ,
71
- removeLabel : PropTypes . node . isRequired
83
+ removeLabel : PropTypes . node . isRequired ,
84
+ FieldContainerProps : PropTypes . object ,
85
+ FieldGroupGridProps : PropTypes . object ,
86
+ RemoveButtonGridProps : PropTypes . object ,
87
+ RemoveButtonProps : PropTypes . object
88
+ } ;
89
+
90
+ ArrayItem . defaultProps = {
91
+ FieldContainerProps : { } ,
92
+ FieldGroupGridProps : { } ,
93
+ RemoveButtonGridProps : { } ,
94
+ RemoveButtonProps : { }
72
95
} ;
73
96
74
97
const defaultButtonLabels = {
@@ -122,6 +145,22 @@ const DynamicArray = ({ ...props }) => {
122
145
FormFieldGridProps,
123
146
FormControlProps,
124
147
buttonLabels,
148
+ GridContainerProps,
149
+ HeaderGridProps,
150
+ HeaderProps,
151
+ UndoButtonProps,
152
+ RedoButtonProps,
153
+ AddButtonProps,
154
+ DescriptionGridProps,
155
+ DescriptionProps,
156
+ BodyGridProps,
157
+ NoItemsProps,
158
+ FormHelperTextGridProps,
159
+ FormHelperTextProps,
160
+ FieldContainerProps,
161
+ FieldGroupGridProps,
162
+ RemoveButtonGridProps,
163
+ RemoveButtonProps,
125
164
...rest
126
165
} = useFieldApi ( props ) ;
127
166
const [ state , dispatch ] = useReducer ( reducer , initialState ) ;
@@ -167,31 +206,40 @@ const DynamicArray = ({ ...props }) => {
167
206
} ;
168
207
169
208
return (
170
- < Grid container spacing = { 3 } >
171
- < Grid item xs = { 12 } className = { classes . header } >
209
+ < Grid container spacing = { 3 } { ... GridContainerProps } >
210
+ < Grid item xs = { 12 } className = { classes . header } { ... HeaderGridProps } >
172
211
{ label && (
173
- < Typography variant = "h6" className = { classes . label } >
212
+ < Typography variant = "h6" className = { classes . label } { ... HeaderProps } >
174
213
{ label }
175
214
</ Typography >
176
215
) }
177
- < IconButton color = "primary" aria-label = "undo" component = "span" disabled = { state . index === 0 } onClick = { undo } >
216
+ < IconButton color = "primary" aria-label = "undo" component = "span" disabled = { state . index === 0 } onClick = { undo } { ... UndoButtonProps } >
178
217
< UndoIcon />
179
218
</ IconButton >
180
- < IconButton color = "primary" aria-label = "redo" component = "span" disabled = { state . index === state . history . length } onClick = { redo } >
219
+ < IconButton
220
+ color = "primary"
221
+ aria-label = "redo"
222
+ component = "span"
223
+ disabled = { state . index === state . history . length }
224
+ onClick = { redo }
225
+ { ...RedoButtonProps }
226
+ >
181
227
< RedoIcon />
182
228
</ IconButton >
183
- < Button color = "primary" onClick = { pushWrapper } disabled = { value . length >= maxItems } >
229
+ < Button color = "primary" onClick = { pushWrapper } disabled = { value . length >= maxItems } { ... AddButtonProps } >
184
230
{ combinedButtonLabels . add }
185
231
</ Button >
186
232
</ Grid >
187
233
{ description && (
188
- < Grid item xs = { 12 } >
189
- < Typography variant = "subtitle1" > { description } </ Typography >
234
+ < Grid item xs = { 12 } { ...DescriptionGridProps } >
235
+ < Typography variant = "subtitle1" { ...DescriptionProps } >
236
+ { description }
237
+ </ Typography >
190
238
</ Grid >
191
239
) }
192
- < Grid item xs = { 12 } >
240
+ < Grid item xs = { 12 } { ... BodyGridProps } >
193
241
{ value . length <= 0 ? (
194
- < Typography variant = "body1" gutterBottom className = { classes . centerText } >
242
+ < Typography variant = "body1" gutterBottom className = { classes . centerText } { ... NoItemsProps } >
195
243
{ noItemsMessage }
196
244
</ Typography >
197
245
) : (
@@ -205,13 +253,17 @@ const DynamicArray = ({ ...props }) => {
205
253
length = { value . length }
206
254
minItems = { minItems }
207
255
removeLabel = { combinedButtonLabels . remove }
256
+ FieldContainerProps = { FieldContainerProps }
257
+ FieldGroupGridProps = { FieldGroupGridProps }
258
+ RemoveButtonGridProps = { RemoveButtonGridProps }
259
+ RemoveButtonProps = { RemoveButtonProps }
208
260
/>
209
261
) )
210
262
) }
211
263
</ Grid >
212
264
{ ( isError || submitError ) && (
213
- < Grid item xs = { 12 } >
214
- < FormHelperText > { error || submitError } </ FormHelperText >
265
+ < Grid item xs = { 12 } { ... FormHelperTextGridProps } >
266
+ < FormHelperText { ... FormHelperTextProps } > { error || submitError } </ FormHelperText >
215
267
</ Grid >
216
268
) }
217
269
</ Grid >
@@ -233,15 +285,47 @@ DynamicArray.propTypes = {
233
285
noItemsMessage : PropTypes . node ,
234
286
FormControlProps : PropTypes . object ,
235
287
FormFieldGridProps : PropTypes . object ,
236
- buttonLabels : PropTypes . object
288
+ buttonLabels : PropTypes . object ,
289
+ GridContainerProps : PropTypes . object ,
290
+ HeaderGridProps : PropTypes . object ,
291
+ HeaderProps : PropTypes . object ,
292
+ UndoButtonProps : PropTypes . object ,
293
+ RedoButtonProps : PropTypes . object ,
294
+ AddButtonProps : PropTypes . object ,
295
+ DescriptionGridProps : PropTypes . object ,
296
+ DescriptionProps : PropTypes . object ,
297
+ BodyGridProps : PropTypes . object ,
298
+ NoItemsProps : PropTypes . object ,
299
+ FormHelperTextGridProps : PropTypes . object ,
300
+ FormHelperTextProps : PropTypes . object ,
301
+ FieldContainerProps : PropTypes . object ,
302
+ FieldGroupGridProps : PropTypes . object ,
303
+ RemoveButtonGridProps : PropTypes . object ,
304
+ RemoveButtonProps : PropTypes . object
237
305
} ;
238
306
239
307
DynamicArray . defaultProps = {
240
308
maxItems : Infinity ,
241
309
minItems : 0 ,
242
310
noItemsMessage : 'No items added' ,
243
311
FormControlProps : { } ,
244
- FormFieldGridProps : { }
312
+ FormFieldGridProps : { } ,
313
+ GridContainerProps : { } ,
314
+ HeaderGridProps : { } ,
315
+ HeaderProps : { } ,
316
+ UndoButtonProps : { } ,
317
+ RedoButtonProps : { } ,
318
+ AddButtonProps : { } ,
319
+ DescriptionGridProps : { } ,
320
+ DescriptionProps : { } ,
321
+ BodyGridProps : { } ,
322
+ NoItemsProps : { } ,
323
+ FormHelperTextGridProps : { } ,
324
+ FormHelperTextProps : { } ,
325
+ FieldContainerProps : { } ,
326
+ FieldGroupGridProps : { } ,
327
+ RemoveButtonGridProps : { } ,
328
+ RemoveButtonProps : { }
245
329
} ;
246
330
247
331
export default DynamicArray ;
0 commit comments