forked from rjsf-team/react-jsonschema-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateTimeWidget.tsx
46 lines (43 loc) · 944 Bytes
/
DateTimeWidget.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
import React from "react";
import {
WidgetProps,
getTemplate,
localToUTC,
utcToLocal,
StrictRJSFSchema,
RJSFSchema,
FormContextType,
} from "@rjsf/utils";
export default function DateTimeWidget<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
>(props: WidgetProps<T, S, F>) {
const { registry } = props;
const uiProps: any = props.options["props"] || {};
const options = {
...props.options,
props: {
type: "datetime-local",
...uiProps,
},
};
const BaseInputTemplate = getTemplate<"BaseInputTemplate", T, S, F>(
"BaseInputTemplate",
registry,
options
);
const value = utcToLocal(props.value);
const onChange = (value: any) => {
props.onChange(localToUTC(value));
};
// TODO: rows and columns.
return (
<BaseInputTemplate
{...props}
options={options}
value={value}
onChange={onChange}
/>
);
}