@@ -36,7 +36,7 @@ const useFielArrayStyles = makeStyles({
36
36
}
37
37
} ) ;
38
38
39
- const ArrayItem = ( { fields, fieldIndex, name, remove, length, minItems, removeLabel } ) => {
39
+ const ArrayItem = ( { fields, fieldIndex, name, remove, length, minItems, removeLabel, FieldContainerProps , FieldGroupGridProps , RemoveButtonGridProps , RemoveButtonProps } ) => {
40
40
const { renderForm } = useFormApi ( ) ;
41
41
const classes = useFielArrayStyles ( ) ;
42
42
@@ -46,14 +46,14 @@ const ArrayItem = ({ fields, fieldIndex, name, remove, length, minItems, removeL
46
46
} ) ;
47
47
48
48
return (
49
- < Grid container spacing = { 3 } >
50
- < Grid item xs = { 12 } >
49
+ < Grid container spacing = { 3 } { ... FieldContainerProps } >
50
+ < Grid item xs = { 12 } { ... FieldGroupGridProps } >
51
51
< Grid container spacing = { 3 } >
52
52
{ renderForm ( [ editedFields ] ) }
53
53
</ Grid >
54
54
</ Grid >
55
- < Grid item xs = { 12 } className = { classes . buttonsToEnd } >
56
- < Button color = "secondary" onClick = { ( ) => remove ( fieldIndex ) } disabled = { length <= minItems } >
55
+ < Grid item xs = { 12 } className = { classes . buttonsToEnd } { ... RemoveButtonGridProps } >
56
+ < Button color = "secondary" onClick = { ( ) => remove ( fieldIndex ) } disabled = { length <= minItems } { ... RemoveButtonProps } >
57
57
{ removeLabel }
58
58
</ Button >
59
59
</ Grid >
@@ -68,7 +68,18 @@ ArrayItem.propTypes = {
68
68
remove : PropTypes . func . isRequired ,
69
69
length : PropTypes . number ,
70
70
minItems : PropTypes . number ,
71
- removeLabel : PropTypes . node . isRequired
71
+ removeLabel : PropTypes . node . isRequired ,
72
+ FieldContainerProps : PropTypes . object ,
73
+ FieldGroupGridProps : PropTypes . object ,
74
+ RemoveButtonGridProps : PropTypes . object ,
75
+ RemoveButtonProps : PropTypes . object
76
+ } ;
77
+
78
+ ArrayItem . defaultProps = {
79
+ FieldContainerProps : { } ,
80
+ FieldGroupGridProps : { } ,
81
+ RemoveButtonGridProps : { } ,
82
+ RemoveButtonProps : { }
72
83
} ;
73
84
74
85
const defaultButtonLabels = {
@@ -122,6 +133,22 @@ const DynamicArray = ({ ...props }) => {
122
133
FormFieldGridProps,
123
134
FormControlProps,
124
135
buttonLabels,
136
+ GridContainerProps,
137
+ HeaderGridProps,
138
+ HeaderProps,
139
+ UndoButtonProps,
140
+ RedoButtonProps,
141
+ AddButtonProps,
142
+ DescriptionGridProps,
143
+ DescriptionProps,
144
+ BodyGridProps,
145
+ NoItemsProps,
146
+ FormHelperTextGridProps,
147
+ FormHelperTextProps,
148
+ FieldContainerProps,
149
+ FieldGroupGridProps,
150
+ RemoveButtonGridProps,
151
+ RemoveButtonProps,
125
152
...rest
126
153
} = useFieldApi ( props ) ;
127
154
const [ state , dispatch ] = useReducer ( reducer , initialState ) ;
@@ -167,31 +194,31 @@ const DynamicArray = ({ ...props }) => {
167
194
} ;
168
195
169
196
return (
170
- < Grid container spacing = { 3 } >
171
- < Grid item xs = { 12 } className = { classes . header } >
197
+ < Grid container spacing = { 3 } { ... GridContainerProps } >
198
+ < Grid item xs = { 12 } className = { classes . header } { ... HeaderGridProps } >
172
199
{ label && (
173
- < Typography variant = "h6" className = { classes . label } >
200
+ < Typography variant = "h6" className = { classes . label } { ... HeaderProps } >
174
201
{ label }
175
202
</ Typography >
176
203
) }
177
- < IconButton color = "primary" aria-label = "undo" component = "span" disabled = { state . index === 0 } onClick = { undo } >
204
+ < IconButton color = "primary" aria-label = "undo" component = "span" disabled = { state . index === 0 } onClick = { undo } { ... UndoButtonProps } >
178
205
< UndoIcon />
179
206
</ IconButton >
180
- < IconButton color = "primary" aria-label = "redo" component = "span" disabled = { state . index === state . history . length } onClick = { redo } >
207
+ < IconButton color = "primary" aria-label = "redo" component = "span" disabled = { state . index === state . history . length } onClick = { redo } { ... RedoButtonProps } >
181
208
< RedoIcon />
182
209
</ IconButton >
183
- < Button color = "primary" onClick = { pushWrapper } disabled = { value . length >= maxItems } >
210
+ < Button color = "primary" onClick = { pushWrapper } disabled = { value . length >= maxItems } { ... AddButtonProps } >
184
211
{ combinedButtonLabels . add }
185
212
</ Button >
186
213
</ Grid >
187
214
{ description && (
188
- < Grid item xs = { 12 } >
189
- < Typography variant = "subtitle1" > { description } </ Typography >
215
+ < Grid item xs = { 12 } { ... DescriptionGridProps } >
216
+ < Typography variant = "subtitle1" { ... DescriptionProps } > { description } </ Typography >
190
217
</ Grid >
191
218
) }
192
- < Grid item xs = { 12 } >
219
+ < Grid item xs = { 12 } { ... BodyGridProps } >
193
220
{ value . length <= 0 ? (
194
- < Typography variant = "body1" gutterBottom className = { classes . centerText } >
221
+ < Typography variant = "body1" gutterBottom className = { classes . centerText } { ... NoItemsProps } >
195
222
{ noItemsMessage }
196
223
</ Typography >
197
224
) : (
@@ -205,13 +232,17 @@ const DynamicArray = ({ ...props }) => {
205
232
length = { value . length }
206
233
minItems = { minItems }
207
234
removeLabel = { combinedButtonLabels . remove }
235
+ FieldContainerProps = { FieldContainerProps }
236
+ FieldGroupGridProps = { FieldGroupGridProps }
237
+ RemoveButtonGridProps = { RemoveButtonGridProps }
238
+ RemoveButtonProps = { RemoveButtonProps }
208
239
/>
209
240
) )
210
241
) }
211
242
</ Grid >
212
243
{ ( isError || submitError ) && (
213
- < Grid item xs = { 12 } >
214
- < FormHelperText > { error || submitError } </ FormHelperText >
244
+ < Grid item xs = { 12 } { ... FormHelperTextGridProps } >
245
+ < FormHelperText { ... FormHelperTextProps } > { error || submitError } </ FormHelperText >
215
246
</ Grid >
216
247
) }
217
248
</ Grid >
@@ -233,15 +264,47 @@ DynamicArray.propTypes = {
233
264
noItemsMessage : PropTypes . node ,
234
265
FormControlProps : PropTypes . object ,
235
266
FormFieldGridProps : PropTypes . object ,
236
- buttonLabels : PropTypes . object
267
+ buttonLabels : PropTypes . object ,
268
+ GridContainerProps : PropTypes . object ,
269
+ HeaderGridProps : PropTypes . object ,
270
+ HeaderProps : PropTypes . object ,
271
+ UndoButtonProps : PropTypes . object ,
272
+ RedoButtonProps : PropTypes . object ,
273
+ AddButtonProps : PropTypes . object ,
274
+ DescriptionGridProps : PropTypes . object ,
275
+ DescriptionProps : PropTypes . object ,
276
+ BodyGridProps : PropTypes . object ,
277
+ NoItemsProps : PropTypes . object ,
278
+ FormHelperTextGridProps : PropTypes . object ,
279
+ FormHelperTextProps : PropTypes . object ,
280
+ FieldContainerProps : PropTypes . object ,
281
+ FieldGroupGridProps : PropTypes . object ,
282
+ RemoveButtonGridProps : PropTypes . object ,
283
+ RemoveButtonProps : PropTypes . object
237
284
} ;
238
285
239
286
DynamicArray . defaultProps = {
240
287
maxItems : Infinity ,
241
288
minItems : 0 ,
242
289
noItemsMessage : 'No items added' ,
243
290
FormControlProps : { } ,
244
- FormFieldGridProps : { }
291
+ FormFieldGridProps : { } ,
292
+ GridContainerProps : { } ,
293
+ HeaderGridProps : { } ,
294
+ HeaderProps : { } ,
295
+ UndoButtonProps : { } ,
296
+ RedoButtonProps : { } ,
297
+ AddButtonProps : { } ,
298
+ DescriptionGridProps : { } ,
299
+ DescriptionProps : { } ,
300
+ BodyGridProps : { } ,
301
+ NoItemsProps : { } ,
302
+ FormHelperTextGridProps : { } ,
303
+ FormHelperTextProps : { } ,
304
+ FieldContainerProps : { } ,
305
+ FieldGroupGridProps : { } ,
306
+ RemoveButtonGridProps : { } ,
307
+ RemoveButtonProps : { }
245
308
} ;
246
309
247
310
export default DynamicArray ;
0 commit comments