envoc-form 4.0.1-9 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/README.md +9443 -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 +7 -2
  9. package/es/DatePicker/DatePickerGroup.js +18 -7
  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/DateTimePicker/DateTimePickerGroup.d.ts +13 -0
  15. package/es/DateTimePicker/DateTimePickerGroup.js +87 -0
  16. package/es/DateTimePicker/DateTimePickerHelper.d.ts +3 -0
  17. package/es/DateTimePicker/DateTimePickerHelper.js +1 -0
  18. package/es/DateTimePicker/StringDateTimePickerGroup.d.ts +10 -0
  19. package/es/DateTimePicker/StringDateTimePickerGroup.js +53 -0
  20. package/es/Field/Field.d.ts +9 -3
  21. package/es/Field/Field.js +9 -4
  22. package/es/Field/FieldErrorScrollTarget.d.ts +1 -0
  23. package/es/Field/FieldErrorScrollTarget.js +1 -0
  24. package/es/Field/StandAloneInput.d.ts +4 -0
  25. package/es/Field/StandAloneInput.js +1 -0
  26. package/es/Field/useStandardField.d.ts +6 -0
  27. package/es/Field/useStandardField.js +8 -9
  28. package/es/FieldArray/FieldArray.d.ts +11 -2
  29. package/es/FieldArray/FieldArray.js +7 -2
  30. package/es/File/FileGroup.d.ts +3 -1
  31. package/es/File/FileGroup.js +4 -3
  32. package/es/File/FileList.d.ts +2 -2
  33. package/es/Form/FocusError.d.ts +2 -0
  34. package/es/Form/FocusError.js +1 -0
  35. package/es/Form/Form.d.ts +6 -0
  36. package/es/Form/Form.js +1 -0
  37. package/es/Form/FormBasedPreventNavigation.d.ts +3 -1
  38. package/es/Form/FormBasedPreventNavigation.js +12 -45
  39. package/es/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
  40. package/es/Form/LegacyFormBasedPreventNavigation.js +69 -0
  41. package/es/Form/NewFormBasedPreventNavigation.d.ts +14 -0
  42. package/es/Form/NewFormBasedPreventNavigation.js +39 -0
  43. package/es/Form/ServerErrorContext.d.ts +1 -0
  44. package/es/Form/ServerErrorContext.js +1 -0
  45. package/es/FormActions.d.ts +6 -0
  46. package/es/FormActions.js +1 -0
  47. package/es/FormDefaults.d.ts +1 -0
  48. package/es/FormDefaults.js +1 -0
  49. package/es/Group.d.ts +7 -4
  50. package/es/Group.js +4 -3
  51. package/es/Input/IconInputGroup.d.ts +4 -1
  52. package/es/Input/IconInputGroup.js +3 -1
  53. package/es/Input/InputGroup.d.ts +4 -4
  54. package/es/Input/InputGroup.js +4 -4
  55. package/es/Input/MoneyInputGroup.d.ts +3 -1
  56. package/es/Input/MoneyInputGroup.js +1 -0
  57. package/es/Input/NumberInputGroup.d.ts +3 -1
  58. package/es/Input/NumberInputGroup.js +1 -0
  59. package/es/Input/PhoneNumberInputGroup.d.ts +10 -0
  60. package/es/Input/PhoneNumberInputGroup.js +47 -0
  61. package/es/Input/StringInputGroup.d.ts +2 -1
  62. package/es/Input/StringInputGroup.js +3 -1
  63. package/es/Normalization/normalizers.d.ts +4 -2
  64. package/es/Normalization/normalizers.js +2 -0
  65. package/es/Select/BooleanSelectGroup.d.ts +2 -1
  66. package/es/Select/BooleanSelectGroup.js +1 -0
  67. package/es/Select/NumberSelectGroup.d.ts +4 -2
  68. package/es/Select/NumberSelectGroup.js +2 -0
  69. package/es/Select/SelectGroup.d.ts +8 -2
  70. package/es/Select/SelectGroup.js +5 -4
  71. package/es/Select/StringSelectGroup.d.ts +2 -0
  72. package/es/Select/StringSelectGroup.js +2 -0
  73. package/es/StandardFormActions.d.ts +5 -0
  74. package/es/StandardFormActions.js +1 -0
  75. package/es/SubmitFormButton.d.ts +4 -1
  76. package/es/SubmitFormButton.js +1 -0
  77. package/es/TextArea/TextAreaGroup.d.ts +2 -1
  78. package/es/TextArea/TextAreaGroup.js +5 -4
  79. package/es/Validation/validators.d.ts +11 -8
  80. package/es/Validation/validators.js +6 -2
  81. package/es/hooks/index.d.ts +2 -0
  82. package/es/hooks/index.js +2 -0
  83. package/es/hooks/useFormValue.d.ts +2 -0
  84. package/es/hooks/useFormValue.js +7 -0
  85. package/es/index.d.ts +10 -4
  86. package/es/index.js +4 -0
  87. package/es/setupTests.d.ts +1 -0
  88. package/es/setupTests.js +1 -0
  89. package/lib/AddressInput/AddressInput.d.ts +15 -5
  90. package/lib/AddressInput/AddressInput.js +10 -0
  91. package/lib/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
  92. package/lib/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
  93. package/lib/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
  94. package/lib/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
  95. package/lib/DatePicker/DatePickerGroup.d.ts +7 -2
  96. package/lib/DatePicker/DatePickerGroup.js +18 -7
  97. package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +6 -1
  98. package/lib/DatePicker/StringDateOnlyPickerGroup.js +5 -0
  99. package/lib/DatePicker/StringDatePickerGroup.d.ts +6 -1
  100. package/lib/DatePicker/StringDatePickerGroup.js +5 -0
  101. package/lib/DateTimePicker/DateTimePickerGroup.d.ts +13 -0
  102. package/lib/DateTimePicker/DateTimePickerGroup.js +93 -0
  103. package/lib/DateTimePicker/DateTimePickerHelper.d.ts +3 -0
  104. package/lib/DateTimePicker/DateTimePickerHelper.js +2 -0
  105. package/lib/DateTimePicker/StringDateTimePickerGroup.d.ts +10 -0
  106. package/lib/DateTimePicker/StringDateTimePickerGroup.js +59 -0
  107. package/lib/Field/Field.d.ts +9 -3
  108. package/lib/Field/Field.js +9 -4
  109. package/lib/Field/FieldErrorScrollTarget.d.ts +1 -0
  110. package/lib/Field/FieldErrorScrollTarget.js +1 -0
  111. package/lib/Field/StandAloneInput.d.ts +4 -0
  112. package/lib/Field/StandAloneInput.js +1 -0
  113. package/lib/Field/useStandardField.d.ts +6 -0
  114. package/lib/Field/useStandardField.js +8 -9
  115. package/lib/FieldArray/FieldArray.d.ts +11 -2
  116. package/lib/FieldArray/FieldArray.js +7 -2
  117. package/lib/File/FileGroup.d.ts +3 -1
  118. package/lib/File/FileGroup.js +4 -3
  119. package/lib/File/FileList.d.ts +2 -2
  120. package/lib/Form/FocusError.d.ts +2 -0
  121. package/lib/Form/FocusError.js +1 -0
  122. package/lib/Form/Form.d.ts +6 -0
  123. package/lib/Form/Form.js +1 -0
  124. package/lib/Form/FormBasedPreventNavigation.d.ts +3 -1
  125. package/lib/Form/FormBasedPreventNavigation.js +13 -43
  126. package/lib/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
  127. package/lib/Form/LegacyFormBasedPreventNavigation.js +72 -0
  128. package/lib/Form/NewFormBasedPreventNavigation.d.ts +14 -0
  129. package/lib/Form/NewFormBasedPreventNavigation.js +42 -0
  130. package/lib/Form/ServerErrorContext.d.ts +1 -0
  131. package/lib/Form/ServerErrorContext.js +1 -0
  132. package/lib/FormActions.d.ts +6 -0
  133. package/lib/FormActions.js +1 -0
  134. package/lib/FormDefaults.d.ts +1 -0
  135. package/lib/FormDefaults.js +1 -0
  136. package/lib/Group.d.ts +7 -4
  137. package/lib/Group.js +4 -3
  138. package/lib/Input/IconInputGroup.d.ts +4 -1
  139. package/lib/Input/IconInputGroup.js +3 -1
  140. package/lib/Input/InputGroup.d.ts +4 -4
  141. package/lib/Input/InputGroup.js +4 -4
  142. package/lib/Input/MoneyInputGroup.d.ts +3 -1
  143. package/lib/Input/MoneyInputGroup.js +1 -0
  144. package/lib/Input/NumberInputGroup.d.ts +3 -1
  145. package/lib/Input/NumberInputGroup.js +1 -0
  146. package/lib/Input/PhoneNumberInputGroup.d.ts +10 -0
  147. package/lib/Input/PhoneNumberInputGroup.js +52 -0
  148. package/lib/Input/StringInputGroup.d.ts +2 -1
  149. package/lib/Input/StringInputGroup.js +3 -1
  150. package/lib/Normalization/normalizers.d.ts +4 -2
  151. package/lib/Normalization/normalizers.js +2 -0
  152. package/lib/Select/BooleanSelectGroup.d.ts +2 -1
  153. package/lib/Select/BooleanSelectGroup.js +1 -0
  154. package/lib/Select/NumberSelectGroup.d.ts +4 -2
  155. package/lib/Select/NumberSelectGroup.js +2 -0
  156. package/lib/Select/SelectGroup.d.ts +8 -2
  157. package/lib/Select/SelectGroup.js +5 -4
  158. package/lib/Select/StringSelectGroup.d.ts +2 -0
  159. package/lib/Select/StringSelectGroup.js +2 -0
  160. package/lib/StandardFormActions.d.ts +5 -0
  161. package/lib/StandardFormActions.js +1 -0
  162. package/lib/SubmitFormButton.d.ts +4 -1
  163. package/lib/SubmitFormButton.js +1 -0
  164. package/lib/TextArea/TextAreaGroup.d.ts +2 -1
  165. package/lib/TextArea/TextAreaGroup.js +5 -4
  166. package/lib/Validation/validators.d.ts +11 -8
  167. package/lib/Validation/validators.js +6 -2
  168. package/lib/hooks/index.d.ts +2 -0
  169. package/lib/{__Tests__ → hooks}/index.js +3 -3
  170. package/lib/hooks/useFormValue.d.ts +2 -0
  171. package/lib/hooks/useFormValue.js +10 -0
  172. package/lib/index.d.ts +10 -4
  173. package/lib/index.js +8 -1
  174. package/lib/setupTests.d.ts +1 -0
  175. package/lib/setupTests.js +3 -0
  176. package/package.json +12 -8
  177. package/src/AddressInput/AddressInput.tsx +15 -5
  178. package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +8 -4
  179. package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +14 -0
  180. package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +13 -0
  181. package/src/DatePicker/DatePicker.test.tsx +1 -1
  182. package/src/DatePicker/DatePickerGroup.tsx +23 -7
  183. package/src/DatePicker/StringDateOnlyPickerGroup.tsx +7 -2
  184. package/src/DatePicker/StringDatePickerGroup.tsx +7 -1
  185. package/src/DateTimePicker/DateTimePicker.test.tsx +243 -0
  186. package/src/DateTimePicker/DateTimePickerGroup.tsx +116 -0
  187. package/src/DateTimePicker/DateTimePickerHelper.ts +4 -0
  188. package/src/DateTimePicker/StringDateTimePickerGroup.tsx +61 -0
  189. package/src/DateTimePicker/__snapshots__/DateTimePicker.test.tsx.snap +216 -0
  190. package/src/Field/Field.tsx +20 -7
  191. package/src/Field/FieldErrorScrollTarget.tsx +1 -0
  192. package/src/Field/StandAloneInput.tsx +4 -0
  193. package/src/Field/useStandardField.ts +13 -9
  194. package/src/FieldArray/FieldArray.tsx +14 -5
  195. package/src/File/FileGroup.tsx +9 -3
  196. package/src/File/FileList.tsx +2 -2
  197. package/src/Form/FocusError.tsx +3 -0
  198. package/src/Form/Form.tsx +6 -0
  199. package/src/Form/FormBasedPreventNavigation.tsx +28 -46
  200. package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -0
  201. package/src/Form/NewFormBasedPreventNavigation.tsx +59 -0
  202. package/src/Form/ServerErrorContext.ts +1 -0
  203. package/src/FormActions.tsx +7 -0
  204. package/src/FormDefaults.ts +1 -0
  205. package/src/Group.tsx +12 -4
  206. package/src/Input/IconInputGroup.tsx +5 -2
  207. package/src/Input/InputGroup.tsx +13 -5
  208. package/src/Input/MoneyInputGroup.tsx +3 -1
  209. package/src/Input/NumberInputGroup.tsx +3 -1
  210. package/src/Input/PhoneNumberInputGroup.tsx +49 -0
  211. package/src/Input/StringInputGroup.tsx +3 -2
  212. package/src/Input/__Tests__/PhoneNumberInputGroup.test.tsx +37 -0
  213. package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +1 -0
  214. package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +1 -0
  215. package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +1 -0
  216. package/src/Input/__Tests__/__snapshots__/PhoneNumberInputGroup.test.tsx.snap +33 -0
  217. package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +1 -0
  218. package/src/Normalization/normalizers.ts +4 -2
  219. package/src/Select/BooleanSelectGroup.tsx +2 -1
  220. package/src/Select/NumberSelectGroup.tsx +4 -2
  221. package/src/Select/SelectGroup.tsx +13 -2
  222. package/src/Select/StringSelectGroup.tsx +2 -0
  223. package/src/StandardFormActions.tsx +5 -0
  224. package/src/SubmitFormButton.tsx +5 -1
  225. package/src/TextArea/TextAreaGroup.tsx +6 -4
  226. package/src/Validation/validators.ts +19 -14
  227. package/src/__Tests__/FormTestBase.tsx +10 -8
  228. package/src/__Tests__/RealisticForm.test.tsx +82 -0
  229. package/src/hooks/index.ts +3 -0
  230. package/src/hooks/useFormValue.ts +16 -0
  231. package/src/index.ts +14 -4
  232. package/src/setupTests.ts +1 -0
  233. package/es/__Tests__/FormTestBase.d.ts +0 -27
  234. package/es/__Tests__/FormTestBase.js +0 -83
  235. package/es/__Tests__/index.d.ts +0 -2
  236. package/es/__Tests__/index.js +0 -2
  237. package/lib/__Tests__/FormTestBase.d.ts +0 -27
  238. package/lib/__Tests__/FormTestBase.js +0 -86
  239. package/lib/__Tests__/index.d.ts +0 -2
