envoc-form 5.0.3 → 5.0.6

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.
Files changed (145) hide show
  1. package/README.md +163 -20
  2. package/es/ConfirmBaseForm/ConfirmBaseForm.js +2 -2
  3. package/es/DatePicker/DatePickerGroup.js +2 -2
  4. package/es/FieldArray/FieldArray.js +4 -4
  5. package/es/File/FileGroup.js +3 -3
  6. package/es/Form/Form.js +2 -2
  7. package/es/Group.js +3 -3
  8. package/es/Input/CheckboxGroup.d.ts +6 -0
  9. package/es/Input/CheckboxGroup.js +14 -0
  10. package/es/Input/CheckboxInputGroup.d.ts +13 -0
  11. package/es/Input/CheckboxInputGroup.js +41 -0
  12. package/es/Input/IconInputGroup.js +2 -2
  13. package/es/Input/InputGroup.js +2 -2
  14. package/es/Input/MoneyInputGroup.js +2 -2
  15. package/es/Input/NumberInputGroup.js +2 -2
  16. package/es/Input/PhoneNumberInputGroup.js +2 -2
  17. package/es/Input/StringInputGroup.js +2 -2
  18. package/es/Select/SelectGroup.js +3 -3
  19. package/es/StandardFormActions.js +3 -3
  20. package/es/SubmitFormButton.js +2 -2
  21. package/es/TextArea/TextAreaGroup.js +2 -2
  22. package/es/index.d.ts +2 -0
  23. package/es/index.js +1 -0
  24. package/lib/ConfirmBaseForm/ConfirmBaseForm.js +2 -5
  25. package/lib/DatePicker/DatePickerGroup.js +2 -2
  26. package/lib/FieldArray/FieldArray.js +4 -4
  27. package/lib/File/FileGroup.js +3 -3
  28. package/lib/Form/Form.js +2 -2
  29. package/lib/Group.js +3 -3
  30. package/lib/Input/CheckboxGroup.d.ts +6 -0
  31. package/lib/Input/CheckboxGroup.js +20 -0
  32. package/lib/Input/CheckboxInputGroup.d.ts +13 -0
  33. package/lib/Input/CheckboxInputGroup.js +46 -0
  34. package/lib/Input/IconInputGroup.js +2 -2
  35. package/lib/Input/InputGroup.js +2 -2
  36. package/lib/Input/MoneyInputGroup.js +2 -2
  37. package/lib/Input/NumberInputGroup.js +2 -2
  38. package/lib/Input/PhoneNumberInputGroup.js +2 -2
  39. package/lib/Input/StringInputGroup.js +2 -2
  40. package/lib/Select/SelectGroup.js +3 -3
  41. package/lib/StandardFormActions.js +3 -3
  42. package/lib/SubmitFormButton.js +2 -2
  43. package/lib/TextArea/TextAreaGroup.js +2 -2
  44. package/lib/index.d.ts +2 -0
  45. package/lib/index.js +3 -1
  46. package/package.json +111 -111
  47. package/src/AddressInput/AddressInput.test.tsx +27 -27
  48. package/src/AddressInput/AddressInput.tsx +82 -82
  49. package/src/AddressInput/UsStates.ts +55 -55
  50. package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +182 -182
  51. package/src/ConfirmBaseForm/ConfirmBaseForm.test.tsx +24 -24
  52. package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +74 -74
  53. package/src/ConfirmBaseForm/__snapshots__/ConfirmBaseForm.test.tsx.snap +23 -23
  54. package/src/ConfirmDeleteForm/ConfirmDeleteForm.test.tsx +24 -24
  55. package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +87 -87
  56. package/src/ConfirmDeleteForm/__snapshots__/ConfirmDeleteForm.test.tsx.snap +25 -25
  57. package/src/DatePicker/DatePicker.test.tsx +48 -48
  58. package/src/DatePicker/DatePickerGroup.tsx +109 -115
  59. package/src/DatePicker/DatePickerHelper.ts +4 -4
  60. package/src/DatePicker/StringDateOnlyPickerGroup.tsx +28 -28
  61. package/src/DatePicker/StringDatePickerGroup.tsx +20 -20
  62. package/src/DatePicker/__snapshots__/DatePicker.test.tsx.snap +152 -152
  63. package/src/Field/CustomFieldInputProps.ts +10 -10
  64. package/src/Field/CustomFieldMetaProps.ts +5 -5
  65. package/src/Field/Field.tsx +113 -113
  66. package/src/Field/FieldErrorScrollTarget.tsx +12 -12
  67. package/src/Field/FieldNameContext.ts +6 -6
  68. package/src/Field/FieldSection.tsx +18 -18
  69. package/src/Field/InjectedFieldProps.ts +8 -8
  70. package/src/Field/StandAloneInput.tsx +55 -55
  71. package/src/Field/useStandardField.ts +125 -125
  72. package/src/FieldArray/FieldArray.tsx +154 -154
  73. package/src/File/FileGroup.test.tsx +35 -35
  74. package/src/File/FileGroup.tsx +82 -85
  75. package/src/File/FileList.tsx +21 -21
  76. package/src/File/__snapshots__/FileGroup.test.tsx.snap +34 -34
  77. package/src/File/humanFileSize.ts +8 -8
  78. package/src/Form/FocusError.tsx +55 -55
  79. package/src/Form/Form.test.tsx +14 -14
  80. package/src/Form/Form.tsx +234 -237
  81. package/src/Form/FormBasedPreventNavigation.tsx +56 -56
  82. package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -77
  83. package/src/Form/NewFormBasedPreventNavigation.tsx +59 -59
  84. package/src/Form/ServerErrorContext.ts +18 -18
  85. package/src/Form/__snapshots__/Form.test.tsx.snap +10 -10
  86. package/src/FormActions.tsx +47 -47
  87. package/src/FormDefaults.ts +2 -2
  88. package/src/Group.tsx +62 -62
  89. package/src/Input/CheckboxGroup.tsx +60 -0
  90. package/src/Input/CheckboxInputGroup.tsx +78 -0
  91. package/src/Input/IconInputGroup.tsx +54 -54
  92. package/src/Input/InputGroup.tsx +66 -72
  93. package/src/Input/MoneyInputGroup.tsx +47 -50
  94. package/src/Input/NumberInputGroup.tsx +45 -48
  95. package/src/Input/PhoneNumberInputGroup.tsx +45 -45
  96. package/src/Input/StringInputGroup.tsx +50 -53
  97. package/src/Input/__Tests__/CheckboxInputGroup.test.tsx +26 -0
  98. package/src/Input/__Tests__/IconInputGroup.test.tsx +35 -35
  99. package/src/Input/__Tests__/MoneyInputGroup.test.tsx +37 -37
  100. package/src/Input/__Tests__/NumberInputGroup.test.tsx +35 -35
  101. package/src/Input/__Tests__/PhoneNumberInputGroup.test.tsx +36 -36
  102. package/src/Input/__Tests__/StringInputGroup.test.tsx +27 -27
  103. package/src/Input/__Tests__/__snapshots__/CheckboxInputGroup.test.tsx.snap +33 -0
  104. package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +32 -32
  105. package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +34 -34
  106. package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +32 -32
  107. package/src/Input/__Tests__/__snapshots__/PhoneNumberInputGroup.test.tsx.snap +33 -33
  108. package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +31 -31
  109. package/src/Normalization/NormalizationFunction.ts +4 -4
  110. package/src/Normalization/normalizers.ts +44 -44
  111. package/src/Select/BooleanSelectGroup.tsx +28 -28
  112. package/src/Select/NumberSelectGroup.tsx +16 -16
  113. package/src/Select/SelectGroup.tsx +124 -124
  114. package/src/Select/SelectGroupPropsHelper.ts +4 -4
  115. package/src/Select/StringSelectGroup.tsx +16 -16
  116. package/src/Select/__tests__/BooleanSelectGroup.test.tsx +35 -35
  117. package/src/Select/__tests__/NumberSelectGroup.test.tsx +87 -87
  118. package/src/Select/__tests__/StringSelectGroup.test.tsx +89 -89
  119. package/src/Select/__tests__/__snapshots__/BooleanSelectGroup.test.tsx.snap +98 -98
  120. package/src/Select/__tests__/__snapshots__/NumberSelectGroup.test.tsx.snap +195 -195
  121. package/src/Select/__tests__/__snapshots__/StringSelectGroup.test.tsx.snap +195 -195
  122. package/src/StandardFormActions.tsx +41 -41
  123. package/src/SubmitFormButton.tsx +54 -54
  124. package/src/TextArea/TextAreaGroup.tsx +64 -64
  125. package/src/Validation/ValidatedApiResult.ts +8 -8
  126. package/src/Validation/ValidationError.ts +6 -6
  127. package/src/Validation/ValidationFunction.ts +4 -4
  128. package/src/Validation/validators.test.tsx +81 -81
  129. package/src/Validation/validators.ts +97 -97
  130. package/src/__Tests__/FormTestBase.tsx +65 -64
  131. package/src/__Tests__/RealisticForm.test.tsx +82 -82
  132. package/src/__Tests__/StandardFormActions.test.tsx +17 -17
  133. package/src/__Tests__/SubmitFormButton.test.tsx +17 -17
  134. package/src/__Tests__/__snapshots__/StandardFormActions.test.tsx.snap +27 -27
  135. package/src/__Tests__/__snapshots__/SubmitFormButton.test.tsx.snap +20 -20
  136. package/src/__Tests__/index.ts +3 -3
  137. package/src/_variables.scss +11 -11
  138. package/src/index.ts +156 -153
  139. package/src/react-app-env.d.ts +1 -1
  140. package/src/setupTests.ts +1 -1
  141. package/src/utils/objectContainsNonSerializableProperty.test.tsx +49 -49
  142. package/src/utils/objectContainsNonSerializableProperty.ts +17 -17
  143. package/src/utils/objectToFormData.test.tsx +76 -76
  144. package/src/utils/objectToFormData.ts +105 -105
  145. package/src/utils/typeChecks.ts +18 -18
