envoc-form 5.0.2 → 5.0.5
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 +158 -15
- package/es/Input/CheckboxGroup.d.ts +6 -0
- package/es/Input/CheckboxGroup.js +14 -0
- package/es/Input/CheckboxInputGroup.d.ts +13 -0
- package/es/Input/CheckboxInputGroup.js +41 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +1 -0
- package/lib/Input/CheckboxGroup.d.ts +6 -0
- package/lib/Input/CheckboxGroup.js +20 -0
- package/lib/Input/CheckboxInputGroup.d.ts +13 -0
- package/lib/Input/CheckboxInputGroup.js +46 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/package.json +111 -111
- package/src/AddressInput/AddressInput.test.tsx +27 -27
- package/src/AddressInput/AddressInput.tsx +82 -82
- package/src/AddressInput/UsStates.ts +55 -55
- package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +182 -182
- package/src/ConfirmBaseForm/ConfirmBaseForm.test.tsx +24 -24
- package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +74 -74
- package/src/ConfirmBaseForm/__snapshots__/ConfirmBaseForm.test.tsx.snap +23 -23
- package/src/ConfirmDeleteForm/ConfirmDeleteForm.test.tsx +24 -24
- package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +87 -87
- package/src/ConfirmDeleteForm/__snapshots__/ConfirmDeleteForm.test.tsx.snap +25 -25
- package/src/DatePicker/DatePicker.test.tsx +48 -48
- package/src/DatePicker/DatePickerGroup.tsx +115 -115
- package/src/DatePicker/DatePickerHelper.ts +4 -4
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +28 -28
- package/src/DatePicker/StringDatePickerGroup.tsx +20 -20
- package/src/DatePicker/__snapshots__/DatePicker.test.tsx.snap +152 -152
- package/src/Field/CustomFieldInputProps.ts +10 -10
- package/src/Field/CustomFieldMetaProps.ts +5 -5
- package/src/Field/Field.tsx +113 -113
- package/src/Field/FieldErrorScrollTarget.tsx +12 -12
- package/src/Field/FieldNameContext.ts +6 -6
- package/src/Field/FieldSection.tsx +18 -18
- package/src/Field/InjectedFieldProps.ts +8 -8
- package/src/Field/StandAloneInput.tsx +55 -55
- package/src/Field/useStandardField.ts +125 -125
- package/src/FieldArray/FieldArray.tsx +154 -154
- package/src/File/FileGroup.test.tsx +35 -35
- package/src/File/FileGroup.tsx +85 -85
- package/src/File/FileList.tsx +21 -21
- package/src/File/__snapshots__/FileGroup.test.tsx.snap +34 -34
- package/src/File/humanFileSize.ts +8 -8
- package/src/Form/FocusError.tsx +55 -55
- package/src/Form/Form.test.tsx +14 -14
- package/src/Form/Form.tsx +237 -237
- package/src/Form/FormBasedPreventNavigation.tsx +56 -56
- package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -77
- package/src/Form/NewFormBasedPreventNavigation.tsx +59 -59
- package/src/Form/ServerErrorContext.ts +18 -18
- package/src/Form/__snapshots__/Form.test.tsx.snap +10 -10
- package/src/FormActions.tsx +47 -47
- package/src/FormDefaults.ts +2 -2
- package/src/Group.tsx +62 -62
- package/src/Input/CheckboxGroup.tsx +60 -0
- package/src/Input/CheckboxInputGroup.tsx +78 -0
- package/src/Input/IconInputGroup.tsx +54 -54
- package/src/Input/InputGroup.tsx +72 -72
- package/src/Input/MoneyInputGroup.tsx +50 -50
- package/src/Input/NumberInputGroup.tsx +48 -48
- package/src/Input/PhoneNumberInputGroup.tsx +45 -45
- package/src/Input/StringInputGroup.tsx +53 -53
- package/src/Input/__Tests__/CheckboxInputGroup.test.tsx +26 -0
- package/src/Input/__Tests__/IconInputGroup.test.tsx +35 -35
- package/src/Input/__Tests__/MoneyInputGroup.test.tsx +37 -37
- package/src/Input/__Tests__/NumberInputGroup.test.tsx +35 -35
- package/src/Input/__Tests__/PhoneNumberInputGroup.test.tsx +36 -36
- package/src/Input/__Tests__/StringInputGroup.test.tsx +27 -27
- package/src/Input/__Tests__/__snapshots__/CheckboxInputGroup.test.tsx.snap +33 -0
- package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +32 -32
- package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +34 -34
- package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +32 -32
- package/src/Input/__Tests__/__snapshots__/PhoneNumberInputGroup.test.tsx.snap +33 -33
- package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +31 -31
- package/src/Normalization/NormalizationFunction.ts +4 -4
- package/src/Normalization/normalizers.ts +44 -44
- package/src/Select/BooleanSelectGroup.tsx +28 -28
- package/src/Select/NumberSelectGroup.tsx +16 -16
- package/src/Select/SelectGroup.tsx +124 -124
- package/src/Select/SelectGroupPropsHelper.ts +4 -4
- package/src/Select/StringSelectGroup.tsx +16 -16
- package/src/Select/__tests__/BooleanSelectGroup.test.tsx +35 -35
- package/src/Select/__tests__/NumberSelectGroup.test.tsx +87 -87
- package/src/Select/__tests__/StringSelectGroup.test.tsx +89 -89
- package/src/Select/__tests__/__snapshots__/BooleanSelectGroup.test.tsx.snap +98 -98
- package/src/Select/__tests__/__snapshots__/NumberSelectGroup.test.tsx.snap +195 -195
- package/src/Select/__tests__/__snapshots__/StringSelectGroup.test.tsx.snap +195 -195
- package/src/StandardFormActions.tsx +41 -41
- package/src/SubmitFormButton.tsx +54 -54
- package/src/TextArea/TextAreaGroup.tsx +64 -64
- package/src/Validation/ValidatedApiResult.ts +8 -8
- package/src/Validation/ValidationError.ts +6 -6
- package/src/Validation/ValidationFunction.ts +4 -4
- package/src/Validation/validators.test.tsx +81 -81
- package/src/Validation/validators.ts +97 -97
- package/src/__Tests__/FormTestBase.tsx +65 -64
- package/src/__Tests__/RealisticForm.test.tsx +82 -82
- package/src/__Tests__/StandardFormActions.test.tsx +17 -17
- package/src/__Tests__/SubmitFormButton.test.tsx +17 -17
- package/src/__Tests__/__snapshots__/StandardFormActions.test.tsx.snap +27 -27
- package/src/__Tests__/__snapshots__/SubmitFormButton.test.tsx.snap +20 -20
- package/src/__Tests__/index.ts +3 -3
- package/src/_variables.scss +11 -11
- package/src/index.ts +156 -153
- package/src/react-app-env.d.ts +1 -1
- package/src/setupTests.ts +1 -1
- package/src/utils/objectContainsNonSerializableProperty.test.tsx +49 -49
- package/src/utils/objectContainsNonSerializableProperty.ts +17 -17
- package/src/utils/objectToFormData.test.tsx +76 -76
- package/src/utils/objectToFormData.ts +105 -105
- package/src/utils/typeChecks.ts +18 -18
@@ -0,0 +1,78 @@
|
|
1
|
+
import React, { LegacyRef } from 'react';
|
2
|
+
import classNames from 'classnames';
|
3
|
+
import CheckboxGroup from './CheckboxGroup';
|
4
|
+
import { InputGroupProps } from './InputGroup';
|
5
|
+
import { FormDefaults } from '../FormDefaults';
|
6
|
+
|
7
|
+
export interface CheckboxInputGroupProps
|
8
|
+
extends Omit<
|
9
|
+
InputGroupProps<boolean | undefined | null>,
|
10
|
+
'onChange' | 'type' | 'value'
|
11
|
+
> {
|
12
|
+
labelOnLeft?: boolean;
|
13
|
+
}
|
14
|
+
|
15
|
+
function CheckboxInputGroup(
|
16
|
+
{
|
17
|
+
input,
|
18
|
+
meta,
|
19
|
+
disabled,
|
20
|
+
label,
|
21
|
+
required,
|
22
|
+
helpText,
|
23
|
+
className,
|
24
|
+
labelOnLeft,
|
25
|
+
...rest
|
26
|
+
}: CheckboxInputGroupProps,
|
27
|
+
ref: LegacyRef<HTMLInputElement>
|
28
|
+
) {
|
29
|
+
return (
|
30
|
+
<CheckboxGroup
|
31
|
+
input={input}
|
32
|
+
meta={meta}
|
33
|
+
disabled={disabled}
|
34
|
+
required={required}
|
35
|
+
label={label}
|
36
|
+
helpText={helpText}
|
37
|
+
labelOnLeft={labelOnLeft}
|
38
|
+
className={classNames(
|
39
|
+
className,
|
40
|
+
FormDefaults.cssClassPrefix + 'checkbox-group',
|
41
|
+
{ 'label-on-left': labelOnLeft },
|
42
|
+
{ 'label-on-right': !labelOnLeft }
|
43
|
+
)}>
|
44
|
+
<input
|
45
|
+
{...rest}
|
46
|
+
type="checkbox"
|
47
|
+
aria-invalid={!!meta.error}
|
48
|
+
aria-errormessage={!!meta.error ? `${input.name}-error` : undefined}
|
49
|
+
className={classNames(
|
50
|
+
className,
|
51
|
+
FormDefaults.cssClassPrefix + 'checkbox-group'
|
52
|
+
)}
|
53
|
+
checked={input.value === true}
|
54
|
+
onChange={(e) => {
|
55
|
+
input.onChange(e.target.checked);
|
56
|
+
}}
|
57
|
+
disabled={disabled}
|
58
|
+
required={required}
|
59
|
+
onBlur={input.onBlur}
|
60
|
+
id={input.id}
|
61
|
+
name={input.name}
|
62
|
+
ref={ref}
|
63
|
+
/>
|
64
|
+
</CheckboxGroup>
|
65
|
+
);
|
66
|
+
}
|
67
|
+
|
68
|
+
/** Standard checkbox input. Value defaults to `undefined` with no user input and no initial values.
|
69
|
+
*
|
70
|
+
* If the user should be required to decide yes / no before submission, consider using `BooleanSelectGroup`.
|
71
|
+
*
|
72
|
+
* If the user should be required to check the box before submission, use the `required` prop.
|
73
|
+
*/
|
74
|
+
const CheckboxInputGroupWithRef = React.forwardRef(
|
75
|
+
CheckboxInputGroup
|
76
|
+
) as React.ComponentType<CheckboxInputGroupProps>;
|
77
|
+
|
78
|
+
export default CheckboxInputGroupWithRef;
|
@@ -1,54 +1,54 @@
|
|
1
|
-
import React, { LegacyRef } from 'react';
|
2
|
-
import classNames from 'classnames';
|
3
|
-
import InputGroupWithRef, { InputGroupProps } from './InputGroup';
|
4
|
-
import { FormDefaults } from '../FormDefaults';
|
5
|
-
|
6
|
-
// TODO: make className tailwind-able instead of css. make it typeof string ????
|
7
|
-
// or should we just give a div a className and let each project decide? (this seems to be the patern)
|
8
|
-
export interface IconInputGroupProps
|
9
|
-
extends Omit<
|
10
|
-
InputGroupProps<string | undefined | null>,
|
11
|
-
'onChange' | 'type' | 'value'
|
12
|
-
> {
|
13
|
-
type?: 'color' | 'email' | 'search' | 'tel' | 'text' | 'url';
|
14
|
-
/** Icon to display on the input group. */
|
15
|
-
icon: React.ReactNode;
|
16
|
-
/** Text to display after the input group to give more information to the user. */
|
17
|
-
helpText?: string;
|
18
|
-
}
|
19
|
-
|
20
|
-
function IconInputGroup(
|
21
|
-
{ icon, className, ...rest }: IconInputGroupProps,
|
22
|
-
ref: LegacyRef<HTMLInputElement>
|
23
|
-
) {
|
24
|
-
const { input } = rest;
|
25
|
-
|
26
|
-
return (
|
27
|
-
<>
|
28
|
-
<InputGroupWithRef
|
29
|
-
icon={icon}
|
30
|
-
ref={ref}
|
31
|
-
className={classNames(
|
32
|
-
className,
|
33
|
-
FormDefaults.cssClassPrefix + 'icon-input-group'
|
34
|
-
)}
|
35
|
-
value={input.value ?? ''}
|
36
|
-
onChange={(e) => {
|
37
|
-
if (!e.target.value) {
|
38
|
-
input.onChange(undefined);
|
39
|
-
} else {
|
40
|
-
input.onChange(e.target.value);
|
41
|
-
}
|
42
|
-
}}
|
43
|
-
{...rest}
|
44
|
-
/>
|
45
|
-
</>
|
46
|
-
);
|
47
|
-
}
|
48
|
-
|
49
|
-
/** Input group with an icon. */
|
50
|
-
const IconInputGroupWithRef = React.forwardRef(
|
51
|
-
IconInputGroup
|
52
|
-
) as React.ComponentType<IconInputGroupProps>;
|
53
|
-
|
54
|
-
export default IconInputGroupWithRef;
|
1
|
+
import React, { LegacyRef } from 'react';
|
2
|
+
import classNames from 'classnames';
|
3
|
+
import InputGroupWithRef, { InputGroupProps } from './InputGroup';
|
4
|
+
import { FormDefaults } from '../FormDefaults';
|
5
|
+
|
6
|
+
// TODO: make className tailwind-able instead of css. make it typeof string ????
|
7
|
+
// or should we just give a div a className and let each project decide? (this seems to be the patern)
|
8
|
+
export interface IconInputGroupProps
|
9
|
+
extends Omit<
|
10
|
+
InputGroupProps<string | undefined | null>,
|
11
|
+
'onChange' | 'type' | 'value'
|
12
|
+
> {
|
13
|
+
type?: 'color' | 'email' | 'search' | 'tel' | 'text' | 'url';
|
14
|
+
/** Icon to display on the input group. */
|
15
|
+
icon: React.ReactNode;
|
16
|
+
/** Text to display after the input group to give more information to the user. */
|
17
|
+
helpText?: string;
|
18
|
+
}
|
19
|
+
|
20
|
+
function IconInputGroup(
|
21
|
+
{ icon, className, ...rest }: IconInputGroupProps,
|
22
|
+
ref: LegacyRef<HTMLInputElement>
|
23
|
+
) {
|
24
|
+
const { input } = rest;
|
25
|
+
|
26
|
+
return (
|
27
|
+
<>
|
28
|
+
<InputGroupWithRef
|
29
|
+
icon={icon}
|
30
|
+
ref={ref}
|
31
|
+
className={classNames(
|
32
|
+
className,
|
33
|
+
FormDefaults.cssClassPrefix + 'icon-input-group'
|
34
|
+
)}
|
35
|
+
value={input.value ?? ''}
|
36
|
+
onChange={(e) => {
|
37
|
+
if (!e.target.value) {
|
38
|
+
input.onChange(undefined);
|
39
|
+
} else {
|
40
|
+
input.onChange(e.target.value);
|
41
|
+
}
|
42
|
+
}}
|
43
|
+
{...rest}
|
44
|
+
/>
|
45
|
+
</>
|
46
|
+
);
|
47
|
+
}
|
48
|
+
|
49
|
+
/** Input group with an icon. */
|
50
|
+
const IconInputGroupWithRef = React.forwardRef(
|
51
|
+
IconInputGroup
|
52
|
+
) as React.ComponentType<IconInputGroupProps>;
|
53
|
+
|
54
|
+
export default IconInputGroupWithRef;
|
package/src/Input/InputGroup.tsx
CHANGED
@@ -1,72 +1,72 @@
|
|
1
|
-
import React, { ChangeEventHandler, LegacyRef } from 'react';
|
2
|
-
import classNames from 'classnames';
|
3
|
-
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
4
|
-
import { FormDefaults } from '../FormDefaults';
|
5
|
-
import Group, { GroupProps } from '../Group';
|
6
|
-
|
7
|
-
export interface InputGroupProps<TValue>
|
8
|
-
extends InjectedFieldProps<TValue>,
|
9
|
-
Omit<
|
10
|
-
React.HTMLProps<HTMLInputElement>,
|
11
|
-
| keyof InjectedFieldProps<any>
|
12
|
-
| 'children'
|
13
|
-
| 'className'
|
14
|
-
| 'label'
|
15
|
-
| 'value'
|
16
|
-
>,
|
17
|
-
Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
|
18
|
-
onChange: ChangeEventHandler<HTMLInputElement>;
|
19
|
-
value: string | number | null | undefined;
|
20
|
-
icon?: React.ReactNode;
|
21
|
-
}
|
22
|
-
|
23
|
-
function InputGroup<TValue>(
|
24
|
-
{
|
25
|
-
input,
|
26
|
-
meta,
|
27
|
-
label,
|
28
|
-
helpText,
|
29
|
-
className,
|
30
|
-
required,
|
31
|
-
disabled,
|
32
|
-
onChange,
|
33
|
-
value,
|
34
|
-
icon,
|
35
|
-
...rest
|
36
|
-
}: InputGroupProps<TValue>,
|
37
|
-
ref: LegacyRef<HTMLInputElement>
|
38
|
-
) {
|
39
|
-
return (
|
40
|
-
<Group
|
41
|
-
input={input}
|
42
|
-
meta={meta}
|
43
|
-
required={required}
|
44
|
-
disabled={disabled}
|
45
|
-
label={label}
|
46
|
-
helpText={helpText}
|
47
|
-
className={classNames(
|
48
|
-
className,
|
49
|
-
FormDefaults.cssClassPrefix + 'input-group'
|
50
|
-
)}>
|
51
|
-
{icon}
|
52
|
-
<input
|
53
|
-
{...input}
|
54
|
-
{...rest}
|
55
|
-
aria-invalid={!!meta.error}
|
56
|
-
aria-errormessage={!!meta.error ? `${input.name}-error` : undefined}
|
57
|
-
value={value ?? ''}
|
58
|
-
onChange={onChange}
|
59
|
-
ref={ref}
|
60
|
-
className={classNames(
|
61
|
-
className,
|
62
|
-
FormDefaults.cssClassPrefix + 'input-group'
|
63
|
-
)}
|
64
|
-
/>
|
65
|
-
</Group>
|
66
|
-
);
|
67
|
-
}
|
68
|
-
|
69
|
-
/** Generic controlled `<input/>` wrapped by a `<Group/>` */
|
70
|
-
const InputGroupWithRef = React.forwardRef(InputGroup) as typeof InputGroup;
|
71
|
-
|
72
|
-
export default InputGroupWithRef;
|
1
|
+
import React, { ChangeEventHandler, LegacyRef } from 'react';
|
2
|
+
import classNames from 'classnames';
|
3
|
+
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
4
|
+
import { FormDefaults } from '../FormDefaults';
|
5
|
+
import Group, { GroupProps } from '../Group';
|
6
|
+
|
7
|
+
export interface InputGroupProps<TValue>
|
8
|
+
extends InjectedFieldProps<TValue>,
|
9
|
+
Omit<
|
10
|
+
React.HTMLProps<HTMLInputElement>,
|
11
|
+
| keyof InjectedFieldProps<any>
|
12
|
+
| 'children'
|
13
|
+
| 'className'
|
14
|
+
| 'label'
|
15
|
+
| 'value'
|
16
|
+
>,
|
17
|
+
Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
|
18
|
+
onChange: ChangeEventHandler<HTMLInputElement>;
|
19
|
+
value: string | number | null | undefined;
|
20
|
+
icon?: React.ReactNode;
|
21
|
+
}
|
22
|
+
|
23
|
+
function InputGroup<TValue>(
|
24
|
+
{
|
25
|
+
input,
|
26
|
+
meta,
|
27
|
+
label,
|
28
|
+
helpText,
|
29
|
+
className,
|
30
|
+
required,
|
31
|
+
disabled,
|
32
|
+
onChange,
|
33
|
+
value,
|
34
|
+
icon,
|
35
|
+
...rest
|
36
|
+
}: InputGroupProps<TValue>,
|
37
|
+
ref: LegacyRef<HTMLInputElement>
|
38
|
+
) {
|
39
|
+
return (
|
40
|
+
<Group
|
41
|
+
input={input}
|
42
|
+
meta={meta}
|
43
|
+
required={required}
|
44
|
+
disabled={disabled}
|
45
|
+
label={label}
|
46
|
+
helpText={helpText}
|
47
|
+
className={classNames(
|
48
|
+
className,
|
49
|
+
FormDefaults.cssClassPrefix + 'input-group'
|
50
|
+
)}>
|
51
|
+
{icon}
|
52
|
+
<input
|
53
|
+
{...input}
|
54
|
+
{...rest}
|
55
|
+
aria-invalid={!!meta.error}
|
56
|
+
aria-errormessage={!!meta.error ? `${input.name}-error` : undefined}
|
57
|
+
value={value ?? ''}
|
58
|
+
onChange={onChange}
|
59
|
+
ref={ref}
|
60
|
+
className={classNames(
|
61
|
+
className,
|
62
|
+
FormDefaults.cssClassPrefix + 'input-group'
|
63
|
+
)}
|
64
|
+
/>
|
65
|
+
</Group>
|
66
|
+
);
|
67
|
+
}
|
68
|
+
|
69
|
+
/** Generic controlled `<input/>` wrapped by a `<Group/>` */
|
70
|
+
const InputGroupWithRef = React.forwardRef(InputGroup) as typeof InputGroup;
|
71
|
+
|
72
|
+
export default InputGroupWithRef;
|
@@ -1,50 +1,50 @@
|
|
1
|
-
import React, { LegacyRef } from 'react';
|
2
|
-
import classNames from 'classnames';
|
3
|
-
import InputGroup, { InputGroupProps } from './InputGroup';
|
4
|
-
import { FormDefaults } from '../FormDefaults';
|
5
|
-
|
6
|
-
export interface MoneyInputGroupProps
|
7
|
-
extends Omit<
|
8
|
-
InputGroupProps<number | undefined | null>,
|
9
|
-
'onChange' | 'type' | 'value'
|
10
|
-
> {
|
11
|
-
/** Custom parsing function when the value changes. */
|
12
|
-
parseFunc?: typeof parseInt | typeof parseFloat;
|
13
|
-
}
|
14
|
-
|
15
|
-
function MoneyInputGroup(
|
16
|
-
{ parseFunc, className, ...rest }: MoneyInputGroupProps,
|
17
|
-
ref: LegacyRef<HTMLInputElement>
|
18
|
-
) {
|
19
|
-
const effectiveParse = parseFunc ?? parseFloat;
|
20
|
-
const { input } = rest;
|
21
|
-
|
22
|
-
return (
|
23
|
-
<InputGroup
|
24
|
-
ref={ref}
|
25
|
-
step={0.01}
|
26
|
-
min={0}
|
27
|
-
{...rest}
|
28
|
-
type="number"
|
29
|
-
className={classNames(
|
30
|
-
className,
|
31
|
-
FormDefaults.cssClassPrefix + 'money-group'
|
32
|
-
)}
|
33
|
-
value={input.value || ''}
|
34
|
-
onChange={(e) => {
|
35
|
-
if (!e.target.value) {
|
36
|
-
input.onChange(undefined);
|
37
|
-
} else {
|
38
|
-
input.onChange(effectiveParse(e.target.value));
|
39
|
-
}
|
40
|
-
}}
|
41
|
-
/>
|
42
|
-
);
|
43
|
-
}
|
44
|
-
|
45
|
-
/** Input group for inputting money. */
|
46
|
-
const MoneyInputGroupWithRef = React.forwardRef(
|
47
|
-
MoneyInputGroup
|
48
|
-
) as React.FunctionComponent<MoneyInputGroupProps>;
|
49
|
-
|
50
|
-
export default MoneyInputGroupWithRef;
|
1
|
+
import React, { LegacyRef } from 'react';
|
2
|
+
import classNames from 'classnames';
|
3
|
+
import InputGroup, { InputGroupProps } from './InputGroup';
|
4
|
+
import { FormDefaults } from '../FormDefaults';
|
5
|
+
|
6
|
+
export interface MoneyInputGroupProps
|
7
|
+
extends Omit<
|
8
|
+
InputGroupProps<number | undefined | null>,
|
9
|
+
'onChange' | 'type' | 'value'
|
10
|
+
> {
|
11
|
+
/** Custom parsing function when the value changes. */
|
12
|
+
parseFunc?: typeof parseInt | typeof parseFloat;
|
13
|
+
}
|
14
|
+
|
15
|
+
function MoneyInputGroup(
|
16
|
+
{ parseFunc, className, ...rest }: MoneyInputGroupProps,
|
17
|
+
ref: LegacyRef<HTMLInputElement>
|
18
|
+
) {
|
19
|
+
const effectiveParse = parseFunc ?? parseFloat;
|
20
|
+
const { input } = rest;
|
21
|
+
|
22
|
+
return (
|
23
|
+
<InputGroup
|
24
|
+
ref={ref}
|
25
|
+
step={0.01}
|
26
|
+
min={0}
|
27
|
+
{...rest}
|
28
|
+
type="number"
|
29
|
+
className={classNames(
|
30
|
+
className,
|
31
|
+
FormDefaults.cssClassPrefix + 'money-group'
|
32
|
+
)}
|
33
|
+
value={input.value || ''}
|
34
|
+
onChange={(e) => {
|
35
|
+
if (!e.target.value) {
|
36
|
+
input.onChange(undefined);
|
37
|
+
} else {
|
38
|
+
input.onChange(effectiveParse(e.target.value));
|
39
|
+
}
|
40
|
+
}}
|
41
|
+
/>
|
42
|
+
);
|
43
|
+
}
|
44
|
+
|
45
|
+
/** Input group for inputting money. */
|
46
|
+
const MoneyInputGroupWithRef = React.forwardRef(
|
47
|
+
MoneyInputGroup
|
48
|
+
) as React.FunctionComponent<MoneyInputGroupProps>;
|
49
|
+
|
50
|
+
export default MoneyInputGroupWithRef;
|
@@ -1,48 +1,48 @@
|
|
1
|
-
import React, { LegacyRef } from 'react';
|
2
|
-
import classNames from 'classnames';
|
3
|
-
import InputGroup, { InputGroupProps } from './InputGroup';
|
4
|
-
import { FormDefaults } from '../FormDefaults';
|
5
|
-
|
6
|
-
export interface NumberInputGroupProps
|
7
|
-
extends Omit<
|
8
|
-
InputGroupProps<number | undefined | null>,
|
9
|
-
'onChange' | 'type' | 'value'
|
10
|
-
> {
|
11
|
-
/** Custom parsing function when the value changes. */
|
12
|
-
parseFunc?: typeof parseInt | typeof parseFloat;
|
13
|
-
}
|
14
|
-
|
15
|
-
function NumberInputGroup(
|
16
|
-
{ parseFunc, className, ...rest }: NumberInputGroupProps,
|
17
|
-
ref: LegacyRef<HTMLInputElement>
|
18
|
-
) {
|
19
|
-
const effectiveParse = parseFunc ?? parseFloat;
|
20
|
-
const { input } = rest;
|
21
|
-
|
22
|
-
return (
|
23
|
-
<InputGroup
|
24
|
-
ref={ref}
|
25
|
-
{...rest}
|
26
|
-
type="number"
|
27
|
-
className={classNames(
|
28
|
-
className,
|
29
|
-
FormDefaults.cssClassPrefix + 'number-group'
|
30
|
-
)}
|
31
|
-
value={input.value || ''}
|
32
|
-
onChange={(e) => {
|
33
|
-
if (!e.target.value) {
|
34
|
-
input.onChange(undefined);
|
35
|
-
} else {
|
36
|
-
input.onChange(effectiveParse(e.target.value));
|
37
|
-
}
|
38
|
-
}}
|
39
|
-
/>
|
40
|
-
);
|
41
|
-
}
|
42
|
-
|
43
|
-
/** Standard number input group. By default allows for float values. */
|
44
|
-
const NumberInputGroupWithRef = React.forwardRef(
|
45
|
-
NumberInputGroup
|
46
|
-
) as React.ComponentType<NumberInputGroupProps>;
|
47
|
-
|
48
|
-
export default NumberInputGroupWithRef;
|
1
|
+
import React, { LegacyRef } from 'react';
|
2
|
+
import classNames from 'classnames';
|
3
|
+
import InputGroup, { InputGroupProps } from './InputGroup';
|
4
|
+
import { FormDefaults } from '../FormDefaults';
|
5
|
+
|
6
|
+
export interface NumberInputGroupProps
|
7
|
+
extends Omit<
|
8
|
+
InputGroupProps<number | undefined | null>,
|
9
|
+
'onChange' | 'type' | 'value'
|
10
|
+
> {
|
11
|
+
/** Custom parsing function when the value changes. */
|
12
|
+
parseFunc?: typeof parseInt | typeof parseFloat;
|
13
|
+
}
|
14
|
+
|
15
|
+
function NumberInputGroup(
|
16
|
+
{ parseFunc, className, ...rest }: NumberInputGroupProps,
|
17
|
+
ref: LegacyRef<HTMLInputElement>
|
18
|
+
) {
|
19
|
+
const effectiveParse = parseFunc ?? parseFloat;
|
20
|
+
const { input } = rest;
|
21
|
+
|
22
|
+
return (
|
23
|
+
<InputGroup
|
24
|
+
ref={ref}
|
25
|
+
{...rest}
|
26
|
+
type="number"
|
27
|
+
className={classNames(
|
28
|
+
className,
|
29
|
+
FormDefaults.cssClassPrefix + 'number-group'
|
30
|
+
)}
|
31
|
+
value={input.value || ''}
|
32
|
+
onChange={(e) => {
|
33
|
+
if (!e.target.value) {
|
34
|
+
input.onChange(undefined);
|
35
|
+
} else {
|
36
|
+
input.onChange(effectiveParse(e.target.value));
|
37
|
+
}
|
38
|
+
}}
|
39
|
+
/>
|
40
|
+
);
|
41
|
+
}
|
42
|
+
|
43
|
+
/** Standard number input group. By default allows for float values. */
|
44
|
+
const NumberInputGroupWithRef = React.forwardRef(
|
45
|
+
NumberInputGroup
|
46
|
+
) as React.ComponentType<NumberInputGroupProps>;
|
47
|
+
|
48
|
+
export default NumberInputGroupWithRef;
|
@@ -1,45 +1,45 @@
|
|
1
|
-
import React, { LegacyRef } from 'react';
|
2
|
-
import classNames from 'classnames';
|
3
|
-
import InputGroup, { InputGroupProps } from './InputGroup';
|
4
|
-
import { FormDefaults } from '../FormDefaults';
|
5
|
-
import { phoneNumber } from '../Normalization/normalizers';
|
6
|
-
|
7
|
-
export interface PhoneNumberInputGroupProps
|
8
|
-
extends Omit<
|
9
|
-
InputGroupProps<string | undefined | null>,
|
10
|
-
'onChange' | 'type' | 'value'
|
11
|
-
> {}
|
12
|
-
function PhoneNumberInputGroup(
|
13
|
-
{ className, ...rest }: PhoneNumberInputGroupProps,
|
14
|
-
ref: LegacyRef<HTMLInputElement>
|
15
|
-
) {
|
16
|
-
const { input } = rest;
|
17
|
-
return (
|
18
|
-
<InputGroup
|
19
|
-
ref={ref}
|
20
|
-
autoComplete="tel-national"
|
21
|
-
{...rest}
|
22
|
-
type="text"
|
23
|
-
className={classNames(
|
24
|
-
className,
|
25
|
-
FormDefaults.cssClassPrefix + 'phone-number-group'
|
26
|
-
)}
|
27
|
-
value={input.value ?? ''}
|
28
|
-
onChange={(e) => {
|
29
|
-
if (!e.target.value) {
|
30
|
-
input.onChange(undefined);
|
31
|
-
} else {
|
32
|
-
input.onChange(phoneNumber(e.target.value));
|
33
|
-
}
|
34
|
-
}}
|
35
|
-
/>
|
36
|
-
);
|
37
|
-
}
|
38
|
-
/**A standard phone number input. Will display to the user in `+XXX XXX-XXX-XXXX` format as the number is being inputted.
|
39
|
-
* The data will get sent in the same format as displayed. Uses `normalizers.phoneNumber`.
|
40
|
-
* @default autoComplete="tel-national"
|
41
|
-
*/
|
42
|
-
const PhoneNumberInputGroupWithRef = React.forwardRef(
|
43
|
-
PhoneNumberInputGroup
|
44
|
-
) as React.ComponentType<PhoneNumberInputGroupProps>;
|
45
|
-
export default PhoneNumberInputGroupWithRef;
|
1
|
+
import React, { LegacyRef } from 'react';
|
2
|
+
import classNames from 'classnames';
|
3
|
+
import InputGroup, { InputGroupProps } from './InputGroup';
|
4
|
+
import { FormDefaults } from '../FormDefaults';
|
5
|
+
import { phoneNumber } from '../Normalization/normalizers';
|
6
|
+
|
7
|
+
export interface PhoneNumberInputGroupProps
|
8
|
+
extends Omit<
|
9
|
+
InputGroupProps<string | undefined | null>,
|
10
|
+
'onChange' | 'type' | 'value'
|
11
|
+
> {}
|
12
|
+
function PhoneNumberInputGroup(
|
13
|
+
{ className, ...rest }: PhoneNumberInputGroupProps,
|
14
|
+
ref: LegacyRef<HTMLInputElement>
|
15
|
+
) {
|
16
|
+
const { input } = rest;
|
17
|
+
return (
|
18
|
+
<InputGroup
|
19
|
+
ref={ref}
|
20
|
+
autoComplete="tel-national"
|
21
|
+
{...rest}
|
22
|
+
type="text"
|
23
|
+
className={classNames(
|
24
|
+
className,
|
25
|
+
FormDefaults.cssClassPrefix + 'phone-number-group'
|
26
|
+
)}
|
27
|
+
value={input.value ?? ''}
|
28
|
+
onChange={(e) => {
|
29
|
+
if (!e.target.value) {
|
30
|
+
input.onChange(undefined);
|
31
|
+
} else {
|
32
|
+
input.onChange(phoneNumber(e.target.value));
|
33
|
+
}
|
34
|
+
}}
|
35
|
+
/>
|
36
|
+
);
|
37
|
+
}
|
38
|
+
/**A standard phone number input. Will display to the user in `+XXX XXX-XXX-XXXX` format as the number is being inputted.
|
39
|
+
* The data will get sent in the same format as displayed. Uses `normalizers.phoneNumber`.
|
40
|
+
* @default autoComplete="tel-national"
|
41
|
+
*/
|
42
|
+
const PhoneNumberInputGroupWithRef = React.forwardRef(
|
43
|
+
PhoneNumberInputGroup
|
44
|
+
) as React.ComponentType<PhoneNumberInputGroupProps>;
|
45
|
+
export default PhoneNumberInputGroupWithRef;
|