envoc-form 4.0.1-10 → 4.0.1-12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/README.md +5117 -12
  2. package/es/AddressInput/AddressInput.d.ts +15 -5
  3. package/es/AddressInput/AddressInput.js +10 -0
  4. package/es/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
  5. package/es/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
  6. package/es/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
  7. package/es/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
  8. package/es/DatePicker/DatePickerGroup.d.ts +6 -1
  9. package/es/DatePicker/DatePickerGroup.js +14 -4
  10. package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +6 -1
  11. package/es/DatePicker/StringDateOnlyPickerGroup.js +5 -0
  12. package/es/DatePicker/StringDatePickerGroup.d.ts +6 -1
  13. package/es/DatePicker/StringDatePickerGroup.js +5 -0
  14. package/es/Field/Field.d.ts +8 -2
  15. package/es/Field/FieldErrorScrollTarget.d.ts +1 -0
  16. package/es/Field/FieldErrorScrollTarget.js +1 -0
  17. package/es/Field/StandAloneInput.d.ts +4 -0
  18. package/es/Field/StandAloneInput.js +1 -0
  19. package/es/Field/useStandardField.d.ts +6 -0
  20. package/es/Field/useStandardField.js +8 -9
  21. package/es/FieldArray/FieldArray.d.ts +11 -2
  22. package/es/FieldArray/FieldArray.js +7 -2
  23. package/es/File/FileGroup.d.ts +3 -1
  24. package/es/File/FileGroup.js +2 -1
  25. package/es/File/FileList.d.ts +2 -2
  26. package/es/Form/FocusError.d.ts +2 -0
  27. package/es/Form/FocusError.js +1 -0
  28. package/es/Form/Form.d.ts +6 -0
  29. package/es/Form/Form.js +1 -0
  30. package/es/Form/FormBasedPreventNavigation.d.ts +3 -1
  31. package/es/Form/FormBasedPreventNavigation.js +12 -45
  32. package/es/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
  33. package/es/Form/LegacyFormBasedPreventNavigation.js +69 -0
  34. package/es/Form/NewFormBasedPreventNavigation.d.ts +14 -0
  35. package/es/Form/NewFormBasedPreventNavigation.js +39 -0
  36. package/es/Form/ServerErrorContext.d.ts +1 -0
  37. package/es/Form/ServerErrorContext.js +1 -0
  38. package/es/FormActions.d.ts +6 -0
  39. package/es/FormActions.js +1 -0
  40. package/es/FormDefaults.d.ts +1 -0
  41. package/es/FormDefaults.js +1 -0
  42. package/es/Group.d.ts +5 -3
  43. package/es/Group.js +2 -2
  44. package/es/Input/IconInputGroup.d.ts +4 -1
  45. package/es/Input/IconInputGroup.js +3 -1
  46. package/es/Input/InputGroup.d.ts +3 -3
  47. package/es/Input/InputGroup.js +3 -3
  48. package/es/Input/MoneyInputGroup.d.ts +3 -1
  49. package/es/Input/MoneyInputGroup.js +1 -0
  50. package/es/Input/NumberInputGroup.d.ts +3 -1
  51. package/es/Input/NumberInputGroup.js +1 -0
  52. package/es/Input/StringInputGroup.d.ts +2 -1
  53. package/es/Input/StringInputGroup.js +3 -1
  54. package/es/Normalization/normalizers.d.ts +4 -2
  55. package/es/Normalization/normalizers.js +2 -0
  56. package/es/Select/BooleanSelectGroup.d.ts +2 -1
  57. package/es/Select/BooleanSelectGroup.js +1 -0
  58. package/es/Select/NumberSelectGroup.d.ts +4 -2
  59. package/es/Select/NumberSelectGroup.js +2 -0
  60. package/es/Select/SelectGroup.d.ts +7 -1
  61. package/es/Select/SelectGroup.js +2 -1
  62. package/es/Select/StringSelectGroup.d.ts +2 -0
  63. package/es/Select/StringSelectGroup.js +2 -0
  64. package/es/StandardFormActions.d.ts +5 -0
  65. package/es/StandardFormActions.js +1 -0
  66. package/es/SubmitFormButton.d.ts +4 -1
  67. package/es/SubmitFormButton.js +1 -0
  68. package/es/TextArea/TextAreaGroup.d.ts +2 -1
  69. package/es/TextArea/TextAreaGroup.js +4 -3
  70. package/es/Validation/validators.d.ts +11 -8
  71. package/es/Validation/validators.js +6 -2
  72. package/es/index.d.ts +4 -4
  73. package/es/setupTests.d.ts +1 -0
  74. package/es/setupTests.js +1 -0
  75. package/lib/AddressInput/AddressInput.d.ts +15 -5
  76. package/lib/AddressInput/AddressInput.js +10 -0
  77. package/lib/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
  78. package/lib/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
  79. package/lib/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
  80. package/lib/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
  81. package/lib/DatePicker/DatePickerGroup.d.ts +6 -1
  82. package/lib/DatePicker/DatePickerGroup.js +14 -4
  83. package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +6 -1
  84. package/lib/DatePicker/StringDateOnlyPickerGroup.js +5 -0
  85. package/lib/DatePicker/StringDatePickerGroup.d.ts +6 -1
  86. package/lib/DatePicker/StringDatePickerGroup.js +5 -0
  87. package/lib/Field/Field.d.ts +8 -2
  88. package/lib/Field/FieldErrorScrollTarget.d.ts +1 -0
  89. package/lib/Field/FieldErrorScrollTarget.js +1 -0
  90. package/lib/Field/StandAloneInput.d.ts +4 -0
  91. package/lib/Field/StandAloneInput.js +1 -0
  92. package/lib/Field/useStandardField.d.ts +6 -0
  93. package/lib/Field/useStandardField.js +8 -9
  94. package/lib/FieldArray/FieldArray.d.ts +11 -2
  95. package/lib/FieldArray/FieldArray.js +7 -2
  96. package/lib/File/FileGroup.d.ts +3 -1
  97. package/lib/File/FileGroup.js +2 -1
  98. package/lib/File/FileList.d.ts +2 -2
  99. package/lib/Form/FocusError.d.ts +2 -0
  100. package/lib/Form/FocusError.js +1 -0
  101. package/lib/Form/Form.d.ts +6 -0
  102. package/lib/Form/Form.js +1 -0
  103. package/lib/Form/FormBasedPreventNavigation.d.ts +3 -1
  104. package/lib/Form/FormBasedPreventNavigation.js +13 -43
  105. package/lib/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
  106. package/lib/Form/LegacyFormBasedPreventNavigation.js +72 -0
  107. package/lib/Form/NewFormBasedPreventNavigation.d.ts +14 -0
  108. package/lib/Form/NewFormBasedPreventNavigation.js +42 -0
  109. package/lib/Form/ServerErrorContext.d.ts +1 -0
  110. package/lib/Form/ServerErrorContext.js +1 -0
  111. package/lib/FormActions.d.ts +6 -0
  112. package/lib/FormActions.js +1 -0
  113. package/lib/FormDefaults.d.ts +1 -0
  114. package/lib/FormDefaults.js +1 -0
  115. package/lib/Group.d.ts +5 -3
  116. package/lib/Group.js +2 -2
  117. package/lib/Input/IconInputGroup.d.ts +4 -1
  118. package/lib/Input/IconInputGroup.js +3 -1
  119. package/lib/Input/InputGroup.d.ts +3 -3
  120. package/lib/Input/InputGroup.js +3 -3
  121. package/lib/Input/MoneyInputGroup.d.ts +3 -1
  122. package/lib/Input/MoneyInputGroup.js +1 -0
  123. package/lib/Input/NumberInputGroup.d.ts +3 -1
  124. package/lib/Input/NumberInputGroup.js +1 -0
  125. package/lib/Input/StringInputGroup.d.ts +2 -1
  126. package/lib/Input/StringInputGroup.js +3 -1
  127. package/lib/Normalization/normalizers.d.ts +4 -2
  128. package/lib/Normalization/normalizers.js +2 -0
  129. package/lib/Select/BooleanSelectGroup.d.ts +2 -1
  130. package/lib/Select/BooleanSelectGroup.js +1 -0
  131. package/lib/Select/NumberSelectGroup.d.ts +4 -2
  132. package/lib/Select/NumberSelectGroup.js +2 -0
  133. package/lib/Select/SelectGroup.d.ts +7 -1
  134. package/lib/Select/SelectGroup.js +2 -1
  135. package/lib/Select/StringSelectGroup.d.ts +2 -0
  136. package/lib/Select/StringSelectGroup.js +2 -0
  137. package/lib/StandardFormActions.d.ts +5 -0
  138. package/lib/StandardFormActions.js +1 -0
  139. package/lib/SubmitFormButton.d.ts +4 -1
  140. package/lib/SubmitFormButton.js +1 -0
  141. package/lib/TextArea/TextAreaGroup.d.ts +2 -1
  142. package/lib/TextArea/TextAreaGroup.js +4 -3
  143. package/lib/Validation/validators.d.ts +11 -8
  144. package/lib/Validation/validators.js +6 -2
  145. package/lib/index.d.ts +4 -4
  146. package/lib/setupTests.d.ts +1 -0
  147. package/lib/setupTests.js +3 -0
  148. package/package.json +9 -6
  149. package/src/AddressInput/AddressInput.tsx +15 -5
  150. package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +4 -0
  151. package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +14 -0
  152. package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +13 -0
  153. package/src/DatePicker/DatePicker.test.tsx +1 -1
  154. package/src/DatePicker/DatePickerGroup.tsx +13 -6
  155. package/src/DatePicker/StringDateOnlyPickerGroup.tsx +7 -2
  156. package/src/DatePicker/StringDatePickerGroup.tsx +7 -1
  157. package/src/Field/Field.tsx +8 -3
  158. package/src/Field/FieldErrorScrollTarget.tsx +1 -0
  159. package/src/Field/StandAloneInput.tsx +4 -0
  160. package/src/Field/useStandardField.ts +13 -9
  161. package/src/FieldArray/FieldArray.tsx +14 -5
  162. package/src/File/FileGroup.tsx +4 -2
  163. package/src/File/FileList.tsx +2 -2
  164. package/src/Form/FocusError.tsx +3 -0
  165. package/src/Form/Form.tsx +6 -0
  166. package/src/Form/FormBasedPreventNavigation.tsx +28 -46
  167. package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -0
  168. package/src/Form/NewFormBasedPreventNavigation.tsx +59 -0
  169. package/src/Form/ServerErrorContext.ts +1 -0
  170. package/src/FormActions.tsx +7 -0
  171. package/src/FormDefaults.ts +1 -0
  172. package/src/Group.tsx +8 -4
  173. package/src/Input/IconInputGroup.tsx +5 -2
  174. package/src/Input/InputGroup.tsx +11 -5
  175. package/src/Input/MoneyInputGroup.tsx +3 -1
  176. package/src/Input/NumberInputGroup.tsx +3 -1
  177. package/src/Input/StringInputGroup.tsx +3 -2
  178. package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +1 -0
  179. package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +1 -0
  180. package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +1 -0
  181. package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +1 -0
  182. package/src/Normalization/normalizers.ts +4 -2
  183. package/src/Select/BooleanSelectGroup.tsx +2 -1
  184. package/src/Select/NumberSelectGroup.tsx +4 -2
  185. package/src/Select/SelectGroup.tsx +8 -2
  186. package/src/Select/StringSelectGroup.tsx +2 -0
  187. package/src/StandardFormActions.tsx +5 -0
  188. package/src/SubmitFormButton.tsx +5 -1
  189. package/src/TextArea/TextAreaGroup.tsx +4 -4
  190. package/src/Validation/validators.ts +19 -14
  191. package/src/__Tests__/FormTestBase.tsx +9 -8
  192. package/src/__Tests__/RealisticForm.test.tsx +82 -0
  193. package/src/index.ts +4 -4
  194. package/src/setupTests.ts +1 -0
  195. package/es/__Tests__/FormTestBase.d.ts +0 -27
  196. package/es/__Tests__/FormTestBase.js +0 -83
  197. package/es/__Tests__/index.d.ts +0 -2
  198. package/es/__Tests__/index.js +0 -2
  199. package/lib/__Tests__/FormTestBase.d.ts +0 -27
  200. package/lib/__Tests__/FormTestBase.js +0 -86
  201. package/lib/__Tests__/index.d.ts +0 -2
  202. package/lib/__Tests__/index.js +0 -8
