@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,80 +1,80 @@
|
|
|
1
|
-
import React, { useCallback } from "react";
|
|
2
|
-
import type { GenericObjectType, WidgetProps } from "@rjsf/utils";
|
|
3
|
-
import { getTemplate, schemaRequiresTrueValue } from "@rjsf/utils";
|
|
4
|
-
|
|
5
|
-
/** The `CheckBoxWidget` is a widget for rendering boolean properties.
|
|
6
|
-
* It is typically used to represent a boolean.
|
|
7
|
-
*
|
|
8
|
-
* @param props - The `WidgetProps` for this component
|
|
9
|
-
*/
|
|
10
|
-
function CheckboxWidget<T = any, F extends GenericObjectType = any>({
|
|
11
|
-
schema,
|
|
12
|
-
options,
|
|
13
|
-
id,
|
|
14
|
-
value,
|
|
15
|
-
disabled,
|
|
16
|
-
readonly,
|
|
17
|
-
label,
|
|
18
|
-
autofocus = false,
|
|
19
|
-
onBlur,
|
|
20
|
-
onFocus,
|
|
21
|
-
onChange,
|
|
22
|
-
registry,
|
|
23
|
-
}: WidgetProps<T, F>) {
|
|
24
|
-
const DescriptionFieldTemplate = getTemplate<
|
|
25
|
-
"DescriptionFieldTemplate",
|
|
26
|
-
T,
|
|
27
|
-
F
|
|
28
|
-
>("DescriptionFieldTemplate", registry, options);
|
|
29
|
-
// Because an unchecked checkbox will cause html5 validation to fail, only add
|
|
30
|
-
// the "required" attribute if the field value must be "true", due to the
|
|
31
|
-
// "const" or "enum" keywords
|
|
32
|
-
const required = schemaRequiresTrueValue(schema);
|
|
33
|
-
|
|
34
|
-
const handleChange = useCallback(
|
|
35
|
-
(event: React.ChangeEvent<HTMLInputElement>) =>
|
|
36
|
-
onChange(event.target.checked),
|
|
37
|
-
[onChange]
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const handleBlur = useCallback(
|
|
41
|
-
(event: React.FocusEvent<HTMLInputElement>) =>
|
|
42
|
-
onBlur(id, event.target.checked),
|
|
43
|
-
[onBlur, id]
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const handleFocus = useCallback(
|
|
47
|
-
(event: React.FocusEvent<HTMLInputElement>) =>
|
|
48
|
-
onFocus(id, event.target.checked),
|
|
49
|
-
[onFocus, id]
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<div className={`checkbox ${disabled || readonly ? "disabled" : ""}`}>
|
|
54
|
-
{schema.description && (
|
|
55
|
-
<DescriptionFieldTemplate
|
|
56
|
-
schema={schema}
|
|
57
|
-
id={id + "__description"}
|
|
58
|
-
description={schema.description}
|
|
59
|
-
registry={registry}
|
|
60
|
-
/>
|
|
61
|
-
)}
|
|
62
|
-
<label>
|
|
63
|
-
<input
|
|
64
|
-
type="checkbox"
|
|
65
|
-
id={id}
|
|
66
|
-
checked={typeof value === "undefined" ? false : value}
|
|
67
|
-
required={required}
|
|
68
|
-
disabled={disabled || readonly}
|
|
69
|
-
autoFocus={autofocus}
|
|
70
|
-
onChange={handleChange}
|
|
71
|
-
onBlur={handleBlur}
|
|
72
|
-
onFocus={handleFocus}
|
|
73
|
-
/>
|
|
74
|
-
<span>{label}</span>
|
|
75
|
-
</label>
|
|
76
|
-
</div>
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export default CheckboxWidget;
|
|
1
|
+
import React, { useCallback } from "react";
|
|
2
|
+
import type { GenericObjectType, WidgetProps } from "@rjsf/utils";
|
|
3
|
+
import { getTemplate, schemaRequiresTrueValue } from "@rjsf/utils";
|
|
4
|
+
|
|
5
|
+
/** The `CheckBoxWidget` is a widget for rendering boolean properties.
|
|
6
|
+
* It is typically used to represent a boolean.
|
|
7
|
+
*
|
|
8
|
+
* @param props - The `WidgetProps` for this component
|
|
9
|
+
*/
|
|
10
|
+
function CheckboxWidget<T = any, F extends GenericObjectType = any>({
|
|
11
|
+
schema,
|
|
12
|
+
options,
|
|
13
|
+
id,
|
|
14
|
+
value,
|
|
15
|
+
disabled,
|
|
16
|
+
readonly,
|
|
17
|
+
label,
|
|
18
|
+
autofocus = false,
|
|
19
|
+
onBlur,
|
|
20
|
+
onFocus,
|
|
21
|
+
onChange,
|
|
22
|
+
registry,
|
|
23
|
+
}: WidgetProps<T, F>) {
|
|
24
|
+
const DescriptionFieldTemplate = getTemplate<
|
|
25
|
+
"DescriptionFieldTemplate",
|
|
26
|
+
T,
|
|
27
|
+
F
|
|
28
|
+
>("DescriptionFieldTemplate", registry, options);
|
|
29
|
+
// Because an unchecked checkbox will cause html5 validation to fail, only add
|
|
30
|
+
// the "required" attribute if the field value must be "true", due to the
|
|
31
|
+
// "const" or "enum" keywords
|
|
32
|
+
const required = schemaRequiresTrueValue(schema);
|
|
33
|
+
|
|
34
|
+
const handleChange = useCallback(
|
|
35
|
+
(event: React.ChangeEvent<HTMLInputElement>) =>
|
|
36
|
+
onChange(event.target.checked),
|
|
37
|
+
[onChange]
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const handleBlur = useCallback(
|
|
41
|
+
(event: React.FocusEvent<HTMLInputElement>) =>
|
|
42
|
+
onBlur(id, event.target.checked),
|
|
43
|
+
[onBlur, id]
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const handleFocus = useCallback(
|
|
47
|
+
(event: React.FocusEvent<HTMLInputElement>) =>
|
|
48
|
+
onFocus(id, event.target.checked),
|
|
49
|
+
[onFocus, id]
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div className={`checkbox ${disabled || readonly ? "disabled" : ""}`}>
|
|
54
|
+
{schema.description && (
|
|
55
|
+
<DescriptionFieldTemplate
|
|
56
|
+
schema={schema}
|
|
57
|
+
id={id + "__description"}
|
|
58
|
+
description={schema.description}
|
|
59
|
+
registry={registry}
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
62
|
+
<label>
|
|
63
|
+
<input
|
|
64
|
+
type="checkbox"
|
|
65
|
+
id={id}
|
|
66
|
+
checked={typeof value === "undefined" ? false : value}
|
|
67
|
+
required={required}
|
|
68
|
+
disabled={disabled || readonly}
|
|
69
|
+
autoFocus={autofocus}
|
|
70
|
+
onChange={handleChange}
|
|
71
|
+
onBlur={handleBlur}
|
|
72
|
+
onFocus={handleFocus}
|
|
73
|
+
/>
|
|
74
|
+
<span>{label}</span>
|
|
75
|
+
</label>
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default CheckboxWidget;
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import React, { ChangeEvent } from "react";
|
|
2
|
-
import { WidgetProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
-
|
|
4
|
-
function selectValue(value: any, selected: any[], all: any[]) {
|
|
5
|
-
const at = all.indexOf(value);
|
|
6
|
-
const updated = selected.slice(0, at).concat(value, selected.slice(at));
|
|
7
|
-
// As inserting values at predefined index positions doesn't work with empty
|
|
8
|
-
// arrays, we need to reorder the updated selection to match the initial order
|
|
9
|
-
return updated.sort((a, b) => Number(all.indexOf(a) > all.indexOf(b)));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function deselectValue(value: any, selected: any[]) {
|
|
13
|
-
return selected.filter((v) => v !== value);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** The `CheckboxesWidget` is a widget for rendering checkbox groups.
|
|
17
|
-
* It is typically used to represent an array of enums.
|
|
18
|
-
*
|
|
19
|
-
* @param props - The `WidgetProps` for this component
|
|
20
|
-
*/
|
|
21
|
-
function CheckboxesWidget<T = any, F extends GenericObjectType = any>({
|
|
22
|
-
id,
|
|
23
|
-
disabled,
|
|
24
|
-
options: { inline = false, enumOptions, enumDisabled },
|
|
25
|
-
value,
|
|
26
|
-
autofocus = false,
|
|
27
|
-
readonly,
|
|
28
|
-
onChange,
|
|
29
|
-
}: WidgetProps<T, F>) {
|
|
30
|
-
return (
|
|
31
|
-
<div
|
|
32
|
-
className={`flex checkboxes ${inline ? "flex-row gap-2" : "flex-col"}`}
|
|
33
|
-
id={id}
|
|
34
|
-
>
|
|
35
|
-
{Array.isArray(enumOptions) &&
|
|
36
|
-
enumOptions.map((option, index) => {
|
|
37
|
-
const checked = value.indexOf(option.value) !== -1;
|
|
38
|
-
const itemDisabled =
|
|
39
|
-
enumDisabled && enumDisabled.indexOf(option.value) != -1;
|
|
40
|
-
const disabledCls =
|
|
41
|
-
disabled || itemDisabled || readonly ? "disabled" : "";
|
|
42
|
-
|
|
43
|
-
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
44
|
-
const all = enumOptions.map(({ value }) => value);
|
|
45
|
-
if (event.target.checked) {
|
|
46
|
-
onChange(selectValue(option.value, value, all));
|
|
47
|
-
} else {
|
|
48
|
-
onChange(deselectValue(option.value, value));
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<div key={`${id}_${index}_container`} className="form-control">
|
|
54
|
-
<label className="justify-start gap-2 cursor-pointer label">
|
|
55
|
-
<input
|
|
56
|
-
key={`${id}_${index}`}
|
|
57
|
-
className="checkbox checkbox-primary"
|
|
58
|
-
type="checkbox"
|
|
59
|
-
id={`${id}_${index}`}
|
|
60
|
-
checked={checked}
|
|
61
|
-
disabled={disabled || itemDisabled || readonly}
|
|
62
|
-
autoFocus={autofocus && index === 0}
|
|
63
|
-
onChange={handleChange}
|
|
64
|
-
/>
|
|
65
|
-
<span className="label-text">{option.label}</span>
|
|
66
|
-
</label>
|
|
67
|
-
</div>
|
|
68
|
-
);
|
|
69
|
-
})}
|
|
70
|
-
</div>
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export default CheckboxesWidget;
|
|
1
|
+
import React, { ChangeEvent } from "react";
|
|
2
|
+
import { WidgetProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
+
|
|
4
|
+
function selectValue(value: any, selected: any[], all: any[]) {
|
|
5
|
+
const at = all.indexOf(value);
|
|
6
|
+
const updated = selected.slice(0, at).concat(value, selected.slice(at));
|
|
7
|
+
// As inserting values at predefined index positions doesn't work with empty
|
|
8
|
+
// arrays, we need to reorder the updated selection to match the initial order
|
|
9
|
+
return updated.sort((a, b) => Number(all.indexOf(a) > all.indexOf(b)));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function deselectValue(value: any, selected: any[]) {
|
|
13
|
+
return selected.filter((v) => v !== value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The `CheckboxesWidget` is a widget for rendering checkbox groups.
|
|
17
|
+
* It is typically used to represent an array of enums.
|
|
18
|
+
*
|
|
19
|
+
* @param props - The `WidgetProps` for this component
|
|
20
|
+
*/
|
|
21
|
+
function CheckboxesWidget<T = any, F extends GenericObjectType = any>({
|
|
22
|
+
id,
|
|
23
|
+
disabled,
|
|
24
|
+
options: { inline = false, enumOptions, enumDisabled },
|
|
25
|
+
value,
|
|
26
|
+
autofocus = false,
|
|
27
|
+
readonly,
|
|
28
|
+
onChange,
|
|
29
|
+
}: WidgetProps<T, F>) {
|
|
30
|
+
return (
|
|
31
|
+
<div
|
|
32
|
+
className={`flex checkboxes ${inline ? "flex-row gap-2" : "flex-col"}`}
|
|
33
|
+
id={id}
|
|
34
|
+
>
|
|
35
|
+
{Array.isArray(enumOptions) &&
|
|
36
|
+
enumOptions.map((option, index) => {
|
|
37
|
+
const checked = value.indexOf(option.value) !== -1;
|
|
38
|
+
const itemDisabled =
|
|
39
|
+
enumDisabled && enumDisabled.indexOf(option.value) != -1;
|
|
40
|
+
const disabledCls =
|
|
41
|
+
disabled || itemDisabled || readonly ? "disabled" : "";
|
|
42
|
+
|
|
43
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
44
|
+
const all = enumOptions.map(({ value }) => value);
|
|
45
|
+
if (event.target.checked) {
|
|
46
|
+
onChange(selectValue(option.value, value, all));
|
|
47
|
+
} else {
|
|
48
|
+
onChange(deselectValue(option.value, value));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div key={`${id}_${index}_container`} className="form-control">
|
|
54
|
+
<label className="justify-start gap-2 cursor-pointer label">
|
|
55
|
+
<input
|
|
56
|
+
key={`${id}_${index}`}
|
|
57
|
+
className="checkbox checkbox-primary"
|
|
58
|
+
type="checkbox"
|
|
59
|
+
id={`${id}_${index}`}
|
|
60
|
+
checked={checked}
|
|
61
|
+
disabled={disabled || itemDisabled || readonly}
|
|
62
|
+
autoFocus={autofocus && index === 0}
|
|
63
|
+
onChange={handleChange}
|
|
64
|
+
/>
|
|
65
|
+
<span className="label-text">{option.label}</span>
|
|
66
|
+
</label>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
})}
|
|
70
|
+
</div>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default CheckboxesWidget;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type { WidgetProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
-
import { getTemplate } from "@rjsf/utils";
|
|
4
|
-
|
|
5
|
-
/** The `ColorWidget` component uses the `BaseInputTemplate` changing the type to `color` and disables it when it is
|
|
6
|
-
* either disabled or readonly.
|
|
7
|
-
*
|
|
8
|
-
* @param props - The `WidgetProps` for this component
|
|
9
|
-
*/
|
|
10
|
-
export default function ColorWidget<T = any, F extends GenericObjectType = any>(
|
|
11
|
-
props: WidgetProps<T, F>
|
|
12
|
-
) {
|
|
13
|
-
const { disabled, readonly, options, registry } = props;
|
|
14
|
-
const BaseInputTemplate = getTemplate<"BaseInputTemplate", T, F>(
|
|
15
|
-
"BaseInputTemplate",
|
|
16
|
-
registry,
|
|
17
|
-
options
|
|
18
|
-
);
|
|
19
|
-
return (
|
|
20
|
-
<BaseInputTemplate
|
|
21
|
-
type="color"
|
|
22
|
-
{...props}
|
|
23
|
-
disabled={disabled || readonly}
|
|
24
|
-
/>
|
|
25
|
-
);
|
|
26
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { WidgetProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
+
import { getTemplate } from "@rjsf/utils";
|
|
4
|
+
|
|
5
|
+
/** The `ColorWidget` component uses the `BaseInputTemplate` changing the type to `color` and disables it when it is
|
|
6
|
+
* either disabled or readonly.
|
|
7
|
+
*
|
|
8
|
+
* @param props - The `WidgetProps` for this component
|
|
9
|
+
*/
|
|
10
|
+
export default function ColorWidget<T = any, F extends GenericObjectType = any>(
|
|
11
|
+
props: WidgetProps<T, F>
|
|
12
|
+
) {
|
|
13
|
+
const { disabled, readonly, options, registry } = props;
|
|
14
|
+
const BaseInputTemplate = getTemplate<"BaseInputTemplate", T, F>(
|
|
15
|
+
"BaseInputTemplate",
|
|
16
|
+
registry,
|
|
17
|
+
options
|
|
18
|
+
);
|
|
19
|
+
return (
|
|
20
|
+
<BaseInputTemplate
|
|
21
|
+
type="color"
|
|
22
|
+
{...props}
|
|
23
|
+
disabled={disabled || readonly}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type { WidgetProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
-
import { getTemplate, localToUTC, utcToLocal } from "@rjsf/utils";
|
|
4
|
-
|
|
5
|
-
/** The `DateTimeWidget` component uses the `BaseInputTemplate` changing the type to `datetime-local` and transforms
|
|
6
|
-
* the value to/from utc using the appropriate utility functions.
|
|
7
|
-
*
|
|
8
|
-
* @param props - The `WidgetProps` for this component
|
|
9
|
-
*/
|
|
10
|
-
export default function DateTimeWidget<
|
|
11
|
-
T = any,
|
|
12
|
-
F extends GenericObjectType = any
|
|
13
|
-
>(props: WidgetProps<T, F>) {
|
|
14
|
-
const { onChange, value, options, registry } = props;
|
|
15
|
-
const BaseInputTemplate = getTemplate<"BaseInputTemplate", T, F>(
|
|
16
|
-
"BaseInputTemplate",
|
|
17
|
-
registry,
|
|
18
|
-
options
|
|
19
|
-
);
|
|
20
|
-
return (
|
|
21
|
-
<BaseInputTemplate
|
|
22
|
-
type="datetime-local"
|
|
23
|
-
{...props}
|
|
24
|
-
value={utcToLocal(value)}
|
|
25
|
-
onChange={(value) => onChange(localToUTC(value))}
|
|
26
|
-
/>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { WidgetProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
+
import { getTemplate, localToUTC, utcToLocal } from "@rjsf/utils";
|
|
4
|
+
|
|
5
|
+
/** The `DateTimeWidget` component uses the `BaseInputTemplate` changing the type to `datetime-local` and transforms
|
|
6
|
+
* the value to/from utc using the appropriate utility functions.
|
|
7
|
+
*
|
|
8
|
+
* @param props - The `WidgetProps` for this component
|
|
9
|
+
*/
|
|
10
|
+
export default function DateTimeWidget<
|
|
11
|
+
T = any,
|
|
12
|
+
F extends GenericObjectType = any
|
|
13
|
+
>(props: WidgetProps<T, F>) {
|
|
14
|
+
const { onChange, value, options, registry } = props;
|
|
15
|
+
const BaseInputTemplate = getTemplate<"BaseInputTemplate", T, F>(
|
|
16
|
+
"BaseInputTemplate",
|
|
17
|
+
registry,
|
|
18
|
+
options
|
|
19
|
+
);
|
|
20
|
+
return (
|
|
21
|
+
<BaseInputTemplate
|
|
22
|
+
type="datetime-local"
|
|
23
|
+
{...props}
|
|
24
|
+
value={utcToLocal(value)}
|
|
25
|
+
onChange={(value) => onChange(localToUTC(value))}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import React, { useCallback, useEffect } from "react";
|
|
2
|
-
import type { WidgetProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
-
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import DatePicker from "react-datepicker";
|
|
6
|
-
|
|
7
|
-
/** The `DateWidget` component uses the `BaseInputTemplate` changing the type to `date` and transforms
|
|
8
|
-
* the value to undefined when it is falsy during the `onChange` handling.
|
|
9
|
-
*
|
|
10
|
-
* @param props - The `WidgetProps` for this component
|
|
11
|
-
*/
|
|
12
|
-
export default function DateWidget<T = any, F extends GenericObjectType = any>(
|
|
13
|
-
props: WidgetProps<T, F>
|
|
14
|
-
) {
|
|
15
|
-
const { onChange } = props;
|
|
16
|
-
|
|
17
|
-
const handleChange = useCallback(
|
|
18
|
-
(selectedDate: Date) => {
|
|
19
|
-
onChange(selectedDate?.toISOString().split("T")[0] || undefined);
|
|
20
|
-
},
|
|
21
|
-
[onChange]
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const getValue = () => {
|
|
25
|
-
const offset = new Date().getTimezoneOffset();
|
|
26
|
-
return props.value ? new Date(`${props.value}T19:00:00.${offset}Z`) : null;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<DatePicker
|
|
31
|
-
selected={getValue()}
|
|
32
|
-
className="w-full input input-bordered"
|
|
33
|
-
onChange={handleChange}
|
|
34
|
-
/>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
1
|
+
import React, { useCallback, useEffect } from "react";
|
|
2
|
+
import type { WidgetProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
+
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import DatePicker from "react-datepicker";
|
|
6
|
+
|
|
7
|
+
/** The `DateWidget` component uses the `BaseInputTemplate` changing the type to `date` and transforms
|
|
8
|
+
* the value to undefined when it is falsy during the `onChange` handling.
|
|
9
|
+
*
|
|
10
|
+
* @param props - The `WidgetProps` for this component
|
|
11
|
+
*/
|
|
12
|
+
export default function DateWidget<T = any, F extends GenericObjectType = any>(
|
|
13
|
+
props: WidgetProps<T, F>
|
|
14
|
+
) {
|
|
15
|
+
const { onChange } = props;
|
|
16
|
+
|
|
17
|
+
const handleChange = useCallback(
|
|
18
|
+
(selectedDate: Date) => {
|
|
19
|
+
onChange(selectedDate?.toISOString().split("T")[0] || undefined);
|
|
20
|
+
},
|
|
21
|
+
[onChange]
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const getValue = () => {
|
|
25
|
+
const offset = new Date().getTimezoneOffset();
|
|
26
|
+
return props.value ? new Date(`${props.value}T19:00:00.${offset}Z`) : null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<DatePicker
|
|
31
|
+
selected={getValue()}
|
|
32
|
+
className="w-full input input-bordered"
|
|
33
|
+
onChange={handleChange}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type { WidgetProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
-
import { getTemplate } from "@rjsf/utils";
|
|
4
|
-
|
|
5
|
-
/** The `EmailWidget` component uses the `BaseInputTemplate` changing the type to `email`.
|
|
6
|
-
*
|
|
7
|
-
* @param props - The `WidgetProps` for this component
|
|
8
|
-
*/
|
|
9
|
-
export default function EmailWidget<T = any, F extends GenericObjectType = any>(
|
|
10
|
-
props: WidgetProps<T, F>
|
|
11
|
-
) {
|
|
12
|
-
const { options, registry } = props;
|
|
13
|
-
const BaseInputTemplate = getTemplate<"BaseInputTemplate", T, F>(
|
|
14
|
-
"BaseInputTemplate",
|
|
15
|
-
registry,
|
|
16
|
-
options
|
|
17
|
-
);
|
|
18
|
-
return <BaseInputTemplate type="email" {...props} />;
|
|
19
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { WidgetProps, GenericObjectType } from "@rjsf/utils";
|
|
3
|
+
import { getTemplate } from "@rjsf/utils";
|
|
4
|
+
|
|
5
|
+
/** The `EmailWidget` component uses the `BaseInputTemplate` changing the type to `email`.
|
|
6
|
+
*
|
|
7
|
+
* @param props - The `WidgetProps` for this component
|
|
8
|
+
*/
|
|
9
|
+
export default function EmailWidget<T = any, F extends GenericObjectType = any>(
|
|
10
|
+
props: WidgetProps<T, F>
|
|
11
|
+
) {
|
|
12
|
+
const { options, registry } = props;
|
|
13
|
+
const BaseInputTemplate = getTemplate<"BaseInputTemplate", T, F>(
|
|
14
|
+
"BaseInputTemplate",
|
|
15
|
+
registry,
|
|
16
|
+
options
|
|
17
|
+
);
|
|
18
|
+
return <BaseInputTemplate type="email" {...props} />;
|
|
19
|
+
}
|