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
package/package.json CHANGED
@@ -1,111 +1,111 @@
1
- {
2
- "name": "envoc-form",
3
- "version": "5.0.3",
4
- "description": "Envoc form components",
5
- "keywords": [
6
- "react-component",
7
- "react",
8
- "forms",
9
- "components",
10
- "envoc"
11
- ],
12
- "homepage": "",
13
- "repository": "",
14
- "license": "MIT",
15
- "author": "Envoc Developers",
16
- "sideEffects": false,
17
- "main": "lib/index.js",
18
- "module": "es/index.js",
19
- "files": [
20
- "dist",
21
- "src",
22
- "lib",
23
- "es"
24
- ],
25
- "scripts": {
26
- "build": "yarn verify-imports && yarn build:esm && yarn build:cjs && yarn build:css && yarn build:docs",
27
- "rebuild": "rimraf ./{dist,es,lib} && yarn build",
28
- "build:esm": "cross-env BABEL_ENV=esm-dir tsc -p tsconfig.esm.json",
29
- "build:css": "sass src/styles.scss dist/css/envoc-form-styles.css",
30
- "build:cjs": "tsc -p tsconfig.cjs.json",
31
- "build:docs": "yarn rimraf README.md && yarn typedoc --options typedoc.json src/index.ts && npx concat-md --decrease-title-levels --dir-name-as-title docs > README.md && cls && yarn rimraf docs",
32
- "verify-imports": "node ../../scripts/check-for-scss-imports.js envoc-form",
33
- "start": "webpack serve --config ./webpack.demo.config.js",
34
- "test": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts test --watchAll=false",
35
- "coverage": "yarn test --verbose --reporters=default --reporters=jest-junit --coverage --coverageReporters=cobertura"
36
- },
37
- "dependencies": {
38
- "axios": "^0.21.1",
39
- "classnames": "^2.3.1",
40
- "date-fns": "^2.22.1",
41
- "envoc-request": "^5.0.3",
42
- "lru-cache": "^6.0.0",
43
- "prop-types": "^15.7.2",
44
- "react-date-picker": "^8.2.0",
45
- "react-dropzone": "^11.3.4",
46
- "react-router": "^6.2.1",
47
- "react-select": "^5.2.2",
48
- "react-textarea-autosize": "^8.3.3",
49
- "react-toastify": "^7.0.4",
50
- "reactstrap": "^8.9.0",
51
- "history": "^5.2.0",
52
- "smoothscroll-polyfill": "^0.4.4",
53
- "uuid": "^8.3.2",
54
- "@fortawesome/react-fontawesome": "~0.1.16",
55
- "@fortawesome/free-solid-svg-icons": "~5.15.4",
56
- "@fortawesome/fontawesome-svg-core": "~1.2.36"
57
- },
58
- "devDependencies": {
59
- "@babel/cli": "^7.14.5",
60
- "@babel/core": "^7.14.6",
61
- "@babel/plugin-transform-runtime": "^7.14.5",
62
- "@babel/preset-env": "^7.14.7",
63
- "@babel/preset-react": "^7.14.5",
64
- "@testing-library/jest-dom": "^5.14.1",
65
- "@testing-library/react": "^11.2.5",
66
- "@testing-library/user-event": "^12.7.1",
67
- "@types/jest": "^26.0.24",
68
- "@types/react": "~18",
69
- "@types/testing-library__jest-dom": "5.14.5",
70
- "@types/smoothscroll-polyfill": "^0.3.1",
71
- "@types/uuid": "^8.3.2",
72
- "babel-loader": "^8.2.2",
73
- "bootstrap": "^4.6.0",
74
- "clean-webpack-plugin": "^3.0.0",
75
- "cross-env": "7.0.3",
76
- "css-loader": "^5.0.2",
77
- "eslint": "^8.32.0",
78
- "eslint-config-react-app": "^7.0.1",
79
- "html-webpack-plugin": "^5.3.2",
80
- "identity-obj-proxy": "^3.0.0",
81
- "jest-junit": "~12.2.0",
82
- "react": "~18",
83
- "react-dom": "~18",
84
- "react-router-dom": "^6.2.1",
85
- "react-scripts": "^4.0.3",
86
- "rimraf": "~3.0.2",
87
- "sass": "^1.35.2",
88
- "sass-loader": "^11.0.1",
89
- "style-loader": "^2.0.0",
90
- "webpack": "^5.45.0",
91
- "webpack-cli": "^4.7.2",
92
- "webpack-dev-server": "^3.11.2",
93
- "ts-loader": "^9.2.8",
94
- "typescript": "^5.1.6",
95
- "typedoc-plugin-markdown": "^3.15.0",
96
- "typedoc": "^0.24.1",
97
- "concat-md": "~0.3.5"
98
- },
99
- "peerDependencies": {
100
- "@babel/runtime": "^7.14.6",
101
- "formik": "^2.2.9",
102
- "react": ">=18",
103
- "react-dom": ">=18",
104
- "react-router-dom": "^6.2.1"
105
- },
106
- "jest": {
107
- "transformIgnorePatterns": [
108
- "^.+\\.module\\.(css|sass|scss)$"
109
- ]
110
- }
111
- }
1
+ {
2
+ "name": "envoc-form",
3
+ "version": "5.0.6",
4
+ "description": "Envoc form components",
5
+ "keywords": [
6
+ "react-component",
7
+ "react",
8
+ "forms",
9
+ "components",
10
+ "envoc"
11
+ ],
12
+ "homepage": "",
13
+ "repository": "",
14
+ "license": "MIT",
15
+ "author": "Envoc Developers",
16
+ "sideEffects": false,
17
+ "main": "lib/index.js",
18
+ "module": "es/index.js",
19
+ "files": [
20
+ "dist",
21
+ "src",
22
+ "lib",
23
+ "es"
24
+ ],
25
+ "scripts": {
26
+ "build": "yarn verify-imports && yarn build:esm && yarn build:cjs && yarn build:css && yarn build:docs",
27
+ "rebuild": "rimraf ./{dist,es,lib} && yarn build",
28
+ "build:esm": "cross-env BABEL_ENV=esm-dir tsc -p tsconfig.esm.json",
29
+ "build:css": "sass src/styles.scss dist/css/envoc-form-styles.css",
30
+ "build:cjs": "tsc -p tsconfig.cjs.json",
31
+ "build:docs": "yarn rimraf README.md && yarn typedoc --options typedoc.json src/index.ts && npx concat-md --decrease-title-levels --dir-name-as-title docs > README.md && yarn rimraf docs",
32
+ "verify-imports": "node ../../scripts/check-for-scss-imports.js envoc-form",
33
+ "start": "webpack serve --config ./webpack.demo.config.js",
34
+ "test": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts test --watchAll=false",
35
+ "coverage": "yarn test --verbose --reporters=default --reporters=jest-junit --coverage --coverageReporters=cobertura"
36
+ },
37
+ "dependencies": {
38
+ "axios": "^0.21.1",
39
+ "date-fns": "^2.22.1",
40
+ "envoc-request": "^5.0.6",
41
+ "lru-cache": "^6.0.0",
42
+ "prop-types": "^15.7.2",
43
+ "react-date-picker": "^8.2.0",
44
+ "react-dropzone": "^11.3.4",
45
+ "react-router": "^6.2.1",
46
+ "react-select": "^5.2.2",
47
+ "react-textarea-autosize": "^8.3.3",
48
+ "react-toastify": "^7.0.4",
49
+ "reactstrap": "^8.9.0",
50
+ "history": "^5.2.0",
51
+ "smoothscroll-polyfill": "^0.4.4",
52
+ "uuid": "^8.3.2",
53
+ "@fortawesome/react-fontawesome": "~0.1.16",
54
+ "@fortawesome/free-solid-svg-icons": "~5.15.4",
55
+ "@fortawesome/fontawesome-svg-core": "~1.2.36",
56
+ "clsx": "^2.1.0"
57
+ },
58
+ "devDependencies": {
59
+ "@babel/cli": "^7.14.5",
60
+ "@babel/core": "^7.14.6",
61
+ "@babel/plugin-transform-runtime": "^7.14.5",
62
+ "@babel/preset-env": "^7.14.7",
63
+ "@babel/preset-react": "^7.14.5",
64
+ "@testing-library/jest-dom": "^5.14.1",
65
+ "@testing-library/react": "^11.2.5",
66
+ "@testing-library/user-event": "^12.7.1",
67
+ "@types/jest": "^26.0.24",
68
+ "@types/react": "~18",
69
+ "@types/testing-library__jest-dom": "5.14.5",
70
+ "@types/smoothscroll-polyfill": "^0.3.1",
71
+ "@types/uuid": "^8.3.2",
72
+ "babel-loader": "^8.2.2",
73
+ "bootstrap": "^4.6.0",
74
+ "clean-webpack-plugin": "^3.0.0",
75
+ "cross-env": "7.0.3",
76
+ "css-loader": "^5.0.2",
77
+ "eslint": "^8.32.0",
78
+ "eslint-config-react-app": "^7.0.1",
79
+ "html-webpack-plugin": "^5.3.2",
80
+ "identity-obj-proxy": "^3.0.0",
81
+ "jest-junit": "~12.2.0",
82
+ "react": "~18",
83
+ "react-dom": "~18",
84
+ "react-router-dom": "^6.2.1",
85
+ "react-scripts": "^4.0.3",
86
+ "rimraf": "~3.0.2",
87
+ "sass": "^1.35.2",
88
+ "sass-loader": "^11.0.1",
89
+ "style-loader": "^2.0.0",
90
+ "webpack": "^5.45.0",
91
+ "webpack-cli": "^4.7.2",
92
+ "webpack-dev-server": "^3.11.2",
93
+ "ts-loader": "^9.2.8",
94
+ "typescript": "^5.1.6",
95
+ "typedoc-plugin-markdown": "^3.15.0",
96
+ "typedoc": "^0.24.1",
97
+ "concat-md": "~0.3.5"
98
+ },
99
+ "peerDependencies": {
100
+ "@babel/runtime": "^7.14.6",
101
+ "formik": "^2.2.9",
102
+ "react": ">=18",
103
+ "react-dom": ">=18",
104
+ "react-router-dom": "^6.2.1"
105
+ },
106
+ "jest": {
107
+ "transformIgnorePatterns": [
108
+ "^.+/.module/.(css|sass|scss)$"
109
+ ]
110
+ }
111
+ }
@@ -1,27 +1,27 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import AddressInput from './AddressInput';
4
- import FormTestBase from '../__Tests__/FormTestBase';
5
-
6
- describe('AddressInput', () => {
7
- it('renders without crashing', () => {
8
- render(
9
- <FormTestBase>
10
- {({ Field }) => (
11
- <AddressInput fieldBuilder={{ Field }} name="normalAddressInput" />
12
- )}
13
- </FormTestBase>
14
- );
15
- });
16
-
17
- it('has matching snapshot', () => {
18
- const renderResult = render(
19
- <FormTestBase>
20
- {({ Field }) => (
21
- <AddressInput fieldBuilder={{ Field }} name="normalAddressInput" />
22
- )}
23
- </FormTestBase>
24
- );
25
- expect(renderResult.asFragment()).toMatchSnapshot();
26
- });
27
- });
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import AddressInput from './AddressInput';
4
+ import FormTestBase from '../__Tests__/FormTestBase';
5
+
6
+ describe('AddressInput', () => {
7
+ it('renders without crashing', () => {
8
+ render(
9
+ <FormTestBase>
10
+ {({ Field }) => (
11
+ <AddressInput fieldBuilder={{ Field }} name="normalAddressInput" />
12
+ )}
13
+ </FormTestBase>
14
+ );
15
+ });
16
+
17
+ it('has matching snapshot', () => {
18
+ const renderResult = render(
19
+ <FormTestBase>
20
+ {({ Field }) => (
21
+ <AddressInput fieldBuilder={{ Field }} name="normalAddressInput" />
22
+ )}
23
+ </FormTestBase>
24
+ );
25
+ expect(renderResult.asFragment()).toMatchSnapshot();
26
+ });
27
+ });
@@ -1,82 +1,82 @@
1
- import UsStates from './UsStates';
2
- import { SingleStringSelectGroup, StringInputGroup } from '../';
3
- import FieldSection from '../Field/FieldSection';
4
- import { FormBuilderProp } from '../Form/Form';
5
- import { zipCode as zipCodeNormalizer } from '../Normalization/normalizers';
6
- import {
7
- required,
8
- zipCode as zipCodeValidator,
9
- } from '../Validation/validators';
10
-
11
- // TODO: find a permanent home for these interfaces
12
- // TODO: but also, maybe they are comfortable here?
13
- export interface AddressInputProps {
14
- fieldBuilder: Pick<FormBuilderProp<AddressDto>, 'Field'>;
15
- name: string;
16
- }
17
-
18
- interface AddressDto {
19
- address1?: string | null;
20
- address2?: string | null;
21
- zipCode?: string | null;
22
- city?: string | null;
23
- state?: string | null;
24
- }
25
-
26
- /**
27
- * Collection of `<Field/>`s for inputting an address. Includes:
28
- * ```txt
29
- * Address 1
30
- * Address 2
31
- * City
32
- * State
33
- * Zip
34
- * ```
35
- */
36
- export default function AddressInput({
37
- fieldBuilder: { Field },
38
- name,
39
- }: AddressInputProps) {
40
- return (
41
- <>
42
- <FieldSection name={name}>
43
- <Field
44
- name="address1"
45
- placeholder="Address, Line 1"
46
- label="Address 1"
47
- Component={StringInputGroup}
48
- validate={required}
49
- />
50
- <Field
51
- name="address2"
52
- placeholder="Address, Line 2"
53
- label="Address 2"
54
- Component={StringInputGroup}
55
- />
56
- <Field
57
- name="city"
58
- placeholder="City"
59
- label="City"
60
- Component={StringInputGroup}
61
- validate={required}
62
- />
63
- <Field
64
- name="state"
65
- placeholder="State"
66
- label="State"
67
- Component={SingleStringSelectGroup}
68
- options={UsStates}
69
- validate={required}
70
- />
71
- <Field
72
- name="zipCode"
73
- placeholder="Zip"
74
- label="Zip"
75
- Component={StringInputGroup}
76
- normalize={zipCodeNormalizer}
77
- validate={[required, zipCodeValidator]}
78
- />
79
- </FieldSection>
80
- </>
81
- );
82
- }
1
+ import UsStates from './UsStates';
2
+ import { SingleStringSelectGroup, StringInputGroup } from '../';
3
+ import FieldSection from '../Field/FieldSection';
4
+ import { FormBuilderProp } from '../Form/Form';
5
+ import { zipCode as zipCodeNormalizer } from '../Normalization/normalizers';
6
+ import {
7
+ required,
8
+ zipCode as zipCodeValidator,
9
+ } from '../Validation/validators';
10
+
11
+ // TODO: find a permanent home for these interfaces
12
+ // TODO: but also, maybe they are comfortable here?
13
+ export interface AddressInputProps {
14
+ fieldBuilder: Pick<FormBuilderProp<AddressDto>, 'Field'>;
15
+ name: string;
16
+ }
17
+
18
+ interface AddressDto {
19
+ address1?: string | null;
20
+ address2?: string | null;
21
+ zipCode?: string | null;
22
+ city?: string | null;
23
+ state?: string | null;
24
+ }
25
+
26
+ /**
27
+ * Collection of `<Field/>`s for inputting an address. Includes:
28
+ * ```txt
29
+ * Address 1
30
+ * Address 2
31
+ * City
32
+ * State
33
+ * Zip
34
+ * ```
35
+ */
36
+ export default function AddressInput({
37
+ fieldBuilder: { Field },
38
+ name,
39
+ }: AddressInputProps) {
40
+ return (
41
+ <>
42
+ <FieldSection name={name}>
43
+ <Field
44
+ name="address1"
45
+ placeholder="Address, Line 1"
46
+ label="Address 1"
47
+ Component={StringInputGroup}
48
+ validate={required}
49
+ />
50
+ <Field
51
+ name="address2"
52
+ placeholder="Address, Line 2"
53
+ label="Address 2"
54
+ Component={StringInputGroup}
55
+ />
56
+ <Field
57
+ name="city"
58
+ placeholder="City"
59
+ label="City"
60
+ Component={StringInputGroup}
61
+ validate={required}
62
+ />
63
+ <Field
64
+ name="state"
65
+ placeholder="State"
66
+ label="State"
67
+ Component={SingleStringSelectGroup}
68
+ options={UsStates}
69
+ validate={required}
70
+ />
71
+ <Field
72
+ name="zipCode"
73
+ placeholder="Zip"
74
+ label="Zip"
75
+ Component={StringInputGroup}
76
+ normalize={zipCodeNormalizer}
77
+ validate={[required, zipCodeValidator]}
78
+ />
79
+ </FieldSection>
80
+ </>
81
+ );
82
+ }
@@ -1,55 +1,55 @@
1
- import { SelectOption } from '../Select/SelectGroup';
2
-
3
- const states: SelectOption<string>[] = [
4
- { label: 'Alabama', value: 'AL' },
5
- { label: 'Alaska', value: 'AK' },
6
- { label: 'Arizona', value: 'AZ' },
7
- { label: 'Arkansas', value: 'AR' },
8
- { label: 'California', value: 'CA' },
9
- { label: 'Colorado', value: 'CO' },
10
- { label: 'Connecticut', value: 'CT' },
11
- { label: 'Delaware', value: 'DE' },
12
- { label: 'Florida', value: 'FL' },
13
- { label: 'Georgia', value: 'GA' },
14
- { label: 'Hawaii', value: 'HI' },
15
- { label: 'Idaho', value: 'ID' },
16
- { label: 'Illinois', value: 'IL' },
17
- { label: 'Indiana', value: 'IN' },
18
- { label: 'Iowa', value: 'IA' },
19
- { label: 'Kansas', value: 'KS' },
20
- { label: 'Kentucky', value: 'KY' },
21
- { label: 'Louisiana', value: 'LA' },
22
- { label: 'Maine', value: 'ME' },
23
- { label: 'Maryland', value: 'MD' },
24
- { label: 'Massachusetts', value: 'MA' },
25
- { label: 'Michigan', value: 'MI' },
26
- { label: 'Minnesota', value: 'MN' },
27
- { label: 'Mississippi', value: 'MS' },
28
- { label: 'Missouri', value: 'MO' },
29
- { label: 'Montana', value: 'MT' },
30
- { label: 'Nebraska', value: 'NE' },
31
- { label: 'Nevada', value: 'NV' },
32
- { label: 'New Hampshire', value: 'NH' },
33
- { label: 'New Jersey', value: 'NJ' },
34
- { label: 'New Mexico', value: 'NM' },
35
- { label: 'New York', value: 'NY' },
36
- { label: 'North Carolina', value: 'NC' },
37
- { label: 'North Dakota', value: 'ND' },
38
- { label: 'Ohio', value: 'OH' },
39
- { label: 'Oklahoma', value: 'OK' },
40
- { label: 'Oregon', value: 'OR' },
41
- { label: 'Pennsylvania', value: 'PA' },
42
- { label: 'Rhode Island', value: 'RI' },
43
- { label: 'South Carolina', value: 'SC' },
44
- { label: 'South Dakota', value: 'SD' },
45
- { label: 'Tennessee', value: 'TN' },
46
- { label: 'Texas', value: 'TX' },
47
- { label: 'Utah', value: 'UT' },
48
- { label: 'Vermont', value: 'VT' },
49
- { label: 'Virginia', value: 'VA' },
50
- { label: 'Washington', value: 'WA' },
51
- { label: 'West Virginia', value: 'WV' },
52
- { label: 'Wisconsin', value: 'WI' },
53
- { label: 'Wyoming', value: 'WY' },
54
- ];
55
- export default states;
1
+ import { SelectOption } from '../Select/SelectGroup';
2
+
3
+ const states: SelectOption<string>[] = [
4
+ { label: 'Alabama', value: 'AL' },
5
+ { label: 'Alaska', value: 'AK' },
6
+ { label: 'Arizona', value: 'AZ' },
7
+ { label: 'Arkansas', value: 'AR' },
8
+ { label: 'California', value: 'CA' },
9
+ { label: 'Colorado', value: 'CO' },
10
+ { label: 'Connecticut', value: 'CT' },
11
+ { label: 'Delaware', value: 'DE' },
12
+ { label: 'Florida', value: 'FL' },
13
+ { label: 'Georgia', value: 'GA' },
14
+ { label: 'Hawaii', value: 'HI' },
15
+ { label: 'Idaho', value: 'ID' },
16
+ { label: 'Illinois', value: 'IL' },
17
+ { label: 'Indiana', value: 'IN' },
18
+ { label: 'Iowa', value: 'IA' },
19
+ { label: 'Kansas', value: 'KS' },
20
+ { label: 'Kentucky', value: 'KY' },
21
+ { label: 'Louisiana', value: 'LA' },
22
+ { label: 'Maine', value: 'ME' },
23
+ { label: 'Maryland', value: 'MD' },
24
+ { label: 'Massachusetts', value: 'MA' },
25
+ { label: 'Michigan', value: 'MI' },
26
+ { label: 'Minnesota', value: 'MN' },
27
+ { label: 'Mississippi', value: 'MS' },
28
+ { label: 'Missouri', value: 'MO' },
29
+ { label: 'Montana', value: 'MT' },
30
+ { label: 'Nebraska', value: 'NE' },
31
+ { label: 'Nevada', value: 'NV' },
32
+ { label: 'New Hampshire', value: 'NH' },
33
+ { label: 'New Jersey', value: 'NJ' },
34
+ { label: 'New Mexico', value: 'NM' },
35
+ { label: 'New York', value: 'NY' },
36
+ { label: 'North Carolina', value: 'NC' },
37
+ { label: 'North Dakota', value: 'ND' },
38
+ { label: 'Ohio', value: 'OH' },
39
+ { label: 'Oklahoma', value: 'OK' },
40
+ { label: 'Oregon', value: 'OR' },
41
+ { label: 'Pennsylvania', value: 'PA' },
42
+ { label: 'Rhode Island', value: 'RI' },
43
+ { label: 'South Carolina', value: 'SC' },
44
+ { label: 'South Dakota', value: 'SD' },
45
+ { label: 'Tennessee', value: 'TN' },
46
+ { label: 'Texas', value: 'TX' },
47
+ { label: 'Utah', value: 'UT' },
48
+ { label: 'Vermont', value: 'VT' },
49
+ { label: 'Virginia', value: 'VA' },
50
+ { label: 'Washington', value: 'WA' },
51
+ { label: 'West Virginia', value: 'WV' },
52
+ { label: 'Wisconsin', value: 'WI' },
53
+ { label: 'Wyoming', value: 'WY' },
54
+ ];
55
+ export default states;