@@ -1,7 +1,10 @@
1
1
  import React from 'react';
2
2
  export interface SubmitFormButtonProps extends Omit<React.HTMLProps<HTMLButtonElement>, 'type'> {
3
+ /** Allow the form to be submitted without any changes. By default this is not allowed. */
3
4
  allowPristineSubmit?: boolean;
5
+ /** Text to display on the button. Default text is 'Submit'. */
4
6
  children?: React.ReactNode;
5
7
  }
6
- declare const _default: React.ComponentType<SubmitFormButtonProps>;
8
+ declare const _default: React.FunctionComponent<SubmitFormButtonProps>;
9
+ /** Generic submit button for forms. */
7
10
  export default _default;
@@ -41,4 +41,5 @@ function SubmitFormButton(_a, ref) {
41
41
  ? "You haven't made any changes"
42
42
  : '', className: (0, classnames_1.default)(FormDefaults_1.FormDefaults.cssClassPrefix + 'submit-form-button', className) }, { children: children || 'Submit' })));
43
43
  }
44
+ /** Generic submit button for forms. */
44
45
  exports.default = react_1.default.forwardRef(SubmitFormButton);
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
2
  import { InjectedFieldProps } from '../Field/InjectedFieldProps';
3
3
  import { GroupProps } from '../Group';
