envoc-form 4.0.1-10 → 4.0.1-12
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 +5117 -12
- package/es/AddressInput/AddressInput.d.ts +15 -5
- package/es/AddressInput/AddressInput.js +10 -0
- package/es/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
- package/es/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
- package/es/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
- package/es/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
- package/es/DatePicker/DatePickerGroup.d.ts +6 -1
- package/es/DatePicker/DatePickerGroup.js +14 -4
- package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +6 -1
- package/es/DatePicker/StringDateOnlyPickerGroup.js +5 -0
- package/es/DatePicker/StringDatePickerGroup.d.ts +6 -1
- package/es/DatePicker/StringDatePickerGroup.js +5 -0
- package/es/Field/Field.d.ts +8 -2
- package/es/Field/FieldErrorScrollTarget.d.ts +1 -0
- package/es/Field/FieldErrorScrollTarget.js +1 -0
- package/es/Field/StandAloneInput.d.ts +4 -0
- package/es/Field/StandAloneInput.js +1 -0
- package/es/Field/useStandardField.d.ts +6 -0
- package/es/Field/useStandardField.js +8 -9
- package/es/FieldArray/FieldArray.d.ts +11 -2
- package/es/FieldArray/FieldArray.js +7 -2
- package/es/File/FileGroup.d.ts +3 -1
- package/es/File/FileGroup.js +2 -1
- package/es/File/FileList.d.ts +2 -2
- package/es/Form/FocusError.d.ts +2 -0
- package/es/Form/FocusError.js +1 -0
- package/es/Form/Form.d.ts +6 -0
- package/es/Form/Form.js +1 -0
- package/es/Form/FormBasedPreventNavigation.d.ts +3 -1
- package/es/Form/FormBasedPreventNavigation.js +12 -45
- package/es/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
- package/es/Form/LegacyFormBasedPreventNavigation.js +69 -0
- package/es/Form/NewFormBasedPreventNavigation.d.ts +14 -0
- package/es/Form/NewFormBasedPreventNavigation.js +39 -0
- package/es/Form/ServerErrorContext.d.ts +1 -0
- package/es/Form/ServerErrorContext.js +1 -0
- package/es/FormActions.d.ts +6 -0
- package/es/FormActions.js +1 -0
- package/es/FormDefaults.d.ts +1 -0
- package/es/FormDefaults.js +1 -0
- package/es/Group.d.ts +5 -3
- package/es/Group.js +2 -2
- package/es/Input/IconInputGroup.d.ts +4 -1
- package/es/Input/IconInputGroup.js +3 -1
- package/es/Input/InputGroup.d.ts +3 -3
- package/es/Input/InputGroup.js +3 -3
- package/es/Input/MoneyInputGroup.d.ts +3 -1
- package/es/Input/MoneyInputGroup.js +1 -0
- package/es/Input/NumberInputGroup.d.ts +3 -1
- package/es/Input/NumberInputGroup.js +1 -0
- package/es/Input/StringInputGroup.d.ts +2 -1
- package/es/Input/StringInputGroup.js +3 -1
- package/es/Normalization/normalizers.d.ts +4 -2
- package/es/Normalization/normalizers.js +2 -0
- package/es/Select/BooleanSelectGroup.d.ts +2 -1
- package/es/Select/BooleanSelectGroup.js +1 -0
- package/es/Select/NumberSelectGroup.d.ts +4 -2
- package/es/Select/NumberSelectGroup.js +2 -0
- package/es/Select/SelectGroup.d.ts +7 -1
- package/es/Select/SelectGroup.js +2 -1
- package/es/Select/StringSelectGroup.d.ts +2 -0
- package/es/Select/StringSelectGroup.js +2 -0
- package/es/StandardFormActions.d.ts +5 -0
- package/es/StandardFormActions.js +1 -0
- package/es/SubmitFormButton.d.ts +4 -1
- package/es/SubmitFormButton.js +1 -0
- package/es/TextArea/TextAreaGroup.d.ts +2 -1
- package/es/TextArea/TextAreaGroup.js +4 -3
- package/es/Validation/validators.d.ts +11 -8
- package/es/Validation/validators.js +6 -2
- package/es/index.d.ts +4 -4
- package/es/setupTests.d.ts +1 -0
- package/es/setupTests.js +1 -0
- package/lib/AddressInput/AddressInput.d.ts +15 -5
- package/lib/AddressInput/AddressInput.js +10 -0
- package/lib/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
- package/lib/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
- package/lib/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
- package/lib/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
- package/lib/DatePicker/DatePickerGroup.d.ts +6 -1
- package/lib/DatePicker/DatePickerGroup.js +14 -4
- package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +6 -1
- package/lib/DatePicker/StringDateOnlyPickerGroup.js +5 -0
- package/lib/DatePicker/StringDatePickerGroup.d.ts +6 -1
- package/lib/DatePicker/StringDatePickerGroup.js +5 -0
- package/lib/Field/Field.d.ts +8 -2
- package/lib/Field/FieldErrorScrollTarget.d.ts +1 -0
- package/lib/Field/FieldErrorScrollTarget.js +1 -0
- package/lib/Field/StandAloneInput.d.ts +4 -0
- package/lib/Field/StandAloneInput.js +1 -0
- package/lib/Field/useStandardField.d.ts +6 -0
- package/lib/Field/useStandardField.js +8 -9
- package/lib/FieldArray/FieldArray.d.ts +11 -2
- package/lib/FieldArray/FieldArray.js +7 -2
- package/lib/File/FileGroup.d.ts +3 -1
- package/lib/File/FileGroup.js +2 -1
- package/lib/File/FileList.d.ts +2 -2
- package/lib/Form/FocusError.d.ts +2 -0
- package/lib/Form/FocusError.js +1 -0
- package/lib/Form/Form.d.ts +6 -0
- package/lib/Form/Form.js +1 -0
- package/lib/Form/FormBasedPreventNavigation.d.ts +3 -1
- package/lib/Form/FormBasedPreventNavigation.js +13 -43
- package/lib/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
- package/lib/Form/LegacyFormBasedPreventNavigation.js +72 -0
- package/lib/Form/NewFormBasedPreventNavigation.d.ts +14 -0
- package/lib/Form/NewFormBasedPreventNavigation.js +42 -0
- package/lib/Form/ServerErrorContext.d.ts +1 -0
- package/lib/Form/ServerErrorContext.js +1 -0
- package/lib/FormActions.d.ts +6 -0
- package/lib/FormActions.js +1 -0
- package/lib/FormDefaults.d.ts +1 -0
- package/lib/FormDefaults.js +1 -0
- package/lib/Group.d.ts +5 -3
- package/lib/Group.js +2 -2
- package/lib/Input/IconInputGroup.d.ts +4 -1
- package/lib/Input/IconInputGroup.js +3 -1
- package/lib/Input/InputGroup.d.ts +3 -3
- package/lib/Input/InputGroup.js +3 -3
- package/lib/Input/MoneyInputGroup.d.ts +3 -1
- package/lib/Input/MoneyInputGroup.js +1 -0
- package/lib/Input/NumberInputGroup.d.ts +3 -1
- package/lib/Input/NumberInputGroup.js +1 -0
- package/lib/Input/StringInputGroup.d.ts +2 -1
- package/lib/Input/StringInputGroup.js +3 -1
- package/lib/Normalization/normalizers.d.ts +4 -2
- package/lib/Normalization/normalizers.js +2 -0
- package/lib/Select/BooleanSelectGroup.d.ts +2 -1
- package/lib/Select/BooleanSelectGroup.js +1 -0
- package/lib/Select/NumberSelectGroup.d.ts +4 -2
- package/lib/Select/NumberSelectGroup.js +2 -0
- package/lib/Select/SelectGroup.d.ts +7 -1
- package/lib/Select/SelectGroup.js +2 -1
- package/lib/Select/StringSelectGroup.d.ts +2 -0
- package/lib/Select/StringSelectGroup.js +2 -0
- package/lib/StandardFormActions.d.ts +5 -0
- package/lib/StandardFormActions.js +1 -0
- package/lib/SubmitFormButton.d.ts +4 -1
- package/lib/SubmitFormButton.js +1 -0
- package/lib/TextArea/TextAreaGroup.d.ts +2 -1
- package/lib/TextArea/TextAreaGroup.js +4 -3
- package/lib/Validation/validators.d.ts +11 -8
- package/lib/Validation/validators.js +6 -2
- package/lib/index.d.ts +4 -4
- package/lib/setupTests.d.ts +1 -0
- package/lib/setupTests.js +3 -0
- package/package.json +9 -6
- package/src/AddressInput/AddressInput.tsx +15 -5
- package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +4 -0
- package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +14 -0
- package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +13 -0
- package/src/DatePicker/DatePicker.test.tsx +1 -1
- package/src/DatePicker/DatePickerGroup.tsx +13 -6
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +7 -2
- package/src/DatePicker/StringDatePickerGroup.tsx +7 -1
- package/src/Field/Field.tsx +8 -3
- package/src/Field/FieldErrorScrollTarget.tsx +1 -0
- package/src/Field/StandAloneInput.tsx +4 -0
- package/src/Field/useStandardField.ts +13 -9
- package/src/FieldArray/FieldArray.tsx +14 -5
- package/src/File/FileGroup.tsx +4 -2
- package/src/File/FileList.tsx +2 -2
- package/src/Form/FocusError.tsx +3 -0
- package/src/Form/Form.tsx +6 -0
- package/src/Form/FormBasedPreventNavigation.tsx +28 -46
- package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -0
- package/src/Form/NewFormBasedPreventNavigation.tsx +59 -0
- package/src/Form/ServerErrorContext.ts +1 -0
- package/src/FormActions.tsx +7 -0
- package/src/FormDefaults.ts +1 -0
- package/src/Group.tsx +8 -4
- package/src/Input/IconInputGroup.tsx +5 -2
- package/src/Input/InputGroup.tsx +11 -5
- package/src/Input/MoneyInputGroup.tsx +3 -1
- package/src/Input/NumberInputGroup.tsx +3 -1
- package/src/Input/StringInputGroup.tsx +3 -2
- package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +1 -0
- package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +1 -0
- package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +1 -0
- package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +1 -0
- package/src/Normalization/normalizers.ts +4 -2
- package/src/Select/BooleanSelectGroup.tsx +2 -1
- package/src/Select/NumberSelectGroup.tsx +4 -2
- package/src/Select/SelectGroup.tsx +8 -2
- package/src/Select/StringSelectGroup.tsx +2 -0
- package/src/StandardFormActions.tsx +5 -0
- package/src/SubmitFormButton.tsx +5 -1
- package/src/TextArea/TextAreaGroup.tsx +4 -4
- package/src/Validation/validators.ts +19 -14
- package/src/__Tests__/FormTestBase.tsx +9 -8
- package/src/__Tests__/RealisticForm.test.tsx +82 -0
- package/src/index.ts +4 -4
- package/src/setupTests.ts +1 -0
- package/es/__Tests__/FormTestBase.d.ts +0 -27
- package/es/__Tests__/FormTestBase.js +0 -83
- package/es/__Tests__/index.d.ts +0 -2
- package/es/__Tests__/index.js +0 -2
- package/lib/__Tests__/FormTestBase.d.ts +0 -27
- package/lib/__Tests__/FormTestBase.js +0 -86
- package/lib/__Tests__/index.d.ts +0 -2
- package/lib/__Tests__/index.js +0 -8
@@ -7,7 +7,7 @@ export var required = function (value) {
|
|
7
7
|
? undefined
|
8
8
|
: 'Required';
|
9
9
|
};
|
10
|
-
|
10
|
+
/** Asserts that the value is a certain number of characters. numbers are coerced to a string */
|
11
11
|
export var length = function (len) { return function (value) {
|
12
12
|
var hasError = getLengthOfValue(value) !== len;
|
13
13
|
return !hasError ? undefined : "Length must be ".concat(len);
|
@@ -40,12 +40,13 @@ export var minValue = function (min) { return function (value) {
|
|
40
40
|
var hasError = !value || value < min;
|
41
41
|
return !hasError ? undefined : "Minimum value ".concat(min, " not met");
|
42
42
|
}; };
|
43
|
+
/** Validate for a ZIP Code. Accepts formats: ##### and #####-#### */
|
43
44
|
export var zipCode = function (value) {
|
44
45
|
return value && !/^[0-9]{5}(?:-[0-9]{4})?$/.test(value)
|
45
46
|
? 'Invalid ZIP Code'
|
46
47
|
: undefined;
|
47
48
|
};
|
48
|
-
|
49
|
+
/** One of the validators provided must be true. */
|
49
50
|
export var any = function (validatorList) {
|
50
51
|
return function (value) {
|
51
52
|
if (validatorList.length === 0 || !value) {
|
@@ -55,6 +56,9 @@ export var any = function (validatorList) {
|
|
55
56
|
};
|
56
57
|
};
|
57
58
|
function getLengthOfValue(value) {
|
59
|
+
if (value === null) {
|
60
|
+
return 0;
|
61
|
+
}
|
58
62
|
switch (typeof value) {
|
59
63
|
case 'undefined':
|
60
64
|
return 0;
|
package/es/index.d.ts
CHANGED
@@ -7,7 +7,7 @@ export type { ConfirmBaseFormProps } from './ConfirmBaseForm/ConfirmBaseForm';
|
|
7
7
|
export { default as ConfirmDeleteForm } from './ConfirmDeleteForm/ConfirmDeleteForm';
|
8
8
|
export type { ConfirmDeleteFormProps } from './ConfirmDeleteForm/ConfirmDeleteForm';
|
9
9
|
export { default as DatePickerGroup } from './DatePicker/DatePickerGroup';
|
10
|
-
export type { DatePickerGroupProps
|
10
|
+
export type { DatePickerGroupProps } from './DatePicker/DatePickerGroup';
|
11
11
|
export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGroup';
|
12
12
|
export type { DatePickerHelper } from './DatePicker/DatePickerHelper';
|
13
13
|
export { default as StringDatePickerGroup } from './DatePicker/StringDatePickerGroup';
|
@@ -34,12 +34,12 @@ export type { FormBuilderProp, FormProps } from './Form/Form';
|
|
34
34
|
export { ServerErrorContext } from './Form/ServerErrorContext';
|
35
35
|
export type { ServerErrorContextProps, ServerErrors, } from './Form/ServerErrorContext';
|
36
36
|
export { default as FormActions } from './FormActions';
|
37
|
-
export type { FormActionsProps
|
37
|
+
export type { FormActionsProps } from './FormActions';
|
38
38
|
export { default as StandardFormActions } from './StandardFormActions';
|
39
|
-
export type { StandardFormActionsProps
|
39
|
+
export type { StandardFormActionsProps } from './StandardFormActions';
|
40
40
|
export { FormDefaults } from './FormDefaults';
|
41
41
|
export { default as Group } from './Group';
|
42
|
-
export type { GroupProps
|
42
|
+
export type { GroupProps } from './Group';
|
43
43
|
export { default as IconInputGroup } from './Input/IconInputGroup';
|
44
44
|
export type { IconInputGroupProps } from './Input/IconInputGroup';
|
45
45
|
export { default as InputGroup } from './Input/InputGroup';
|
@@ -0,0 +1 @@
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
package/es/setupTests.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
@@ -5,11 +5,21 @@ export interface AddressInputProps {
|
|
5
5
|
name: string;
|
6
6
|
}
|
7
7
|
interface AddressDto {
|
8
|
-
address1?: string;
|
9
|
-
address2?: string;
|
10
|
-
zipCode?: string;
|
11
|
-
city?: string;
|
12
|
-
state?: string;
|
8
|
+
address1?: string | null;
|
9
|
+
address2?: string | null;
|
10
|
+
zipCode?: string | null;
|
11
|
+
city?: string | null;
|
12
|
+
state?: string | null;
|
13
13
|
}
|
14
|
+
/**
|
15
|
+
* Collection of `<Field/>`s for inputting an address. Includes:
|
16
|
+
* ```txt
|
17
|
+
* Address 1
|
18
|
+
* Address 2
|
19
|
+
* City
|
20
|
+
* State
|
21
|
+
* Zip
|
22
|
+
* ```
|
23
|
+
*/
|
14
24
|
export default function AddressInput({ fieldBuilder: { Field }, name, }: AddressInputProps): JSX.Element;
|
15
25
|
export {};
|
@@ -20,6 +20,16 @@ var __1 = require("../");
|
|
20
20
|
var FieldSection_1 = __importDefault(require("../Field/FieldSection"));
|
21
21
|
var normalizers_1 = require("../Normalization/normalizers");
|
22
22
|
var validators_1 = require("../Validation/validators");
|
23
|
+
/**
|
24
|
+
* Collection of `<Field/>`s for inputting an address. Includes:
|
25
|
+
* ```txt
|
26
|
+
* Address 1
|
27
|
+
* Address 2
|
28
|
+
* City
|
29
|
+
* State
|
30
|
+
* Zip
|
31
|
+
* ```
|
32
|
+
*/
|
23
33
|
function AddressInput(_a) {
|
24
34
|
var Field = _a.fieldBuilder.Field, name = _a.name;
|
25
35
|
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(FieldSection_1.default, __assign({ name: name }, { children: [(0, jsx_runtime_1.jsx)(Field, { name: "address1", placeholder: "Address, Line 1", label: "Address 1", Component: __1.StringInputGroup, validate: validators_1.required }), (0, jsx_runtime_1.jsx)(Field, { name: "address2", placeholder: "Address, Line 2", label: "Address 2", Component: __1.StringInputGroup }), (0, jsx_runtime_1.jsx)(Field, { name: "city", placeholder: "City", label: "City", Component: __1.StringInputGroup, validate: validators_1.required }), (0, jsx_runtime_1.jsx)(Field, { name: "state", placeholder: "State", label: "State", Component: __1.SingleStringSelectGroup, options: UsStates_1.default, validate: validators_1.required }), (0, jsx_runtime_1.jsx)(Field, { name: "zipCode", placeholder: "Zip", label: "Zip", Component: __1.StringInputGroup, normalize: normalizers_1.zipCode, validate: [validators_1.required, validators_1.zipCode] })] })) }));
|
@@ -1,12 +1,26 @@
|
|
1
1
|
import React, { MouseEventHandler } from 'react';
|
2
2
|
import { useAxiosRequestProps } from 'envoc-request';
|
3
3
|
export interface ConfirmBaseFormProps {
|
4
|
+
/** Function to run when cancel button is clicked. */
|
4
5
|
handleCancel?: MouseEventHandler<HTMLButtonElement>;
|
6
|
+
/** Axios request upon confirmation */
|
5
7
|
request: useAxiosRequestProps;
|
6
8
|
style?: React.CSSProperties;
|
9
|
+
/** `<h3/>` title text on top of the form. */
|
7
10
|
title?: string;
|
11
|
+
/** Custom confirm button text.
|
12
|
+
* @defaultValue `Confirm`
|
13
|
+
*/
|
8
14
|
confirmButtonText?: string;
|
15
|
+
/** CSS class for the buttons. */
|
9
16
|
confirmButtonClass?: string;
|
17
|
+
/** Any components to be rendered in between the title and the buttons. */
|
10
18
|
children?: React.ReactNode;
|
11
19
|
}
|
20
|
+
/**
|
21
|
+
* Confimation dialog. Navigates to a different route to allow the user to either confirm or cancel an action.
|
22
|
+
* Commonly used for confirming delete and archive.
|
23
|
+
*
|
24
|
+
* See `<ConfirmDeleteForm/>` if the confirmation is specifically for deletion.
|
25
|
+
*/
|
12
26
|
export default function ConfirmBaseForm({ handleCancel, request, style, title, confirmButtonText, confirmButtonClass, children, ...props }: ConfirmBaseFormProps): JSX.Element;
|
@@ -30,6 +30,12 @@ var classnames_1 = __importDefault(require("classnames"));
|
|
30
30
|
var envoc_request_1 = require("envoc-request");
|
31
31
|
var FormDefaults_1 = require("../FormDefaults");
|
32
32
|
// TODO: ask about how we should use 'children'
|
33
|
+
/**
|
34
|
+
* Confimation dialog. Navigates to a different route to allow the user to either confirm or cancel an action.
|
35
|
+
* Commonly used for confirming delete and archive.
|
36
|
+
*
|
37
|
+
* See `<ConfirmDeleteForm/>` if the confirmation is specifically for deletion.
|
38
|
+
*/
|
33
39
|
function ConfirmBaseForm(_a) {
|
34
40
|
var handleCancel = _a.handleCancel, request = _a.request, style = _a.style, title = _a.title, confirmButtonText = _a.confirmButtonText, confirmButtonClass = _a.confirmButtonClass, children = _a.children, props = __rest(_a, ["handleCancel", "request", "style", "title", "confirmButtonText", "confirmButtonClass", "children"]);
|
35
41
|
var webRequest = (0, envoc_request_1.useAxiosRequest)(Object.assign({}, request, { autoExecute: false }));
|
@@ -1,11 +1,24 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { ConfirmBaseFormProps } from '../ConfirmBaseForm/ConfirmBaseForm';
|
3
3
|
export interface ConfirmDeleteFormProps extends Pick<ConfirmBaseFormProps, 'style'> {
|
4
|
+
/** Url to navigate to on success. */
|
4
5
|
successUrl?: string;
|
6
|
+
/** Form name (key) to apply the confirmation on. */
|
5
7
|
form: string;
|
8
|
+
/** Custom message to display.
|
9
|
+
* @defaultValue `Are you sure you want to delete this?`
|
10
|
+
*/
|
6
11
|
title?: string;
|
12
|
+
/** Custom function when the axios request succeeds. */
|
7
13
|
handleComplete?: Function;
|
14
|
+
/** Custom function when the axios request fails. */
|
8
15
|
handleError?: Function;
|
16
|
+
/** Any components to be rendered in between the title and the buttons. */
|
9
17
|
children?: React.ReactNode;
|
10
18
|
}
|
19
|
+
/**
|
20
|
+
* Deletion confirmation. Navigates to a different route to allow the user to either confirm or cancel an action.
|
21
|
+
*
|
22
|
+
* Wraps `<ConfirmBaseForm/>`.
|
23
|
+
*/
|
11
24
|
export default function ConfirmDeleteForm({ successUrl, form, title, handleComplete, handleError, children, ...props }: ConfirmDeleteFormProps): JSX.Element;
|
@@ -30,6 +30,11 @@ var react_router_dom_1 = require("react-router-dom");
|
|
30
30
|
var react_toastify_1 = require("react-toastify");
|
31
31
|
var ConfirmBaseForm_1 = __importDefault(require("../ConfirmBaseForm/ConfirmBaseForm"));
|
32
32
|
var FormDefaults_1 = require("../FormDefaults");
|
33
|
+
/**
|
34
|
+
* Deletion confirmation. Navigates to a different route to allow the user to either confirm or cancel an action.
|
35
|
+
*
|
36
|
+
* Wraps `<ConfirmBaseForm/>`.
|
37
|
+
*/
|
33
38
|
function ConfirmDeleteForm(_a) {
|
34
39
|
var successUrl = _a.successUrl, form = _a.form, title = _a.title, handleComplete = _a.handleComplete, handleError = _a.handleError, children = _a.children, props = __rest(_a, ["successUrl", "form", "title", "handleComplete", "handleError", "children"]);
|
35
40
|
var navigate = (0, react_router_dom_1.useNavigate)();
|
@@ -2,8 +2,13 @@
|
|
2
2
|
import { DatePickerProps } from 'react-date-picker/dist/entry.nostyle';
|
3
3
|
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
4
4
|
import { GroupProps } from '../Group';
|
5
|
-
export interface DatePickerGroupProps<T> extends InjectedFieldProps<T | undefined>, Omit<DatePickerProps, keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'>, Omit<GroupProps, keyof InjectedFieldProps<T> | 'children'> {
|
5
|
+
export interface DatePickerGroupProps<T> extends InjectedFieldProps<T | undefined | null>, Omit<DatePickerProps, keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'>, Omit<GroupProps, keyof InjectedFieldProps<T> | 'children'> {
|
6
6
|
convert: (arg: Date) => T;
|
7
7
|
}
|
8
|
+
/**
|
9
|
+
* Field for inputting dates. Uses `<Group/>` and `<DatePicker/>`.
|
10
|
+
*
|
11
|
+
* Uses [react-date-picker](https://www.npmjs.com/package/react-date-picker)
|
12
|
+
*/
|
8
13
|
export default function DatePickerGroup<T>({ input, meta, label, helpText, className, required, disabled, convert, ...rest }: DatePickerGroupProps<T>): JSX.Element;
|
9
14
|
export declare function convertToTimeZoneInsensitiveISOString(date: Date): string;
|
@@ -33,16 +33,26 @@ var classnames_1 = __importDefault(require("classnames"));
|
|
33
33
|
var parseISO_1 = __importDefault(require("date-fns/parseISO"));
|
34
34
|
var FormDefaults_1 = require("../FormDefaults");
|
35
35
|
var Group_1 = __importDefault(require("../Group"));
|
36
|
+
/**
|
37
|
+
* Field for inputting dates. Uses `<Group/>` and `<DatePicker/>`.
|
38
|
+
*
|
39
|
+
* Uses [react-date-picker](https://www.npmjs.com/package/react-date-picker)
|
40
|
+
*/
|
36
41
|
function DatePickerGroup(_a) {
|
37
42
|
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, convert = _a.convert, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "convert"]);
|
38
43
|
var _b = (0, react_1.useState)(null), displayDate = _b[0], setDisplayDate = _b[1];
|
39
44
|
(0, react_1.useEffect)(function () {
|
40
|
-
if (input.value
|
41
|
-
setDisplayDate(new Date("".concat(input.value, "T00:00:00.000")));
|
42
|
-
}
|
43
|
-
else {
|
45
|
+
if (!input.value) {
|
44
46
|
setDisplayDate(null);
|
45
47
|
}
|
48
|
+
else if (typeof input.value === 'string') {
|
49
|
+
if (input.value.indexOf('T') === -1) {
|
50
|
+
setDisplayDate(new Date("".concat(input.value, "T00:00:00.000")));
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
setDisplayDate(new Date(input.value));
|
54
|
+
}
|
55
|
+
}
|
46
56
|
}, [setDisplayDate, input.value]);
|
47
57
|
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'), required: required, 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 })) })));
|
48
58
|
function handleChange(e) {
|
@@ -1,5 +1,10 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { DatePickerHelper } from './DatePickerHelper';
|
3
|
-
export interface StringDateOnlyPickerGroupProps extends DatePickerHelper<string | undefined> {
|
3
|
+
export interface StringDateOnlyPickerGroupProps extends DatePickerHelper<string | undefined | null> {
|
4
4
|
}
|
5
|
+
/**
|
6
|
+
* Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DD`.
|
7
|
+
*
|
8
|
+
* Default display to the user is in `MM/DD/YYYY` format.
|
9
|
+
*/
|
5
10
|
export default function StringDatePickerGroup(props: StringDateOnlyPickerGroupProps): JSX.Element;
|
@@ -16,6 +16,11 @@ 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
|
+
/**
|
20
|
+
* Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DD`.
|
21
|
+
*
|
22
|
+
* Default display to the user is in `MM/DD/YYYY` format.
|
23
|
+
*/
|
19
24
|
function StringDatePickerGroup(props) {
|
20
25
|
return (0, jsx_runtime_1.jsx)(DatePickerGroup_1.default, __assign({}, props, { convert: convertToDateOnly }));
|
21
26
|
}
|
@@ -1,5 +1,10 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { DatePickerHelper } from './DatePickerHelper';
|
3
|
-
export interface StringDatePickerGroupProps extends DatePickerHelper<string | undefined> {
|
3
|
+
export interface StringDatePickerGroupProps extends DatePickerHelper<string | undefined | null> {
|
4
4
|
}
|
5
|
+
/**
|
6
|
+
* Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DDTHH:mm:ss.sssZ` or `±YYYYYY-MM-DDTHH:mm:ss.sssZ`
|
7
|
+
*
|
8
|
+
* If you need `YYYY-MM-DD` format use `<StringDateOnlyPickerGroup/>`.
|
9
|
+
*/
|
5
10
|
export default function StringDatePickerGroup(props: StringDatePickerGroupProps): JSX.Element;
|
@@ -16,6 +16,11 @@ 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
|
+
/**
|
20
|
+
* Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DDTHH:mm:ss.sssZ` or `±YYYYYY-MM-DDTHH:mm:ss.sssZ`
|
21
|
+
*
|
22
|
+
* If you need `YYYY-MM-DD` format use `<StringDateOnlyPickerGroup/>`.
|
23
|
+
*/
|
19
24
|
function StringDatePickerGroup(props) {
|
20
25
|
return (0, jsx_runtime_1.jsx)(DatePickerGroup_1.default, __assign({}, props, { convert: convertToDateOnly }));
|
21
26
|
}
|
package/lib/Field/Field.d.ts
CHANGED
@@ -2,15 +2,21 @@ import { ComponentProps, ElementType, LegacyRef } from 'react';
|
|
2
2
|
import { InjectedFieldProps } from './InjectedFieldProps';
|
3
3
|
import { NormalizationFunction } from '../Normalization/NormalizationFunction';
|
4
4
|
import { ValidationFunction } from '../Validation/ValidationFunction';
|
5
|
-
export declare type RenderComponent<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined>> ? TRenderComponent : never;
|
6
|
-
export declare type RenderComponentProps<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined>> ? ComponentProps<TRenderComponent> : never;
|
5
|
+
export declare type RenderComponent<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined | null>> ? TRenderComponent : never;
|
6
|
+
export declare type RenderComponentProps<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined | null>> ? ComponentProps<TRenderComponent> : never;
|
7
7
|
/** A specific Field instance to be rendered by the given TRenderComponent or by whatever default is reasonable */
|
8
8
|
export declare type FieldProps<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType> = {
|
9
|
+
/** Name of the field. Used on submission. */
|
9
10
|
name: TProp;
|
11
|
+
/** Component to be rendered. Usually this is a type of input group e.g. `<StringInputGroup/>` */
|
10
12
|
Component: RenderComponent<TForm[TProp], TRenderComponent>;
|
13
|
+
/** Id of the field. */
|
11
14
|
id?: string;
|
15
|
+
/** Whether the field should be disabled. */
|
12
16
|
disabled?: boolean;
|
17
|
+
/** Client side validation functions */
|
13
18
|
validate?: ValidationFunction<TForm[TProp]> | ValidationFunction<TForm[TProp]>[];
|
19
|
+
/** Function to modify the field value without making the form dirty. (e.g. phone number) */
|
14
20
|
normalize?: NormalizationFunction<TForm[TProp]>;
|
15
21
|
} & Omit<RenderComponentProps<TForm[TProp], TRenderComponent>, keyof InjectedFieldProps<TForm[TProp]>>;
|
16
22
|
/**
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
4
4
|
var react_1 = require("react");
|
5
5
|
var FieldNameContext_1 = require("./FieldNameContext");
|
6
|
+
/** Hidden `<div/>` that acts as an anchor to scroll to when a form error occurs. */
|
6
7
|
function FieldErrorScrollTarget() {
|
7
8
|
var name = (0, react_1.useContext)(FieldNameContext_1.FieldNameContext);
|
8
9
|
if (!name) {
|
@@ -2,8 +2,12 @@ import { ElementType } from 'react';
|
|
2
2
|
import { RenderComponent, RenderComponentProps } from './Field';
|
3
3
|
import { InjectedFieldProps } from './InjectedFieldProps';
|
4
4
|
export declare type StandAloneInputProps<TValue, TRenderComponent extends ElementType> = {
|
5
|
+
/** Component to render inside of the field. */
|
5
6
|
Component: RenderComponent<TValue, TRenderComponent>;
|
7
|
+
/** Value of the field. */
|
6
8
|
value: TValue;
|
9
|
+
/** Function to change the value of the field. */
|
7
10
|
onChange: (arg: TValue) => void;
|
8
11
|
} & Omit<RenderComponentProps<TValue, TRenderComponent>, keyof InjectedFieldProps<TValue> | 'value' | 'onChange' | 'normalize' | 'validate'>;
|
12
|
+
/** The stand alone version of `<Field/>`. Can use a type of input component outside of a `<Form/>`. */
|
9
13
|
export default function StandAloneInput<TValue, TComponent extends ElementType>(props: StandAloneInputProps<TValue, TComponent>): JSX.Element;
|
@@ -48,6 +48,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
48
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
49
49
|
var react_1 = require("react");
|
50
50
|
var uuid = __importStar(require("uuid"));
|
51
|
+
/** The stand alone version of `<Field/>`. Can use a type of input component outside of a `<Form/>`. */
|
51
52
|
function StandAloneInput(props) {
|
52
53
|
var Component = props.Component, value = props.value, onChange = props.onChange, disabled = props.disabled, rest = __rest(props, ["Component", "value", "onChange", "disabled"]);
|
53
54
|
var handleChange = function (arg) {
|
@@ -3,12 +3,18 @@ import { CustomFieldMetaProps } from './CustomFieldMetaProps';
|
|
3
3
|
import { NormalizationFunction } from '../Normalization/NormalizationFunction';
|
4
4
|
import { ValidationFunction } from '../Validation/ValidationFunction';
|
5
5
|
export interface useStandardFieldProps<TValue> {
|
6
|
+
/** Id of the field. */
|
6
7
|
id?: string;
|
8
|
+
/** Name of the field. */
|
7
9
|
name: string;
|
10
|
+
/** Whether the field should be disabled. */
|
8
11
|
disabled?: boolean;
|
12
|
+
/** Function to validate the field. */
|
9
13
|
validate?: ValidationFunction<TValue> | ValidationFunction<TValue>[];
|
14
|
+
/** Function to modify the field value without making the form dirty. (e.g. phone number) */
|
10
15
|
normalize?: NormalizationFunction<TValue>;
|
11
16
|
}
|
17
|
+
/** Provides a consistent way to deal with all form fields (non array). */
|
12
18
|
export default function useStandardField<TValue>({ id: providedId, name: providedName, disabled, validate, normalize, }: useStandardFieldProps<TValue>): [
|
13
19
|
CustomFieldInputProps<TValue>,
|
14
20
|
CustomFieldMetaProps<TValue>
|
@@ -15,7 +15,7 @@ var react_1 = require("react");
|
|
15
15
|
var formik_1 = require("formik");
|
16
16
|
var FieldNameContext_1 = require("./FieldNameContext");
|
17
17
|
var ServerErrorContext_1 = require("../Form/ServerErrorContext");
|
18
|
-
|
18
|
+
/** Provides a consistent way to deal with all form fields (non array). */
|
19
19
|
function useStandardField(_a) {
|
20
20
|
var providedId = _a.id, providedName = _a.name, disabled = _a.disabled, validate = _a.validate, normalize = _a.normalize;
|
21
21
|
// because the formik errors are evaluated all at the same time we need to keep server errors separate
|
@@ -39,20 +39,19 @@ function useStandardField(_a) {
|
|
39
39
|
disabled: disabled,
|
40
40
|
validate: callAllValidators,
|
41
41
|
}), formikInput = _c[0], formikMeta = _c[1];
|
42
|
-
var _d = (0, formik_1.useFormikContext)(), setFieldValue = _d.setFieldValue, isSubmitting = _d.isSubmitting;
|
42
|
+
var _d = (0, formik_1.useFormikContext)(), setFieldTouched = _d.setFieldTouched, setFieldValue = _d.setFieldValue, isSubmitting = _d.isSubmitting;
|
43
43
|
var touched = formikMeta.touched !== false && formikMeta.touched !== undefined;
|
44
44
|
(0, react_1.useEffect)(function () {
|
45
45
|
if (!touched && isSubmitting) {
|
46
46
|
// because we do not always register all fields up front.
|
47
47
|
// e.g. formik expects even a 'create' form to have all fields given, at least, blank values
|
48
|
-
//
|
49
|
-
//
|
50
|
-
//
|
51
|
-
//
|
52
|
-
|
53
|
-
handleBlur();
|
48
|
+
// It looks like this was going to be a thing: https://github.com/jaredpalmer/formik/issues/691
|
49
|
+
// Formik appears to not have an active maintainer: https://github.com/jaredpalmer/formik/discussions/3526
|
50
|
+
// We previously had a different fix in place using handleBlur, but it was causing an infinite update cycle.
|
51
|
+
// This was noted as existing, but there was a note about it not working for FieldArray (this does appear to work in my testing with FieldArray)
|
52
|
+
setFieldTouched(name);
|
54
53
|
}
|
55
|
-
});
|
54
|
+
}, [isSubmitting, name, setFieldTouched, touched]);
|
56
55
|
// these are the props we expect consumers of this hook to pass directly to the input (or other control)
|
57
56
|
var resultInput = {
|
58
57
|
name: formikInput.name,
|
@@ -1,15 +1,24 @@
|
|
1
1
|
import { ElementType } from 'react';
|
2
2
|
import { FieldProps } from '../Field/Field';
|
3
3
|
import { ValidationFunction } from '../Validation/ValidationFunction';
|
4
|
-
export declare type FieldArrayProps<TForm extends object, TProp extends keyof TForm> = TForm[TProp] extends Array<any> | undefined ? {
|
4
|
+
export declare type FieldArrayProps<TForm extends object, TProp extends keyof TForm> = TForm[TProp] extends Array<any> | undefined | null ? {
|
5
|
+
/** Name of the field, used on submission. If using codegen this must be the provided dto. */
|
5
6
|
name: TProp;
|
7
|
+
/** Label of the field. */
|
6
8
|
label?: string;
|
9
|
+
/** Whether the field should be disabled. */
|
7
10
|
disabled?: boolean;
|
11
|
+
/** Function to validate the value. */
|
8
12
|
validate?: ValidationFunction<TForm[TProp]> | ValidationFunction<TForm[TProp]>[];
|
9
13
|
children: (formBuilder: ArrayFormBuilderProp<TForm[TProp]>) => JSX.Element;
|
10
14
|
} : never;
|
11
|
-
export declare type ArrayFormBuilderProp<TValue extends Array<any> | undefined> = TValue extends Array<infer TForm> | undefined ? TForm extends object ? {
|
15
|
+
export declare type ArrayFormBuilderProp<TValue extends Array<any> | undefined | null> = TValue extends Array<infer TForm> | undefined | null ? TForm extends object ? {
|
12
16
|
Field: <TProp extends keyof TForm, TRenderComponent extends ElementType>(props: FieldProps<TForm, TProp, TRenderComponent>) => JSX.Element;
|
13
17
|
FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
|
14
18
|
} : never : never;
|
19
|
+
/**
|
20
|
+
* An array of fields that allows the user to add multiple instances of the same field.
|
21
|
+
*
|
22
|
+
* Includes "Add Item" and "Remove Item" buttons to allow the user to speicify the number of fields.
|
23
|
+
*/
|
15
24
|
export default function FieldArray<TForm extends object, TProp extends keyof TForm>({ name, label, validate, disabled, children, ...rest }: FieldArrayProps<TForm, TProp>): JSX.Element;
|
@@ -40,14 +40,19 @@ var Field_1 = __importDefault(require("../Field/Field"));
|
|
40
40
|
var FieldNameContext_1 = require("../Field/FieldNameContext");
|
41
41
|
var useStandardField_1 = __importDefault(require("../Field/useStandardField"));
|
42
42
|
var FormDefaults_1 = require("../FormDefaults");
|
43
|
+
/**
|
44
|
+
* An array of fields that allows the user to add multiple instances of the same field.
|
45
|
+
*
|
46
|
+
* Includes "Add Item" and "Remove Item" buttons to allow the user to speicify the number of fields.
|
47
|
+
*/
|
43
48
|
function FieldArray(_a) {
|
44
49
|
var _b;
|
45
50
|
var name = _a.name, label = _a.label, validate = _a.validate, disabled = _a.disabled, children = _a.children, rest = __rest(_a, ["name", "label", "validate", "disabled", "children"]);
|
46
|
-
var
|
51
|
+
var input = (0, useStandardField_1.default)({
|
47
52
|
name: String(name),
|
48
53
|
validate: validate,
|
49
54
|
disabled: disabled,
|
50
|
-
})
|
55
|
+
})[0];
|
51
56
|
var values = !input.value
|
52
57
|
? []
|
53
58
|
: Array.isArray(input.value)
|
package/lib/File/FileGroup.d.ts
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
3
3
|
import { GroupProps } from '../Group';
|
4
|
-
export interface FileGroupProps extends InjectedFieldProps<any | undefined>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'>, Omit<React.HTMLProps<HTMLInputElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'> {
|
4
|
+
export interface FileGroupProps extends InjectedFieldProps<any | undefined | null>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'>, Omit<React.HTMLProps<HTMLInputElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'> {
|
5
|
+
/** Allow multiple files to be uploaded. */
|
5
6
|
multiple?: boolean | undefined;
|
6
7
|
}
|
8
|
+
/** File upload input group. */
|
7
9
|
declare const FileGroupWithRef: React.ComponentType<FileGroupProps>;
|
8
10
|
export default FileGroupWithRef;
|
package/lib/File/FileGroup.js
CHANGED
@@ -29,8 +29,8 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
29
29
|
var react_1 = __importDefault(require("react"));
|
30
30
|
var classnames_1 = __importDefault(require("classnames"));
|
31
31
|
var FileList_1 = __importDefault(require("./FileList"));
|
32
|
-
var Group_1 = __importDefault(require("../Group"));
|
33
32
|
var FormDefaults_1 = require("../FormDefaults");
|
33
|
+
var Group_1 = __importDefault(require("../Group"));
|
34
34
|
function FileGroup(_a, ref) {
|
35
35
|
var _b;
|
36
36
|
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, multiple = _a.multiple, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "multiple"]);
|
@@ -53,5 +53,6 @@ function FileGroup(_a, ref) {
|
|
53
53
|
}
|
54
54
|
}, value: undefined, ref: ref, type: "file", className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'file-group') })), (0, jsx_runtime_1.jsx)(FileList_1.default, { files: input.value })] })));
|
55
55
|
}
|
56
|
+
/** File upload input group. */
|
56
57
|
var FileGroupWithRef = react_1.default.forwardRef(FileGroup);
|
57
58
|
exports.default = FileGroupWithRef;
|
package/lib/File/FileList.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
export interface FileListProps {
|
3
|
-
files?: File | File[] | undefined;
|
4
|
-
rejectedFiles?: File | File[] | undefined;
|
3
|
+
files?: File | File[] | undefined | null;
|
4
|
+
rejectedFiles?: File | File[] | undefined | null;
|
5
5
|
}
|
6
6
|
export default function FileList({ files, rejectedFiles }: FileListProps): JSX.Element;
|
package/lib/Form/FocusError.d.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import { ServerErrorContextProps } from './ServerErrorContext';
|
2
2
|
export interface FocusErrorProps {
|
3
|
+
/** Validation errors that have been received from the server. */
|
3
4
|
serverErrors: ServerErrorContextProps;
|
4
5
|
}
|
6
|
+
/** Function to scroll to the field that has an error. */
|
5
7
|
export default function FocusError(props: FocusErrorProps): null;
|
package/lib/Form/FocusError.js
CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var react_1 = require("react");
|
7
7
|
var formik_1 = require("formik");
|
8
8
|
var smoothscroll_polyfill_1 = __importDefault(require("smoothscroll-polyfill"));
|
9
|
+
/** Function to scroll to the field that has an error. */
|
9
10
|
function FocusError(props) {
|
10
11
|
var _a = (0, formik_1.useFormikContext)(), errors = _a.errors, isSubmitting = _a.isSubmitting, isValidating = _a.isValidating;
|
11
12
|
smoothscroll_polyfill_1.default.polyfill();
|
package/lib/Form/Form.d.ts
CHANGED
@@ -8,18 +8,24 @@ export declare type FormBuilderProp<TForm extends object> = {
|
|
8
8
|
FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
|
9
9
|
};
|
10
10
|
export interface FullFormProps<TForm extends object> {
|
11
|
+
/** The `<Field/>` and `<FieldArray/>` components. */
|
11
12
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
13
|
+
/** Submission handler */
|
12
14
|
onSubmit: (formValues: TForm, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
|
15
|
+
/** Submission handler for forms that use [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData).*/
|
13
16
|
onFormDataSubmit: (formValues: FormData, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
|
14
17
|
className?: string;
|
15
18
|
style?: CSSProperties;
|
19
|
+
/** Prevent the user from leaving the form if they have edited any field. This is presented as a JS `alert()`. */
|
16
20
|
ignoreLostChanges?: boolean;
|
21
|
+
/** The intitial values of the form. */
|
17
22
|
initialValues?: TForm;
|
18
23
|
}
|
19
24
|
declare type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
|
20
25
|
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
|
21
26
|
}[Keys];
|
22
27
|
export declare type FormProps<TForm extends object> = RequireAtLeastOne<FullFormProps<TForm>, 'onSubmit' | 'onFormDataSubmit'>;
|
28
|
+
/** Define a form. Uses [formik](https://formik.org/docs/overview). Usually contains many `<Field/>` components. */
|
23
29
|
declare function Form<TForm extends object>({ children, className, style, ignoreLostChanges, onSubmit, onFormDataSubmit, initialValues, ...props }: FormProps<TForm>): JSX.Element;
|
24
30
|
declare namespace Form {
|
25
31
|
var DisplayFormState: () => JSX.Element;
|
package/lib/Form/Form.js
CHANGED
@@ -37,6 +37,7 @@ var FieldArray_1 = __importDefault(require("../FieldArray/FieldArray"));
|
|
37
37
|
var FormDefaults_1 = require("../FormDefaults");
|
38
38
|
var objectContainsNonSerializableProperty_1 = __importDefault(require("../utils/objectContainsNonSerializableProperty"));
|
39
39
|
var objectToFormData_1 = __importDefault(require("../utils/objectToFormData"));
|
40
|
+
/** Define a form. Uses [formik](https://formik.org/docs/overview). Usually contains many `<Field/>` components. */
|
40
41
|
function Form(_a) {
|
41
42
|
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
43
|
// formik resets all error on each blur (with our settings)
|
@@ -1,5 +1,7 @@
|
|
1
|
+
/// <reference types="react" />
|
1
2
|
export interface FormBasedPreventNavigationProps {
|
2
3
|
ignoreLostChanges?: boolean;
|
3
4
|
promptMessage?: string;
|
4
5
|
}
|
5
|
-
|
6
|
+
/** Prevent the user from navigating away from a form if there are any changes. */
|
7
|
+
export default function FormBasedPreventNavigation({ ignoreLostChanges, promptMessage, }: FormBasedPreventNavigationProps): JSX.Element;
|