envoc-form 4.0.1-6 → 4.0.1-8
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/README.md +2 -2
- package/es/DatePicker/DatePickerGroup.js +10 -2
- package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
- package/es/DatePicker/{DateOnlyDatePickerGroup.js → StringDateOnlyPickerGroup.js} +7 -6
- package/es/Form/Form.d.ts +8 -3
- package/es/Form/Form.js +30 -3
- package/es/SubmitFormButton.js +2 -1
- package/es/__Tests__/FormTestBase.d.ts +3 -3
- package/es/index.d.ts +2 -2
- package/es/index.js +1 -1
- package/lib/DatePicker/DatePickerGroup.js +9 -1
- package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
- package/lib/DatePicker/{DateOnlyDatePickerGroup.js → StringDateOnlyPickerGroup.js} +8 -7
- package/lib/Form/Form.d.ts +8 -3
- package/lib/Form/Form.js +30 -3
- package/lib/SubmitFormButton.js +2 -1
- package/lib/__Tests__/FormTestBase.d.ts +3 -3
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -3
- package/package.json +4 -2
- package/src/DatePicker/DatePicker.test.tsx +3 -3
- package/src/DatePicker/DatePickerGroup.tsx +11 -5
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +23 -0
- package/src/Form/Form.tsx +49 -4
- package/src/SubmitFormButton.tsx +2 -0
- package/src/__Tests__/FormTestBase.tsx +3 -3
- package/src/__Tests__/__snapshots__/StandardFormActions.test.tsx.snap +1 -0
- package/src/__Tests__/__snapshots__/SubmitFormButton.test.tsx.snap +1 -0
- package/src/index.ts +3 -6
- package/es/DatePicker/DateOnlyDatePickerGroup.d.ts +0 -10
- package/lib/DatePicker/DateOnlyDatePickerGroup.d.ts +0 -10
- package/src/DatePicker/DateOnlyDatePickerGroup.tsx +0 -24
package/README.md
CHANGED
@@ -10,8 +10,8 @@ Base form package for envoc projects.
|
|
10
10
|
Important naming conventions for our sanity while creating envoc-form types:
|
11
11
|
|
12
12
|
- TForm = The type of the some form. e.g. LoginDto
|
13
|
-
- TProp = The key / symbol of a
|
14
|
-
- TValue = The value of an
|
13
|
+
- TProp = The key / symbol of a individual property of some form. e.g. TProp would be literally "Username" for the prop of the same name for a LoginDto
|
14
|
+
- TValue = The value of an individual property of some form. e.g. a "Username" property would probably have a TValue of string
|
15
15
|
- Field = the abstract thing that deals with some specific TProp. Might represent several composed elements (e.g. label, input, helperText, etc) or may just be a direct component
|
16
16
|
- TRenderComponent = The type of any 'Component' passed to a Field, e.g. 'StandardTextInputGroup' passed to Component means TRenderComponent is typeof(StandardTextInputGroup)
|
17
17
|
- TComponentProps = For any 'Component' passed to a Field as a prop, this represents that Component's props
|
@@ -21,15 +21,23 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
21
21
|
return t;
|
22
22
|
};
|
23
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
24
|
-
import { useState } from 'react';
|
24
|
+
import { useEffect, useState } from 'react';
|
25
25
|
import DatePicker from 'react-date-picker/dist/entry.nostyle';
|
26
26
|
import classnames from 'classnames';
|
27
27
|
import parseISO from 'date-fns/parseISO';
|
28
|
-
import Group from '../Group';
|
29
28
|
import { FormDefaults } from '../FormDefaults';
|
29
|
+
import Group from '../Group';
|
30
30
|
export default function DatePickerGroup(_a) {
|
31
31
|
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, disabled = _a.disabled, convert = _a.convert, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "disabled", "convert"]);
|
32
32
|
var _b = useState(null), displayDate = _b[0], setDisplayDate = _b[1];
|
33
|
+
useEffect(function () {
|
34
|
+
if (input.value != null) {
|
35
|
+
setDisplayDate(new Date("".concat(input.value, "T00:00:00.000")));
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
setDisplayDate(null);
|
39
|
+
}
|
40
|
+
}, [setDisplayDate, input.value]);
|
33
41
|
return (_jsx(Group, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: classnames(className, FormDefaults.cssClassPrefix + 'date-picker'), disabled: disabled }, { children: _jsx(DatePicker, __assign({}, rest, { className: classnames(FormDefaults.cssClassPrefix + 'date-picker', className), value: displayDate, onChange: handleChange })) })));
|
34
42
|
function handleChange(e) {
|
35
43
|
var onChange = input.onChange;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { DatePickerHelper } from './DatePickerHelper';
|
3
|
+
export interface StringDateOnlyPickerGroupProps extends DatePickerHelper<string | undefined> {
|
4
|
+
}
|
5
|
+
export default function StringDatePickerGroup(props: StringDateOnlyPickerGroupProps): JSX.Element;
|
@@ -11,13 +11,14 @@ var __assign = (this && this.__assign) || function () {
|
|
11
11
|
};
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
13
13
|
import DatePickerGroup from './DatePickerGroup';
|
14
|
-
export default function
|
14
|
+
export default function StringDatePickerGroup(props) {
|
15
15
|
return _jsx(DatePickerGroup, __assign({}, props, { convert: convertToDateOnly }));
|
16
16
|
}
|
17
17
|
function convertToDateOnly(arg) {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
};
|
18
|
+
var year = new Intl.DateTimeFormat('en', { year: 'numeric' })
|
19
|
+
.format(arg)
|
20
|
+
.padStart(4, '0');
|
21
|
+
var month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(arg);
|
22
|
+
var day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(arg);
|
23
|
+
return "".concat(year, "-").concat(month, "-").concat(day);
|
23
24
|
}
|
package/es/Form/Form.d.ts
CHANGED
@@ -7,15 +7,20 @@ export declare type FormBuilderProp<TForm extends object> = {
|
|
7
7
|
Field: <TProp extends keyof TForm, TRenderComponent extends ElementType>(props: FieldProps<TForm, TProp, TRenderComponent>) => JSX.Element;
|
8
8
|
FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
|
9
9
|
};
|
10
|
-
export interface
|
10
|
+
export interface FullFormProps<TForm extends object> {
|
11
11
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
12
|
-
onSubmit: (formValues:
|
12
|
+
onSubmit: (formValues: TForm, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
|
13
|
+
onFormDataSubmit: (formValues: FormData, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
|
13
14
|
className?: string;
|
14
15
|
style?: CSSProperties;
|
15
16
|
ignoreLostChanges?: boolean;
|
16
17
|
initialValues?: TForm;
|
17
18
|
}
|
18
|
-
declare
|
19
|
+
declare type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
|
20
|
+
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
|
21
|
+
}[Keys];
|
22
|
+
export declare type FormProps<TForm extends object> = RequireAtLeastOne<FullFormProps<TForm>, 'onSubmit' | 'onFormDataSubmit'>;
|
23
|
+
declare function Form<TForm extends object>({ children, className, style, ignoreLostChanges, onSubmit, onFormDataSubmit, initialValues, ...props }: FormProps<TForm>): JSX.Element;
|
19
24
|
declare namespace Form {
|
20
25
|
var DisplayFormState: () => JSX.Element;
|
21
26
|
}
|
package/es/Form/Form.js
CHANGED
@@ -29,11 +29,11 @@ import FormBasedPreventNavigation from './FormBasedPreventNavigation';
|
|
29
29
|
import { ServerErrorContext, } from './ServerErrorContext';
|
30
30
|
import Field from '../Field/Field';
|
31
31
|
import FieldArray from '../FieldArray/FieldArray';
|
32
|
+
import { FormDefaults } from '../FormDefaults';
|
32
33
|
import objectContainsNonSerializableProperty from '../utils/objectContainsNonSerializableProperty';
|
33
34
|
import objectToFormData from '../utils/objectToFormData';
|
34
|
-
import { FormDefaults } from '../FormDefaults';
|
35
35
|
export default function Form(_a) {
|
36
|
-
var children = _a.children, className = _a.className, style = _a.style, ignoreLostChanges = _a.ignoreLostChanges, onSubmit = _a.onSubmit, initialValues = _a.initialValues, props = __rest(_a, ["children", "className", "style", "ignoreLostChanges", "onSubmit", "initialValues"]);
|
36
|
+
var children = _a.children, className = _a.className, style = _a.style, ignoreLostChanges = _a.ignoreLostChanges, onSubmit = _a.onSubmit, onFormDataSubmit = _a.onFormDataSubmit, initialValues = _a.initialValues, props = __rest(_a, ["children", "className", "style", "ignoreLostChanges", "onSubmit", "onFormDataSubmit", "initialValues"]);
|
37
37
|
// formik resets all error on each blur (with our settings)
|
38
38
|
// this means that ALL errors from the server disappear when any one field is blurred
|
39
39
|
// So, we have to store server errors ourselves
|
@@ -60,6 +60,7 @@ export default function Form(_a) {
|
|
60
60
|
})] })) })) })));
|
61
61
|
function handleSubmit(values, formikBag) {
|
62
62
|
var formData = undefined;
|
63
|
+
var submitFunc;
|
63
64
|
if (objectContainsNonSerializableProperty(values)) {
|
64
65
|
formData = objectToFormData(values, {
|
65
66
|
indices: true,
|
@@ -67,8 +68,34 @@ export default function Form(_a) {
|
|
67
68
|
allowEmptyArrays: true,
|
68
69
|
noFileListBrackets: true,
|
69
70
|
});
|
71
|
+
if (onFormDataSubmit === undefined) {
|
72
|
+
throw new Error('No onFormDataSubmit supplied for non-serializable properties.');
|
73
|
+
}
|
74
|
+
submitFunc = function () {
|
75
|
+
return onFormDataSubmit(formData !== null && formData !== void 0 ? formData : new FormData(), formikBag);
|
76
|
+
};
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
if (onSubmit === undefined) {
|
80
|
+
formData = objectToFormData(values, {
|
81
|
+
indices: true,
|
82
|
+
dotNotation: true,
|
83
|
+
allowEmptyArrays: true,
|
84
|
+
noFileListBrackets: true,
|
85
|
+
});
|
86
|
+
if (onFormDataSubmit === undefined) {
|
87
|
+
// This error should never occur, as this case is covered by RequireAtLeastOne type safety
|
88
|
+
throw new Error('No onFormDataSubmit supplied for non-serializable properties.');
|
89
|
+
}
|
90
|
+
submitFunc = function () {
|
91
|
+
return onFormDataSubmit(formData !== null && formData !== void 0 ? formData : new FormData(), formikBag);
|
92
|
+
};
|
93
|
+
}
|
94
|
+
else {
|
95
|
+
submitFunc = function () { return onSubmit(values, formikBag); };
|
96
|
+
}
|
70
97
|
}
|
71
|
-
return
|
98
|
+
return submitFunc()
|
72
99
|
.then(function (response) {
|
73
100
|
return response;
|
74
101
|
})
|
package/es/SubmitFormButton.js
CHANGED
@@ -29,7 +29,8 @@ function SubmitFormButton(_a, ref) {
|
|
29
29
|
var allowPristineSubmit = _a.allowPristineSubmit, children = _a.children, disabled = _a.disabled, title = _a.title, className = _a.className, props = __rest(_a, ["allowPristineSubmit", "children", "disabled", "title", "className"]);
|
30
30
|
var _b = useFormikContext(), isSubmitting = _b.isSubmitting, dirty = _b.dirty;
|
31
31
|
var preventSubmit = (!dirty && !allowPristineSubmit) || isSubmitting;
|
32
|
-
|
32
|
+
var buttonName = typeof children === 'string' ? children : 'Submit';
|
33
|
+
return (_jsx("button", __assign({}, props, { ref: ref, type: "submit", disabled: preventSubmit || disabled, "aria-label": buttonName, title: title || isSubmitting
|
33
34
|
? 'Loading, please wait...'
|
34
35
|
: preventSubmit
|
35
36
|
? "You haven't made any changes"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import '@testing-library/jest-dom/extend-expect';
|
3
|
-
import {
|
3
|
+
import { FormBuilderProp } from '../../src';
|
4
4
|
interface FormTestBaseProps<TForm extends object> {
|
5
5
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
6
6
|
initialValues?: TForm;
|
@@ -13,8 +13,8 @@ interface PersonDto {
|
|
13
13
|
phoneNumber?: string;
|
14
14
|
yearlySalaryUSD?: number;
|
15
15
|
isCool?: boolean;
|
16
|
-
gradDate?:
|
17
|
-
favoriteDate?:
|
16
|
+
gradDate?: string;
|
17
|
+
favoriteDate?: string;
|
18
18
|
favoriteNumber?: number;
|
19
19
|
favoriteColor?: string;
|
20
20
|
favoriteColors?: string[];
|
package/es/index.d.ts
CHANGED
@@ -10,10 +10,10 @@ export { default as DatePickerGroup } from './DatePicker/DatePickerGroup';
|
|
10
10
|
export type { DatePickerGroupProps as DatePickerGroupProps } from './DatePicker/DatePickerGroup';
|
11
11
|
export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGroup';
|
12
12
|
export type { DatePickerHelper } from './DatePicker/DatePickerHelper';
|
13
|
-
export { default as DateOnlyDatePickerGroup } from './DatePicker/DateOnlyDatePickerGroup';
|
14
|
-
export type { DateOnly, DateOnlyDatePickerGroupProps, } from './DatePicker/DateOnlyDatePickerGroup';
|
15
13
|
export { default as StringDatePickerGroup } from './DatePicker/StringDatePickerGroup';
|
16
14
|
export type { StringDatePickerGroupProps } from './DatePicker/StringDatePickerGroup';
|
15
|
+
export { default as StringDateOnlyPickerGroup } from './DatePicker/StringDateOnlyPickerGroup';
|
16
|
+
export type { StringDateOnlyPickerGroupProps } from './DatePicker/StringDateOnlyPickerGroup';
|
17
17
|
export { default as Field } from './Field/Field';
|
18
18
|
export type { FieldProps } from './Field/Field';
|
19
19
|
export type { RenderComponent } from './Field/Field';
|
package/es/index.js
CHANGED
@@ -9,8 +9,8 @@ export { default as ConfirmDeleteForm } from './ConfirmDeleteForm/ConfirmDeleteF
|
|
9
9
|
// Date
|
10
10
|
export { default as DatePickerGroup } from './DatePicker/DatePickerGroup';
|
11
11
|
export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGroup';
|
12
|
-
export { default as DateOnlyDatePickerGroup } from './DatePicker/DateOnlyDatePickerGroup';
|
13
12
|
export { default as StringDatePickerGroup } from './DatePicker/StringDatePickerGroup';
|
13
|
+
export { default as StringDateOnlyPickerGroup } from './DatePicker/StringDateOnlyPickerGroup';
|
14
14
|
// Field
|
15
15
|
export { default as Field } from './Field/Field';
|
16
16
|
export { default as FieldErrorScrollTarget } from './Field/FieldErrorScrollTarget';
|
@@ -31,11 +31,19 @@ var react_1 = require("react");
|
|
31
31
|
var entry_nostyle_1 = __importDefault(require("react-date-picker/dist/entry.nostyle"));
|
32
32
|
var classnames_1 = __importDefault(require("classnames"));
|
33
33
|
var parseISO_1 = __importDefault(require("date-fns/parseISO"));
|
34
|
-
var Group_1 = __importDefault(require("../Group"));
|
35
34
|
var FormDefaults_1 = require("../FormDefaults");
|
35
|
+
var Group_1 = __importDefault(require("../Group"));
|
36
36
|
function DatePickerGroup(_a) {
|
37
37
|
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, disabled = _a.disabled, convert = _a.convert, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "disabled", "convert"]);
|
38
38
|
var _b = (0, react_1.useState)(null), displayDate = _b[0], setDisplayDate = _b[1];
|
39
|
+
(0, react_1.useEffect)(function () {
|
40
|
+
if (input.value != null) {
|
41
|
+
setDisplayDate(new Date("".concat(input.value, "T00:00:00.000")));
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
setDisplayDate(null);
|
45
|
+
}
|
46
|
+
}, [setDisplayDate, input.value]);
|
39
47
|
return ((0, jsx_runtime_1.jsx)(Group_1.default, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'date-picker'), disabled: disabled }, { children: (0, jsx_runtime_1.jsx)(entry_nostyle_1.default, __assign({}, rest, { className: (0, classnames_1.default)(FormDefaults_1.FormDefaults.cssClassPrefix + 'date-picker', className), value: displayDate, onChange: handleChange })) })));
|
40
48
|
function handleChange(e) {
|
41
49
|
var onChange = input.onChange;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { DatePickerHelper } from './DatePickerHelper';
|
3
|
+
export interface StringDateOnlyPickerGroupProps extends DatePickerHelper<string | undefined> {
|
4
|
+
}
|
5
|
+
export default function StringDatePickerGroup(props: StringDateOnlyPickerGroupProps): JSX.Element;
|
@@ -16,14 +16,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
18
18
|
var DatePickerGroup_1 = __importDefault(require("./DatePickerGroup"));
|
19
|
-
function
|
19
|
+
function StringDatePickerGroup(props) {
|
20
20
|
return (0, jsx_runtime_1.jsx)(DatePickerGroup_1.default, __assign({}, props, { convert: convertToDateOnly }));
|
21
21
|
}
|
22
|
-
exports.default =
|
22
|
+
exports.default = StringDatePickerGroup;
|
23
23
|
function convertToDateOnly(arg) {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
};
|
24
|
+
var year = new Intl.DateTimeFormat('en', { year: 'numeric' })
|
25
|
+
.format(arg)
|
26
|
+
.padStart(4, '0');
|
27
|
+
var month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(arg);
|
28
|
+
var day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(arg);
|
29
|
+
return "".concat(year, "-").concat(month, "-").concat(day);
|
29
30
|
}
|
package/lib/Form/Form.d.ts
CHANGED
@@ -7,15 +7,20 @@ export declare type FormBuilderProp<TForm extends object> = {
|
|
7
7
|
Field: <TProp extends keyof TForm, TRenderComponent extends ElementType>(props: FieldProps<TForm, TProp, TRenderComponent>) => JSX.Element;
|
8
8
|
FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
|
9
9
|
};
|
10
|
-
export interface
|
10
|
+
export interface FullFormProps<TForm extends object> {
|
11
11
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
12
|
-
onSubmit: (formValues:
|
12
|
+
onSubmit: (formValues: TForm, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
|
13
|
+
onFormDataSubmit: (formValues: FormData, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
|
13
14
|
className?: string;
|
14
15
|
style?: CSSProperties;
|
15
16
|
ignoreLostChanges?: boolean;
|
16
17
|
initialValues?: TForm;
|
17
18
|
}
|
18
|
-
declare
|
19
|
+
declare type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
|
20
|
+
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
|
21
|
+
}[Keys];
|
22
|
+
export declare type FormProps<TForm extends object> = RequireAtLeastOne<FullFormProps<TForm>, 'onSubmit' | 'onFormDataSubmit'>;
|
23
|
+
declare function Form<TForm extends object>({ children, className, style, ignoreLostChanges, onSubmit, onFormDataSubmit, initialValues, ...props }: FormProps<TForm>): JSX.Element;
|
19
24
|
declare namespace Form {
|
20
25
|
var DisplayFormState: () => JSX.Element;
|
21
26
|
}
|
package/lib/Form/Form.js
CHANGED
@@ -34,11 +34,11 @@ var FormBasedPreventNavigation_1 = __importDefault(require("./FormBasedPreventNa
|
|
34
34
|
var ServerErrorContext_1 = require("./ServerErrorContext");
|
35
35
|
var Field_1 = __importDefault(require("../Field/Field"));
|
36
36
|
var FieldArray_1 = __importDefault(require("../FieldArray/FieldArray"));
|
37
|
+
var FormDefaults_1 = require("../FormDefaults");
|
37
38
|
var objectContainsNonSerializableProperty_1 = __importDefault(require("../utils/objectContainsNonSerializableProperty"));
|
38
39
|
var objectToFormData_1 = __importDefault(require("../utils/objectToFormData"));
|
39
|
-
var FormDefaults_1 = require("../FormDefaults");
|
40
40
|
function Form(_a) {
|
41
|
-
var children = _a.children, className = _a.className, style = _a.style, ignoreLostChanges = _a.ignoreLostChanges, onSubmit = _a.onSubmit, initialValues = _a.initialValues, props = __rest(_a, ["children", "className", "style", "ignoreLostChanges", "onSubmit", "initialValues"]);
|
41
|
+
var children = _a.children, className = _a.className, style = _a.style, ignoreLostChanges = _a.ignoreLostChanges, onSubmit = _a.onSubmit, onFormDataSubmit = _a.onFormDataSubmit, initialValues = _a.initialValues, props = __rest(_a, ["children", "className", "style", "ignoreLostChanges", "onSubmit", "onFormDataSubmit", "initialValues"]);
|
42
42
|
// formik resets all error on each blur (with our settings)
|
43
43
|
// this means that ALL errors from the server disappear when any one field is blurred
|
44
44
|
// So, we have to store server errors ourselves
|
@@ -65,6 +65,7 @@ function Form(_a) {
|
|
65
65
|
})] })) })) })));
|
66
66
|
function handleSubmit(values, formikBag) {
|
67
67
|
var formData = undefined;
|
68
|
+
var submitFunc;
|
68
69
|
if ((0, objectContainsNonSerializableProperty_1.default)(values)) {
|
69
70
|
formData = (0, objectToFormData_1.default)(values, {
|
70
71
|
indices: true,
|
@@ -72,8 +73,34 @@ function Form(_a) {
|
|
72
73
|
allowEmptyArrays: true,
|
73
74
|
noFileListBrackets: true,
|
74
75
|
});
|
76
|
+
if (onFormDataSubmit === undefined) {
|
77
|
+
throw new Error('No onFormDataSubmit supplied for non-serializable properties.');
|
78
|
+
}
|
79
|
+
submitFunc = function () {
|
80
|
+
return onFormDataSubmit(formData !== null && formData !== void 0 ? formData : new FormData(), formikBag);
|
81
|
+
};
|
82
|
+
}
|
83
|
+
else {
|
84
|
+
if (onSubmit === undefined) {
|
85
|
+
formData = (0, objectToFormData_1.default)(values, {
|
86
|
+
indices: true,
|
87
|
+
dotNotation: true,
|
88
|
+
allowEmptyArrays: true,
|
89
|
+
noFileListBrackets: true,
|
90
|
+
});
|
91
|
+
if (onFormDataSubmit === undefined) {
|
92
|
+
// This error should never occur, as this case is covered by RequireAtLeastOne type safety
|
93
|
+
throw new Error('No onFormDataSubmit supplied for non-serializable properties.');
|
94
|
+
}
|
95
|
+
submitFunc = function () {
|
96
|
+
return onFormDataSubmit(formData !== null && formData !== void 0 ? formData : new FormData(), formikBag);
|
97
|
+
};
|
98
|
+
}
|
99
|
+
else {
|
100
|
+
submitFunc = function () { return onSubmit(values, formikBag); };
|
101
|
+
}
|
75
102
|
}
|
76
|
-
return
|
103
|
+
return submitFunc()
|
77
104
|
.then(function (response) {
|
78
105
|
return response;
|
79
106
|
})
|
package/lib/SubmitFormButton.js
CHANGED
@@ -34,7 +34,8 @@ function SubmitFormButton(_a, ref) {
|
|
34
34
|
var allowPristineSubmit = _a.allowPristineSubmit, children = _a.children, disabled = _a.disabled, title = _a.title, className = _a.className, props = __rest(_a, ["allowPristineSubmit", "children", "disabled", "title", "className"]);
|
35
35
|
var _b = (0, formik_1.useFormikContext)(), isSubmitting = _b.isSubmitting, dirty = _b.dirty;
|
36
36
|
var preventSubmit = (!dirty && !allowPristineSubmit) || isSubmitting;
|
37
|
-
|
37
|
+
var buttonName = typeof children === 'string' ? children : 'Submit';
|
38
|
+
return ((0, jsx_runtime_1.jsx)("button", __assign({}, props, { ref: ref, type: "submit", disabled: preventSubmit || disabled, "aria-label": buttonName, title: title || isSubmitting
|
38
39
|
? 'Loading, please wait...'
|
39
40
|
: preventSubmit
|
40
41
|
? "You haven't made any changes"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import '@testing-library/jest-dom/extend-expect';
|
3
|
-
import {
|
3
|
+
import { FormBuilderProp } from '../../src';
|
4
4
|
interface FormTestBaseProps<TForm extends object> {
|
5
5
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
6
6
|
initialValues?: TForm;
|
@@ -13,8 +13,8 @@ interface PersonDto {
|
|
13
13
|
phoneNumber?: string;
|
14
14
|
yearlySalaryUSD?: number;
|
15
15
|
isCool?: boolean;
|
16
|
-
gradDate?:
|
17
|
-
favoriteDate?:
|
16
|
+
gradDate?: string;
|
17
|
+
favoriteDate?: string;
|
18
18
|
favoriteNumber?: number;
|
19
19
|
favoriteColor?: string;
|
20
20
|
favoriteColors?: string[];
|
package/lib/index.d.ts
CHANGED
@@ -10,10 +10,10 @@ export { default as DatePickerGroup } from './DatePicker/DatePickerGroup';
|
|
10
10
|
export type { DatePickerGroupProps as DatePickerGroupProps } from './DatePicker/DatePickerGroup';
|
11
11
|
export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGroup';
|
12
12
|
export type { DatePickerHelper } from './DatePicker/DatePickerHelper';
|
13
|
-
export { default as DateOnlyDatePickerGroup } from './DatePicker/DateOnlyDatePickerGroup';
|
14
|
-
export type { DateOnly, DateOnlyDatePickerGroupProps, } from './DatePicker/DateOnlyDatePickerGroup';
|
15
13
|
export { default as StringDatePickerGroup } from './DatePicker/StringDatePickerGroup';
|
16
14
|
export type { StringDatePickerGroupProps } from './DatePicker/StringDatePickerGroup';
|
15
|
+
export { default as StringDateOnlyPickerGroup } from './DatePicker/StringDateOnlyPickerGroup';
|
16
|
+
export type { StringDateOnlyPickerGroupProps } from './DatePicker/StringDateOnlyPickerGroup';
|
17
17
|
export { default as Field } from './Field/Field';
|
18
18
|
export type { FieldProps } from './Field/Field';
|
19
19
|
export type { RenderComponent } from './Field/Field';
|
package/lib/index.js
CHANGED
@@ -29,7 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
30
30
|
};
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
32
|
-
exports.validators = exports.serialize = exports.objectContainsNonSerializableProperty = exports.TextAreaGroup = exports.SingleStringSelectGroup = exports.MultiStringSelectGroup = exports.SingleNumberSelectGroup = exports.MultiNumberSelectGroup = exports.BooleanSelectGroup = exports.SelectGroup = exports.normalizers = exports.StringInputGroup = exports.NumberInputGroup = exports.MoneyInputGroup = exports.InputGroup = exports.IconInputGroup = exports.Group = exports.FormDefaults = exports.StandardFormActions = exports.FormActions = exports.ServerErrorContext = exports.Form = exports.FileGroup = exports.FieldArray = exports.useStandardField = exports.StandAloneInput = exports.FieldNameContext = exports.FieldErrorScrollTarget = exports.Field = exports.
|
32
|
+
exports.validators = exports.serialize = exports.objectContainsNonSerializableProperty = exports.TextAreaGroup = exports.SingleStringSelectGroup = exports.MultiStringSelectGroup = exports.SingleNumberSelectGroup = exports.MultiNumberSelectGroup = exports.BooleanSelectGroup = exports.SelectGroup = exports.normalizers = exports.StringInputGroup = exports.NumberInputGroup = exports.MoneyInputGroup = exports.InputGroup = exports.IconInputGroup = exports.Group = exports.FormDefaults = exports.StandardFormActions = exports.FormActions = exports.ServerErrorContext = exports.Form = exports.FileGroup = exports.FieldArray = exports.useStandardField = exports.StandAloneInput = exports.FieldNameContext = exports.FieldErrorScrollTarget = exports.Field = exports.StringDateOnlyPickerGroup = exports.StringDatePickerGroup = exports.convertToTimeZoneInsensitiveISOString = exports.DatePickerGroup = exports.ConfirmDeleteForm = exports.ConfirmBaseForm = exports.SubmitFormButton = exports.AddressInput = void 0;
|
33
33
|
// Address
|
34
34
|
var AddressInput_1 = require("./AddressInput/AddressInput");
|
35
35
|
Object.defineProperty(exports, "AddressInput", { enumerable: true, get: function () { return __importDefault(AddressInput_1).default; } });
|
@@ -47,10 +47,10 @@ var DatePickerGroup_1 = require("./DatePicker/DatePickerGroup");
|
|
47
47
|
Object.defineProperty(exports, "DatePickerGroup", { enumerable: true, get: function () { return __importDefault(DatePickerGroup_1).default; } });
|
48
48
|
var DatePickerGroup_2 = require("./DatePicker/DatePickerGroup");
|
49
49
|
Object.defineProperty(exports, "convertToTimeZoneInsensitiveISOString", { enumerable: true, get: function () { return DatePickerGroup_2.convertToTimeZoneInsensitiveISOString; } });
|
50
|
-
var DateOnlyDatePickerGroup_1 = require("./DatePicker/DateOnlyDatePickerGroup");
|
51
|
-
Object.defineProperty(exports, "DateOnlyDatePickerGroup", { enumerable: true, get: function () { return __importDefault(DateOnlyDatePickerGroup_1).default; } });
|
52
50
|
var StringDatePickerGroup_1 = require("./DatePicker/StringDatePickerGroup");
|
53
51
|
Object.defineProperty(exports, "StringDatePickerGroup", { enumerable: true, get: function () { return __importDefault(StringDatePickerGroup_1).default; } });
|
52
|
+
var StringDateOnlyPickerGroup_1 = require("./DatePicker/StringDateOnlyPickerGroup");
|
53
|
+
Object.defineProperty(exports, "StringDateOnlyPickerGroup", { enumerable: true, get: function () { return __importDefault(StringDateOnlyPickerGroup_1).default; } });
|
54
54
|
// Field
|
55
55
|
var Field_1 = require("./Field/Field");
|
56
56
|
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return __importDefault(Field_1).default; } });
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "envoc-form",
|
3
|
-
"version": "4.0.1-
|
3
|
+
"version": "4.0.1-8",
|
4
4
|
"description": "Envoc form components",
|
5
5
|
"keywords": [
|
6
6
|
"react-component",
|
@@ -37,7 +37,7 @@
|
|
37
37
|
"axios": "^0.21.1",
|
38
38
|
"classnames": "^2.3.1",
|
39
39
|
"date-fns": "^2.22.1",
|
40
|
-
"envoc-request": "^4.0.1-
|
40
|
+
"envoc-request": "^4.0.1-8",
|
41
41
|
"lru-cache": "^6.0.0",
|
42
42
|
"prop-types": "^15.7.2",
|
43
43
|
"react-date-picker": "^8.2.0",
|
@@ -72,6 +72,8 @@
|
|
72
72
|
"clean-webpack-plugin": "^3.0.0",
|
73
73
|
"cross-env": "7.0.3",
|
74
74
|
"css-loader": "^5.0.2",
|
75
|
+
"eslint": "^8.32.0",
|
76
|
+
"eslint-config-react-app": "^7.0.1",
|
75
77
|
"html-webpack-plugin": "^5.3.2",
|
76
78
|
"identity-obj-proxy": "^3.0.0",
|
77
79
|
"jest-junit": "~12.2.0",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { render } from '@testing-library/react';
|
3
|
-
import
|
3
|
+
import StringDatePickerGroup from './StringDatePickerGroup';
|
4
4
|
import FormTestBase from '../__Tests__/FormTestBase';
|
5
5
|
|
6
6
|
//hack so the datepicker internals don't complain about this not existing in the context of jest
|
@@ -13,7 +13,7 @@ describe('IconInputGroup', () => {
|
|
13
13
|
{({ Field }) => (
|
14
14
|
<Field
|
15
15
|
name="favoriteDate"
|
16
|
-
Component={
|
16
|
+
Component={StringDatePickerGroup}
|
17
17
|
label="Favorite Date"
|
18
18
|
monthPlaceholder="mm"
|
19
19
|
dayPlaceholder="dd"
|
@@ -32,7 +32,7 @@ describe('IconInputGroup', () => {
|
|
32
32
|
{({ Field }) => (
|
33
33
|
<Field
|
34
34
|
name="favoriteDate"
|
35
|
-
Component={
|
35
|
+
Component={StringDatePickerGroup}
|
36
36
|
label="Favorite Date"
|
37
37
|
monthPlaceholder="mm"
|
38
38
|
dayPlaceholder="dd"
|
@@ -1,12 +1,10 @@
|
|
1
|
-
import { useState } from 'react';
|
2
|
-
import DatePicker, {
|
3
|
-
DatePickerProps,
|
4
|
-
} from 'react-date-picker/dist/entry.nostyle';
|
1
|
+
import { useEffect, useState } from 'react';
|
2
|
+
import DatePicker, { DatePickerProps } from 'react-date-picker/dist/entry.nostyle';
|
5
3
|
import classnames from 'classnames';
|
6
4
|
import parseISO from 'date-fns/parseISO';
|
7
5
|
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
8
|
-
import Group, { GroupProps } from '../Group';
|
9
6
|
import { FormDefaults } from '../FormDefaults';
|
7
|
+
import Group, { GroupProps } from '../Group';
|
10
8
|
|
11
9
|
// Docs for react-date-picker https://www.npmjs.com/package/react-date-picker
|
12
10
|
|
@@ -32,6 +30,14 @@ export default function DatePickerGroup<T>({
|
|
32
30
|
}: DatePickerGroupProps<T>) {
|
33
31
|
const [displayDate, setDisplayDate] = useState<Date | null>(null);
|
34
32
|
|
33
|
+
useEffect(() => {
|
34
|
+
if (input.value != null) {
|
35
|
+
setDisplayDate(new Date(`${input.value}T00:00:00.000`));
|
36
|
+
} else {
|
37
|
+
setDisplayDate(null);
|
38
|
+
}
|
39
|
+
}, [setDisplayDate, input.value]);
|
40
|
+
|
35
41
|
return (
|
36
42
|
<Group
|
37
43
|
input={input}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { DatePickerHelper } from './DatePickerHelper';
|
2
|
+
import DatePickerGroup from './DatePickerGroup';
|
3
|
+
|
4
|
+
export interface StringDateOnlyPickerGroupProps
|
5
|
+
extends DatePickerHelper<string | undefined> {}
|
6
|
+
|
7
|
+
export default function StringDatePickerGroup(
|
8
|
+
props: StringDateOnlyPickerGroupProps
|
9
|
+
) {
|
10
|
+
return <DatePickerGroup {...props} convert={convertToDateOnly} />;
|
11
|
+
}
|
12
|
+
|
13
|
+
function convertToDateOnly(arg: Date) {
|
14
|
+
const year = new Intl.DateTimeFormat('en', { year: 'numeric' })
|
15
|
+
.format(arg)
|
16
|
+
.padStart(4, '0');
|
17
|
+
|
18
|
+
const month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(arg);
|
19
|
+
|
20
|
+
const day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(arg);
|
21
|
+
|
22
|
+
return `${year}-${month}-${day}`;
|
23
|
+
}
|
package/src/Form/Form.tsx
CHANGED
@@ -21,11 +21,11 @@ import {
|
|
21
21
|
} from './ServerErrorContext';
|
22
22
|
import Field, { FieldProps } from '../Field/Field';
|
23
23
|
import FieldArray, { FieldArrayProps } from '../FieldArray/FieldArray';
|
24
|
+
import { FormDefaults } from '../FormDefaults';
|
24
25
|
import objectContainsNonSerializableProperty from '../utils/objectContainsNonSerializableProperty';
|
25
26
|
import objectToFormData from '../utils/objectToFormData';
|
26
27
|
import { ValidatedApiResult } from '../Validation/ValidatedApiResult';
|
27
28
|
import { ValidationError } from '../Validation/ValidationError';
|
28
|
-
import { FormDefaults } from '../FormDefaults';
|
29
29
|
|
30
30
|
// This exposes the builder that ensures only "name" values on the given TForm can be used
|
31
31
|
// Further, each Field can then infer the proper type given the name
|
@@ -40,10 +40,14 @@ export type FormBuilderProp<TForm extends object> = {
|
|
40
40
|
) => JSX.Element;
|
41
41
|
};
|
42
42
|
|
43
|
-
export interface
|
43
|
+
export interface FullFormProps<TForm extends object> {
|
44
44
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
45
45
|
onSubmit: (
|
46
|
-
formValues:
|
46
|
+
formValues: TForm,
|
47
|
+
formikBag: FormikHelpers<TForm>
|
48
|
+
) => Promise<ValidatedApiResult>;
|
49
|
+
onFormDataSubmit: (
|
50
|
+
formValues: FormData,
|
47
51
|
formikBag: FormikHelpers<TForm>
|
48
52
|
) => Promise<ValidatedApiResult>;
|
49
53
|
className?: string;
|
@@ -52,12 +56,26 @@ export interface FormProps<TForm extends object> {
|
|
52
56
|
initialValues?: TForm;
|
53
57
|
}
|
54
58
|
|
59
|
+
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<
|
60
|
+
T,
|
61
|
+
Exclude<keyof T, Keys>
|
62
|
+
> &
|
63
|
+
{
|
64
|
+
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
|
65
|
+
}[Keys];
|
66
|
+
|
67
|
+
export type FormProps<TForm extends object> = RequireAtLeastOne<
|
68
|
+
FullFormProps<TForm>,
|
69
|
+
'onSubmit' | 'onFormDataSubmit'
|
70
|
+
>;
|
71
|
+
|
55
72
|
export default function Form<TForm extends object>({
|
56
73
|
children,
|
57
74
|
className,
|
58
75
|
style,
|
59
76
|
ignoreLostChanges,
|
60
77
|
onSubmit,
|
78
|
+
onFormDataSubmit,
|
61
79
|
initialValues,
|
62
80
|
...props
|
63
81
|
}: FormProps<TForm>) {
|
@@ -114,6 +132,7 @@ export default function Form<TForm extends object>({
|
|
114
132
|
|
115
133
|
function handleSubmit(values: TForm, formikBag: FormikHelpers<TForm>) {
|
116
134
|
let formData: FormData | undefined = undefined;
|
135
|
+
let submitFunc: () => Promise<ValidatedApiResult>;
|
117
136
|
if (objectContainsNonSerializableProperty(values)) {
|
118
137
|
formData = objectToFormData(values, {
|
119
138
|
indices: true,
|
@@ -121,9 +140,35 @@ export default function Form<TForm extends object>({
|
|
121
140
|
allowEmptyArrays: true,
|
122
141
|
noFileListBrackets: true,
|
123
142
|
});
|
143
|
+
if (onFormDataSubmit === undefined) {
|
144
|
+
throw new Error(
|
145
|
+
'No onFormDataSubmit supplied for non-serializable properties.'
|
146
|
+
);
|
147
|
+
}
|
148
|
+
submitFunc = () =>
|
149
|
+
onFormDataSubmit(formData ?? new FormData(), formikBag);
|
150
|
+
} else {
|
151
|
+
if (onSubmit === undefined) {
|
152
|
+
formData = objectToFormData(values, {
|
153
|
+
indices: true,
|
154
|
+
dotNotation: true,
|
155
|
+
allowEmptyArrays: true,
|
156
|
+
noFileListBrackets: true,
|
157
|
+
});
|
158
|
+
if (onFormDataSubmit === undefined) {
|
159
|
+
// This error should never occur, as this case is covered by RequireAtLeastOne type safety
|
160
|
+
throw new Error(
|
161
|
+
'No onFormDataSubmit supplied for non-serializable properties.'
|
162
|
+
);
|
163
|
+
}
|
164
|
+
submitFunc = () =>
|
165
|
+
onFormDataSubmit(formData ?? new FormData(), formikBag);
|
166
|
+
} else {
|
167
|
+
submitFunc = () => onSubmit(values, formikBag);
|
168
|
+
}
|
124
169
|
}
|
125
170
|
|
126
|
-
return
|
171
|
+
return submitFunc()
|
127
172
|
.then((response) => {
|
128
173
|
return response;
|
129
174
|
})
|
package/src/SubmitFormButton.tsx
CHANGED
@@ -21,12 +21,14 @@ function SubmitFormButton(
|
|
21
21
|
) {
|
22
22
|
const { isSubmitting, dirty } = useFormikContext();
|
23
23
|
const preventSubmit = (!dirty && !allowPristineSubmit) || isSubmitting;
|
24
|
+
const buttonName = typeof children === 'string' ? children : 'Submit';
|
24
25
|
return (
|
25
26
|
<button
|
26
27
|
{...props}
|
27
28
|
ref={ref}
|
28
29
|
type="submit"
|
29
30
|
disabled={preventSubmit || disabled}
|
31
|
+
aria-label={buttonName}
|
30
32
|
title={
|
31
33
|
title || isSubmitting
|
32
34
|
? 'Loading, please wait...'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import '@testing-library/jest-dom/extend-expect';
|
2
2
|
import { HashRouter } from 'react-router-dom';
|
3
3
|
import { ValidatedApiResult } from 'Validation/ValidatedApiResult';
|
4
|
-
import {
|
4
|
+
import { Form, FormBuilderProp } from '../../src';
|
5
5
|
|
6
6
|
interface FormTestBaseProps<TForm extends object> {
|
7
7
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
@@ -50,8 +50,8 @@ interface PersonDto {
|
|
50
50
|
phoneNumber?: string;
|
51
51
|
yearlySalaryUSD?: number;
|
52
52
|
isCool?: boolean;
|
53
|
-
gradDate?:
|
54
|
-
favoriteDate?:
|
53
|
+
gradDate?: string;
|
54
|
+
favoriteDate?: string;
|
55
55
|
favoriteNumber?: number;
|
56
56
|
favoriteColor?: string;
|
57
57
|
favoriteColors?: string[];
|
package/src/index.ts
CHANGED
@@ -21,15 +21,12 @@ export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGr
|
|
21
21
|
|
22
22
|
export type { DatePickerHelper } from './DatePicker/DatePickerHelper';
|
23
23
|
|
24
|
-
export { default as DateOnlyDatePickerGroup } from './DatePicker/DateOnlyDatePickerGroup';
|
25
|
-
export type {
|
26
|
-
DateOnly,
|
27
|
-
DateOnlyDatePickerGroupProps,
|
28
|
-
} from './DatePicker/DateOnlyDatePickerGroup';
|
29
|
-
|
30
24
|
export { default as StringDatePickerGroup } from './DatePicker/StringDatePickerGroup';
|
31
25
|
export type { StringDatePickerGroupProps } from './DatePicker/StringDatePickerGroup';
|
32
26
|
|
27
|
+
export { default as StringDateOnlyPickerGroup } from './DatePicker/StringDateOnlyPickerGroup';
|
28
|
+
export type { StringDateOnlyPickerGroupProps } from './DatePicker/StringDateOnlyPickerGroup';
|
29
|
+
|
33
30
|
// Field
|
34
31
|
export { default as Field } from './Field/Field';
|
35
32
|
export type { FieldProps } from './Field/Field';
|
@@ -1,10 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
import { DatePickerHelper } from './DatePickerHelper';
|
3
|
-
export interface DateOnly {
|
4
|
-
year?: number;
|
5
|
-
month?: number;
|
6
|
-
day?: number;
|
7
|
-
}
|
8
|
-
export interface DateOnlyDatePickerGroupProps extends DatePickerHelper<DateOnly | undefined> {
|
9
|
-
}
|
10
|
-
export default function DateOnlyDatePickerGroup(props: DateOnlyDatePickerGroupProps): JSX.Element;
|
@@ -1,10 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
import { DatePickerHelper } from './DatePickerHelper';
|
3
|
-
export interface DateOnly {
|
4
|
-
year?: number;
|
5
|
-
month?: number;
|
6
|
-
day?: number;
|
7
|
-
}
|
8
|
-
export interface DateOnlyDatePickerGroupProps extends DatePickerHelper<DateOnly | undefined> {
|
9
|
-
}
|
10
|
-
export default function DateOnlyDatePickerGroup(props: DateOnlyDatePickerGroupProps): JSX.Element;
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import DatePickerGroup from './DatePickerGroup';
|
2
|
-
import { DatePickerHelper } from './DatePickerHelper';
|
3
|
-
|
4
|
-
export interface DateOnly {
|
5
|
-
year?: number;
|
6
|
-
month?: number;
|
7
|
-
day?: number;
|
8
|
-
}
|
9
|
-
|
10
|
-
export interface DateOnlyDatePickerGroupProps
|
11
|
-
extends DatePickerHelper<DateOnly | undefined> {}
|
12
|
-
export default function DateOnlyDatePickerGroup(
|
13
|
-
props: DateOnlyDatePickerGroupProps
|
14
|
-
) {
|
15
|
-
return <DatePickerGroup {...props} convert={convertToDateOnly} />;
|
16
|
-
}
|
17
|
-
|
18
|
-
function convertToDateOnly(arg: Date) {
|
19
|
-
return {
|
20
|
-
year: arg.getFullYear(),
|
21
|
-
month: arg.getMonth() + 1,
|
22
|
-
day: arg.getDate(),
|
23
|
-
};
|
24
|
-
}
|