4
- export interface TextAreaGroupProps extends InjectedFieldProps<string | undefined>, Omit<React.HTMLProps<HTMLTextAreaElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
4
+ export interface TextAreaGroupProps extends InjectedFieldProps<string | undefined | null>, Omit<React.HTMLProps<HTMLTextAreaElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
5
5
  icon?: React.ReactNode;
6
6
  }
7
+ /** Generic controlled `<textarea/>` wrapped by a `<Group/>` */
7
8
  declare const TextAreaGroupWithRef: React.ComponentType<TextAreaGroupProps>;
8
9
  export default TextAreaGroupWithRef;
@@ -28,12 +28,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
28
28
  var jsx_runtime_1 = require("react/jsx-runtime");
29
29
  var react_1 = __importDefault(require("react"));
30
30
  var classnames_1 = __importDefault(require("classnames"));
31
- var Group_1 = __importDefault(require("../Group"));
32
31
  var FormDefaults_1 = require("../FormDefaults");
33
- /** generic controlled <textarea/> wrapped by a Group */
32
+ var Group_1 = __importDefault(require("../Group"));
34
33
  function TextAreaGroup(_a, ref) {
34
+ var _b;
35
35
  var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, icon = _a.icon, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "icon"]);
36
- return ((0, jsx_runtime_1.jsxs)(Group_1.default, __assign({ input: input, meta: meta, required: required, disabled: disabled, label: label, helpText: helpText, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'text-area-group') }, { children: [icon, (0, jsx_runtime_1.jsx)("textarea", __assign({}, input, rest, { value: input.value, onChange: function (val) { return input.onChange(val.target.value); }, ref: ref, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'text-area-group') }))] })));
36
+ return ((0, jsx_runtime_1.jsxs)(Group_1.default, __assign({ input: input, meta: meta, required: required, disabled: disabled, label: label, helpText: helpText, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'text-area-group') }, { children: [icon, (0, jsx_runtime_1.jsx)("textarea", __assign({}, input, rest, { value: (_b = input.value) !== null && _b !== void 0 ? _b : '', onChange: function (val) { return input.onChange(val.target.value); }, ref: ref, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'text-area-group') }))] })));
37
37
  }
38
+ /** Generic controlled `<textarea/>` wrapped by a `<Group/>` */
38
39
  var TextAreaGroupWithRef = react_1.default.forwardRef(TextAreaGroup);
39
40
  exports.default = TextAreaGroupWithRef;
@@ -1,15 +1,18 @@
1
1
  import { ValidationFunction } from './ValidationFunction';
2
2
  export declare const required: (value: any) => "Required" | undefined;
