forked from rjsf-team/react-jsonschema-form
/
ObjectFieldTemplate.tsx
92 lines (88 loc) · 2.31 KB
/
ObjectFieldTemplate.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React from "react";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import Container from "react-bootstrap/Container";
import {
canExpand,
getTemplate,
getUiOptions,
ObjectFieldTemplateProps,
} from "@rjsf/utils";
const ObjectFieldTemplate = ({
description,
title,
properties,
required,
uiSchema,
idSchema,
schema,
formData,
onAddClick,
disabled,
readonly,
registry,
}: ObjectFieldTemplateProps) => {
const uiOptions = getUiOptions(uiSchema);
const TitleFieldTemplate = getTemplate<"TitleFieldTemplate">(
"TitleFieldTemplate",
registry,
uiOptions
);
const DescriptionFieldTemplate = getTemplate<"DescriptionFieldTemplate">(
"DescriptionFieldTemplate",
registry,
uiOptions
);
// Button templates are not overridden in the uiSchema
const {
ButtonTemplates: { AddButton },
} = registry.templates;
return (
<>
{(uiOptions.title || title) && (
<TitleFieldTemplate
id={`${idSchema.$id}-title`}
title={uiOptions.title || title}
required={required}
schema={schema}
uiSchema={uiSchema}
registry={registry}
/>
)}
{(uiOptions.description || description) && (
<DescriptionFieldTemplate
id={`${idSchema.$id}-description`}
description={uiOptions.description || description!}
schema={schema}
uiSchema={uiSchema}
registry={registry}
/>
)}
<Container fluid className="p-0">
{properties.map((element: any, index: number) => (
<Row
key={index}
style={{ marginBottom: "10px" }}
className={element.hidden ? "d-none" : undefined}
>
<Col xs={12}> {element.content}</Col>
</Row>
))}
{canExpand(schema, uiSchema, formData) ? (
<Row>
<Col xs={{ offset: 9, span: 3 }} className="py-4">
<AddButton
onClick={onAddClick(schema)}
disabled={disabled || readonly}
className="object-property-expand"
uiSchema={uiSchema}
registry={registry}
/>
</Col>
</Row>
) : null}
</Container>
</>
);
};
export default ObjectFieldTemplate;