@springmicro/forms 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +22 -22
- package/README.md +11 -11
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/index.umd.cjs +0 -0
- package/package.json +3 -3
- package/src/builder/bottom-drawer.tsx +429 -429
- package/src/builder/form-builder.tsx +256 -256
- package/src/builder/modal.tsx +39 -39
- package/src/builder/nodes/node-base.tsx +94 -94
- package/src/builder/nodes/node-child-helpers.tsx +273 -273
- package/src/builder/nodes/node-parent.tsx +187 -187
- package/src/builder/nodes/node-types/array-node.tsx +134 -134
- package/src/builder/nodes/node-types/date-node.tsx +60 -60
- package/src/builder/nodes/node-types/file-node.tsx +67 -67
- package/src/builder/nodes/node-types/integer-node.tsx +60 -60
- package/src/builder/nodes/node-types/object-node.tsx +67 -67
- package/src/builder/nodes/node-types/text-node.tsx +66 -66
- package/src/fields/ArrayField.tsx +875 -875
- package/src/fields/BooleanField.tsx +110 -110
- package/src/fields/MultiSchemaField.tsx +236 -236
- package/src/fields/NullField.tsx +22 -22
- package/src/fields/NumberField.tsx +87 -87
- package/src/fields/ObjectField.tsx +338 -338
- package/src/fields/SchemaField.tsx +402 -402
- package/src/fields/StringField.tsx +67 -67
- package/src/fields/index.ts +24 -24
- package/src/index.tsx +26 -26
- package/src/interfaces/MessagesProps.interface.ts +5 -5
- package/src/interfaces/Option.interface.ts +4 -4
- package/src/styles/select.styles.ts +28 -28
- package/src/templates/ArrayFieldDescriptionTemplate.tsx +42 -42
- package/src/templates/ArrayFieldItemTemplate.tsx +78 -78
- package/src/templates/ArrayFieldTemplate.tsx +90 -90
- package/src/templates/ArrayFieldTitleTemplate.tsx +44 -44
- package/src/templates/BaseInputTemplate.tsx +94 -94
- package/src/templates/ButtonTemplates/AddButton.tsx +29 -29
- package/src/templates/ButtonTemplates/IconButton.tsx +49 -49
- package/src/templates/ButtonTemplates/SubmitButton.tsx +29 -29
- package/src/templates/ButtonTemplates/index.ts +16 -16
- package/src/templates/DescriptionField.tsx +29 -29
- package/src/templates/ErrorList.tsx +25 -25
- package/src/templates/FieldTemplate/FieldTemplate.tsx +39 -39
- package/src/templates/FieldTemplate/Label.tsx +29 -29
- package/src/templates/FieldTemplate/WrapIfAdditional.tsx +85 -85
- package/src/templates/FieldTemplate/index.ts +3 -3
- package/src/templates/ObjectFieldTemplate.tsx +79 -79
- package/src/templates/TitleField.tsx +20 -20
- package/src/templates/UnsupportedField.tsx +29 -29
- package/src/templates/index.ts +32 -32
- package/src/types/Message.type.ts +6 -6
- package/src/types/RawMessage.type.ts +15 -15
- package/src/types/form-builder.ts +135 -135
- package/src/types/utils.type.ts +1 -1
- package/src/utils/form-builder.ts +424 -424
- package/src/utils/processSelectValue.ts +50 -50
- package/src/widgets/AltDateTimeWidget.tsx +17 -17
- package/src/widgets/AltDateWidget.tsx +216 -216
- package/src/widgets/CheckboxWidget.tsx +80 -80
- package/src/widgets/CheckboxesWidget.tsx +74 -74
- package/src/widgets/ColorWidget.tsx +26 -26
- package/src/widgets/DateTimeWidget.tsx +28 -28
- package/src/widgets/DateWidget.tsx +36 -36
- package/src/widgets/EmailWidget.tsx +19 -19
- package/src/widgets/FileWidget.tsx +144 -144
- package/src/widgets/HiddenWidget.tsx +22 -22
- package/src/widgets/PasswordWidget.tsx +20 -20
- package/src/widgets/RadioWidget.tsx +87 -87
- package/src/widgets/RangeWidget.tsx +24 -24
- package/src/widgets/SelectWidget.tsx +99 -99
- package/src/widgets/TextWidget.tsx +19 -19
- package/src/widgets/TextareaWidget.tsx +64 -64
- package/src/widgets/URLWidget.tsx +19 -19
- package/src/widgets/UpDownWidget.tsx +20 -20
- package/src/widgets/index.ts +43 -43
- package/tsconfig.json +24 -24
- package/tsconfig.node.json +10 -10
- package/vite.config.ts +25 -25
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type { FieldProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
-
import { getWidget, getUiOptions, optionsList, hasWidget } from "@rjsf/utils";
|
|
4
|
-
|
|
5
|
-
/** The `StringField` component is used to render a schema field that represents a string type
|
|
6
|
-
*
|
|
7
|
-
* @param props - The `FieldProps` for this template
|
|
8
|
-
*/
|
|
9
|
-
function StringField<T = any, F extends GenericObjectType = any>(
|
|
10
|
-
props: FieldProps<T, F>
|
|
11
|
-
) {
|
|
12
|
-
const {
|
|
13
|
-
schema,
|
|
14
|
-
name,
|
|
15
|
-
uiSchema,
|
|
16
|
-
idSchema,
|
|
17
|
-
formData,
|
|
18
|
-
required,
|
|
19
|
-
disabled = false,
|
|
20
|
-
readonly = false,
|
|
21
|
-
autofocus = false,
|
|
22
|
-
onChange,
|
|
23
|
-
onBlur,
|
|
24
|
-
onFocus,
|
|
25
|
-
registry,
|
|
26
|
-
rawErrors,
|
|
27
|
-
} = props;
|
|
28
|
-
const { title, format } = schema;
|
|
29
|
-
const { widgets, formContext, schemaUtils } = registry;
|
|
30
|
-
const enumOptions = schemaUtils.isSelect(schema)
|
|
31
|
-
? optionsList(schema)
|
|
32
|
-
: undefined;
|
|
33
|
-
let defaultWidget = enumOptions ? "select" : "text";
|
|
34
|
-
if (format && hasWidget<T, F>(schema, format, widgets)) {
|
|
35
|
-
defaultWidget = format;
|
|
36
|
-
}
|
|
37
|
-
const {
|
|
38
|
-
widget = defaultWidget,
|
|
39
|
-
placeholder = "",
|
|
40
|
-
...options
|
|
41
|
-
} = getUiOptions<T, F>(uiSchema);
|
|
42
|
-
const Widget = getWidget<T, F>(schema, widget, widgets);
|
|
43
|
-
return (
|
|
44
|
-
<Widget
|
|
45
|
-
name={name}
|
|
46
|
-
options={{ ...options, enumOptions }}
|
|
47
|
-
schema={schema}
|
|
48
|
-
uiSchema={uiSchema}
|
|
49
|
-
id={idSchema && idSchema.$id}
|
|
50
|
-
label={title === undefined ? name : title}
|
|
51
|
-
value={formData}
|
|
52
|
-
onChange={onChange}
|
|
53
|
-
onBlur={onBlur}
|
|
54
|
-
onFocus={onFocus}
|
|
55
|
-
required={required}
|
|
56
|
-
disabled={disabled}
|
|
57
|
-
readonly={readonly}
|
|
58
|
-
formContext={formContext}
|
|
59
|
-
autofocus={autofocus}
|
|
60
|
-
registry={registry}
|
|
61
|
-
placeholder={placeholder}
|
|
62
|
-
rawErrors={rawErrors}
|
|
63
|
-
/>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default StringField;
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { FieldProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
+
import { getWidget, getUiOptions, optionsList, hasWidget } from "@rjsf/utils";
|
|
4
|
+
|
|
5
|
+
/** The `StringField` component is used to render a schema field that represents a string type
|
|
6
|
+
*
|
|
7
|
+
* @param props - The `FieldProps` for this template
|
|
8
|
+
*/
|
|
9
|
+
function StringField<T = any, F extends GenericObjectType = any>(
|
|
10
|
+
props: FieldProps<T, F>
|
|
11
|
+
) {
|
|
12
|
+
const {
|
|
13
|
+
schema,
|
|
14
|
+
name,
|
|
15
|
+
uiSchema,
|
|
16
|
+
idSchema,
|
|
17
|
+
formData,
|
|
18
|
+
required,
|
|
19
|
+
disabled = false,
|
|
20
|
+
readonly = false,
|
|
21
|
+
autofocus = false,
|
|
22
|
+
onChange,
|
|
23
|
+
onBlur,
|
|
24
|
+
onFocus,
|
|
25
|
+
registry,
|
|
26
|
+
rawErrors,
|
|
27
|
+
} = props;
|
|
28
|
+
const { title, format } = schema;
|
|
29
|
+
const { widgets, formContext, schemaUtils } = registry;
|
|
30
|
+
const enumOptions = schemaUtils.isSelect(schema)
|
|
31
|
+
? optionsList(schema)
|
|
32
|
+
: undefined;
|
|
33
|
+
let defaultWidget = enumOptions ? "select" : "text";
|
|
34
|
+
if (format && hasWidget<T, F>(schema, format, widgets)) {
|
|
35
|
+
defaultWidget = format;
|
|
36
|
+
}
|
|
37
|
+
const {
|
|
38
|
+
widget = defaultWidget,
|
|
39
|
+
placeholder = "",
|
|
40
|
+
...options
|
|
41
|
+
} = getUiOptions<T, F>(uiSchema);
|
|
42
|
+
const Widget = getWidget<T, F>(schema, widget, widgets);
|
|
43
|
+
return (
|
|
44
|
+
<Widget
|
|
45
|
+
name={name}
|
|
46
|
+
options={{ ...options, enumOptions }}
|
|
47
|
+
schema={schema}
|
|
48
|
+
uiSchema={uiSchema}
|
|
49
|
+
id={idSchema && idSchema.$id}
|
|
50
|
+
label={title === undefined ? name : title}
|
|
51
|
+
value={formData}
|
|
52
|
+
onChange={onChange}
|
|
53
|
+
onBlur={onBlur}
|
|
54
|
+
onFocus={onFocus}
|
|
55
|
+
required={required}
|
|
56
|
+
disabled={disabled}
|
|
57
|
+
readonly={readonly}
|
|
58
|
+
formContext={formContext}
|
|
59
|
+
autofocus={autofocus}
|
|
60
|
+
registry={registry}
|
|
61
|
+
placeholder={placeholder}
|
|
62
|
+
rawErrors={rawErrors}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default StringField;
|
package/src/fields/index.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { RegistryFieldsType } from "@rjsf/utils";
|
|
2
|
-
|
|
3
|
-
import ArrayField from "./ArrayField";
|
|
4
|
-
import BooleanField from "./BooleanField";
|
|
5
|
-
import MultiSchemaField from "./MultiSchemaField";
|
|
6
|
-
import NumberField from "./NumberField";
|
|
7
|
-
import ObjectField from "./ObjectField";
|
|
8
|
-
import SchemaField from "./SchemaField";
|
|
9
|
-
import StringField from "./StringField";
|
|
10
|
-
import NullField from "./NullField";
|
|
11
|
-
|
|
12
|
-
const fields: RegistryFieldsType = {
|
|
13
|
-
AnyOfField: MultiSchemaField,
|
|
14
|
-
ArrayField,
|
|
15
|
-
BooleanField,
|
|
16
|
-
NumberField,
|
|
17
|
-
ObjectField,
|
|
18
|
-
OneOfField: MultiSchemaField,
|
|
19
|
-
SchemaField,
|
|
20
|
-
StringField,
|
|
21
|
-
NullField,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default fields;
|
|
1
|
+
import { RegistryFieldsType } from "@rjsf/utils";
|
|
2
|
+
|
|
3
|
+
import ArrayField from "./ArrayField";
|
|
4
|
+
import BooleanField from "./BooleanField";
|
|
5
|
+
import MultiSchemaField from "./MultiSchemaField";
|
|
6
|
+
import NumberField from "./NumberField";
|
|
7
|
+
import ObjectField from "./ObjectField";
|
|
8
|
+
import SchemaField from "./SchemaField";
|
|
9
|
+
import StringField from "./StringField";
|
|
10
|
+
import NullField from "./NullField";
|
|
11
|
+
|
|
12
|
+
const fields: RegistryFieldsType = {
|
|
13
|
+
AnyOfField: MultiSchemaField,
|
|
14
|
+
ArrayField,
|
|
15
|
+
BooleanField,
|
|
16
|
+
NumberField,
|
|
17
|
+
ObjectField,
|
|
18
|
+
OneOfField: MultiSchemaField,
|
|
19
|
+
SchemaField,
|
|
20
|
+
StringField,
|
|
21
|
+
NullField,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default fields;
|
package/src/index.tsx
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import widgets from "./widgets";
|
|
2
|
-
import templates from "./templates";
|
|
3
|
-
import fields from "./fields";
|
|
4
|
-
import { ThemeProps, withTheme } from "@rjsf/core";
|
|
5
|
-
import type { IChangeEvent } from "@rjsf/core";
|
|
6
|
-
import type { RJSFSchema } from "@rjsf/utils";
|
|
7
|
-
import validator from "@rjsf/validator-ajv8";
|
|
8
|
-
import { emailOnlySG, emailOnlySGJSON } from "@springmicro/utils/forms";
|
|
9
|
-
|
|
10
|
-
const rjsfDaisyUiTheme: ThemeProps = {
|
|
11
|
-
fields,
|
|
12
|
-
templates,
|
|
13
|
-
widgets,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const BaseForm = withTheme(rjsfDaisyUiTheme);
|
|
17
|
-
|
|
18
|
-
export {
|
|
19
|
-
rjsfDaisyUiTheme,
|
|
20
|
-
IChangeEvent,
|
|
21
|
-
RJSFSchema,
|
|
22
|
-
validator,
|
|
23
|
-
BaseForm,
|
|
24
|
-
emailOnlySG,
|
|
25
|
-
emailOnlySGJSON,
|
|
26
|
-
};
|
|
1
|
+
import widgets from "./widgets";
|
|
2
|
+
import templates from "./templates";
|
|
3
|
+
import fields from "./fields";
|
|
4
|
+
import { ThemeProps, withTheme } from "@rjsf/core";
|
|
5
|
+
import type { IChangeEvent } from "@rjsf/core";
|
|
6
|
+
import type { RJSFSchema } from "@rjsf/utils";
|
|
7
|
+
import validator from "@rjsf/validator-ajv8";
|
|
8
|
+
import { emailOnlySG, emailOnlySGJSON } from "@springmicro/utils/forms";
|
|
9
|
+
|
|
10
|
+
const rjsfDaisyUiTheme: ThemeProps = {
|
|
11
|
+
fields,
|
|
12
|
+
templates,
|
|
13
|
+
widgets,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const BaseForm = withTheme(rjsfDaisyUiTheme);
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
rjsfDaisyUiTheme,
|
|
20
|
+
IChangeEvent,
|
|
21
|
+
RJSFSchema,
|
|
22
|
+
validator,
|
|
23
|
+
BaseForm,
|
|
24
|
+
emailOnlySG,
|
|
25
|
+
emailOnlySGJSON,
|
|
26
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Message } from "../types/Message.type";
|
|
2
|
-
|
|
3
|
-
export interface MessagesProps {
|
|
4
|
-
data: Message[];
|
|
5
|
-
}
|
|
1
|
+
import { Message } from "../types/Message.type";
|
|
2
|
+
|
|
3
|
+
export interface MessagesProps {
|
|
4
|
+
data: Message[];
|
|
5
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface Option {
|
|
2
|
-
label: string;
|
|
3
|
-
value: string;
|
|
4
|
-
}
|
|
1
|
+
export interface Option {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { GroupBase, StylesConfig } from "react-select";
|
|
2
|
-
import { Option } from "../interfaces/Option.interface";
|
|
3
|
-
|
|
4
|
-
export const selectStyles: StylesConfig<Option, boolean, GroupBase<Option>> = {
|
|
5
|
-
option: (provided, state) => ({
|
|
6
|
-
...provided,
|
|
7
|
-
}),
|
|
8
|
-
control: (provided) => ({
|
|
9
|
-
...provided,
|
|
10
|
-
borderRadius: "0.5rem",
|
|
11
|
-
height: "3rem",
|
|
12
|
-
}),
|
|
13
|
-
singleValue: (provided, state) => {
|
|
14
|
-
const opacity = state.isDisabled ? 0.5 : 1;
|
|
15
|
-
const transition = "opacity 300ms";
|
|
16
|
-
|
|
17
|
-
return { ...provided, opacity, transition };
|
|
18
|
-
},
|
|
19
|
-
multiValue: (styles, { data }) => ({
|
|
20
|
-
...styles,
|
|
21
|
-
backgroundColor: "#560DF8",
|
|
22
|
-
color: "white",
|
|
23
|
-
}),
|
|
24
|
-
multiValueLabel: (styles, { data }) => ({
|
|
25
|
-
...styles,
|
|
26
|
-
color: "white",
|
|
27
|
-
}),
|
|
28
|
-
};
|
|
1
|
+
import { GroupBase, StylesConfig } from "react-select";
|
|
2
|
+
import { Option } from "../interfaces/Option.interface";
|
|
3
|
+
|
|
4
|
+
export const selectStyles: StylesConfig<Option, boolean, GroupBase<Option>> = {
|
|
5
|
+
option: (provided, state) => ({
|
|
6
|
+
...provided,
|
|
7
|
+
}),
|
|
8
|
+
control: (provided) => ({
|
|
9
|
+
...provided,
|
|
10
|
+
borderRadius: "0.5rem",
|
|
11
|
+
height: "3rem",
|
|
12
|
+
}),
|
|
13
|
+
singleValue: (provided, state) => {
|
|
14
|
+
const opacity = state.isDisabled ? 0.5 : 1;
|
|
15
|
+
const transition = "opacity 300ms";
|
|
16
|
+
|
|
17
|
+
return { ...provided, opacity, transition };
|
|
18
|
+
},
|
|
19
|
+
multiValue: (styles, { data }) => ({
|
|
20
|
+
...styles,
|
|
21
|
+
backgroundColor: "#560DF8",
|
|
22
|
+
color: "white",
|
|
23
|
+
}),
|
|
24
|
+
multiValueLabel: (styles, { data }) => ({
|
|
25
|
+
...styles,
|
|
26
|
+
color: "white",
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type {
|
|
3
|
-
ArrayFieldDescriptionProps,
|
|
4
|
-
GenericObjectType,
|
|
5
|
-
UiSchema,
|
|
6
|
-
Registry,
|
|
7
|
-
} from "@rjsf/utils";
|
|
8
|
-
import { getTemplate, getUiOptions } from "@rjsf/utils";
|
|
9
|
-
|
|
10
|
-
/** The `ArrayFieldDescriptionTemplate` component renders a `DescriptionFieldTemplate` with an `id` derived from
|
|
11
|
-
* the `idSchema`.
|
|
12
|
-
*
|
|
13
|
-
* @param props - The `ArrayFieldDescriptionProps` for the component
|
|
14
|
-
*/
|
|
15
|
-
export default function ArrayFieldDescriptionTemplate<
|
|
16
|
-
T = any,
|
|
17
|
-
F extends GenericObjectType = any
|
|
18
|
-
>(props: ArrayFieldDescriptionProps) {
|
|
19
|
-
const { schema, idSchema, description, registry, uiSchema } = props;
|
|
20
|
-
if (!description || !uiSchema) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
const options = getUiOptions<T, F>(uiSchema as UiSchema<T, F, any>);
|
|
24
|
-
const DescriptionFieldTemplate = getTemplate<
|
|
25
|
-
"DescriptionFieldTemplate",
|
|
26
|
-
T,
|
|
27
|
-
F
|
|
28
|
-
>(
|
|
29
|
-
"DescriptionFieldTemplate",
|
|
30
|
-
registry as unknown as Registry<T, F, any>,
|
|
31
|
-
options
|
|
32
|
-
);
|
|
33
|
-
const id = `${idSchema.$id}__description`;
|
|
34
|
-
return (
|
|
35
|
-
<DescriptionFieldTemplate
|
|
36
|
-
schema={schema as F}
|
|
37
|
-
id={id}
|
|
38
|
-
description={description}
|
|
39
|
-
registry={registry as unknown as Registry<T, F, any>}
|
|
40
|
-
/>
|
|
41
|
-
);
|
|
42
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type {
|
|
3
|
+
ArrayFieldDescriptionProps,
|
|
4
|
+
GenericObjectType,
|
|
5
|
+
UiSchema,
|
|
6
|
+
Registry,
|
|
7
|
+
} from "@rjsf/utils";
|
|
8
|
+
import { getTemplate, getUiOptions } from "@rjsf/utils";
|
|
9
|
+
|
|
10
|
+
/** The `ArrayFieldDescriptionTemplate` component renders a `DescriptionFieldTemplate` with an `id` derived from
|
|
11
|
+
* the `idSchema`.
|
|
12
|
+
*
|
|
13
|
+
* @param props - The `ArrayFieldDescriptionProps` for the component
|
|
14
|
+
*/
|
|
15
|
+
export default function ArrayFieldDescriptionTemplate<
|
|
16
|
+
T = any,
|
|
17
|
+
F extends GenericObjectType = any
|
|
18
|
+
>(props: ArrayFieldDescriptionProps) {
|
|
19
|
+
const { schema, idSchema, description, registry, uiSchema } = props;
|
|
20
|
+
if (!description || !uiSchema) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const options = getUiOptions<T, F>(uiSchema as UiSchema<T, F, any>);
|
|
24
|
+
const DescriptionFieldTemplate = getTemplate<
|
|
25
|
+
"DescriptionFieldTemplate",
|
|
26
|
+
T,
|
|
27
|
+
F
|
|
28
|
+
>(
|
|
29
|
+
"DescriptionFieldTemplate",
|
|
30
|
+
registry as unknown as Registry<T, F, any>,
|
|
31
|
+
options
|
|
32
|
+
);
|
|
33
|
+
const id = `${idSchema.$id}__description`;
|
|
34
|
+
return (
|
|
35
|
+
<DescriptionFieldTemplate
|
|
36
|
+
schema={schema as F}
|
|
37
|
+
id={id}
|
|
38
|
+
description={description}
|
|
39
|
+
registry={registry as unknown as Registry<T, F, any>}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import React, { CSSProperties } from "react";
|
|
2
|
-
import type {
|
|
3
|
-
ArrayFieldTemplateItemType,
|
|
4
|
-
GenericObjectType,
|
|
5
|
-
} from "@rjsf/utils";
|
|
6
|
-
|
|
7
|
-
/** The `ArrayFieldItemTemplate` component is the template used to render an items of an array.
|
|
8
|
-
*
|
|
9
|
-
* @param props - The `ArrayFieldTemplateItemType` props for the component
|
|
10
|
-
*/
|
|
11
|
-
export default function ArrayFieldItemTemplate<
|
|
12
|
-
T = any,
|
|
13
|
-
F extends GenericObjectType = any
|
|
14
|
-
>(props: ArrayFieldTemplateItemType<T, F>) {
|
|
15
|
-
const {
|
|
16
|
-
children,
|
|
17
|
-
className,
|
|
18
|
-
disabled,
|
|
19
|
-
hasToolbar,
|
|
20
|
-
hasMoveDown,
|
|
21
|
-
hasMoveUp,
|
|
22
|
-
hasRemove,
|
|
23
|
-
index,
|
|
24
|
-
onDropIndexClick,
|
|
25
|
-
onReorderClick,
|
|
26
|
-
readonly,
|
|
27
|
-
registry,
|
|
28
|
-
} = props;
|
|
29
|
-
const { MoveDownButton, MoveUpButton, RemoveButton } =
|
|
30
|
-
registry.templates.ButtonTemplates;
|
|
31
|
-
const btnStyle: CSSProperties = {
|
|
32
|
-
flex: 1,
|
|
33
|
-
paddingLeft: 6,
|
|
34
|
-
paddingRight: 6,
|
|
35
|
-
fontWeight: "bold",
|
|
36
|
-
};
|
|
37
|
-
return (
|
|
38
|
-
<div className={className}>
|
|
39
|
-
<div className={hasToolbar ? "col-xs-9" : "col-xs-12"}>{children}</div>
|
|
40
|
-
{hasToolbar && (
|
|
41
|
-
<div className="col-xs-3 array-item-toolbox">
|
|
42
|
-
<div
|
|
43
|
-
className="btn-group"
|
|
44
|
-
style={{
|
|
45
|
-
display: "flex",
|
|
46
|
-
justifyContent: "space-around",
|
|
47
|
-
}}
|
|
48
|
-
>
|
|
49
|
-
{(hasMoveUp || hasMoveDown) && (
|
|
50
|
-
<MoveUpButton
|
|
51
|
-
registry={registry}
|
|
52
|
-
style={btnStyle}
|
|
53
|
-
disabled={disabled || readonly || !hasMoveUp}
|
|
54
|
-
onClick={onReorderClick(index, index - 1)}
|
|
55
|
-
/>
|
|
56
|
-
)}
|
|
57
|
-
{(hasMoveUp || hasMoveDown) && (
|
|
58
|
-
<MoveDownButton
|
|
59
|
-
registry={registry}
|
|
60
|
-
style={btnStyle}
|
|
61
|
-
disabled={disabled || readonly || !hasMoveDown}
|
|
62
|
-
onClick={onReorderClick(index, index + 1)}
|
|
63
|
-
/>
|
|
64
|
-
)}
|
|
65
|
-
{hasRemove && (
|
|
66
|
-
<RemoveButton
|
|
67
|
-
registry={registry}
|
|
68
|
-
style={btnStyle}
|
|
69
|
-
disabled={disabled || readonly}
|
|
70
|
-
onClick={onDropIndexClick(index)}
|
|
71
|
-
/>
|
|
72
|
-
)}
|
|
73
|
-
</div>
|
|
74
|
-
</div>
|
|
75
|
-
)}
|
|
76
|
-
</div>
|
|
77
|
-
);
|
|
78
|
-
}
|
|
1
|
+
import React, { CSSProperties } from "react";
|
|
2
|
+
import type {
|
|
3
|
+
ArrayFieldTemplateItemType,
|
|
4
|
+
GenericObjectType,
|
|
5
|
+
} from "@rjsf/utils";
|
|
6
|
+
|
|
7
|
+
/** The `ArrayFieldItemTemplate` component is the template used to render an items of an array.
|
|
8
|
+
*
|
|
9
|
+
* @param props - The `ArrayFieldTemplateItemType` props for the component
|
|
10
|
+
*/
|
|
11
|
+
export default function ArrayFieldItemTemplate<
|
|
12
|
+
T = any,
|
|
13
|
+
F extends GenericObjectType = any
|
|
14
|
+
>(props: ArrayFieldTemplateItemType<T, F>) {
|
|
15
|
+
const {
|
|
16
|
+
children,
|
|
17
|
+
className,
|
|
18
|
+
disabled,
|
|
19
|
+
hasToolbar,
|
|
20
|
+
hasMoveDown,
|
|
21
|
+
hasMoveUp,
|
|
22
|
+
hasRemove,
|
|
23
|
+
index,
|
|
24
|
+
onDropIndexClick,
|
|
25
|
+
onReorderClick,
|
|
26
|
+
readonly,
|
|
27
|
+
registry,
|
|
28
|
+
} = props;
|
|
29
|
+
const { MoveDownButton, MoveUpButton, RemoveButton } =
|
|
30
|
+
registry.templates.ButtonTemplates;
|
|
31
|
+
const btnStyle: CSSProperties = {
|
|
32
|
+
flex: 1,
|
|
33
|
+
paddingLeft: 6,
|
|
34
|
+
paddingRight: 6,
|
|
35
|
+
fontWeight: "bold",
|
|
36
|
+
};
|
|
37
|
+
return (
|
|
38
|
+
<div className={className}>
|
|
39
|
+
<div className={hasToolbar ? "col-xs-9" : "col-xs-12"}>{children}</div>
|
|
40
|
+
{hasToolbar && (
|
|
41
|
+
<div className="col-xs-3 array-item-toolbox">
|
|
42
|
+
<div
|
|
43
|
+
className="btn-group"
|
|
44
|
+
style={{
|
|
45
|
+
display: "flex",
|
|
46
|
+
justifyContent: "space-around",
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
{(hasMoveUp || hasMoveDown) && (
|
|
50
|
+
<MoveUpButton
|
|
51
|
+
registry={registry}
|
|
52
|
+
style={btnStyle}
|
|
53
|
+
disabled={disabled || readonly || !hasMoveUp}
|
|
54
|
+
onClick={onReorderClick(index, index - 1)}
|
|
55
|
+
/>
|
|
56
|
+
)}
|
|
57
|
+
{(hasMoveUp || hasMoveDown) && (
|
|
58
|
+
<MoveDownButton
|
|
59
|
+
registry={registry}
|
|
60
|
+
style={btnStyle}
|
|
61
|
+
disabled={disabled || readonly || !hasMoveDown}
|
|
62
|
+
onClick={onReorderClick(index, index + 1)}
|
|
63
|
+
/>
|
|
64
|
+
)}
|
|
65
|
+
{hasRemove && (
|
|
66
|
+
<RemoveButton
|
|
67
|
+
registry={registry}
|
|
68
|
+
style={btnStyle}
|
|
69
|
+
disabled={disabled || readonly}
|
|
70
|
+
onClick={onDropIndexClick(index)}
|
|
71
|
+
/>
|
|
72
|
+
)}
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
)}
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
}
|