3
- export declare const length: (len: number) => (value: string | number | undefined) => string | undefined;
4
- export declare const integer: (val: string | number | undefined) => "Must be a whole number" | undefined;
5
- export declare const maxLength: (len: number) => (value: string | number | undefined) => string | undefined;
3
+ /** Asserts that the value is a certain number of characters. numbers are coerced to a string */
4
+ export declare const length: (len: number) => (value: string | number | undefined | null) => string | undefined;
5
+ export declare const integer: (val: string | number | undefined | null) => "Must be a whole number" | undefined;
6
+ export declare const maxLength: (len: number) => (value: string | number | undefined | null) => string | undefined;
6
7
  export declare const maxCount: (count: number) => (value: {
7
8
  isDeleted?: boolean;
8
- }[] | undefined) => string | undefined;
9
+ }[] | undefined | null) => string | undefined;
9
10
  export declare const minCount: (count: number) => (value: {
10
11
  isDeleted?: boolean;
11
- }[] | undefined) => string | undefined;
12
- export declare const maxValue: (max: number) => (value: number | undefined) => string | undefined;
13
- export declare const minValue: (min: number) => (value: number | undefined) => string | undefined;
14
- export declare const zipCode: (value: string | undefined) => "Invalid ZIP Code" | undefined;
12
+ }[] | undefined | null) => string | undefined;
13
+ export declare const maxValue: (max: number) => (value: number | undefined | null) => string | undefined;
14
+ export declare const minValue: (min: number) => (value: number | undefined | null) => string | undefined;
15
+ /** Validate for a ZIP Code. Accepts formats: ##### and #####-#### */
16
+ export declare const zipCode: (value: string | undefined | null) => "Invalid ZIP Code" | undefined;
17
+ /** One of the validators provided must be true. */
15
18
  export declare const any: <TValue>(validatorList: ValidationFunction<TValue>[]) => (value: TValue) => string | undefined;
@@ -11,7 +11,7 @@ var required = function (value) {
11
11
  : 'Required';
12
12
  };
13
13
  exports.required = required;
