envoc-form 4.0.1-9 → 4.2.0
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 +9443 -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 +7 -2
- package/es/DatePicker/DatePickerGroup.js +18 -7
- 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/DateTimePicker/DateTimePickerGroup.d.ts +13 -0
- package/es/DateTimePicker/DateTimePickerGroup.js +87 -0
- package/es/DateTimePicker/DateTimePickerHelper.d.ts +3 -0
- package/es/DateTimePicker/DateTimePickerHelper.js +1 -0
- package/es/DateTimePicker/StringDateTimePickerGroup.d.ts +10 -0
- package/es/DateTimePicker/StringDateTimePickerGroup.js +53 -0
- package/es/Field/Field.d.ts +9 -3
- package/es/Field/Field.js +9 -4
- 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 +4 -3
- 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 +7 -4
- package/es/Group.js +4 -3
- package/es/Input/IconInputGroup.d.ts +4 -1
- package/es/Input/IconInputGroup.js +3 -1
- package/es/Input/InputGroup.d.ts +4 -4
- package/es/Input/InputGroup.js +4 -4
- 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/PhoneNumberInputGroup.d.ts +10 -0
- package/es/Input/PhoneNumberInputGroup.js +47 -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 +8 -2
- package/es/Select/SelectGroup.js +5 -4
- 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 +5 -4
- package/es/Validation/validators.d.ts +11 -8
- package/es/Validation/validators.js +6 -2
- package/es/hooks/index.d.ts +2 -0
- package/es/hooks/index.js +2 -0
- package/es/hooks/useFormValue.d.ts +2 -0
- package/es/hooks/useFormValue.js +7 -0
- package/es/index.d.ts +10 -4
- package/es/index.js +4 -0
- 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 +7 -2
- package/lib/DatePicker/DatePickerGroup.js +18 -7
- 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/DateTimePicker/DateTimePickerGroup.d.ts +13 -0
- package/lib/DateTimePicker/DateTimePickerGroup.js +93 -0
- package/lib/DateTimePicker/DateTimePickerHelper.d.ts +3 -0
- package/lib/DateTimePicker/DateTimePickerHelper.js +2 -0
- package/lib/DateTimePicker/StringDateTimePickerGroup.d.ts +10 -0
- package/lib/DateTimePicker/StringDateTimePickerGroup.js +59 -0
- package/lib/Field/Field.d.ts +9 -3
- package/lib/Field/Field.js +9 -4
- 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 +4 -3
- 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 +7 -4
- package/lib/Group.js +4 -3
- package/lib/Input/IconInputGroup.d.ts +4 -1
- package/lib/Input/IconInputGroup.js +3 -1
- package/lib/Input/InputGroup.d.ts +4 -4
- package/lib/Input/InputGroup.js +4 -4
- 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/PhoneNumberInputGroup.d.ts +10 -0
- package/lib/Input/PhoneNumberInputGroup.js +52 -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 +8 -2
- package/lib/Select/SelectGroup.js +5 -4
- 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 +5 -4
- package/lib/Validation/validators.d.ts +11 -8
- package/lib/Validation/validators.js +6 -2
- package/lib/hooks/index.d.ts +2 -0
- package/lib/{__Tests__ → hooks}/index.js +3 -3
- package/lib/hooks/useFormValue.d.ts +2 -0
- package/lib/hooks/useFormValue.js +10 -0
- package/lib/index.d.ts +10 -4
- package/lib/index.js +8 -1
- package/lib/setupTests.d.ts +1 -0
- package/lib/setupTests.js +3 -0
- package/package.json +12 -8
- package/src/AddressInput/AddressInput.tsx +15 -5
- package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +8 -4
- 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 +23 -7
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +7 -2
- package/src/DatePicker/StringDatePickerGroup.tsx +7 -1
- package/src/DateTimePicker/DateTimePicker.test.tsx +243 -0
- package/src/DateTimePicker/DateTimePickerGroup.tsx +116 -0
- package/src/DateTimePicker/DateTimePickerHelper.ts +4 -0
- package/src/DateTimePicker/StringDateTimePickerGroup.tsx +61 -0
- package/src/DateTimePicker/__snapshots__/DateTimePicker.test.tsx.snap +216 -0
- package/src/Field/Field.tsx +20 -7
- 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 +9 -3
- 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 +12 -4
- package/src/Input/IconInputGroup.tsx +5 -2
- package/src/Input/InputGroup.tsx +13 -5
- package/src/Input/MoneyInputGroup.tsx +3 -1
- package/src/Input/NumberInputGroup.tsx +3 -1
- package/src/Input/PhoneNumberInputGroup.tsx +49 -0
- package/src/Input/StringInputGroup.tsx +3 -2
- package/src/Input/__Tests__/PhoneNumberInputGroup.test.tsx +37 -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__/PhoneNumberInputGroup.test.tsx.snap +33 -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 +13 -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 +6 -4
- package/src/Validation/validators.ts +19 -14
- package/src/__Tests__/FormTestBase.tsx +10 -8
- package/src/__Tests__/RealisticForm.test.tsx +82 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useFormValue.ts +16 -0
- package/src/index.ts +14 -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
@@ -35,14 +35,19 @@ import Field from '../Field/Field';
|
|
35
35
|
import { FieldNameContext } from '../Field/FieldNameContext';
|
36
36
|
import useStandardFormInput from '../Field/useStandardField';
|
37
37
|
import { FormDefaults } from '../FormDefaults';
|
38
|
+
/**
|
39
|
+
* An array of fields that allows the user to add multiple instances of the same field.
|
40
|
+
*
|
41
|
+
* Includes "Add Item" and "Remove Item" buttons to allow the user to speicify the number of fields.
|
42
|
+
*/
|
38
43
|
export default function FieldArray(_a) {
|
39
44
|
var _b;
|
40
45
|
var name = _a.name, label = _a.label, validate = _a.validate, disabled = _a.disabled, children = _a.children, rest = __rest(_a, ["name", "label", "validate", "disabled", "children"]);
|
41
|
-
var
|
46
|
+
var input = useStandardFormInput({
|
42
47
|
name: String(name),
|
43
48
|
validate: validate,
|
44
49
|
disabled: disabled,
|
45
|
-
})
|
50
|
+
})[0];
|
46
51
|
var values = !input.value
|
47
52
|
? []
|
48
53
|
: Array.isArray(input.value)
|
package/es/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/es/File/FileGroup.js
CHANGED
@@ -24,12 +24,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
24
|
import React from 'react';
|
25
25
|
import classNames from 'classnames';
|
26
26
|
import FileList from './FileList';
|
27
|
-
import Group from '../Group';
|
28
27
|
import { FormDefaults } from '../FormDefaults';
|
28
|
+
import Group from '../Group';
|
29
29
|
function FileGroup(_a, ref) {
|
30
30
|
var _b;
|
31
|
-
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, multiple = _a.multiple, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "multiple"]);
|
32
|
-
return (_jsxs(Group, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: classNames(className, (_b = {}, _b[FormDefaults.cssClassPrefix + 'multiple'] = multiple, _b), FormDefaults.cssClassPrefix + 'file-group') }, { children: [_jsx("input", __assign({}, input, rest, { multiple: multiple, onChange: function (e) {
|
31
|
+
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"]);
|
32
|
+
return (_jsxs(Group, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: classNames(className, (_b = {}, _b[FormDefaults.cssClassPrefix + 'multiple'] = multiple, _b), FormDefaults.cssClassPrefix + 'file-group'), required: required, disabled: disabled }, { children: [_jsx("input", __assign({}, input, rest, { multiple: multiple, onChange: function (e) {
|
33
33
|
var _a, _b;
|
34
34
|
if (!((_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b.length)) {
|
35
35
|
input.onChange(undefined);
|
@@ -48,5 +48,6 @@ function FileGroup(_a, ref) {
|
|
48
48
|
}
|
49
49
|
}, value: undefined, ref: ref, type: "file", className: classNames(className, FormDefaults.cssClassPrefix + 'file-group') })), _jsx(FileList, { files: input.value })] })));
|
50
50
|
}
|
51
|
+
/** File upload input group. */
|
51
52
|
var FileGroupWithRef = React.forwardRef(FileGroup);
|
52
53
|
export default FileGroupWithRef;
|
package/es/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/es/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/es/Form/FocusError.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { useEffect } from 'react';
|
2
2
|
import { useFormikContext } from 'formik';
|
3
3
|
import smoothscroll from 'smoothscroll-polyfill';
|
4
|
+
/** Function to scroll to the field that has an error. */
|
4
5
|
export default function FocusError(props) {
|
5
6
|
var _a = useFormikContext(), errors = _a.errors, isSubmitting = _a.isSubmitting, isValidating = _a.isValidating;
|
6
7
|
smoothscroll.polyfill();
|
package/es/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/es/Form/Form.js
CHANGED
@@ -32,6 +32,7 @@ import FieldArray from '../FieldArray/FieldArray';
|
|
32
32
|
import { FormDefaults } from '../FormDefaults';
|
33
33
|
import objectContainsNonSerializableProperty from '../utils/objectContainsNonSerializableProperty';
|
34
34
|
import objectToFormData from '../utils/objectToFormData';
|
35
|
+
/** Define a form. Uses [formik](https://formik.org/docs/overview). Usually contains many `<Field/>` components. */
|
35
36
|
export default function Form(_a) {
|
36
37
|
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
38
|
// 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,53 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
-
s = arguments[i];
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
-
t[p] = s[p];
|
7
|
-
}
|
8
|
-
return t;
|
9
|
-
};
|
10
|
-
return __assign.apply(this, arguments);
|
11
|
-
};
|
12
|
-
import { useContext, useEffect } from 'react';
|
13
|
-
// see: https://gist.github.com/rmorse/426ffcc579922a82749934826fa9f743
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { useContext } from 'react';
|
14
3
|
import { UNSAFE_NavigationContext as NavigationContext, } from 'react-router-dom';
|
15
4
|
import { useFormikContext } from 'formik';
|
5
|
+
import LegacyFormBasedPreventNavigation from './LegacyFormBasedPreventNavigation';
|
6
|
+
import NewFormBasedPreventNavigation from './NewFormBasedPreventNavigation';
|
7
|
+
/** Prevent the user from navigating away from a form if there are any changes. */
|
16
8
|
export default function FormBasedPreventNavigation(_a) {
|
17
9
|
var ignoreLostChanges = _a.ignoreLostChanges, _b = _a.promptMessage, promptMessage = _b === void 0 ? 'Changes you made may not be saved.' : _b;
|
18
10
|
var _c = useFormikContext(), dirty = _c.dirty, isSubmitting = _c.isSubmitting;
|
19
11
|
var preventNavigate = !ignoreLostChanges && dirty && !isSubmitting;
|
20
12
|
var navigator = useContext(NavigationContext).navigator;
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
if (window.confirm(promptMessage)) {
|
29
|
-
tx.retry();
|
30
|
-
}
|
31
|
-
};
|
32
|
-
var unblock = navigator.block(function (tx) {
|
33
|
-
var autoUnblockingTx = __assign(__assign({}, tx), { retry: function () {
|
34
|
-
// Automatically unblock the transition so it can play all the way
|
35
|
-
// through before retrying it. TODO: Figure out how to re-enable
|
36
|
-
// this block if the transition is cancelled for some reason.
|
37
|
-
unblock();
|
38
|
-
tx.retry();
|
39
|
-
} });
|
40
|
-
blocker(autoUnblockingTx);
|
41
|
-
});
|
42
|
-
window.addEventListener('beforeunload', beforeUnload);
|
43
|
-
return function () {
|
44
|
-
unblock();
|
45
|
-
window.removeEventListener('beforeunload', beforeUnload);
|
46
|
-
};
|
47
|
-
function beforeUnload(e) {
|
48
|
-
e.preventDefault();
|
49
|
-
e.returnValue = promptMessage;
|
50
|
-
}
|
51
|
-
}, [preventNavigate, promptMessage, navigator]);
|
52
|
-
return null;
|
13
|
+
var isUsingDataRouter = navigator.location === undefined;
|
14
|
+
if (isUsingDataRouter) {
|
15
|
+
return (_jsx(NewFormBasedPreventNavigation, { promptMessage: promptMessage, preventNavigate: preventNavigate, navigator: navigator }));
|
16
|
+
}
|
17
|
+
else {
|
18
|
+
return (_jsx(LegacyFormBasedPreventNavigation, { promptMessage: promptMessage, preventNavigate: preventNavigate, navigator: navigator }));
|
19
|
+
}
|
53
20
|
}
|
@@ -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,69 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
import { useEffect } from 'react';
|
13
|
+
/** Only use this if the project uses `<BrowserRouter/>` or any router that does not support the new
|
14
|
+
* [react-router Data API](https://reactrouter.com/en/main/routers/picking-a-router#using-v64-data-apis)
|
15
|
+
*
|
16
|
+
* Legacy function to prevent the user from navigating away from a form if there are any changes.
|
17
|
+
*/
|
18
|
+
export default function LegacyFormBasedPreventNavigation(_a) {
|
19
|
+
var _b = _a.promptMessage, promptMessage = _b === void 0 ? 'Changes you made may not be saved.' : _b, preventNavigate = _a.preventNavigate, navigator = _a.navigator;
|
20
|
+
useEffect(function () {
|
21
|
+
if (!preventNavigate) {
|
22
|
+
return;
|
23
|
+
}
|
24
|
+
var unblock = function () { };
|
25
|
+
var push = navigator.push;
|
26
|
+
// TODO: https://reactrouter.com/docs/en/v6/upgrading/v5#prompt-is-not-currently-supported
|
27
|
+
// this is a workaround until we get native support for prompt on navigate
|
28
|
+
if (navigator.block) {
|
29
|
+
var blocker_1 = function (tx) {
|
30
|
+
if (window.confirm(promptMessage)) {
|
31
|
+
tx.retry();
|
32
|
+
}
|
33
|
+
};
|
34
|
+
unblock = navigator.block(function (tx) {
|
35
|
+
var autoUnblockingTx = __assign(__assign({}, tx), { retry: function () {
|
36
|
+
// Automatically unblock the transition so it can play all the way
|
37
|
+
// through before retrying it. TODO: Figure out how to re-enable
|
38
|
+
// this block if the transition is cancelled for some reason.
|
39
|
+
unblock();
|
40
|
+
tx.retry();
|
41
|
+
} });
|
42
|
+
blocker_1(autoUnblockingTx);
|
43
|
+
});
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
//https://gist.github.com/MarksCode/64e438c82b0b2a1161e01c88ca0d0355
|
47
|
+
navigator.push = function () {
|
48
|
+
var args = [];
|
49
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
50
|
+
args[_i] = arguments[_i];
|
51
|
+
}
|
52
|
+
if (window.confirm(promptMessage)) {
|
53
|
+
push.apply(void 0, args);
|
54
|
+
}
|
55
|
+
};
|
56
|
+
}
|
57
|
+
window.addEventListener('beforeunload', beforeUnload);
|
58
|
+
return function () {
|
59
|
+
unblock();
|
60
|
+
navigator.push = push;
|
61
|
+
window.removeEventListener('beforeunload', beforeUnload);
|
62
|
+
};
|
63
|
+
function beforeUnload(e) {
|
64
|
+
e.preventDefault();
|
65
|
+
e.returnValue = promptMessage;
|
66
|
+
}
|
67
|
+
}, [preventNavigate, promptMessage, navigator]);
|
68
|
+
return null;
|
69
|
+
}
|
@@ -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,39 @@
|
|
1
|
+
import { useEffect } from 'react';
|
2
|
+
import { unstable_usePrompt as usePrompt, } from 'react-router-dom';
|
3
|
+
/** Temporary function to allow backwards compatibility with routers that do not use the new Data API */
|
4
|
+
export default function NewFormBasedPreventNavigation(_a) {
|
5
|
+
var _b = _a.promptMessage, promptMessage = _b === void 0 ? 'Changes you made may not be saved.' : _b, preventNavigate = _a.preventNavigate, navigator = _a.navigator;
|
6
|
+
usePrompt({
|
7
|
+
when: preventNavigate,
|
8
|
+
message: promptMessage,
|
9
|
+
});
|
10
|
+
// TODO: Once react-router fully supports usePrompt and when we do not want to support routers
|
11
|
+
// that do not support the react-router Data API we can remove this.
|
12
|
+
useEffect(function () {
|
13
|
+
if (!preventNavigate) {
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
var unblock = function () { };
|
17
|
+
var push = navigator.push;
|
18
|
+
navigator.push = function () {
|
19
|
+
var args = [];
|
20
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
21
|
+
args[_i] = arguments[_i];
|
22
|
+
}
|
23
|
+
if (window.confirm(promptMessage)) {
|
24
|
+
push.apply(void 0, args);
|
25
|
+
}
|
26
|
+
};
|
27
|
+
window.addEventListener('beforeunload', beforeUnload);
|
28
|
+
return function () {
|
29
|
+
unblock();
|
30
|
+
navigator.push = push;
|
31
|
+
window.removeEventListener('beforeunload', beforeUnload);
|
32
|
+
};
|
33
|
+
function beforeUnload(e) {
|
34
|
+
e.preventDefault();
|
35
|
+
e.returnValue = promptMessage;
|
36
|
+
}
|
37
|
+
}, [preventNavigate, promptMessage, navigator]);
|
38
|
+
return null;
|
39
|
+
}
|
@@ -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>;
|
package/es/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/es/FormActions.js
CHANGED
@@ -13,6 +13,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
13
13
|
import { FormDefaults } from './FormDefaults';
|
14
14
|
import { useFormikContext } from 'formik';
|
15
15
|
import SubmitFormButton from './SubmitFormButton';
|
16
|
+
/** Standard cancel and submit buttons. */
|
16
17
|
export default function FormActions(_a) {
|
17
18
|
var allowPristineSubmit = _a.allowPristineSubmit, handleCancel = _a.handleCancel, disabled = _a.disabled;
|
18
19
|
var isSubmitting = useFormikContext().isSubmitting;
|
package/es/FormDefaults.d.ts
CHANGED
package/es/FormDefaults.js
CHANGED
package/es/Group.d.ts
CHANGED
@@ -1,13 +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;
|
13
|
+
required?: boolean;
|
11
14
|
}
|
12
|
-
/**
|
13
|
-
export default function Group({ className, children, label, helpText, meta, input, disabled, }: GroupProps): JSX.Element;
|
15
|
+
/** Contains standard field bits like a label, helper text, error scroll target, validation message container, etc. */
|
16
|
+
export default function Group({ className, children, label, helpText, meta, input, disabled, required, }: GroupProps): JSX.Element;
|
package/es/Group.js
CHANGED
@@ -13,12 +13,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import classNames from 'classnames';
|
14
14
|
import { FormDefaults } from './FormDefaults';
|
15
15
|
import FieldErrorScrollTarget from './Field/FieldErrorScrollTarget';
|
16
|
-
/**
|
16
|
+
/** Contains standard field bits like a label, helper text, error scroll target, validation message container, etc. */
|
17
17
|
export default function Group(_a) {
|
18
18
|
var _b;
|
19
|
-
var className = _a.className, children = _a.children, label = _a.label, helpText = _a.helpText, meta = _a.meta, input = _a.input, disabled = _a.disabled;
|
19
|
+
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;
|
20
20
|
return (_jsxs("div", __assign({ className: classNames(className, FormDefaults.cssClassPrefix + 'group', (_b = {},
|
21
21
|
_b[FormDefaults.cssClassPrefix + 'invalid'] = meta.error,
|
22
22
|
_b[FormDefaults.cssClassPrefix + 'disabled'] = disabled,
|
23
|
-
_b
|
23
|
+
_b[FormDefaults.cssClassPrefix + 'required'] = required,
|
24
|
+
_b)) }, { children: [_jsx(FieldErrorScrollTarget, {}), meta.warning && (_jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'warning' }, { children: meta.warning }))), _jsx("label", __assign({ htmlFor: input.id }, { children: label })), children, meta.error && (_jsx("div", __assign({ id: "".concat(input.id, "-error"), className: FormDefaults.cssClassPrefix + 'error' }, { children: meta.error }))), helpText && (_jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'help' }, { children: helpText })))] })));
|
24
25
|
}
|
@@ -1,9 +1,12 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { InputGroupProps } from './InputGroup';
|
3
|
-
export interface IconInputGroupProps extends Omit<InputGroupProps<string | undefined>, 'onChange' | 'type' | 'value'> {
|
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;
|
@@ -26,9 +26,10 @@ import classNames from 'classnames';
|
|
26
26
|
import InputGroupWithRef from './InputGroup';
|
27
27
|
import { FormDefaults } from '../FormDefaults';
|
28
28
|
function IconInputGroup(_a, ref) {
|
29
|
+
var _b;
|
29
30
|
var icon = _a.icon, className = _a.className, rest = __rest(_a, ["icon", "className"]);
|
30
31
|
var input = rest.input;
|
31
|
-
return (_jsx(_Fragment, { children: _jsx(InputGroupWithRef, __assign({ icon: icon, ref: ref, className: classNames(className, FormDefaults.cssClassPrefix + 'icon-input-group'), value: input.value
|
32
|
+
return (_jsx(_Fragment, { children: _jsx(InputGroupWithRef, __assign({ icon: icon, ref: ref, className: classNames(className, FormDefaults.cssClassPrefix + 'icon-input-group'), value: (_b = input.value) !== null && _b !== void 0 ? _b : '', onChange: function (e) {
|
32
33
|
if (!e.target.value) {
|
33
34
|
input.onChange(undefined);
|
34
35
|
}
|
@@ -37,5 +38,6 @@ function IconInputGroup(_a, ref) {
|
|
37
38
|
}
|
38
39
|
} }, rest)) }));
|
39
40
|
}
|
41
|
+
/** Input group with an icon. */
|
40
42
|
var IconInputGroupWithRef = React.forwardRef(IconInputGroup);
|
41
43
|
export default IconInputGroupWithRef;
|
package/es/Input/InputGroup.d.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import React, { ChangeEventHandler, LegacyRef } from 'react';
|
2
2
|
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
3
3
|
import { GroupProps } from '../Group';
|
4
|
-
export interface InputGroupProps<TValue> extends InjectedFieldProps<TValue>, Omit<React.HTMLProps<HTMLInputElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
|
4
|
+
export interface InputGroupProps<TValue> extends InjectedFieldProps<TValue>, Omit<React.HTMLProps<HTMLInputElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label' | 'value'>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
|
5
5
|
onChange: ChangeEventHandler<HTMLInputElement>;
|
6
|
-
value: string | number;
|
6
|
+
value: string | number | null | undefined;
|
7
7
|
icon?: React.ReactNode;
|
8
8
|
}
|
9
|
-
|
10
|
-
|
9
|
+
declare function InputGroup<TValue>({ input, meta, label, helpText, className, required, disabled, onChange, value, icon, ...rest }: InputGroupProps<TValue>, ref: LegacyRef<HTMLInputElement>): JSX.Element;
|
10
|
+
/** Generic controlled `<input/>` wrapped by a `<Group/>` */
|
11
11
|
declare const InputGroupWithRef: typeof InputGroup;
|
12
12
|
export default InputGroupWithRef;
|
package/es/Input/InputGroup.js
CHANGED
@@ -23,12 +23,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
23
23
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
24
24
|
import React from 'react';
|
25
25
|
import classNames from 'classnames';
|
26
|
-
import Group from '../Group';
|
27
26
|
import { FormDefaults } from '../FormDefaults';
|
28
|
-
|
27
|
+
import Group from '../Group';
|
29
28
|
function InputGroup(_a, ref) {
|
30
|
-
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, disabled = _a.disabled, onChange = _a.onChange, value = _a.value, icon = _a.icon, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "disabled", "onChange", "value", "icon"]);
|
31
|
-
return (_jsxs(Group, __assign({ input: input, meta: meta, disabled: disabled, label: label, helpText: helpText, className: classNames(className, FormDefaults.cssClassPrefix + 'input-group') }, { children: [icon, _jsx("input", __assign({}, input, rest, { value: value, onChange: onChange, ref: ref, className: classNames(className, FormDefaults.cssClassPrefix + 'input-group') }))] })));
|
29
|
+
var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, onChange = _a.onChange, value = _a.value, icon = _a.icon, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "onChange", "value", "icon"]);
|
30
|
+
return (_jsxs(Group, __assign({ input: input, meta: meta, required: required, disabled: disabled, label: label, helpText: helpText, className: classNames(className, FormDefaults.cssClassPrefix + 'input-group') }, { children: [icon, _jsx("input", __assign({}, input, rest, { "aria-invalid": !!meta.error, "aria-errormessage": !!meta.error ? "".concat(input.name, "-error") : undefined, value: value !== null && value !== void 0 ? value : '', onChange: onChange, ref: ref, className: classNames(className, FormDefaults.cssClassPrefix + 'input-group') }))] })));
|
32
31
|
}
|
32
|
+
/** Generic controlled `<input/>` wrapped by a `<Group/>` */
|
33
33
|
var InputGroupWithRef = React.forwardRef(InputGroup);
|
34
34
|
export default InputGroupWithRef;
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { InputGroupProps } from './InputGroup';
|
3
|
-
export interface MoneyInputGroupProps extends Omit<InputGroupProps<number | undefined>, 'onChange' | 'type' | 'value'> {
|
3
|
+
export interface MoneyInputGroupProps extends Omit<InputGroupProps<number | undefined | null>, 'onChange' | 'type' | 'value'> {
|
4
|
+
/** Custom parsing function when the value changes. */
|
4
5
|
parseFunc?: typeof parseInt | typeof parseFloat;
|
5
6
|
}
|
7
|
+
/** Input group for inputting money. */
|
6
8
|
declare const MoneyInputGroupWithRef: React.FunctionComponent<MoneyInputGroupProps>;
|
7
9
|
export default MoneyInputGroupWithRef;
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { InputGroupProps } from './InputGroup';
|
3
|
-
export interface NumberInputGroupProps extends Omit<InputGroupProps<number | undefined>, 'onChange' | 'type' | 'value'> {
|
3
|
+
export interface NumberInputGroupProps extends Omit<InputGroupProps<number | undefined | null>, 'onChange' | 'type' | 'value'> {
|
4
|
+
/** Custom parsing function when the value changes. */
|
4
5
|
parseFunc?: typeof parseInt | typeof parseFloat;
|
5
6
|
}
|
7
|
+
/** Standard number input group. By default allows for float values. */
|
6
8
|
declare const NumberInputGroupWithRef: React.ComponentType<NumberInputGroupProps>;
|
7
9
|
export default NumberInputGroupWithRef;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { InputGroupProps } from './InputGroup';
|
3
|
+
export interface PhoneNumberInputGroupProps extends Omit<InputGroupProps<string | undefined | null>, 'onChange' | 'type' | 'value'> {
|
4
|
+
}
|
5
|
+
/**A standard phone number input. Will display to the user in `+XXX XXX-XXX-XXXX` format as the number is being inputted.
|
6
|
+
* The data will get sent in the same format as displayed. Uses `normalizers.phoneNumber`.
|
7
|
+
* @default autoComplete="tel-national"
|
8
|
+
*/
|
9
|
+
declare const PhoneNumberInputGroupWithRef: React.ComponentType<PhoneNumberInputGroupProps>;
|
10
|
+
export default PhoneNumberInputGroupWithRef;
|
@@ -0,0 +1,47 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
13
|
+
var t = {};
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
+
t[p] = s[p];
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
+
t[p[i]] = s[p[i]];
|
20
|
+
}
|
21
|
+
return t;
|
22
|
+
};
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
24
|
+
import React from 'react';
|
25
|
+
import classNames from 'classnames';
|
26
|
+
import InputGroup from './InputGroup';
|
27
|
+
import { FormDefaults } from '../FormDefaults';
|
28
|
+
import { phoneNumber } from '../Normalization/normalizers';
|
29
|
+
function PhoneNumberInputGroup(_a, ref) {
|
30
|
+
var _b;
|
31
|
+
var className = _a.className, rest = __rest(_a, ["className"]);
|
32
|
+
var input = rest.input;
|
33
|
+
return (_jsx(InputGroup, __assign({ ref: ref, autoComplete: "tel-national" }, rest, { type: "text", className: classNames(className, FormDefaults.cssClassPrefix + 'phone-number-group'), value: (_b = input.value) !== null && _b !== void 0 ? _b : '', onChange: function (e) {
|
34
|
+
if (!e.target.value) {
|
35
|
+
input.onChange(undefined);
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
input.onChange(phoneNumber(e.target.value));
|
39
|
+
}
|
40
|
+
} })));
|
41
|
+
}
|
42
|
+
/**A standard phone number input. Will display to the user in `+XXX XXX-XXX-XXXX` format as the number is being inputted.
|
43
|
+
* The data will get sent in the same format as displayed. Uses `normalizers.phoneNumber`.
|
44
|
+
* @default autoComplete="tel-national"
|
45
|
+
*/
|
46
|
+
var PhoneNumberInputGroupWithRef = React.forwardRef(PhoneNumberInputGroup);
|
47
|
+
export default PhoneNumberInputGroupWithRef;
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { InputGroupProps } from './InputGroup';
|
3
|
-
export interface StringInputGroupProps extends Omit<InputGroupProps<string | undefined>, 'onChange' | 'type' | 'value'> {
|
3
|
+
export interface StringInputGroupProps extends Omit<InputGroupProps<string | undefined | null>, 'onChange' | 'type' | 'value'> {
|
4
4
|
type?: 'color' | 'email' | 'search' | 'tel' | 'text' | 'url' | 'password' | 'textarea';
|
5
5
|
}
|
6
|
+
/** Standard string input group. */
|
6
7
|
declare const StringInputGroupWithRef: React.ComponentType<StringInputGroupProps>;
|
7
8
|
export default StringInputGroupWithRef;
|