envoc-form 4.0.1-11 → 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 +10 -0
- 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 +5 -0
- package/es/DatePicker/DatePickerGroup.js +5 -0
- package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
- package/es/DatePicker/StringDateOnlyPickerGroup.js +5 -0
- package/es/DatePicker/StringDatePickerGroup.d.ts +5 -0
- package/es/DatePicker/StringDatePickerGroup.js +5 -0
- package/es/Field/Field.d.ts +6 -0
- 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 +9 -0
- package/es/FieldArray/FieldArray.js +5 -0
- package/es/File/FileGroup.d.ts +2 -0
- package/es/File/FileGroup.js +1 -0
- 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 -62
- 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 +3 -0
- package/es/Input/IconInputGroup.js +1 -0
- package/es/Input/InputGroup.d.ts +1 -1
- package/es/Input/InputGroup.js +2 -2
- package/es/Input/MoneyInputGroup.d.ts +2 -0
- package/es/Input/MoneyInputGroup.js +1 -0
- package/es/Input/NumberInputGroup.d.ts +2 -0
- package/es/Input/NumberInputGroup.js +1 -0
- package/es/Input/StringInputGroup.d.ts +1 -0
- package/es/Input/StringInputGroup.js +1 -0
- package/es/Normalization/normalizers.d.ts +2 -0
- package/es/Normalization/normalizers.js +2 -0
- package/es/Select/BooleanSelectGroup.d.ts +1 -0
- package/es/Select/BooleanSelectGroup.js +1 -0
- package/es/Select/NumberSelectGroup.d.ts +2 -0
- package/es/Select/NumberSelectGroup.js +2 -0
- package/es/Select/SelectGroup.d.ts +6 -0
- package/es/Select/SelectGroup.js +1 -0
- 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 +3 -0
- package/es/SubmitFormButton.js +1 -0
- package/es/TextArea/TextAreaGroup.d.ts +1 -0
- package/es/TextArea/TextAreaGroup.js +1 -1
- package/es/Validation/validators.d.ts +3 -0
- package/es/Validation/validators.js +3 -2
- package/es/setupTests.d.ts +1 -0
- package/es/setupTests.js +1 -0
- package/lib/AddressInput/AddressInput.d.ts +10 -0
- 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 +5 -0
- package/lib/DatePicker/DatePickerGroup.js +5 -0
- package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
- package/lib/DatePicker/StringDateOnlyPickerGroup.js +5 -0
- package/lib/DatePicker/StringDatePickerGroup.d.ts +5 -0
- package/lib/DatePicker/StringDatePickerGroup.js +5 -0
- package/lib/Field/Field.d.ts +6 -0
- 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 +9 -0
- package/lib/FieldArray/FieldArray.js +5 -0
- package/lib/File/FileGroup.d.ts +2 -0
- package/lib/File/FileGroup.js +1 -0
- 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 -60
- 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 +3 -0
- package/lib/Input/IconInputGroup.js +1 -0
- package/lib/Input/InputGroup.d.ts +1 -1
- package/lib/Input/InputGroup.js +2 -2
- package/lib/Input/MoneyInputGroup.d.ts +2 -0
- package/lib/Input/MoneyInputGroup.js +1 -0
- package/lib/Input/NumberInputGroup.d.ts +2 -0
- package/lib/Input/NumberInputGroup.js +1 -0
- package/lib/Input/StringInputGroup.d.ts +1 -0
- package/lib/Input/StringInputGroup.js +1 -0
- package/lib/Normalization/normalizers.d.ts +2 -0
- package/lib/Normalization/normalizers.js +2 -0
- package/lib/Select/BooleanSelectGroup.d.ts +1 -0
- package/lib/Select/BooleanSelectGroup.js +1 -0
- package/lib/Select/NumberSelectGroup.d.ts +2 -0
- package/lib/Select/NumberSelectGroup.js +2 -0
- package/lib/Select/SelectGroup.d.ts +6 -0
- package/lib/Select/SelectGroup.js +1 -0
- 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 +3 -0
- package/lib/SubmitFormButton.js +1 -0
- package/lib/TextArea/TextAreaGroup.d.ts +1 -0
- package/lib/TextArea/TextAreaGroup.js +1 -1
- package/lib/Validation/validators.d.ts +3 -0
- package/lib/Validation/validators.js +3 -2
- package/lib/setupTests.d.ts +1 -0
- package/lib/setupTests.js +3 -0
- package/package.json +9 -6
- package/src/AddressInput/AddressInput.tsx +10 -0
- 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 +5 -2
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +5 -0
- package/src/DatePicker/StringDatePickerGroup.tsx +6 -0
- package/src/Field/Field.tsx +6 -1
- 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 +9 -0
- package/src/File/FileGroup.tsx +2 -0
- package/src/Form/FocusError.tsx +3 -0
- package/src/Form/Form.tsx +6 -0
- package/src/Form/FormBasedPreventNavigation.tsx +26 -60
- 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 +3 -0
- package/src/Input/InputGroup.tsx +3 -1
- package/src/Input/MoneyInputGroup.tsx +2 -0
- package/src/Input/NumberInputGroup.tsx +2 -0
- package/src/Input/StringInputGroup.tsx +1 -0
- 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 +2 -0
- package/src/Select/BooleanSelectGroup.tsx +1 -0
- package/src/Select/NumberSelectGroup.tsx +2 -0
- package/src/Select/SelectGroup.tsx +6 -0
- package/src/Select/StringSelectGroup.tsx +2 -0
- package/src/StandardFormActions.tsx +5 -0
- package/src/SubmitFormButton.tsx +3 -0
- package/src/TextArea/TextAreaGroup.tsx +1 -1
- package/src/Validation/validators.ts +3 -2
- package/src/__Tests__/FormTestBase.tsx +7 -6
- package/src/__Tests__/RealisticForm.test.tsx +82 -0
- 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
@@ -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
|
}
|
@@ -2,4 +2,9 @@
|
|
2
2
|
import { DatePickerHelper } from './DatePickerHelper';
|
3
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
@@ -6,11 +6,17 @@ export declare type RenderComponent<TValue, TRenderComponent extends ElementType
|
|
6
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,
|
@@ -2,9 +2,13 @@ import { ElementType } from 'react';
|
|
2
2
|
import { FieldProps } from '../Field/Field';
|
3
3
|
import { ValidationFunction } from '../Validation/ValidationFunction';
|
4
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;
|
@@ -12,4 +16,9 @@ export declare type ArrayFormBuilderProp<TValue extends Array<any> | undefined |
|
|
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,6 +40,11 @@ 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"]);
|
package/lib/File/FileGroup.d.ts
CHANGED
@@ -2,7 +2,9 @@ import React from 'react';
|
|
2
2
|
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
3
3
|
import { GroupProps } from '../Group';
|
4
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
@@ -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/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;
|
@@ -1,73 +1,26 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
-
s = arguments[i];
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
-
t[p] = s[p];
|
8
|
-
}
|
9
|
-
return t;
|
10
|
-
};
|
11
|
-
return __assign.apply(this, arguments);
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
12
4
|
};
|
13
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
14
7
|
var react_1 = require("react");
|
15
|
-
// see: https://gist.github.com/rmorse/426ffcc579922a82749934826fa9f743
|
16
8
|
var react_router_dom_1 = require("react-router-dom");
|
17
9
|
var formik_1 = require("formik");
|
10
|
+
var LegacyFormBasedPreventNavigation_1 = __importDefault(require("./LegacyFormBasedPreventNavigation"));
|
11
|
+
var NewFormBasedPreventNavigation_1 = __importDefault(require("./NewFormBasedPreventNavigation"));
|
12
|
+
/** Prevent the user from navigating away from a form if there are any changes. */
|
18
13
|
function FormBasedPreventNavigation(_a) {
|
19
14
|
var ignoreLostChanges = _a.ignoreLostChanges, _b = _a.promptMessage, promptMessage = _b === void 0 ? 'Changes you made may not be saved.' : _b;
|
20
15
|
var _c = (0, formik_1.useFormikContext)(), dirty = _c.dirty, isSubmitting = _c.isSubmitting;
|
21
16
|
var preventNavigate = !ignoreLostChanges && dirty && !isSubmitting;
|
22
17
|
var navigator = (0, react_1.useContext)(react_router_dom_1.UNSAFE_NavigationContext).navigator;
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
// this is a workaround until we get native support for prompt on navigate
|
31
|
-
if (navigator.block) {
|
32
|
-
var blocker_1 = function (tx) {
|
33
|
-
if (window.confirm(promptMessage)) {
|
34
|
-
tx.retry();
|
35
|
-
}
|
36
|
-
};
|
37
|
-
unblock = navigator.block(function (tx) {
|
38
|
-
var autoUnblockingTx = __assign(__assign({}, tx), { retry: function () {
|
39
|
-
// Automatically unblock the transition so it can play all the way
|
40
|
-
// through before retrying it. TODO: Figure out how to re-enable
|
41
|
-
// this block if the transition is cancelled for some reason.
|
42
|
-
unblock();
|
43
|
-
tx.retry();
|
44
|
-
} });
|
45
|
-
blocker_1(autoUnblockingTx);
|
46
|
-
});
|
47
|
-
}
|
48
|
-
else {
|
49
|
-
//https://gist.github.com/MarksCode/64e438c82b0b2a1161e01c88ca0d0355
|
50
|
-
navigator.push = function () {
|
51
|
-
var args = [];
|
52
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
53
|
-
args[_i] = arguments[_i];
|
54
|
-
}
|
55
|
-
if (window.confirm(promptMessage)) {
|
56
|
-
push.apply(void 0, args);
|
57
|
-
}
|
58
|
-
};
|
59
|
-
}
|
60
|
-
window.addEventListener('beforeunload', beforeUnload);
|
61
|
-
return function () {
|
62
|
-
unblock();
|
63
|
-
navigator.push = push;
|
64
|
-
window.removeEventListener('beforeunload', beforeUnload);
|
65
|
-
};
|
66
|
-
function beforeUnload(e) {
|
67
|
-
e.preventDefault();
|
68
|
-
e.returnValue = promptMessage;
|
69
|
-
}
|
70
|
-
}, [preventNavigate, promptMessage, navigator]);
|
71
|
-
return null;
|
18
|
+
var isUsingDataRouter = navigator.location === undefined;
|
19
|
+
if (isUsingDataRouter) {
|
20
|
+
return ((0, jsx_runtime_1.jsx)(NewFormBasedPreventNavigation_1.default, { promptMessage: promptMessage, preventNavigate: preventNavigate, navigator: navigator }));
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
return ((0, jsx_runtime_1.jsx)(LegacyFormBasedPreventNavigation_1.default, { promptMessage: promptMessage, preventNavigate: preventNavigate, navigator: navigator }));
|
24
|
+
}
|
72
25
|
}
|
73
26
|
exports.default = FormBasedPreventNavigation;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { History } from 'history';
|
2
|
+
import { Navigator as BaseNavigator } from 'react-router-dom';
|
3
|
+
interface Navigator extends BaseNavigator {
|
4
|
+
block?: History['block'];
|
5
|
+
}
|
6
|
+
export interface FormBasedPreventNavigationProps {
|
7
|
+
promptMessage?: string;
|
8
|
+
preventNavigate: boolean;
|
9
|
+
navigator: Navigator;
|
10
|
+
}
|
11
|
+
/** Only use this if the project uses `<BrowserRouter/>` or any router that does not support the new
|
12
|
+
* [react-router Data API](https://reactrouter.com/en/main/routers/picking-a-router#using-v64-data-apis)
|
13
|
+
*
|
14
|
+
* Legacy function to prevent the user from navigating away from a form if there are any changes.
|
15
|
+
*/
|
16
|
+
export default function LegacyFormBasedPreventNavigation({ promptMessage, preventNavigate, navigator, }: FormBasedPreventNavigationProps): null;
|
17
|
+
export {};
|
@@ -0,0 +1,72 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
3
|
+
__assign = Object.assign || function(t) {
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
+
s = arguments[i];
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
+
t[p] = s[p];
|
8
|
+
}
|
9
|
+
return t;
|
10
|
+
};
|
11
|
+
return __assign.apply(this, arguments);
|
12
|
+
};
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
14
|
+
var react_1 = require("react");
|
15
|
+
/** Only use this if the project uses `<BrowserRouter/>` or any router that does not support the new
|
16
|
+
* [react-router Data API](https://reactrouter.com/en/main/routers/picking-a-router#using-v64-data-apis)
|
17
|
+
*
|
18
|
+
* Legacy function to prevent the user from navigating away from a form if there are any changes.
|
19
|
+
*/
|
20
|
+
function LegacyFormBasedPreventNavigation(_a) {
|
21
|
+
var _b = _a.promptMessage, promptMessage = _b === void 0 ? 'Changes you made may not be saved.' : _b, preventNavigate = _a.preventNavigate, navigator = _a.navigator;
|
22
|
+
(0, react_1.useEffect)(function () {
|
23
|
+
if (!preventNavigate) {
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
var unblock = function () { };
|
27
|
+
var push = navigator.push;
|
28
|
+
// TODO: https://reactrouter.com/docs/en/v6/upgrading/v5#prompt-is-not-currently-supported
|
29
|
+
// this is a workaround until we get native support for prompt on navigate
|
30
|
+
if (navigator.block) {
|
31
|
+
var blocker_1 = function (tx) {
|
32
|
+
if (window.confirm(promptMessage)) {
|
33
|
+
tx.retry();
|
34
|
+
}
|
35
|
+
};
|
36
|
+
unblock = navigator.block(function (tx) {
|
37
|
+
var autoUnblockingTx = __assign(__assign({}, tx), { retry: function () {
|
38
|
+
// Automatically unblock the transition so it can play all the way
|
39
|
+
// through before retrying it. TODO: Figure out how to re-enable
|
40
|
+
// this block if the transition is cancelled for some reason.
|
41
|
+
unblock();
|
42
|
+
tx.retry();
|
43
|
+
} });
|
44
|
+
blocker_1(autoUnblockingTx);
|
45
|
+
});
|
46
|
+
}
|
47
|
+
else {
|
48
|
+
//https://gist.github.com/MarksCode/64e438c82b0b2a1161e01c88ca0d0355
|
49
|
+
navigator.push = function () {
|
50
|
+
var args = [];
|
51
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
52
|
+
args[_i] = arguments[_i];
|
53
|
+
}
|
54
|
+
if (window.confirm(promptMessage)) {
|
55
|
+
push.apply(void 0, args);
|
56
|
+
}
|
57
|
+
};
|
58
|
+
}
|
59
|
+
window.addEventListener('beforeunload', beforeUnload);
|
60
|
+
return function () {
|
61
|
+
unblock();
|
62
|
+
navigator.push = push;
|
63
|
+
window.removeEventListener('beforeunload', beforeUnload);
|
64
|
+
};
|
65
|
+
function beforeUnload(e) {
|
66
|
+
e.preventDefault();
|
67
|
+
e.returnValue = promptMessage;
|
68
|
+
}
|
69
|
+
}, [preventNavigate, promptMessage, navigator]);
|
70
|
+
return null;
|
71
|
+
}
|
72
|
+
exports.default = LegacyFormBasedPreventNavigation;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { History } from 'history';
|
2
|
+
import { Navigator as BaseNavigator } from 'react-router-dom';
|
3
|
+
interface Navigator extends BaseNavigator {
|
4
|
+
block?: History['block'];
|
5
|
+
location: Location;
|
6
|
+
}
|
7
|
+
interface FormBasedPreventNavigationProps {
|
8
|
+
promptMessage?: string;
|
9
|
+
preventNavigate: boolean;
|
10
|
+
navigator: Navigator;
|
11
|
+
}
|
12
|
+
/** Temporary function to allow backwards compatibility with routers that do not use the new Data API */
|
13
|
+
export default function NewFormBasedPreventNavigation({ promptMessage, preventNavigate, navigator, }: FormBasedPreventNavigationProps): null;
|
14
|
+
export {};
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
var react_1 = require("react");
|
4
|
+
var react_router_dom_1 = require("react-router-dom");
|
5
|
+
/** Temporary function to allow backwards compatibility with routers that do not use the new Data API */
|
6
|
+
function NewFormBasedPreventNavigation(_a) {
|
7
|
+
var _b = _a.promptMessage, promptMessage = _b === void 0 ? 'Changes you made may not be saved.' : _b, preventNavigate = _a.preventNavigate, navigator = _a.navigator;
|
8
|
+
(0, react_router_dom_1.unstable_usePrompt)({
|
9
|
+
when: preventNavigate,
|
10
|
+
message: promptMessage,
|
11
|
+
});
|
12
|
+
// TODO: Once react-router fully supports usePrompt and when we do not want to support routers
|
13
|
+
// that do not support the react-router Data API we can remove this.
|
14
|
+
(0, react_1.useEffect)(function () {
|
15
|
+
if (!preventNavigate) {
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
var unblock = function () { };
|
19
|
+
var push = navigator.push;
|
20
|
+
navigator.push = function () {
|
21
|
+
var args = [];
|
22
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
23
|
+
args[_i] = arguments[_i];
|
24
|
+
}
|
25
|
+
if (window.confirm(promptMessage)) {
|
26
|
+
push.apply(void 0, args);
|
27
|
+
}
|
28
|
+
};
|
29
|
+
window.addEventListener('beforeunload', beforeUnload);
|
30
|
+
return function () {
|
31
|
+
unblock();
|
32
|
+
navigator.push = push;
|
33
|
+
window.removeEventListener('beforeunload', beforeUnload);
|
34
|
+
};
|
35
|
+
function beforeUnload(e) {
|
36
|
+
e.preventDefault();
|
37
|
+
e.returnValue = promptMessage;
|
38
|
+
}
|
39
|
+
}, [preventNavigate, promptMessage, navigator]);
|
40
|
+
return null;
|
41
|
+
}
|
42
|
+
exports.default = NewFormBasedPreventNavigation;
|
@@ -7,4 +7,5 @@ export interface ServerErrorContextProps {
|
|
7
7
|
getError: (path: string) => string | undefined;
|
8
8
|
setError: (path: string, errorMessage: string | undefined) => void;
|
9
9
|
}
|
10
|
+
/** Context to store the API errors from the server for the form. */
|
10
11
|
export declare const ServerErrorContext: React.Context<ServerErrorContextProps>;
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.ServerErrorContext = void 0;
|
7
7
|
var react_1 = __importDefault(require("react"));
|
8
|
+
/** Context to store the API errors from the server for the form. */
|
8
9
|
exports.ServerErrorContext = react_1.default.createContext({
|
9
10
|
errors: {},
|
10
11
|
getError: function (path) {
|
package/lib/FormActions.d.ts
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
export interface FormActionsProps {
|
3
|
+
/** Allow the form to be submitted without any changes. By default this is not allowed. */
|
3
4
|
allowPristineSubmit?: boolean;
|
5
|
+
/** The cancel button's `onClick`.
|
6
|
+
* @defaultValue `window.history.back()`
|
7
|
+
*/
|
4
8
|
handleCancel?: () => void;
|
9
|
+
/** Whether both buttons should be disabled. */
|
5
10
|
disabled?: boolean;
|
6
11
|
}
|
12
|
+
/** Standard cancel and submit buttons. */
|
7
13
|
export default function FormActions({ allowPristineSubmit, handleCancel, disabled, }: FormActionsProps): JSX.Element;
|
package/lib/FormActions.js
CHANGED
@@ -18,6 +18,7 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
18
18
|
var FormDefaults_1 = require("./FormDefaults");
|
19
19
|
var formik_1 = require("formik");
|
20
20
|
var SubmitFormButton_1 = __importDefault(require("./SubmitFormButton"));
|
21
|
+
/** Standard cancel and submit buttons. */
|
21
22
|
function FormActions(_a) {
|
22
23
|
var allowPristineSubmit = _a.allowPristineSubmit, handleCancel = _a.handleCancel, disabled = _a.disabled;
|
23
24
|
var isSubmitting = (0, formik_1.useFormikContext)().isSubmitting;
|
package/lib/FormDefaults.d.ts
CHANGED
package/lib/FormDefaults.js
CHANGED
package/lib/Group.d.ts
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { InjectedFieldProps } from './Field/InjectedFieldProps';
|
3
3
|
export interface GroupProps extends InjectedFieldProps<any> {
|
4
|
+
/** Extra class names to apply. */
|
4
5
|
className?: string;
|
5
6
|
children: React.ReactNode;
|
6
|
-
/**
|
7
|
+
/** Simple text label before the input. */
|
7
8
|
label?: string;
|
8
|
-
/**
|
9
|
+
/** Simple helper text after the input. */
|
9
10
|
helpText?: string | React.ReactNode;
|
11
|
+
/** Whether the field should be disabled. */
|
10
12
|
disabled?: boolean;
|
11
13
|
required?: boolean;
|
12
14
|
}
|
13
|
-
/**
|
15
|
+
/** Contains standard field bits like a label, helper text, error scroll target, validation message container, etc. */
|
14
16
|
export default function Group({ className, children, label, helpText, meta, input, disabled, required, }: GroupProps): JSX.Element;
|
package/lib/Group.js
CHANGED
@@ -18,7 +18,7 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
18
18
|
var classnames_1 = __importDefault(require("classnames"));
|
19
19
|
var FormDefaults_1 = require("./FormDefaults");
|
20
20
|
var FieldErrorScrollTarget_1 = __importDefault(require("./Field/FieldErrorScrollTarget"));
|
21
|
-
/**
|
21
|
+
/** Contains standard field bits like a label, helper text, error scroll target, validation message container, etc. */
|
22
22
|
function Group(_a) {
|
23
23
|
var _b;
|
24
24
|
var className = _a.className, children = _a.children, label = _a.label, helpText = _a.helpText, meta = _a.meta, input = _a.input, disabled = _a.disabled, required = _a.required;
|
@@ -26,6 +26,6 @@ function Group(_a) {
|
|
26
26
|
_b[FormDefaults_1.FormDefaults.cssClassPrefix + 'invalid'] = meta.error,
|
27
27
|
_b[FormDefaults_1.FormDefaults.cssClassPrefix + 'disabled'] = disabled,
|
28
28
|
_b[FormDefaults_1.FormDefaults.cssClassPrefix + 'required'] = required,
|
29
|
-
_b)) }, { children: [(0, jsx_runtime_1.jsx)(FieldErrorScrollTarget_1.default, {}), meta.warning && ((0, jsx_runtime_1.jsx)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'warning' }, { children: meta.warning }))), (0, jsx_runtime_1.jsx)("label", __assign({ htmlFor: input.id }, { children: label })), children, meta.error && ((0, jsx_runtime_1.jsx)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'error' }, { children: meta.error }))), helpText && ((0, jsx_runtime_1.jsx)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'help' }, { children: helpText })))] })));
|
29
|
+
_b)) }, { children: [(0, jsx_runtime_1.jsx)(FieldErrorScrollTarget_1.default, {}), meta.warning && ((0, jsx_runtime_1.jsx)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'warning' }, { children: meta.warning }))), (0, jsx_runtime_1.jsx)("label", __assign({ htmlFor: input.id }, { children: label })), children, meta.error && ((0, jsx_runtime_1.jsx)("div", __assign({ id: "".concat(input.id, "-error"), className: FormDefaults_1.FormDefaults.cssClassPrefix + 'error' }, { children: meta.error }))), helpText && ((0, jsx_runtime_1.jsx)("div", __assign({ className: FormDefaults_1.FormDefaults.cssClassPrefix + 'help' }, { children: helpText })))] })));
|
30
30
|
}
|
31
31
|
exports.default = Group;
|
@@ -2,8 +2,11 @@ import React from 'react';
|
|
2
2
|
import { InputGroupProps } from './InputGroup';
|
3
3
|
export interface IconInputGroupProps extends Omit<InputGroupProps<string | undefined | null>, 'onChange' | 'type' | 'value'> {
|
4
4
|
type?: 'color' | 'email' | 'search' | 'tel' | 'text' | 'url';
|
5
|
+
/** Icon to display on the input group. */
|
5
6
|
icon: React.ReactNode;
|
7
|
+
/** Text to display after the input group to give more information to the user. */
|
6
8
|
helpText?: string;
|
7
9
|
}
|
10
|
+
/** Input group with an icon. */
|
8
11
|
declare const IconInputGroupWithRef: React.ComponentType<IconInputGroupProps>;
|
9
12
|
export default IconInputGroupWithRef;
|