14
- //asserts that the value is a certain number of characters. numbers are coerced to a string
14
+ /** Asserts that the value is a certain number of characters. numbers are coerced to a string */
15
15
  var length = function (len) { return function (value) {
16
16
  var hasError = getLengthOfValue(value) !== len;
17
17
  return !hasError ? undefined : "Length must be ".concat(len);
@@ -51,13 +51,14 @@ var minValue = function (min) { return function (value) {
51
51
  return !hasError ? undefined : "Minimum value ".concat(min, " not met");
52
52
  }; };
53
53
  exports.minValue = minValue;
54
+ /** Validate for a ZIP Code. Accepts formats: ##### and #####-#### */
54
55
  var zipCode = function (value) {
55
56
  return value && !/^[0-9]{5}(?:-[0-9]{4})?$/.test(value)
56
57
  ? 'Invalid ZIP Code'
57
58
  : undefined;
58
59
  };
59
60
  exports.zipCode = zipCode;
60
- //one of the validators provided must be true
61
+ /** One of the validators provided must be true. */
61
62
  var any = function (validatorList) {
62
63
  return function (value) {
63
64
  if (validatorList.length === 0 || !value) {
@@ -68,6 +69,9 @@ var any = function (validatorList) {
68
69
  };
69
70
  exports.any = any;
70
71
  function getLengthOfValue(value) {
72
+ if (value === null) {
73
+ return 0;
74
+ }
71
75
  switch (typeof value) {
72
76
  case 'undefined':
73
77
  return 0;
package/lib/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export type { ConfirmBaseFormProps } from './ConfirmBaseForm/ConfirmBaseForm';
7
7
  export { default as ConfirmDeleteForm } from './ConfirmDeleteForm/ConfirmDeleteForm';
8
8
  export type { ConfirmDeleteFormProps } from './ConfirmDeleteForm/ConfirmDeleteForm';
9
9
  export { default as DatePickerGroup } from './DatePicker/DatePickerGroup';
10
- export type { DatePickerGroupProps as DatePickerGroupProps } from './DatePicker/DatePickerGroup';
10
+ export type { DatePickerGroupProps } from './DatePicker/DatePickerGroup';
11
11
  export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGroup';
12
12
  export type { DatePickerHelper } from './DatePicker/DatePickerHelper';
13
13
  export { default as StringDatePickerGroup } from './DatePicker/StringDatePickerGroup';
@@ -34,12 +34,12 @@ export type { FormBuilderProp, FormProps } from './Form/Form';
34
34
  export { ServerErrorContext } from './Form/ServerErrorContext';
35
35
  export type { ServerErrorContextProps, ServerErrors, } from './Form/ServerErrorContext';
36
36
  export { default as FormActions } from './FormActions';
37
- export type { FormActionsProps as FormActionsProps } from './FormActions';
37
+ export type { FormActionsProps } from './FormActions';
38
38
  export { default as StandardFormActions } from './StandardFormActions';
39
- export type { StandardFormActionsProps as StandardFormActionsProps } from './StandardFormActions';
39
+ export type { StandardFormActionsProps } from './StandardFormActions';
40
40
  export { FormDefaults } from './FormDefaults';
41
41
  export { default as Group } from './Group';
42
- export type { GroupProps as GroupProps } from './Group';
42
+ export type { GroupProps } from './Group';
43
43
  export { default as IconInputGroup } from './Input/IconInputGroup';
44
44
  export type { IconInputGroupProps } from './Input/IconInputGroup';
45
45
  export { default as InputGroup } from './Input/InputGroup';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/extend-expect';
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("@testing-library/jest-dom/extend-expect");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envoc-form",
3
- "version": "4.0.1-10",
3
+ "version": "4.0.1-12",
4
4
  "description": "Envoc form components",
5
5
  "keywords": [
6
6
  "react-component",
@@ -23,11 +23,12 @@
23
23
  "es"
24
24
  ],
25
25
  "scripts": {
26
- "build": "yarn verify-imports && yarn build:esm && yarn build:cjs && yarn build:css",
26
+ "build": "yarn verify-imports && yarn build:esm && yarn build:cjs && yarn build:css && yarn build:docs",
27
27
  "rebuild": "rimraf ./{dist,es,lib} && yarn build",
28
28
  "build:esm": "cross-env BABEL_ENV=esm-dir tsc -p tsconfig.esm.json",
29
29
  "build:css": "sass src/styles.scss dist/css/envoc-form-styles.css",
30
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",
31
32
  "verify-imports": "node ../../scripts/check-for-scss-imports.js envoc-form",
32
33
  "start": "webpack serve --config ./webpack.demo.config.js",
33
34
  "test": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts test --watchAll=false",
@@ -37,12 +38,12 @@
37
38
  "axios": "^0.21.1",
38
39
  "classnames": "^2.3.1",
39
40
  "date-fns": "^2.22.1",
40
- "envoc-request": "^4.0.1-10",
41
+ "envoc-request": "^4.0.1-12",
41
42
  "lru-cache": "^6.0.0",
42
43
  "prop-types": "^15.7.2",
43
44
  "react-date-picker": "^8.2.0",
44
45
  "react-dropzone": "^11.3.4",
45
- "react-router": "^6.2.1",
46
+ "react-router": "^6.14.1",
46
47
  "react-select": "^5.2.2",
47
48
  "react-textarea-autosize": "^8.3.3",
48
49
  "react-toastify": "^7.0.4",
@@ -65,6 +66,7 @@
65
66
  "@testing-library/user-event": "^12.7.1",
66
67
  "@types/jest": "^26.0.24",
67
68
  "@types/react": "^16.9.56",
69
+ "@types/testing-library__jest-dom": "5.14.5",
68
70
  "@types/smoothscroll-polyfill": "^0.3.1",
69
71
  "@types/uuid": "^8.3.2",
70
72
  "babel-loader": "^8.2.2",
@@ -79,7 +81,7 @@
79
81
  "jest-junit": "~12.2.0",
80
82
  "react": "^17.0.1",
81
83
  "react-dom": "^17.0.1",
82
- "react-router-dom": "^6.2.1",
84
+ "react-router-dom": "^6.14.1",
83
85
  "react-scripts": "^4.0.3",
84
86
  "rimraf": "~3.0.2",
85
87
  "sass": "^1.35.2",
@@ -91,7 +93,8 @@
91
93
  "ts-loader": "^9.2.8",
92
94
  "typescript": "^4.6.3",
93
95
  "typedoc-plugin-markdown": "~3.10.3",
94
- "typedoc": "~0.21.4"
96
+ "typedoc": "~0.21.4",
97
+ "concat-md": "~0.3.5"
95
98
  },
96
99
  "peerDependencies": {
97
100
  "@babel/runtime": "^7.14.6",
@@ -16,13 +16,23 @@ export interface AddressInputProps {
16
16
  }
17
17
 
18
18
  interface AddressDto {
19
- address1?: string;
20
- address2?: string;
21
- zipCode?: string;
22
- city?: string;
23
- state?: string;
19
+ address1?: string | null;
20
+ address2?: string | null;
21
+ zipCode?: string | null;
22
+ city?: string | null;
23
+ state?: string | null;
24
24
  }
25
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
+ */
26
36
  export default function AddressInput({
27
37
  fieldBuilder: { Field },
28
38
  name,
@@ -19,6 +19,7 @@ exports[`AddressInput has matching snapshot 1`] = `
19
19
  Address 1
20
20
  </label>
21
21
  <input
22
+ aria-invalid="false"
22
23
  class="envoc-form-string-group envoc-form-input-group"
23
24
  id="normalAddressInput.address1"
24
25
  name="normalAddressInput.address1"
@@ -39,6 +40,7 @@ exports[`AddressInput has matching snapshot 1`] = `
39
40
  Address 2
40
41
  </label>
41
42
  <input
43
+ aria-invalid="false"
42
44
  class="envoc-form-string-group envoc-form-input-group"
43
45
  id="normalAddressInput.address2"
44
46
  name="normalAddressInput.address2"
@@ -59,6 +61,7 @@ exports[`AddressInput has matching snapshot 1`] = `
59
61
  City
60
62
  </label>
61
63
  <input
64
+ aria-invalid="false"
62
65
  class="envoc-form-string-group envoc-form-input-group"
63
66
  id="normalAddressInput.city"
64
67
  name="normalAddressInput.city"
@@ -168,6 +171,7 @@ exports[`AddressInput has matching snapshot 1`] = `
168
171
  Zip
169
172
  </label>
170
173
  <input
174
+ aria-invalid="false"
171
175
  class="envoc-form-string-group envoc-form-input-group"
172
176
  id="normalAddressInput.zipCode"
173
177
  name="normalAddressInput.zipCode"
@@ -6,16 +6,30 @@ import { FormDefaults } from '../FormDefaults';
6
6
  // TODO: change the style prop type to Tailwind type (does this exist before Tailwind 3.1 ???), or
7
7
  // should this just be type 'string'
8
8
  export interface ConfirmBaseFormProps {
9
+ /** Function to run when cancel button is clicked. */
9
10
  handleCancel?: MouseEventHandler<HTMLButtonElement>;
11
+ /** Axios request upon confirmation */
10
12
  request: useAxiosRequestProps;
11
13
  style?: React.CSSProperties;
14
+ /** `<h3/>` title text on top of the form. */
12
15
  title?: string;
16
+ /** Custom confirm button text.
17
+ * @defaultValue `Confirm`
18
+ */
13
19
  confirmButtonText?: string;
20
+ /** CSS class for the buttons. */
14
21
  confirmButtonClass?: string;
22
+ /** Any components to be rendered in between the title and the buttons. */
15
23
  children?: React.ReactNode;
16
24
  }
17
25
 
18
26
  // TODO: ask about how we should use 'children'
27
+ /**
28
+ * Confimation dialog. Navigates to a different route to allow the user to either confirm or cancel an action.
29
+ * Commonly used for confirming delete and archive.
30
+ *
31
+ * See `<ConfirmDeleteForm/>` if the confirmation is specifically for deletion.
32
+ */
19
33
  export default function ConfirmBaseForm({
20
34
  handleCancel,
21
35
  request,
@@ -9,14 +9,27 @@ import { FormDefaults } from '../FormDefaults';
9
9
 
10
10
  export interface ConfirmDeleteFormProps
11
11
  extends Pick<ConfirmBaseFormProps, 'style'> {
12
+ /** Url to navigate to on success. */
12
13
  successUrl?: string;
14
+ /** Form name (key) to apply the confirmation on. */
13
15
  form: string;
16
+ /** Custom message to display.
17
+ * @defaultValue `Are you sure you want to delete this?`
18
+ */
14
19
  title?: string;
20
+ /** Custom function when the axios request succeeds. */
15
21
  handleComplete?: Function;
22
+ /** Custom function when the axios request fails. */
16
23
  handleError?: Function;
24
+ /** Any components to be rendered in between the title and the buttons. */
17
25
  children?: React.ReactNode;
18
26
  }
19
27
 
28
+ /**
29
+ * Deletion confirmation. Navigates to a different route to allow the user to either confirm or cancel an action.
30
+ *
31
+ * Wraps `<ConfirmBaseForm/>`.
32
+ */
20
33
  export default function ConfirmDeleteForm({
21
34
  successUrl,
22
35
  form,
@@ -4,7 +4,7 @@ import StringDatePickerGroup from './StringDatePickerGroup';
4
4
  import FormTestBase from '../__Tests__/FormTestBase';
5
5
 
6
6
  //hack so the datepicker internals don't complain about this not existing in the context of jest
7
- HTMLCanvasElement.prototype.getContext = () => {};
7
+ HTMLCanvasElement.prototype.getContext = () => null;
8
8
 
9
9
  describe('IconInputGroup', () => {
10
10
  it('renders without crashing', () => {
@@ -8,10 +8,8 @@ import { InjectedFieldProps } from '../Field/InjectedFieldProps';
8
8
  import { FormDefaults } from '../FormDefaults';
9
9
  import Group, { GroupProps } from '../Group';
10
10
 
11
- // Docs for react-date-picker https://www.npmjs.com/package/react-date-picker
12
-
13
11
  export interface DatePickerGroupProps<T>
14
- extends InjectedFieldProps<T | undefined>,
12
+ extends InjectedFieldProps<T | undefined | null>,
15
13
  Omit<
16
14
  DatePickerProps,
17
15
  keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'
@@ -20,6 +18,11 @@ export interface DatePickerGroupProps<T>
20
18
  convert: (arg: Date) => T;
21
19
  }
22
20
 
21
+ /**
22
+ * Field for inputting dates. Uses `<Group/>` and `<DatePicker/>`.
23
+ *
24
+ * Uses [react-date-picker](https://www.npmjs.com/package/react-date-picker)
25
+ */
23
26
  export default function DatePickerGroup<T>({
24
27
  input,
25
28
  meta,
@@ -34,10 +37,14 @@ export default function DatePickerGroup<T>({
34
37
  const [displayDate, setDisplayDate] = useState<Date | null>(null);
35
38
 
36
39
  useEffect(() => {
37
- if (input.value != null) {
38
- setDisplayDate(new Date(`${input.value}T00:00:00.000`));
39
- } else {
40
+ if (!input.value) {
40
41
  setDisplayDate(null);
42
+ } else if (typeof input.value === 'string') {
43
+ if (input.value.indexOf('T') === -1) {
44
+ setDisplayDate(new Date(`${input.value}T00:00:00.000`));
45
+ } else {
46
+ setDisplayDate(new Date(input.value));
47
+ }
41
48
  }
42
49
  }, [setDisplayDate, input.value]);
43
50
 
@@ -1,9 +1,14 @@
1
- import { DatePickerHelper } from './DatePickerHelper';
2
1
  import DatePickerGroup from './DatePickerGroup';
2
+ import { DatePickerHelper } from './DatePickerHelper';
3
3
 
4
4
  export interface StringDateOnlyPickerGroupProps
5
- extends DatePickerHelper<string | undefined> {}
5
+ extends DatePickerHelper<string | undefined | null> {}
6
6
 
7
+ /**
8
+ * Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DD`.
9
+ *
10
+ * Default display to the user is in `MM/DD/YYYY` format.
11
+ */
7
12
  export default function StringDatePickerGroup(
8
13
  props: StringDateOnlyPickerGroupProps
9
14
  ) {
@@ -2,7 +2,13 @@ import DatePickerGroup from './DatePickerGroup';
2
2
  import { DatePickerHelper } from './DatePickerHelper';
3
3
 
4
4
  export interface StringDatePickerGroupProps
5
- extends DatePickerHelper<string | undefined> {}
5
+ extends DatePickerHelper<string | undefined | null> {}
6
+
7
+ /**
8
+ * Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DDTHH:mm:ss.sssZ` or `±YYYYYY-MM-DDTHH:mm:ss.sssZ`
9
+ *
10
+ * If you need `YYYY-MM-DD` format use `<StringDateOnlyPickerGroup/>`.
11
+ */
6
12
  export default function StringDatePickerGroup(
7
13
  props: StringDatePickerGroupProps
8
14
  ) {
@@ -14,7 +14,7 @@ export type RenderComponent<
14
14
  TValue,
15
15
  TRenderComponent extends ElementType
16
16
  > = Partial<ComponentProps<TRenderComponent>> extends Partial<
17
- InjectedFieldProps<TValue | undefined>
17
+ InjectedFieldProps<TValue | undefined | null>
18
18
  >
19
19
  ? TRenderComponent
20
20
  : never;
@@ -23,7 +23,7 @@ export type RenderComponentProps<
23
23
  TValue,
24
24
  TRenderComponent extends ElementType
25
25
  > = Partial<ComponentProps<TRenderComponent>> extends Partial<
26
- InjectedFieldProps<TValue | undefined>
26
+ InjectedFieldProps<TValue | undefined | null>
27
27
  >
28
28
  ? ComponentProps<TRenderComponent>
29
29
  : never;
@@ -34,14 +34,19 @@ export type FieldProps<
34
34
  TProp extends keyof TForm,
35
35
  TRenderComponent extends ElementType
36
36
  > = {
37
+ /** Name of the field. Used on submission. */
37
38
  name: TProp; // somewhat duplicated from useStandardFormInputProps but better for autocomplete
39
+ /** Component to be rendered. Usually this is a type of input group e.g. `<StringInputGroup/>` */
38
40
  Component: RenderComponent<TForm[TProp], TRenderComponent>;
39
-
41
+ /** Id of the field. */
40
42
  id?: string;
43
+ /** Whether the field should be disabled. */
41
44
  disabled?: boolean;
45
+ /** Client side validation functions */
42
46
  validate?:
43
47
  | ValidationFunction<TForm[TProp]>
44
48
  | ValidationFunction<TForm[TProp]>[];
49
+ /** Function to modify the field value without making the form dirty. (e.g. phone number) */
45
50
  normalize?: NormalizationFunction<TForm[TProp]>;
46
51
  } & Omit<
47
52
  RenderComponentProps<TForm[TProp], TRenderComponent>,
@@ -1,6 +1,7 @@
1
1
  import { useContext } from 'react';
2
2
  import { FieldNameContext } from './FieldNameContext';
3
3
 
4
+ /** Hidden `<div/>` that acts as an anchor to scroll to when a form error occurs. */
4
5
  export default function FieldErrorScrollTarget() {
5
6
  const name = useContext(FieldNameContext);
6
7
  if (!name) {
@@ -9,8 +9,11 @@ export type StandAloneInputProps<
9
9
  TValue,
10
10
  TRenderComponent extends ElementType
11
11
  > = {
12
+ /** Component to render inside of the field. */
12
13
  Component: RenderComponent<TValue, TRenderComponent>;
14
+ /** Value of the field. */
13
15
  value: TValue;
16
+ /** Function to change the value of the field. */
14
17
  onChange: (arg: TValue) => void;
15
18
  } & Omit<
16
19
  RenderComponentProps<TValue, TRenderComponent>,
@@ -21,6 +24,7 @@ export type StandAloneInputProps<
21
24
  | 'validate'
22
25
  >;
23
26
 
27
+ /** The stand alone version of `<Field/>`. Can use a type of input component outside of a `<Form/>`. */
24
28
  export default function StandAloneInput<TValue, TComponent extends ElementType>(
25
29
  props: StandAloneInputProps<TValue, TComponent>
26
30
  ) {
@@ -8,14 +8,19 @@ import { NormalizationFunction } from '../Normalization/NormalizationFunction';
8
8
  import { ValidationFunction } from '../Validation/ValidationFunction';
9
9
 
10
10
  export interface useStandardFieldProps<TValue> {
11
+ /** Id of the field. */
11
12
  id?: string;
13
+ /** Name of the field. */
12
14
  name: string;
15
+ /** Whether the field should be disabled. */
13
16
  disabled?: boolean;
17
+ /** Function to validate the field. */
14
18
  validate?: ValidationFunction<TValue> | ValidationFunction<TValue>[];
19
+ /** Function to modify the field value without making the form dirty. (e.g. phone number) */
15
20
  normalize?: NormalizationFunction<TValue>;
16
21
  }
17
22
 
18
- // provides a consistent way to deal with all form fields (non array)
23
+ /** Provides a consistent way to deal with all form fields (non array). */
19
24
  export default function useStandardField<TValue>({
20
25
  id: providedId,
21
26
  name: providedName,
@@ -51,7 +56,7 @@ export default function useStandardField<TValue>({
51
56
  disabled: disabled,
52
57
  validate: callAllValidators,
53
58
  });
54
- const { setFieldValue, isSubmitting } = useFormikContext();
59
+ const { setFieldTouched, setFieldValue, isSubmitting } = useFormikContext();
55
60
 
56
61
  const touched =
57
62
  formikMeta.touched !== false && formikMeta.touched !== undefined;
@@ -59,14 +64,13 @@ export default function useStandardField<TValue>({
59
64
  if (!touched && isSubmitting) {
60
65
  // because we do not always register all fields up front.
61
66
  // e.g. formik expects even a 'create' form to have all fields given, at least, blank values
62
- // that seems to be how it touches on submit:
63
- // see: https://codesandbox.io/s/formik-example-4n7n8 vs https://codesandbox.io/s/formik-example-kttk5
64
- // note in particular the change in line 24
65
- // thus, we manually touch all fields here by calling onBlur
66
- // there is a "setFieldTouched" from useFormikContext but it doesn't appear to work on field arrays
67
- handleBlur();
67
+ // It looks like this was going to be a thing: https://github.com/jaredpalmer/formik/issues/691
68
+ // Formik appears to not have an active maintainer: https://github.com/jaredpalmer/formik/discussions/3526
69
+ // We previously had a different fix in place using handleBlur, but it was causing an infinite update cycle.
70
+ // This was noted as existing, but there was a note about it not working for FieldArray (this does appear to work in my testing with FieldArray)
71
+ setFieldTouched(name);
68
72
  }
69
- });
73
+ }, [isSubmitting, name, setFieldTouched, touched]);
70
74
 
71
75
  // these are the props we expect consumers of this hook to pass directly to the input (or other control)
72
76
  const resultInput: CustomFieldInputProps<TValue> = {
@@ -3,17 +3,21 @@ import classNames from 'classnames';
3
3
  import Field, { FieldProps } from '../Field/Field';
4
4
  import { FieldNameContext } from '../Field/FieldNameContext';
5
5
  import useStandardFormInput from '../Field/useStandardField';
6
- import { ValidationFunction } from '../Validation/ValidationFunction';
7
6
  import { FormDefaults } from '../FormDefaults';
7
+ import { ValidationFunction } from '../Validation/ValidationFunction';
8
8
 
9
9
  export type FieldArrayProps<
10
10
  TForm extends object,
11
11
  TProp extends keyof TForm
12
- > = TForm[TProp] extends Array<any> | undefined
12
+ > = TForm[TProp] extends Array<any> | undefined | null
13
13
  ? {
14
+ /** Name of the field, used on submission. If using codegen this must be the provided dto. */
14
15
  name: TProp;
16
+ /** Label of the field. */
15
17
  label?: string;
18
+ /** Whether the field should be disabled. */
16
19
  disabled?: boolean;
20
+ /** Function to validate the value. */
17
21
  validate?:
18
22
  | ValidationFunction<TForm[TProp]>
19
23
  | ValidationFunction<TForm[TProp]>[];
@@ -23,8 +27,8 @@ export type FieldArrayProps<
23
27
  }
24
28
  : never;
25
29
 
26
- export type ArrayFormBuilderProp<TValue extends Array<any> | undefined> =
27
- TValue extends Array<infer TForm> | undefined
30
+ export type ArrayFormBuilderProp<TValue extends Array<any> | undefined | null> =
31
+ TValue extends Array<infer TForm> | undefined | null
28
32
  ? TForm extends object
29
33
  ? {
30
34
  Field: <
@@ -41,6 +45,11 @@ export type ArrayFormBuilderProp<TValue extends Array<any> | undefined> =
41
45
  : never
42
46
  : never;
43
47
 
48
+ /**
49
+ * An array of fields that allows the user to add multiple instances of the same field.
50
+ *
51
+ * Includes "Add Item" and "Remove Item" buttons to allow the user to speicify the number of fields.
52
+ */
44
53
  export default function FieldArray<
45
54
  TForm extends object,
46
55
  TProp extends keyof TForm
@@ -52,7 +61,7 @@ export default function FieldArray<
52
61
  children,
53
62
  ...rest
54
63
  }: FieldArrayProps<TForm, TProp>) {
55
- const [input, meta] = useStandardFormInput<TForm[TProp]>({
64
+ const [input] = useStandardFormInput<TForm[TProp]>({
56
65
  name: String(name),
57
66
  validate: validate,
58
67
  disabled: disabled,
@@ -2,17 +2,18 @@ import React, { ComponentType, LegacyRef } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import FileList from './FileList';
4
4
  import { InjectedFieldProps } from '../Field/InjectedFieldProps';
5
- import Group, { GroupProps } from '../Group';
6
5
  import { FormDefaults } from '../FormDefaults';
6
+ import Group, { GroupProps } from '../Group';
7
7
 
8
8
  export interface FileGroupProps
9
9
  // note: file props are of type "any" with the current type generation
10
- extends InjectedFieldProps<any | undefined>,
10
+ extends InjectedFieldProps<any | undefined | null>,
11
11
  Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'>,
12
12
  Omit<
13
13
  React.HTMLProps<HTMLInputElement>,
14
14
  keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'
15
15
  > {
16
+ /** Allow multiple files to be uploaded. */
16
17
  multiple?: boolean | undefined;
17
18
  }
18
19
 
@@ -76,6 +77,7 @@ function FileGroup(
76
77
  );
77
78
  }
78
79
 
80
+ /** File upload input group. */
79
81
  const FileGroupWithRef = React.forwardRef(
80
82
  FileGroup
81
83
  ) as ComponentType<FileGroupProps>;
@@ -1,8 +1,8 @@
1
1
  import { FormDefaults } from '../FormDefaults';
2
2
 
3
3
  export interface FileListProps {
4
- files?: File | File[] | undefined;
5
- rejectedFiles?: File | File[] | undefined;
4
+ files?: File | File[] | undefined | null;
5
+ rejectedFiles?: File | File[] | undefined | null;
6
6
  }
7
7
  export default function FileList({ files, rejectedFiles }: FileListProps) {
8
8
  return (