|
1 | 1 | import React from "react"; |
2 | | -import { |
3 | | - ArrayFieldTemplateItemType, |
4 | | - FormContextType, |
5 | | - RJSFSchema, |
6 | | - StrictRJSFSchema, |
7 | | -} from "@rjsf/utils"; |
| 2 | +import { ArrayFieldTemplateItemType, FormContextType, RJSFSchema, StrictRJSFSchema } from "@rjsf/utils"; |
| 3 | +import { Grid } from "@trussworks/react-uswds"; // Updated import |
8 | 4 |
|
| 5 | +/** The `ArrayFieldItemTemplate` component is the template used to render an items of an array. |
| 6 | + * |
| 7 | + * @param props - The `ArrayFieldTemplateItemType` props for the component |
| 8 | + */ |
9 | 9 | const ArrayFieldItemTemplate = < |
10 | 10 | T = any, |
11 | 11 | S extends StrictRJSFSchema = RJSFSchema, |
12 | 12 | F extends FormContextType = any, |
13 | | ->( |
14 | | - props: ArrayFieldTemplateItemType<T, S, F>, |
15 | | -) => { |
16 | | - const { |
17 | | - children, |
18 | | - disabled, |
19 | | - hasToolbar, |
20 | | - hasMoveDown, |
21 | | - hasMoveUp, |
22 | | - hasRemove, |
23 | | - hasCopy, // Added for completeness, though icon not requested |
24 | | - index, |
25 | | - onCopyIndexClick, // Added for completeness |
26 | | - onDropIndexClick, |
27 | | - onReorderClick, |
28 | | - readonly, |
29 | | - registry, |
30 | | - uiSchema, |
31 | | - } = props; |
32 | | - |
33 | | - const { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } = |
34 | | - registry.templates.ButtonTemplates; |
| 13 | +>({ |
| 14 | + children, |
| 15 | + className, |
| 16 | + disabled, |
| 17 | + hasToolbar, |
| 18 | + hasCopy, |
| 19 | + hasMoveDown, |
| 20 | + hasMoveUp, |
| 21 | + hasRemove, |
| 22 | + index, |
| 23 | + onCopyIndexClick, |
| 24 | + onDropIndexClick, |
| 25 | + onReorderClick, |
| 26 | + readonly, |
| 27 | + registry, |
| 28 | + required, |
| 29 | + schema, |
| 30 | + uiSchema, |
| 31 | + buttonsProps, // Added buttonsProps |
| 32 | +}: ArrayFieldTemplateItemType<T, S, F>) => { |
| 33 | + const { ArrayFieldItemButtonsTemplate } = registry.templates; // Get ArrayFieldItemButtonsTemplate |
35 | 34 |
|
36 | 35 | return ( |
37 | | - <div className="rjsf-uswds-array-item"> |
38 | | - <div className="grid-row grid-gap"> |
39 | | - <div className={hasToolbar ? "grid-col-9" : "grid-col-12"}> |
40 | | - {children} |
41 | | - </div> |
42 | | - |
43 | | - {hasToolbar && ( |
44 | | - <div className="grid-col-3 rjsf-uswds-array-item-toolbox"> |
45 | | - <div |
46 | | - className="usa-button-group usa-button-group--segmented display-flex flex-justify-end grid-gap-1" // Use utility classes |
47 | | - > |
48 | | - {(hasMoveUp || hasMoveDown) && ( |
49 | | - <MoveUpButton |
50 | | - className="array-item-move-up" |
51 | | - disabled={disabled || readonly || !hasMoveUp} |
52 | | - onClick={onReorderClick(index, index - 1)} |
53 | | - uiSchema={uiSchema} |
54 | | - registry={registry} |
55 | | - /> |
56 | | - )} |
57 | | - |
58 | | - {(hasMoveUp || hasMoveDown) && ( |
59 | | - <MoveDownButton |
60 | | - className="array-item-move-down" |
61 | | - disabled={disabled || readonly || !hasMoveDown} |
62 | | - onClick={onReorderClick(index, index + 1)} |
63 | | - uiSchema={uiSchema} |
64 | | - registry={registry} |
65 | | - /> |
66 | | - )} |
67 | | - |
68 | | - {hasCopy && ( |
69 | | - <CopyButton |
70 | | - className="array-item-copy" |
71 | | - disabled={disabled || readonly} |
72 | | - onClick={onCopyIndexClick(index)} |
73 | | - uiSchema={uiSchema} |
74 | | - registry={registry} |
75 | | - /> |
76 | | - )} |
77 | | - |
78 | | - {hasRemove && ( |
79 | | - <RemoveButton |
80 | | - className="array-item-remove" |
81 | | - disabled={disabled || readonly} |
82 | | - onClick={onDropIndexClick(index)} |
83 | | - uiSchema={uiSchema} |
84 | | - registry={registry} |
85 | | - /> |
86 | | - )} |
87 | | - </div> |
88 | | - </div> |
89 | | - )} |
90 | | - </div> |
91 | | - </div> |
| 36 | + <Grid row gap className={className}> |
| 37 | + <Grid col={true} className="rjsf-uswds-array-item-content"> |
| 38 | + {children} |
| 39 | + </Grid> |
| 40 | + {hasToolbar && ( |
| 41 | + <Grid col="auto" className="rjsf-uswds-array-item-toolbox"> |
| 42 | + {/* Render the buttons template */} |
| 43 | + <ArrayFieldItemButtonsTemplate {...buttonsProps} /> |
| 44 | + </Grid> |
| 45 | + )} |
| 46 | + </Grid> |
92 | 47 | ); |
93 | 48 | }; |
94 | 49 |
|
|
0 commit comments