@@ -16,6 +16,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  var jsx_runtime_1 = require("react/jsx-runtime");
18
18
  var DatePickerGroup_1 = __importDefault(require("./DatePickerGroup"));
19
+ /**
20
+ * Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DD`.
21
+ *
22
+ * Default display to the user is in `MM/DD/YYYY` format.
23
+ */
19
24
  function StringDatePickerGroup(props) {
20
25
  return (0, jsx_runtime_1.jsx)(DatePickerGroup_1.default, __assign({}, props, { convert: convertToDateOnly }));
21
26
  }
@@ -1,5 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { DatePickerHelper } from './DatePickerHelper';
3
- export interface StringDatePickerGroupProps extends DatePickerHelper<string | undefined> {
3
+ export interface StringDatePickerGroupProps extends DatePickerHelper<string | undefined | null> {
4
4
  }
5
+ /**
6
+ * 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`
7
+ *
8
+ * If you need `YYYY-MM-DD` format use `<StringDateOnlyPickerGroup/>`.
9
+ */
5
10
  export default function StringDatePickerGroup(props: StringDatePickerGroupProps): JSX.Element;
@@ -16,6 +16,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  var jsx_runtime_1 = require("react/jsx-runtime");
18
18
  var DatePickerGroup_1 = __importDefault(require("./DatePickerGroup"));
19
+ /**
20
+ * 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`
21
+ *
22
+ * If you need `YYYY-MM-DD` format use `<StringDateOnlyPickerGroup/>`.
23
+ */
19
24
  function StringDatePickerGroup(props) {
20
25
  return (0, jsx_runtime_1.jsx)(DatePickerGroup_1.default, __assign({}, props, { convert: convertToDateOnly }));
21
26
  }
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import { DateTimePickerProps } from 'react-datetime-picker';
3
+ import { InjectedFieldProps } from '../Field/InjectedFieldProps';
4
+ import { GroupProps } from '../Group';
5
+ export interface DateTimePickerGroupProps<T> extends InjectedFieldProps<T | undefined | null>, Omit<DateTimePickerProps, keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'>, Omit<GroupProps, keyof InjectedFieldProps<T> | 'children'> {
6
+ convert: (date: Date) => T;
7
+ }
8
+ /**
9
+ * Field for inputting date and time. Uses `<Group/>` and `<DateTimePicker/>`.
10
+ *
11
+ * Uses [react-datetime-picker](https://www.npmjs.com/package/react-datetime-picker)
12
+ */
13
+ export default function DateTimePickerGroup<T>({ input, meta, label, helpText, className, required, disabled, convert, ...rest }: DateTimePickerGroupProps<T>): JSX.Element;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ var jsx_runtime_1 = require("react/jsx-runtime");
29
+ var react_1 = require("react");
30
+ var react_datetime_picker_1 = require("react-datetime-picker");
31
+ var classnames_1 = __importDefault(require("classnames"));
32
+ var parseISO_1 = __importDefault(require("date-fns/parseISO"));
33
+ var FormDefaults_1 = require("../FormDefaults");
34
+ var Group_1 = __importDefault(require("../Group"));
35
+ /**
36
+ * Field for inputting date and time. Uses `<Group/>` and `<DateTimePicker/>`.
37
+ *
38
+ * Uses [react-datetime-picker](https://www.npmjs.com/package/react-datetime-picker)
39
+ */
40
+ function DateTimePickerGroup(_a) {
41
+ var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, convert = _a.convert, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "convert"]);
42
+ var _b = (0, react_1.useState)(null), displayDateTime = _b[0], setDisplayDateTime = _b[1];
43
+ (0, react_1.useEffect)(function () {
44
+ var inputValue = input.value;
45
+ if (!inputValue) {
46
+ setDisplayDateTime(null);
47
+ }
48
+ else if (typeof inputValue === 'string') {
49
+ var parsedDateTime = convertISODateTimeStringToDate(inputValue);
50
+ setDisplayDateTime(parsedDateTime);
51
+ }
52
+ else if (inputValue instanceof Date) {
53
+ setDisplayDateTime(inputValue);
54
+ }
55
+ }, [setDisplayDateTime, input.value]);
56
+ return ((0, jsx_runtime_1.jsx)(Group_1.default, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'date-time-picker'), required: required, disabled: disabled }, { children: (0, jsx_runtime_1.jsx)(react_datetime_picker_1.DateTimePicker, __assign({}, rest, { className: (0, classnames_1.default)(FormDefaults_1.FormDefaults.cssClassPrefix + 'date-time-picker', className), value: displayDateTime, onChange: handleChange })) })));
57
+ function handleChange(newDateTime) {
58
+ var onChange = input.onChange;
59
+ if (onChange === null) {
60
+ return;
61
+ }
62
+ if (!newDateTime) {
63
+ onChange(undefined);
64
+ setDisplayDateTime(null);
65
+ return;
66
+ }
67
+ else if (typeof newDateTime === 'string') {
68
+ var parsedDateTime = (0, parseISO_1.default)(newDateTime);
69
+ setDisplayDateTime(parsedDateTime);
70
+ onChange(convert(parsedDateTime));
71
+ }
72
+ else if (newDateTime instanceof Date) {
73
+ setDisplayDateTime(newDateTime);
74
+ onChange(convert(newDateTime));
75
+ }
76
+ }
77
+ }
78
+ exports.default = DateTimePickerGroup;
79
+ function convertISODateTimeStringToDate(isoDateTimeString) {
80
+ var isoDateTimeRegex = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?)([+-]\d{2}:\d{2}|Z)?$/;
81
+ var isValidIsoDateTimeString = isoDateTimeRegex.test(isoDateTimeString);
82
+ if (isValidIsoDateTimeString) {
83
+ return new Date(isoDateTimeString);
84
+ }
85
+ var errorMessage = "Invalid \"date time\" value of ".concat(isoDateTimeString, " provided to DateTimePickerGroup component. Please provide ISO 8601 string that includes the time zone designator. Sample strings: 2022-09-24T:08:54:12+00:00, 2022-09-24T:08:54:12Z, 2022-09-24T:08:54:12.123-05:00");
86
+ if (process.env.NODE_ENV !== 'production') {
87
+ throw new Error(errorMessage);
88
+ }
89
+ else {
90
+ console.error(errorMessage);
91
+ }
92
+ return null;
93
+ }
@@ -0,0 +1,3 @@
1
+ import { DateTimePickerGroupProps } from './DateTimePickerGroup';
2
+ export interface DateTimePickerHelper<T> extends Omit<DateTimePickerGroupProps<T>, 'convert'> {
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { DateTimePickerHelper } from './DateTimePickerHelper';
3
+ export interface StringDateTimePickerGroupProps extends DateTimePickerHelper<string | undefined | null> {
4
+ }
5
+ /**
6
+ * Date Time picker input that consumes JS Date object and outputs as a date time offset string in ISO format `YYYY-MM-DDTHH:mm:ss.sss±hh:mm`.
7
+ *
8
+ * Default display to the user is in `MM/DD/YYYY HH:mm:ss AM/PM` format.
9
+ */
10
+ export default function StringDateTimePickerGroup(props: StringDateTimePickerGroupProps): JSX.Element;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var jsx_runtime_1 = require("react/jsx-runtime");
18
+ var DateTimePickerGroup_1 = __importDefault(require("./DateTimePickerGroup"));
19
+ /**
20
+ * Date Time picker input that consumes JS Date object and outputs as a date time offset string in ISO format `YYYY-MM-DDTHH:mm:ss.sss±hh:mm`.
21
+ *
22
+ * Default display to the user is in `MM/DD/YYYY HH:mm:ss AM/PM` format.
23
+ */
24
+ function StringDateTimePickerGroup(props) {
25
+ return (0, jsx_runtime_1.jsx)(DateTimePickerGroup_1.default, __assign({}, props, { convert: convertToISOString }));
26
+ }
27
+ exports.default = StringDateTimePickerGroup;
28
+ function convertToISOString(date) {
29
+ // Get the offset in minutes
30
+ var offsetMinutes = date.getTimezoneOffset();
31
+ // Calculate the offset in hours and minutes
32
+ var offsetHours = Math.floor(Math.abs(offsetMinutes) / 60);
33
+ var offsetMinutesPart = Math.abs(offsetMinutes) % 60;
34
+ // Format the offset in the required format (+/-hh:mm)
35
+ var offsetString = (offsetMinutes >= 0 ? '-' : '+') +
36
+ String(offsetHours).padStart(2, '0') +
37
+ ':' +
38
+ String(offsetMinutesPart).padStart(2, '0');
39
+ // Format the date in the required format using `intl.DateTimeFormat`
40
+ var year = new Intl.DateTimeFormat('en', { year: 'numeric' })
41
+ .format(date)
42
+ .padStart(4, '0');
43
+ var month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(date);
44
+ var day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(date);
45
+ var hour = new Intl.DateTimeFormat('en', {
46
+ hour: '2-digit',
47
+ hourCycle: 'h23',
48
+ }).format(date);
49
+ var minute = new Intl.DateTimeFormat('en', { minute: '2-digit' })
50
+ .format(date)
51
+ .padStart(2, '0');
52
+ var second = new Intl.DateTimeFormat('en', {
53
+ second: '2-digit',
54
+ fractionalSecondDigits: 3,
55
+ })
56
+ .format(date)
57
+ .padStart(6, '0');
58
+ return "".concat(year, "-").concat(month, "-").concat(day, "T").concat(hour, ":").concat(minute, ":").concat(second).concat(offsetString);
59
+ }
@@ -2,21 +2,27 @@ import { ComponentProps, ElementType, LegacyRef } from 'react';
2
2
  import { InjectedFieldProps } from './InjectedFieldProps';
3
3
  import { NormalizationFunction } from '../Normalization/NormalizationFunction';
4
4
  import { ValidationFunction } from '../Validation/ValidationFunction';
5
- export declare type RenderComponent<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined>> ? TRenderComponent : never;
6
- export declare type RenderComponentProps<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined>> ? ComponentProps<TRenderComponent> : never;
5
+ export declare type RenderComponent<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined | null>> ? TRenderComponent : never;
6
+ export declare type RenderComponentProps<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined | null>> ? ComponentProps<TRenderComponent> : never;
7
7
  /** A specific Field instance to be rendered by the given TRenderComponent or by whatever default is reasonable */
8
8
  export declare type FieldProps<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType> = {
9
+ /** Name of the field. Used on submission. */
9
10
  name: TProp;
11
+ /** Component to be rendered. Usually this is a type of input group e.g. `<StringInputGroup/>` */
10
12
  Component: RenderComponent<TForm[TProp], TRenderComponent>;
13
+ /** Id of the field. */
11
14
  id?: string;
15
+ /** Whether the field should be disabled. */
12
16
  disabled?: boolean;
17
+ /** Client side validation functions */
13
18
  validate?: ValidationFunction<TForm[TProp]> | ValidationFunction<TForm[TProp]>[];
19
+ /** Function to modify the field value without making the form dirty. (e.g. phone number) */
14
20
  normalize?: NormalizationFunction<TForm[TProp]>;
15
21
  } & Omit<RenderComponentProps<TForm[TProp], TRenderComponent>, keyof InjectedFieldProps<TForm[TProp]>>;
16
22
  /**
17
23
  * Renders whatever Component is passed - injecting the formik values needed to finish wiring up that individual field.
18
24
  * Should no Component be used then the default will be provided by the default lookup based on typeof(TForm[TProp])
19
25
  */
20
- declare function Field<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType>({ name, Component, id, normalize, validate, disabled, ...rest }: FieldProps<TForm, TProp, TRenderComponent>, ref: LegacyRef<any>): JSX.Element;
26
+ declare function Field<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType>({ name, Component, id, disabled, validate, normalize, ...rest }: FieldProps<TForm, TProp, TRenderComponent>, ref: LegacyRef<any>): JSX.Element;
21
27
  declare const _default: typeof Field;
22
28
  export default _default;
@@ -29,22 +29,27 @@ var jsx_runtime_1 = require("react/jsx-runtime");
29
29
  var react_1 = __importDefault(require("react"));
30
30
  var FieldNameContext_1 = require("./FieldNameContext");
31
31
  var useStandardField_1 = __importDefault(require("./useStandardField"));
32
+ var validators_1 = require("../Validation/validators");
32
33
  /**
33
34
  * Renders whatever Component is passed - injecting the formik values needed to finish wiring up that individual field.
34
35
  * Should no Component be used then the default will be provided by the default lookup based on typeof(TForm[TProp])
35
36
  */
36
37
  function Field(_a, ref) {
37
- var name = _a.name, Component = _a.Component, id = _a.id, normalize = _a.normalize, validate = _a.validate, disabled = _a.disabled, rest = __rest(_a, ["name", "Component", "id", "normalize", "validate", "disabled"]);
38
+ var name = _a.name, Component = _a.Component, id = _a.id, disabled = _a.disabled, validate = _a.validate, normalize = _a.normalize, rest = __rest(_a, ["name", "Component", "id", "disabled", "validate", "normalize"]);
38
39
  var _b = (0, useStandardField_1.default)({
39
40
  name: String(name),
40
41
  id: id,
41
- normalize: normalize,
42
- validate: validate,
43
42
  disabled: disabled,
43
+ validate: validate,
44
+ normalize: normalize,
44
45
  }), input = _b[0], meta = _b[1];
46
+ var isRequired = (rest === null || rest === void 0 ? void 0 : rest.required) !== undefined
47
+ ? rest.required
48
+ : validate === validators_1.required ||
49
+ (Array.isArray(validate) && validate.includes(validators_1.required));
45
50
  // a bit of a hack so JSX is happy with us
46
51
  var Wrapped = Component;
47
- return ((0, jsx_runtime_1.jsx)(FieldNameContext_1.FieldNameContext.Provider, __assign({ value: input.name }, { children: (0, jsx_runtime_1.jsx)(Wrapped, __assign({}, rest, { ref: ref, id: input.id, input: input, meta: meta, disabled: disabled })) })));
52
+ return ((0, jsx_runtime_1.jsx)(FieldNameContext_1.FieldNameContext.Provider, __assign({ value: input.name }, { children: (0, jsx_runtime_1.jsx)(Wrapped, __assign({}, rest, { ref: ref, id: input.id, input: input, meta: meta, required: isRequired, disabled: disabled })) })));
48
53
  }
49
54
  // hack to get forwarded refs to work
50
55
  var FieldWithRef = react_1.default.forwardRef(Field);
@@ -1,2 +1,3 @@
1
1
  /// <reference types="react" />
2
+ /** Hidden `<div/>` that acts as an anchor to scroll to when a form error occurs. */
2
3
  export default function FieldErrorScrollTarget(): JSX.Element | null;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var jsx_runtime_1 = require("react/jsx-runtime");
4
4
  var react_1 = require("react");
5
5
  var FieldNameContext_1 = require("./FieldNameContext");
6
+ /** Hidden `<div/>` that acts as an anchor to scroll to when a form error occurs. */
6
7
  function FieldErrorScrollTarget() {
7
8
  var name = (0, react_1.useContext)(FieldNameContext_1.FieldNameContext);
8
9
  if (!name) {
@@ -2,8 +2,12 @@ import { ElementType } from 'react';
2
2
  import { RenderComponent, RenderComponentProps } from './Field';
3
3
  import { InjectedFieldProps } from './InjectedFieldProps';
4
4
  export declare type StandAloneInputProps<TValue, TRenderComponent extends ElementType> = {
5
+ /** Component to render inside of the field. */
5
6
  Component: RenderComponent<TValue, TRenderComponent>;
7
+ /** Value of the field. */
6
8
  value: TValue;
9
+ /** Function to change the value of the field. */
7
10
  onChange: (arg: TValue) => void;
8
11
  } & Omit<RenderComponentProps<TValue, TRenderComponent>, keyof InjectedFieldProps<TValue> | 'value' | 'onChange' | 'normalize' | 'validate'>;
12
+ /** The stand alone version of `<Field/>`. Can use a type of input component outside of a `<Form/>`. */
9
13
  export default function StandAloneInput<TValue, TComponent extends ElementType>(props: StandAloneInputProps<TValue, TComponent>): JSX.Element;
@@ -48,6 +48,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
48
48
  var jsx_runtime_1 = require("react/jsx-runtime");
49
49
  var react_1 = require("react");
50
50
  var uuid = __importStar(require("uuid"));
51
+ /** The stand alone version of `<Field/>`. Can use a type of input component outside of a `<Form/>`. */
51
52
  function StandAloneInput(props) {
52
53
  var Component = props.Component, value = props.value, onChange = props.onChange, disabled = props.disabled, rest = __rest(props, ["Component", "value", "onChange", "disabled"]);
53
54
  var handleChange = function (arg) {
@@ -3,12 +3,18 @@ import { CustomFieldMetaProps } from './CustomFieldMetaProps';
3
3
  import { NormalizationFunction } from '../Normalization/NormalizationFunction';
4
4
  import { ValidationFunction } from '../Validation/ValidationFunction';
5
5
  export interface useStandardFieldProps<TValue> {
6
+ /** Id of the field. */
6
7
  id?: string;
8
+ /** Name of the field. */
7
9
  name: string;
10
+ /** Whether the field should be disabled. */
8
11
  disabled?: boolean;
12
+ /** Function to validate the field. */
9
13
  validate?: ValidationFunction<TValue> | ValidationFunction<TValue>[];
14
+ /** Function to modify the field value without making the form dirty. (e.g. phone number) */
10
15
  normalize?: NormalizationFunction<TValue>;
11
16
  }
17
+ /** Provides a consistent way to deal with all form fields (non array). */
12
18
  export default function useStandardField<TValue>({ id: providedId, name: providedName, disabled, validate, normalize, }: useStandardFieldProps<TValue>): [
13
19
  CustomFieldInputProps<TValue>,
14
20
  CustomFieldMetaProps<TValue>
@@ -15,7 +15,7 @@ var react_1 = require("react");
15
15
  var formik_1 = require("formik");
16
16
  var FieldNameContext_1 = require("./FieldNameContext");
17
17
  var ServerErrorContext_1 = require("../Form/ServerErrorContext");
18
- // provides a consistent way to deal with all form fields (non array)
18
+ /** Provides a consistent way to deal with all form fields (non array). */
19
19
  function useStandardField(_a) {
20
20
  var providedId = _a.id, providedName = _a.name, disabled = _a.disabled, validate = _a.validate, normalize = _a.normalize;
21
21
  // because the formik errors are evaluated all at the same time we need to keep server errors separate
@@ -39,20 +39,19 @@ function useStandardField(_a) {
39
39
  disabled: disabled,
40
40
  validate: callAllValidators,
41
41
  }), formikInput = _c[0], formikMeta = _c[1];
42
- var _d = (0, formik_1.useFormikContext)(), setFieldValue = _d.setFieldValue, isSubmitting = _d.isSubmitting;
42
+ var _d = (0, formik_1.useFormikContext)(), setFieldTouched = _d.setFieldTouched, setFieldValue = _d.setFieldValue, isSubmitting = _d.isSubmitting;
43
43
  var touched = formikMeta.touched !== false && formikMeta.touched !== undefined;
44
44
  (0, react_1.useEffect)(function () {
45
45
  if (!touched && isSubmitting) {
46
46
  // because we do not always register all fields up front.
47
47
  // e.g. formik expects even a 'create' form to have all fields given, at least, blank values
48
- // that seems to be how it touches on submit:
49
- // see: https://codesandbox.io/s/formik-example-4n7n8 vs https://codesandbox.io/s/formik-example-kttk5
50
- // note in particular the change in line 24
51
- // thus, we manually touch all fields here by calling onBlur
52
- // there is a "setFieldTouched" from useFormikContext but it doesn't appear to work on field arrays
53
- handleBlur();
48
+ // It looks like this was going to be a thing: https://github.com/jaredpalmer/formik/issues/691
49
+ // Formik appears to not have an active maintainer: https://github.com/jaredpalmer/formik/discussions/3526
50
+ // We previously had a different fix in place using handleBlur, but it was causing an infinite update cycle.
51
+ // 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)
52
+ setFieldTouched(name);
54
53
  }
55
- });
54
+ }, [isSubmitting, name, setFieldTouched, touched]);
56
55
  // these are the props we expect consumers of this hook to pass directly to the input (or other control)
57
56
  var resultInput = {
58
57
  name: formikInput.name,
@@ -1,15 +1,24 @@
1
1
  import { ElementType } from 'react';
2
2
  import { FieldProps } from '../Field/Field';
3
3
  import { ValidationFunction } from '../Validation/ValidationFunction';
4
- export declare type FieldArrayProps<TForm extends object, TProp extends keyof TForm> = TForm[TProp] extends Array<any> | undefined ? {
4
+ export declare type FieldArrayProps<TForm extends object, TProp extends keyof TForm> = TForm[TProp] extends Array<any> | undefined | null ? {
5
+ /** Name of the field, used on submission. If using codegen this must be the provided dto. */
5
6
  name: TProp;
7
+ /** Label of the field. */
6
8
  label?: string;
9
+ /** Whether the field should be disabled. */
7
10
  disabled?: boolean;
11
+ /** Function to validate the value. */
8
12
  validate?: ValidationFunction<TForm[TProp]> | ValidationFunction<TForm[TProp]>[];
9
13
  children: (formBuilder: ArrayFormBuilderProp<TForm[TProp]>) => JSX.Element;
10
14
  } : never;
11
- export declare type ArrayFormBuilderProp<TValue extends Array<any> | undefined> = TValue extends Array<infer TForm> | undefined ? TForm extends object ? {
15
+ export declare type ArrayFormBuilderProp<TValue extends Array<any> | undefined | null> = TValue extends Array<infer TForm> | undefined | null ? TForm extends object ? {
12
16
  Field: <TProp extends keyof TForm, TRenderComponent extends ElementType>(props: FieldProps<TForm, TProp, TRenderComponent>) => JSX.Element;
13
17
  FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
14
18
  } : never : never;
19
+ /**
20
+ * An array of fields that allows the user to add multiple instances of the same field.
21
+ *
22
+ * Includes "Add Item" and "Remove Item" buttons to allow the user to speicify the number of fields.
23
+ */
15
24
  export default function FieldArray<TForm extends object, TProp extends keyof TForm>({ name, label, validate, disabled, children, ...rest }: FieldArrayProps<TForm, TProp>): JSX.Element;
@@ -40,14 +40,19 @@ var Field_1 = __importDefault(require("../Field/Field"));
40
40
  var FieldNameContext_1 = require("../Field/FieldNameContext");
41
41
  var useStandardField_1 = __importDefault(require("../Field/useStandardField"));
42
42
  var FormDefaults_1 = require("../FormDefaults");
43
+ /**
44
+ * An array of fields that allows the user to add multiple instances of the same field.
45
+ *
46
+ * Includes "Add Item" and "Remove Item" buttons to allow the user to speicify the number of fields.
47
+ */
43
48
  function FieldArray(_a) {
44
49
  var _b;
45
50
  var name = _a.name, label = _a.label, validate = _a.validate, disabled = _a.disabled, children = _a.children, rest = __rest(_a, ["name", "label", "validate", "disabled", "children"]);
46
- var _c = (0, useStandardField_1.default)({
51
+ var input = (0, useStandardField_1.default)({
47
52
  name: String(name),
48
53
  validate: validate,
49
54
  disabled: disabled,
50
- }), input = _c[0], meta = _c[1];
55
+ })[0];
51
56
  var values = !input.value
52
57
  ? []
53
58
  : Array.isArray(input.value)
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
2
  import { InjectedFieldProps } from '../Field/InjectedFieldProps';
3
3
  import { GroupProps } from '../Group';
4
- export interface FileGroupProps extends InjectedFieldProps<any | undefined>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'>, Omit<React.HTMLProps<HTMLInputElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'> {
4
+ export interface FileGroupProps extends InjectedFieldProps<any | undefined | null>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'>, Omit<React.HTMLProps<HTMLInputElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'> {
5
+ /** Allow multiple files to be uploaded. */
5
6
  multiple?: boolean | undefined;
6
7
  }
8
+ /** File upload input group. */
7
9
  declare const FileGroupWithRef: React.ComponentType<FileGroupProps>;
8
10
  export default FileGroupWithRef;
@@ -29,12 +29,12 @@ 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
31
  var FileList_1 = __importDefault(require("./FileList"));
32
- var Group_1 = __importDefault(require("../Group"));
33
32
  var FormDefaults_1 = require("../FormDefaults");
33
+ var Group_1 = __importDefault(require("../Group"));
34
34
  function FileGroup(_a, ref) {
35
35
  var _b;
36
- var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, multiple = _a.multiple, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "multiple"]);
37
- return ((0, jsx_runtime_1.jsxs)(Group_1.default, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: (0, classnames_1.default)(className, (_b = {}, _b[FormDefaults_1.FormDefaults.cssClassPrefix + 'multiple'] = multiple, _b), FormDefaults_1.FormDefaults.cssClassPrefix + 'file-group') }, { children: [(0, jsx_runtime_1.jsx)("input", __assign({}, input, rest, { multiple: multiple, onChange: function (e) {
36
+ var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, multiple = _a.multiple, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "multiple"]);
37
+ return ((0, jsx_runtime_1.jsxs)(Group_1.default, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: (0, classnames_1.default)(className, (_b = {}, _b[FormDefaults_1.FormDefaults.cssClassPrefix + 'multiple'] = multiple, _b), FormDefaults_1.FormDefaults.cssClassPrefix + 'file-group'), required: required, disabled: disabled }, { children: [(0, jsx_runtime_1.jsx)("input", __assign({}, input, rest, { multiple: multiple, onChange: function (e) {
38
38
  var _a, _b;
39
39
  if (!((_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b.length)) {
40
40
  input.onChange(undefined);
@@ -53,5 +53,6 @@ function FileGroup(_a, ref) {
53
53
  }
54
54
  }, value: undefined, ref: ref, type: "file", className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'file-group') })), (0, jsx_runtime_1.jsx)(FileList_1.default, { files: input.value })] })));
55
55
  }
56
+ /** File upload input group. */
56
57
  var FileGroupWithRef = react_1.default.forwardRef(FileGroup);
57
58
  exports.default = FileGroupWithRef;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  export interface FileListProps {
3
- files?: File | File[] | undefined;
4
- rejectedFiles?: File | File[] | undefined;
3
+ files?: File | File[] | undefined | null;
4
+ rejectedFiles?: File | File[] | undefined | null;
5
5
  }
6
6
  export default function FileList({ files, rejectedFiles }: FileListProps): JSX.Element;
@@ -1,5 +1,7 @@
1
1
  import { ServerErrorContextProps } from './ServerErrorContext';
2
2
  export interface FocusErrorProps {
3
+ /** Validation errors that have been received from the server. */
3
4
  serverErrors: ServerErrorContextProps;
4
5
  }
6
+ /** Function to scroll to the field that has an error. */
5
7
  export default function FocusError(props: FocusErrorProps): null;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var react_1 = require("react");
7
7
  var formik_1 = require("formik");
8
8
  var smoothscroll_polyfill_1 = __importDefault(require("smoothscroll-polyfill"));
9
+ /** Function to scroll to the field that has an error. */
9
10
  function FocusError(props) {
10
11
  var _a = (0, formik_1.useFormikContext)(), errors = _a.errors, isSubmitting = _a.isSubmitting, isValidating = _a.isValidating;
11
12
  smoothscroll_polyfill_1.default.polyfill();
@@ -8,18 +8,24 @@ export declare type FormBuilderProp<TForm extends object> = {
8
8
  FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
9
9
  };
10
10
  export interface FullFormProps<TForm extends object> {
11
+ /** The `<Field/>` and `<FieldArray/>` components. */
11
12
  children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
13
+ /** Submission handler */
12
14
  onSubmit: (formValues: TForm, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
15
+ /** Submission handler for forms that use [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData).*/
13
16
  onFormDataSubmit: (formValues: FormData, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
14
17
  className?: string;
15
18
  style?: CSSProperties;
19
+ /** Prevent the user from leaving the form if they have edited any field. This is presented as a JS `alert()`. */
16
20
  ignoreLostChanges?: boolean;
21
+ /** The intitial values of the form. */
17
22
  initialValues?: TForm;
18
23
  }
19
24
  declare type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
20
25
  [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
21
26
  }[Keys];
22
27
  export declare type FormProps<TForm extends object> = RequireAtLeastOne<FullFormProps<TForm>, 'onSubmit' | 'onFormDataSubmit'>;
28
+ /** Define a form. Uses [formik](https://formik.org/docs/overview). Usually contains many `<Field/>` components. */
23
29
  declare function Form<TForm extends object>({ children, className, style, ignoreLostChanges, onSubmit, onFormDataSubmit, initialValues, ...props }: FormProps<TForm>): JSX.Element;
24
30
  declare namespace Form {
25
31
  var DisplayFormState: () => JSX.Element;
package/lib/Form/Form.js CHANGED
@@ -37,6 +37,7 @@ var FieldArray_1 = __importDefault(require("../FieldArray/FieldArray"));
37
37
  var FormDefaults_1 = require("../FormDefaults");
38
38
  var objectContainsNonSerializableProperty_1 = __importDefault(require("../utils/objectContainsNonSerializableProperty"));
39
39
  var objectToFormData_1 = __importDefault(require("../utils/objectToFormData"));
40
+ /** Define a form. Uses [formik](https://formik.org/docs/overview). Usually contains many `<Field/>` components. */
40
41
  function Form(_a) {
41
42
  var children = _a.children, className = _a.className, style = _a.style, ignoreLostChanges = _a.ignoreLostChanges, onSubmit = _a.onSubmit, onFormDataSubmit = _a.onFormDataSubmit, initialValues = _a.initialValues, props = __rest(_a, ["children", "className", "style", "ignoreLostChanges", "onSubmit", "onFormDataSubmit", "initialValues"]);
42
43
  // formik resets all error on each blur (with our settings)
@@ -1,5 +1,7 @@
1
+ /// <reference types="react" />
1
2
  export interface FormBasedPreventNavigationProps {
2
3
  ignoreLostChanges?: boolean;
3
4
  promptMessage?: string;
4
5
  }
5
- export default function FormBasedPreventNavigation({ ignoreLostChanges, promptMessage, }: FormBasedPreventNavigationProps): null;
6
+ /** Prevent the user from navigating away from a form if there are any changes. */
7
+ export default function FormBasedPreventNavigation({ ignoreLostChanges, promptMessage, }: FormBasedPreventNavigationProps): JSX.Element;