@springmicro/forms 0.7.0 → 0.7.2
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 +4146 -4143
- package/dist/index.umd.cjs +37 -37
- 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,90 +1,90 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type {
|
|
3
|
-
ArrayFieldTemplateProps,
|
|
4
|
-
ArrayFieldTemplateItemType,
|
|
5
|
-
GenericObjectType,
|
|
6
|
-
} from "@rjsf/utils";
|
|
7
|
-
import { getTemplate, getUiOptions } from "@rjsf/utils";
|
|
8
|
-
|
|
9
|
-
/** The `ArrayFieldTemplate` component is the template used to render all items in an array.
|
|
10
|
-
*
|
|
11
|
-
* @param props - The `ArrayFieldTemplateItemType` props for the component
|
|
12
|
-
*/
|
|
13
|
-
export default function ArrayFieldTemplate<
|
|
14
|
-
T = any,
|
|
15
|
-
F extends GenericObjectType = any
|
|
16
|
-
>(props: ArrayFieldTemplateProps<T, F>) {
|
|
17
|
-
const {
|
|
18
|
-
canAdd,
|
|
19
|
-
className,
|
|
20
|
-
disabled,
|
|
21
|
-
idSchema,
|
|
22
|
-
uiSchema,
|
|
23
|
-
items,
|
|
24
|
-
onAddClick,
|
|
25
|
-
readonly,
|
|
26
|
-
registry,
|
|
27
|
-
required,
|
|
28
|
-
schema,
|
|
29
|
-
title,
|
|
30
|
-
} = props;
|
|
31
|
-
const uiOptions = getUiOptions<T, F>(uiSchema);
|
|
32
|
-
const ArrayFieldDescriptionTemplate = getTemplate<
|
|
33
|
-
"ArrayFieldDescriptionTemplate",
|
|
34
|
-
T,
|
|
35
|
-
F
|
|
36
|
-
>("ArrayFieldDescriptionTemplate", registry, uiOptions);
|
|
37
|
-
const ArrayFieldItemTemplate = getTemplate<"ArrayFieldItemTemplate", T, F>(
|
|
38
|
-
"ArrayFieldItemTemplate",
|
|
39
|
-
registry,
|
|
40
|
-
uiOptions
|
|
41
|
-
);
|
|
42
|
-
const ArrayFieldTitleTemplate = getTemplate<"ArrayFieldTitleTemplate", T, F>(
|
|
43
|
-
"ArrayFieldTitleTemplate",
|
|
44
|
-
registry,
|
|
45
|
-
uiOptions
|
|
46
|
-
);
|
|
47
|
-
// Button templates are not overridden in the uiSchema
|
|
48
|
-
const {
|
|
49
|
-
ButtonTemplates: { AddButton },
|
|
50
|
-
} = registry.templates;
|
|
51
|
-
return (
|
|
52
|
-
<fieldset className={className} id={idSchema.$id}>
|
|
53
|
-
<ArrayFieldTitleTemplate
|
|
54
|
-
schema={schema}
|
|
55
|
-
idSchema={idSchema}
|
|
56
|
-
title={uiOptions.title || title}
|
|
57
|
-
required={required}
|
|
58
|
-
uiSchema={uiSchema}
|
|
59
|
-
registry={registry}
|
|
60
|
-
/>
|
|
61
|
-
{(uiOptions.description || schema.description) && (
|
|
62
|
-
<ArrayFieldDescriptionTemplate
|
|
63
|
-
schema={schema}
|
|
64
|
-
idSchema={idSchema}
|
|
65
|
-
description={(uiOptions.description || schema.description)!}
|
|
66
|
-
uiSchema={uiSchema}
|
|
67
|
-
registry={registry}
|
|
68
|
-
/>
|
|
69
|
-
)}
|
|
70
|
-
<div className="row array-item-list">
|
|
71
|
-
{items &&
|
|
72
|
-
items.map(
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
({ key, ...itemProps }: ArrayFieldTemplateItemType) => (
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
<ArrayFieldItemTemplate key={key} {...itemProps} />
|
|
77
|
-
)
|
|
78
|
-
)}
|
|
79
|
-
</div>
|
|
80
|
-
{canAdd && (
|
|
81
|
-
<AddButton
|
|
82
|
-
registry={registry}
|
|
83
|
-
className="array-item-add"
|
|
84
|
-
onClick={onAddClick}
|
|
85
|
-
disabled={disabled || readonly}
|
|
86
|
-
/>
|
|
87
|
-
)}
|
|
88
|
-
</fieldset>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type {
|
|
3
|
+
ArrayFieldTemplateProps,
|
|
4
|
+
ArrayFieldTemplateItemType,
|
|
5
|
+
GenericObjectType,
|
|
6
|
+
} from "@rjsf/utils";
|
|
7
|
+
import { getTemplate, getUiOptions } from "@rjsf/utils";
|
|
8
|
+
|
|
9
|
+
/** The `ArrayFieldTemplate` component is the template used to render all items in an array.
|
|
10
|
+
*
|
|
11
|
+
* @param props - The `ArrayFieldTemplateItemType` props for the component
|
|
12
|
+
*/
|
|
13
|
+
export default function ArrayFieldTemplate<
|
|
14
|
+
T = any,
|
|
15
|
+
F extends GenericObjectType = any
|
|
16
|
+
>(props: ArrayFieldTemplateProps<T, F>) {
|
|
17
|
+
const {
|
|
18
|
+
canAdd,
|
|
19
|
+
className,
|
|
20
|
+
disabled,
|
|
21
|
+
idSchema,
|
|
22
|
+
uiSchema,
|
|
23
|
+
items,
|
|
24
|
+
onAddClick,
|
|
25
|
+
readonly,
|
|
26
|
+
registry,
|
|
27
|
+
required,
|
|
28
|
+
schema,
|
|
29
|
+
title,
|
|
30
|
+
} = props;
|
|
31
|
+
const uiOptions = getUiOptions<T, F>(uiSchema);
|
|
32
|
+
const ArrayFieldDescriptionTemplate = getTemplate<
|
|
33
|
+
"ArrayFieldDescriptionTemplate",
|
|
34
|
+
T,
|
|
35
|
+
F
|
|
36
|
+
>("ArrayFieldDescriptionTemplate", registry, uiOptions);
|
|
37
|
+
const ArrayFieldItemTemplate = getTemplate<"ArrayFieldItemTemplate", T, F>(
|
|
38
|
+
"ArrayFieldItemTemplate",
|
|
39
|
+
registry,
|
|
40
|
+
uiOptions
|
|
41
|
+
);
|
|
42
|
+
const ArrayFieldTitleTemplate = getTemplate<"ArrayFieldTitleTemplate", T, F>(
|
|
43
|
+
"ArrayFieldTitleTemplate",
|
|
44
|
+
registry,
|
|
45
|
+
uiOptions
|
|
46
|
+
);
|
|
47
|
+
// Button templates are not overridden in the uiSchema
|
|
48
|
+
const {
|
|
49
|
+
ButtonTemplates: { AddButton },
|
|
50
|
+
} = registry.templates;
|
|
51
|
+
return (
|
|
52
|
+
<fieldset className={className} id={idSchema.$id}>
|
|
53
|
+
<ArrayFieldTitleTemplate
|
|
54
|
+
schema={schema}
|
|
55
|
+
idSchema={idSchema}
|
|
56
|
+
title={uiOptions.title || title}
|
|
57
|
+
required={required}
|
|
58
|
+
uiSchema={uiSchema}
|
|
59
|
+
registry={registry}
|
|
60
|
+
/>
|
|
61
|
+
{(uiOptions.description || schema.description) && (
|
|
62
|
+
<ArrayFieldDescriptionTemplate
|
|
63
|
+
schema={schema}
|
|
64
|
+
idSchema={idSchema}
|
|
65
|
+
description={(uiOptions.description || schema.description)!}
|
|
66
|
+
uiSchema={uiSchema}
|
|
67
|
+
registry={registry}
|
|
68
|
+
/>
|
|
69
|
+
)}
|
|
70
|
+
<div className="row array-item-list">
|
|
71
|
+
{items &&
|
|
72
|
+
items.map(
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
({ key, ...itemProps }: ArrayFieldTemplateItemType) => (
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
<ArrayFieldItemTemplate key={key} {...itemProps} />
|
|
77
|
+
)
|
|
78
|
+
)}
|
|
79
|
+
</div>
|
|
80
|
+
{canAdd && (
|
|
81
|
+
<AddButton
|
|
82
|
+
registry={registry}
|
|
83
|
+
className="array-item-add"
|
|
84
|
+
onClick={onAddClick}
|
|
85
|
+
disabled={disabled || readonly}
|
|
86
|
+
/>
|
|
87
|
+
)}
|
|
88
|
+
</fieldset>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type {
|
|
3
|
-
ArrayFieldTitleProps,
|
|
4
|
-
TemplatesType,
|
|
5
|
-
GenericObjectType,
|
|
6
|
-
Registry,
|
|
7
|
-
UiSchema,
|
|
8
|
-
} from "@rjsf/utils";
|
|
9
|
-
import { getTemplate, getUiOptions } from "@rjsf/utils";
|
|
10
|
-
|
|
11
|
-
/** The `ArrayFieldTitleTemplate` component renders a `TitleFieldTemplate` with an `id` derived from
|
|
12
|
-
* the `idSchema`.
|
|
13
|
-
*
|
|
14
|
-
* @param props - The `ArrayFieldTitleProps` for the component
|
|
15
|
-
*/
|
|
16
|
-
export default function ArrayFieldTitleTemplate<
|
|
17
|
-
T = any,
|
|
18
|
-
F extends GenericObjectType = any
|
|
19
|
-
>(props: ArrayFieldTitleProps) {
|
|
20
|
-
const { schema, idSchema, title, uiSchema, required, registry } = props;
|
|
21
|
-
if (!title) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
const options = getUiOptions<T, F>(
|
|
25
|
-
uiSchema as unknown as UiSchema<T, F, any>
|
|
26
|
-
);
|
|
27
|
-
const TitleFieldTemplate: TemplatesType<T, F>["TitleFieldTemplate"] =
|
|
28
|
-
getTemplate<"TitleFieldTemplate", T, F>(
|
|
29
|
-
"TitleFieldTemplate",
|
|
30
|
-
registry as unknown as Registry<T, F, any>,
|
|
31
|
-
options
|
|
32
|
-
);
|
|
33
|
-
const id = `${idSchema.$id}__title`;
|
|
34
|
-
return (
|
|
35
|
-
<TitleFieldTemplate
|
|
36
|
-
schema={schema as unknown as F}
|
|
37
|
-
id={id}
|
|
38
|
-
title={title}
|
|
39
|
-
required={required}
|
|
40
|
-
uiSchema={uiSchema as unknown as UiSchema<T, F, any>}
|
|
41
|
-
registry={registry as unknown as Registry<T, F, any>}
|
|
42
|
-
/>
|
|
43
|
-
);
|
|
44
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type {
|
|
3
|
+
ArrayFieldTitleProps,
|
|
4
|
+
TemplatesType,
|
|
5
|
+
GenericObjectType,
|
|
6
|
+
Registry,
|
|
7
|
+
UiSchema,
|
|
8
|
+
} from "@rjsf/utils";
|
|
9
|
+
import { getTemplate, getUiOptions } from "@rjsf/utils";
|
|
10
|
+
|
|
11
|
+
/** The `ArrayFieldTitleTemplate` component renders a `TitleFieldTemplate` with an `id` derived from
|
|
12
|
+
* the `idSchema`.
|
|
13
|
+
*
|
|
14
|
+
* @param props - The `ArrayFieldTitleProps` for the component
|
|
15
|
+
*/
|
|
16
|
+
export default function ArrayFieldTitleTemplate<
|
|
17
|
+
T = any,
|
|
18
|
+
F extends GenericObjectType = any
|
|
19
|
+
>(props: ArrayFieldTitleProps) {
|
|
20
|
+
const { schema, idSchema, title, uiSchema, required, registry } = props;
|
|
21
|
+
if (!title) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const options = getUiOptions<T, F>(
|
|
25
|
+
uiSchema as unknown as UiSchema<T, F, any>
|
|
26
|
+
);
|
|
27
|
+
const TitleFieldTemplate: TemplatesType<T, F>["TitleFieldTemplate"] =
|
|
28
|
+
getTemplate<"TitleFieldTemplate", T, F>(
|
|
29
|
+
"TitleFieldTemplate",
|
|
30
|
+
registry as unknown as Registry<T, F, any>,
|
|
31
|
+
options
|
|
32
|
+
);
|
|
33
|
+
const id = `${idSchema.$id}__title`;
|
|
34
|
+
return (
|
|
35
|
+
<TitleFieldTemplate
|
|
36
|
+
schema={schema as unknown as F}
|
|
37
|
+
id={id}
|
|
38
|
+
title={title}
|
|
39
|
+
required={required}
|
|
40
|
+
uiSchema={uiSchema as unknown as UiSchema<T, F, any>}
|
|
41
|
+
registry={registry as unknown as Registry<T, F, any>}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
import React, { useCallback } from "react";
|
|
2
|
-
import type { WidgetProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
-
import { getInputProps } from "@rjsf/utils";
|
|
4
|
-
|
|
5
|
-
/** The `BaseInputTemplate` is the template to use to render the basic `<input>` component for the `core` theme.
|
|
6
|
-
* It is used as the template for rendering many of the <input> based widgets that differ by `type` and callbacks only.
|
|
7
|
-
* It can be customized/overridden for other themes or individual implementations as needed.
|
|
8
|
-
*
|
|
9
|
-
* @param props - The `WidgetProps` for this template
|
|
10
|
-
*/
|
|
11
|
-
export default function BaseInputTemplate<
|
|
12
|
-
T = any,
|
|
13
|
-
F extends GenericObjectType = any
|
|
14
|
-
>(props: WidgetProps<T, F>) {
|
|
15
|
-
const {
|
|
16
|
-
id,
|
|
17
|
-
value,
|
|
18
|
-
readonly,
|
|
19
|
-
disabled,
|
|
20
|
-
autofocus,
|
|
21
|
-
onBlur,
|
|
22
|
-
onFocus,
|
|
23
|
-
onChange,
|
|
24
|
-
options,
|
|
25
|
-
schema,
|
|
26
|
-
uiSchema,
|
|
27
|
-
formContext,
|
|
28
|
-
registry,
|
|
29
|
-
rawErrors,
|
|
30
|
-
type,
|
|
31
|
-
...rest
|
|
32
|
-
} = props;
|
|
33
|
-
|
|
34
|
-
// Note: since React 15.2.0 we can't forward unknown element attributes, so we
|
|
35
|
-
// exclude the "options" and "schema" ones here.
|
|
36
|
-
if (!id) {
|
|
37
|
-
console.log("No id for", props);
|
|
38
|
-
throw new Error(`no id for props ${JSON.stringify(props)}`);
|
|
39
|
-
}
|
|
40
|
-
const inputProps = { ...rest, ...getInputProps<T, F>(schema, type, options) };
|
|
41
|
-
|
|
42
|
-
let inputValue;
|
|
43
|
-
if (inputProps.type === "number" || inputProps.type === "integer") {
|
|
44
|
-
inputValue = value || value === 0 ? value : "";
|
|
45
|
-
} else {
|
|
46
|
-
inputValue = value == null ? "" : value;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const _onChange = useCallback(
|
|
50
|
-
({ target: { value } }: React.ChangeEvent<HTMLInputElement>) =>
|
|
51
|
-
onChange(value === "" ? options.emptyValue : value),
|
|
52
|
-
[onChange, options]
|
|
53
|
-
);
|
|
54
|
-
const _onBlur = useCallback(
|
|
55
|
-
({ target: { value } }: React.FocusEvent<HTMLInputElement>) =>
|
|
56
|
-
onBlur(id, value),
|
|
57
|
-
[onBlur, id]
|
|
58
|
-
);
|
|
59
|
-
const _onFocus = useCallback(
|
|
60
|
-
({ target: { value } }: React.FocusEvent<HTMLInputElement>) =>
|
|
61
|
-
onFocus(id, value),
|
|
62
|
-
[onFocus, id]
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<>
|
|
67
|
-
<input
|
|
68
|
-
key={id}
|
|
69
|
-
id={id}
|
|
70
|
-
className="input input-bordered"
|
|
71
|
-
readOnly={readonly}
|
|
72
|
-
disabled={disabled}
|
|
73
|
-
autoFocus={autofocus}
|
|
74
|
-
value={inputValue}
|
|
75
|
-
{...inputProps}
|
|
76
|
-
list={schema.examples ? `examples_${id}` : undefined}
|
|
77
|
-
onChange={_onChange}
|
|
78
|
-
onBlur={_onBlur}
|
|
79
|
-
onFocus={_onFocus}
|
|
80
|
-
/>
|
|
81
|
-
{Array.isArray(schema.examples) && (
|
|
82
|
-
<datalist key={`datalist_${id}`} id={`examples_${id}`}>
|
|
83
|
-
{[
|
|
84
|
-
...new Set(
|
|
85
|
-
schema.examples.concat(schema.default ? [schema.default] : [])
|
|
86
|
-
),
|
|
87
|
-
].map((example: any) => (
|
|
88
|
-
<option key={example} value={example} />
|
|
89
|
-
))}
|
|
90
|
-
</datalist>
|
|
91
|
-
)}
|
|
92
|
-
</>
|
|
93
|
-
);
|
|
94
|
-
}
|
|
1
|
+
import React, { useCallback } from "react";
|
|
2
|
+
import type { WidgetProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
+
import { getInputProps } from "@rjsf/utils";
|
|
4
|
+
|
|
5
|
+
/** The `BaseInputTemplate` is the template to use to render the basic `<input>` component for the `core` theme.
|
|
6
|
+
* It is used as the template for rendering many of the <input> based widgets that differ by `type` and callbacks only.
|
|
7
|
+
* It can be customized/overridden for other themes or individual implementations as needed.
|
|
8
|
+
*
|
|
9
|
+
* @param props - The `WidgetProps` for this template
|
|
10
|
+
*/
|
|
11
|
+
export default function BaseInputTemplate<
|
|
12
|
+
T = any,
|
|
13
|
+
F extends GenericObjectType = any
|
|
14
|
+
>(props: WidgetProps<T, F>) {
|
|
15
|
+
const {
|
|
16
|
+
id,
|
|
17
|
+
value,
|
|
18
|
+
readonly,
|
|
19
|
+
disabled,
|
|
20
|
+
autofocus,
|
|
21
|
+
onBlur,
|
|
22
|
+
onFocus,
|
|
23
|
+
onChange,
|
|
24
|
+
options,
|
|
25
|
+
schema,
|
|
26
|
+
uiSchema,
|
|
27
|
+
formContext,
|
|
28
|
+
registry,
|
|
29
|
+
rawErrors,
|
|
30
|
+
type,
|
|
31
|
+
...rest
|
|
32
|
+
} = props;
|
|
33
|
+
|
|
34
|
+
// Note: since React 15.2.0 we can't forward unknown element attributes, so we
|
|
35
|
+
// exclude the "options" and "schema" ones here.
|
|
36
|
+
if (!id) {
|
|
37
|
+
console.log("No id for", props);
|
|
38
|
+
throw new Error(`no id for props ${JSON.stringify(props)}`);
|
|
39
|
+
}
|
|
40
|
+
const inputProps = { ...rest, ...getInputProps<T, F>(schema, type, options) };
|
|
41
|
+
|
|
42
|
+
let inputValue;
|
|
43
|
+
if (inputProps.type === "number" || inputProps.type === "integer") {
|
|
44
|
+
inputValue = value || value === 0 ? value : "";
|
|
45
|
+
} else {
|
|
46
|
+
inputValue = value == null ? "" : value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const _onChange = useCallback(
|
|
50
|
+
({ target: { value } }: React.ChangeEvent<HTMLInputElement>) =>
|
|
51
|
+
onChange(value === "" ? options.emptyValue : value),
|
|
52
|
+
[onChange, options]
|
|
53
|
+
);
|
|
54
|
+
const _onBlur = useCallback(
|
|
55
|
+
({ target: { value } }: React.FocusEvent<HTMLInputElement>) =>
|
|
56
|
+
onBlur(id, value),
|
|
57
|
+
[onBlur, id]
|
|
58
|
+
);
|
|
59
|
+
const _onFocus = useCallback(
|
|
60
|
+
({ target: { value } }: React.FocusEvent<HTMLInputElement>) =>
|
|
61
|
+
onFocus(id, value),
|
|
62
|
+
[onFocus, id]
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
<input
|
|
68
|
+
key={id}
|
|
69
|
+
id={id}
|
|
70
|
+
className="input input-bordered"
|
|
71
|
+
readOnly={readonly}
|
|
72
|
+
disabled={disabled}
|
|
73
|
+
autoFocus={autofocus}
|
|
74
|
+
value={inputValue}
|
|
75
|
+
{...inputProps}
|
|
76
|
+
list={schema.examples ? `examples_${id}` : undefined}
|
|
77
|
+
onChange={_onChange}
|
|
78
|
+
onBlur={_onBlur}
|
|
79
|
+
onFocus={_onFocus}
|
|
80
|
+
/>
|
|
81
|
+
{Array.isArray(schema.examples) && (
|
|
82
|
+
<datalist key={`datalist_${id}`} id={`examples_${id}`}>
|
|
83
|
+
{[
|
|
84
|
+
...new Set(
|
|
85
|
+
schema.examples.concat(schema.default ? [schema.default] : [])
|
|
86
|
+
),
|
|
87
|
+
].map((example: any) => (
|
|
88
|
+
<option key={example} value={example} />
|
|
89
|
+
))}
|
|
90
|
+
</datalist>
|
|
91
|
+
)}
|
|
92
|
+
</>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { IconButtonProps } from "@rjsf/utils";
|
|
3
|
-
|
|
4
|
-
import IconButton from "./IconButton";
|
|
5
|
-
|
|
6
|
-
/** The `AddButton` renders a button that represent the `Add` action on a form
|
|
7
|
-
*/
|
|
8
|
-
export default function AddButton({
|
|
9
|
-
registry,
|
|
10
|
-
className,
|
|
11
|
-
onClick,
|
|
12
|
-
disabled,
|
|
13
|
-
}: IconButtonProps) {
|
|
14
|
-
return (
|
|
15
|
-
<div className="row">
|
|
16
|
-
<p className={`col-xs-3 col-xs-offset-9 text-right ${className}`}>
|
|
17
|
-
<IconButton
|
|
18
|
-
registry={registry}
|
|
19
|
-
iconType="info"
|
|
20
|
-
icon="plus"
|
|
21
|
-
className="btn-add col-xs-12"
|
|
22
|
-
title="Add"
|
|
23
|
-
onClick={onClick}
|
|
24
|
-
disabled={disabled}
|
|
25
|
-
/>
|
|
26
|
-
</p>
|
|
27
|
-
</div>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { IconButtonProps } from "@rjsf/utils";
|
|
3
|
+
|
|
4
|
+
import IconButton from "./IconButton";
|
|
5
|
+
|
|
6
|
+
/** The `AddButton` renders a button that represent the `Add` action on a form
|
|
7
|
+
*/
|
|
8
|
+
export default function AddButton({
|
|
9
|
+
registry,
|
|
10
|
+
className,
|
|
11
|
+
onClick,
|
|
12
|
+
disabled,
|
|
13
|
+
}: IconButtonProps) {
|
|
14
|
+
return (
|
|
15
|
+
<div className="row">
|
|
16
|
+
<p className={`col-xs-3 col-xs-offset-9 text-right ${className}`}>
|
|
17
|
+
<IconButton
|
|
18
|
+
registry={registry}
|
|
19
|
+
iconType="info"
|
|
20
|
+
icon="plus"
|
|
21
|
+
className="btn-add col-xs-12"
|
|
22
|
+
title="Add"
|
|
23
|
+
onClick={onClick}
|
|
24
|
+
disabled={disabled}
|
|
25
|
+
/>
|
|
26
|
+
</p>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { IconButtonProps } from "@rjsf/utils";
|
|
3
|
-
|
|
4
|
-
export default function IconButton(props: IconButtonProps) {
|
|
5
|
-
const { iconType = "default", icon, className, ...otherProps } = props;
|
|
6
|
-
return (
|
|
7
|
-
<button
|
|
8
|
-
type="button"
|
|
9
|
-
className={`btn btn-${iconType} ${className}`}
|
|
10
|
-
{...otherProps}
|
|
11
|
-
>
|
|
12
|
-
<i className={`glyphicon glyphicon-${icon}`} />
|
|
13
|
-
</button>
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function MoveDownButton(props: IconButtonProps) {
|
|
18
|
-
return (
|
|
19
|
-
<IconButton
|
|
20
|
-
title="Move down"
|
|
21
|
-
className="array-item-move-down"
|
|
22
|
-
{...props}
|
|
23
|
-
icon="arrow-down"
|
|
24
|
-
/>
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function MoveUpButton(props: IconButtonProps) {
|
|
29
|
-
return (
|
|
30
|
-
<IconButton
|
|
31
|
-
title="Move up"
|
|
32
|
-
className="array-item-move-up"
|
|
33
|
-
{...props}
|
|
34
|
-
icon="arrow-up"
|
|
35
|
-
/>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function RemoveButton(props: IconButtonProps) {
|
|
40
|
-
return (
|
|
41
|
-
<IconButton
|
|
42
|
-
title="Remove"
|
|
43
|
-
className="array-item-remove"
|
|
44
|
-
{...props}
|
|
45
|
-
iconType="danger"
|
|
46
|
-
icon="remove"
|
|
47
|
-
/>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { IconButtonProps } from "@rjsf/utils";
|
|
3
|
+
|
|
4
|
+
export default function IconButton(props: IconButtonProps) {
|
|
5
|
+
const { iconType = "default", icon, className, ...otherProps } = props;
|
|
6
|
+
return (
|
|
7
|
+
<button
|
|
8
|
+
type="button"
|
|
9
|
+
className={`btn btn-${iconType} ${className}`}
|
|
10
|
+
{...otherProps}
|
|
11
|
+
>
|
|
12
|
+
<i className={`glyphicon glyphicon-${icon}`} />
|
|
13
|
+
</button>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function MoveDownButton(props: IconButtonProps) {
|
|
18
|
+
return (
|
|
19
|
+
<IconButton
|
|
20
|
+
title="Move down"
|
|
21
|
+
className="array-item-move-down"
|
|
22
|
+
{...props}
|
|
23
|
+
icon="arrow-down"
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function MoveUpButton(props: IconButtonProps) {
|
|
29
|
+
return (
|
|
30
|
+
<IconButton
|
|
31
|
+
title="Move up"
|
|
32
|
+
className="array-item-move-up"
|
|
33
|
+
{...props}
|
|
34
|
+
icon="arrow-up"
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function RemoveButton(props: IconButtonProps) {
|
|
40
|
+
return (
|
|
41
|
+
<IconButton
|
|
42
|
+
title="Remove"
|
|
43
|
+
className="array-item-remove"
|
|
44
|
+
{...props}
|
|
45
|
+
iconType="danger"
|
|
46
|
+
icon="remove"
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { SubmitButtonProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
-
import { getSubmitButtonOptions } from "@rjsf/utils";
|
|
4
|
-
|
|
5
|
-
/** The `SubmitButton` renders a button that represent the `Submit` action on a form
|
|
6
|
-
*/
|
|
7
|
-
export default function SubmitButton<T, F extends GenericObjectType = any>({
|
|
8
|
-
uiSchema,
|
|
9
|
-
}: SubmitButtonProps<T, F>) {
|
|
10
|
-
const {
|
|
11
|
-
submitText,
|
|
12
|
-
norender,
|
|
13
|
-
props: submitButtonProps = {},
|
|
14
|
-
} = getSubmitButtonOptions(uiSchema);
|
|
15
|
-
if (norender) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return (
|
|
19
|
-
<div>
|
|
20
|
-
<button
|
|
21
|
-
type="submit"
|
|
22
|
-
{...submitButtonProps}
|
|
23
|
-
className={`btn btn-primary ${submitButtonProps.className}`}
|
|
24
|
-
>
|
|
25
|
-
{submitText}
|
|
26
|
-
</button>
|
|
27
|
-
</div>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { SubmitButtonProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
+
import { getSubmitButtonOptions } from "@rjsf/utils";
|
|
4
|
+
|
|
5
|
+
/** The `SubmitButton` renders a button that represent the `Submit` action on a form
|
|
6
|
+
*/
|
|
7
|
+
export default function SubmitButton<T, F extends GenericObjectType = any>({
|
|
8
|
+
uiSchema,
|
|
9
|
+
}: SubmitButtonProps<T, F>) {
|
|
10
|
+
const {
|
|
11
|
+
submitText,
|
|
12
|
+
norender,
|
|
13
|
+
props: submitButtonProps = {},
|
|
14
|
+
} = getSubmitButtonOptions(uiSchema);
|
|
15
|
+
if (norender) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return (
|
|
19
|
+
<div>
|
|
20
|
+
<button
|
|
21
|
+
type="submit"
|
|
22
|
+
{...submitButtonProps}
|
|
23
|
+
className={`btn btn-primary ${submitButtonProps.className}`}
|
|
24
|
+
>
|
|
25
|
+
{submitText}
|
|
26
|
+
</button>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|