@@ -0,0 +1,78 @@
1
+ import React, { LegacyRef } from 'react';
2
+ import { clsx } from 'clsx';
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={clsx(
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={clsx(
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 { clsx } from 'clsx';
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={clsx(
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,72 +1,66 @@
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 { clsx } from 'clsx';
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={clsx(className, FormDefaults.cssClassPrefix + 'input-group')}>
48
+ {icon}
49
+ <input
50
+ {...input}
51
+ {...rest}
52
+ aria-invalid={!!meta.error}
53
+ aria-errormessage={!!meta.error ? `${input.name}-error` : undefined}
54
+ value={value ?? ''}
55
+ onChange={onChange}
56
+ ref={ref}
57
+ className={clsx(className, FormDefaults.cssClassPrefix + 'input-group')}
58
+ />
59
+ </Group>
60
+ );
61
+ }
62
+
63
+ /** Generic controlled `<input/>` wrapped by a `<Group/>` */
64
+ const InputGroupWithRef = React.forwardRef(InputGroup) as typeof InputGroup;
65
+
66
+ export default InputGroupWithRef;
@@ -1,50 +1,47 @@
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 { clsx } from 'clsx';
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={clsx(className, FormDefaults.cssClassPrefix + 'money-group')}
30
+ value={input.value || ''}
31
+ onChange={(e) => {
32
+ if (!e.target.value) {
33
+ input.onChange(undefined);
34
+ } else {
35
+ input.onChange(effectiveParse(e.target.value));
36
+ }
37
+ }}
38
+ />
39
+ );
40
+ }
41
+
42
+ /** Input group for inputting money. */
43
+ const MoneyInputGroupWithRef = React.forwardRef(
44
+ MoneyInputGroup
45
+ ) as React.FunctionComponent<MoneyInputGroupProps>;
46
+
47
+ export default MoneyInputGroupWithRef;
@@ -1,48 +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
-
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 { clsx } from 'clsx';
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={clsx(className, FormDefaults.cssClassPrefix + 'number-group')}
28
+ value={input.value || ''}
29
+ onChange={(e) => {
30
+ if (!e.target.value) {
31
+ input.onChange(undefined);
32
+ } else {
33
+ input.onChange(effectiveParse(e.target.value));
34
+ }
35
+ }}
36
+ />
37
+ );
38
+ }
39
+
40
+ /** Standard number input group. By default allows for float values. */
41
+ const NumberInputGroupWithRef = React.forwardRef(
42
+ NumberInputGroup
43
+ ) as React.ComponentType<NumberInputGroupProps>;
44
+
45
+ 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 { clsx } from 'clsx';
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={clsx(
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;