envoc-form 4.0.1-1 → 4.0.1-11

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 (153) hide show
  1. package/README.md +2 -2
  2. package/es/AddressInput/AddressInput.d.ts +5 -5
  3. package/es/ConfirmBaseForm/ConfirmBaseForm.d.ts +3 -1
  4. package/es/ConfirmBaseForm/ConfirmBaseForm.js +3 -2
  5. package/es/ConfirmDeleteForm/ConfirmDeleteForm.js +2 -1
  6. package/es/DatePicker/DatePickerGroup.d.ts +3 -2
  7. package/es/DatePicker/DatePickerGroup.js +27 -5
  8. package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
  9. package/es/DatePicker/{DateOnlyDatePickerGroup.js → StringDateOnlyPickerGroup.js} +7 -6
  10. package/es/DatePicker/StringDatePickerGroup.d.ts +1 -1
  11. package/es/Field/Field.d.ts +3 -3
  12. package/es/Field/Field.js +9 -4
  13. package/es/FieldArray/FieldArray.d.ts +2 -2
  14. package/es/FieldArray/FieldArray.js +10 -7
  15. package/es/File/FileGroup.d.ts +1 -1
  16. package/es/File/FileGroup.js +5 -3
  17. package/es/File/FileList.d.ts +2 -2
  18. package/es/File/FileList.js +2 -1
  19. package/es/Form/Form.d.ts +8 -3
  20. package/es/Form/Form.js +32 -3
  21. package/es/Form/FormBasedPreventNavigation.js +31 -14
  22. package/es/FormActions.js +5 -1
  23. package/es/FormDefaults.d.ts +3 -0
  24. package/es/FormDefaults.js +1 -0
  25. package/es/Group.d.ts +2 -1
  26. package/es/Group.js +8 -5
  27. package/es/Input/IconInputGroup.d.ts +1 -1
  28. package/es/Input/IconInputGroup.js +3 -1
  29. package/es/Input/InputGroup.d.ts +3 -3
  30. package/es/Input/InputGroup.js +3 -2
  31. package/es/Input/MoneyInputGroup.d.ts +1 -1
  32. package/es/Input/MoneyInputGroup.js +2 -1
  33. package/es/Input/NumberInputGroup.d.ts +1 -1
  34. package/es/Input/NumberInputGroup.js +2 -1
  35. package/es/Input/StringInputGroup.d.ts +1 -1
  36. package/es/Input/StringInputGroup.js +3 -1
  37. package/es/Normalization/normalizers.d.ts +2 -2
  38. package/es/Select/BooleanSelectGroup.d.ts +1 -1
  39. package/es/Select/NumberSelectGroup.d.ts +2 -2
  40. package/es/Select/SelectGroup.d.ts +2 -2
  41. package/es/Select/SelectGroup.js +8 -3
  42. package/es/StandardFormActions.js +2 -1
  43. package/es/SubmitFormButton.d.ts +1 -1
  44. package/es/SubmitFormButton.js +4 -2
  45. package/es/TextArea/TextAreaGroup.d.ts +1 -1
  46. package/es/TextArea/TextAreaGroup.js +4 -2
  47. package/es/Validation/validators.d.ts +8 -8
  48. package/es/Validation/validators.js +3 -0
  49. package/es/__Tests__/FormTestBase.d.ts +3 -3
  50. package/es/__Tests__/FormTestBase.js +1 -1
  51. package/es/index.d.ts +8 -6
  52. package/es/index.js +4 -1
  53. package/lib/AddressInput/AddressInput.d.ts +5 -5
  54. package/lib/ConfirmBaseForm/ConfirmBaseForm.d.ts +3 -1
  55. package/lib/ConfirmBaseForm/ConfirmBaseForm.js +3 -2
  56. package/lib/ConfirmDeleteForm/ConfirmDeleteForm.js +2 -1
  57. package/lib/DatePicker/DatePickerGroup.d.ts +3 -2
  58. package/lib/DatePicker/DatePickerGroup.js +28 -4
  59. package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
  60. package/lib/DatePicker/{DateOnlyDatePickerGroup.js → StringDateOnlyPickerGroup.js} +8 -7
  61. package/lib/DatePicker/StringDatePickerGroup.d.ts +1 -1
  62. package/lib/Field/Field.d.ts +3 -3
  63. package/lib/Field/Field.js +9 -4
  64. package/lib/FieldArray/FieldArray.d.ts +2 -2
  65. package/lib/FieldArray/FieldArray.js +10 -7
  66. package/lib/File/FileGroup.d.ts +1 -1
  67. package/lib/File/FileGroup.js +5 -3
  68. package/lib/File/FileList.d.ts +2 -2
  69. package/lib/File/FileList.js +2 -1
  70. package/lib/Form/Form.d.ts +8 -3
  71. package/lib/Form/Form.js +32 -3
  72. package/lib/Form/FormBasedPreventNavigation.js +31 -14
  73. package/lib/FormActions.js +5 -1
  74. package/lib/FormDefaults.d.ts +3 -0
  75. package/lib/FormDefaults.js +4 -0
  76. package/lib/Group.d.ts +2 -1
  77. package/lib/Group.js +8 -5
  78. package/lib/Input/IconInputGroup.d.ts +1 -1
  79. package/lib/Input/IconInputGroup.js +3 -1
  80. package/lib/Input/InputGroup.d.ts +3 -3
  81. package/lib/Input/InputGroup.js +3 -2
  82. package/lib/Input/MoneyInputGroup.d.ts +1 -1
  83. package/lib/Input/MoneyInputGroup.js +2 -1
  84. package/lib/Input/NumberInputGroup.d.ts +1 -1
  85. package/lib/Input/NumberInputGroup.js +2 -1
  86. package/lib/Input/StringInputGroup.d.ts +1 -1
  87. package/lib/Input/StringInputGroup.js +3 -1
  88. package/lib/Normalization/normalizers.d.ts +2 -2
  89. package/lib/Select/BooleanSelectGroup.d.ts +1 -1
  90. package/lib/Select/NumberSelectGroup.d.ts +2 -2
  91. package/lib/Select/SelectGroup.d.ts +2 -2
  92. package/lib/Select/SelectGroup.js +8 -3
  93. package/lib/StandardFormActions.js +2 -1
  94. package/lib/SubmitFormButton.d.ts +1 -1
  95. package/lib/SubmitFormButton.js +4 -2
  96. package/lib/TextArea/TextAreaGroup.d.ts +1 -1
  97. package/lib/TextArea/TextAreaGroup.js +4 -2
  98. package/lib/Validation/validators.d.ts +8 -8
  99. package/lib/Validation/validators.js +3 -0
  100. package/lib/__Tests__/FormTestBase.d.ts +3 -3
  101. package/lib/__Tests__/FormTestBase.js +2 -2
  102. package/lib/index.d.ts +8 -6
  103. package/lib/index.js +8 -3
  104. package/package.json +4 -2
  105. package/src/AddressInput/AddressInput.tsx +5 -5
  106. package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +15 -10
  107. package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +13 -3
  108. package/src/ConfirmBaseForm/__snapshots__/ConfirmBaseForm.test.tsx.snap +3 -3
  109. package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +8 -1
  110. package/src/ConfirmDeleteForm/__snapshots__/ConfirmDeleteForm.test.tsx.snap +2 -2
  111. package/src/DatePicker/DatePicker.test.tsx +3 -3
  112. package/src/DatePicker/DatePickerGroup.tsx +45 -8
  113. package/src/DatePicker/StringDateOnlyPickerGroup.tsx +23 -0
  114. package/src/DatePicker/StringDatePickerGroup.tsx +1 -1
  115. package/src/DatePicker/__snapshots__/DatePicker.test.tsx.snap +3 -2
  116. package/src/Field/Field.tsx +22 -7
  117. package/src/FieldArray/FieldArray.tsx +25 -13
  118. package/src/File/FileGroup.tsx +15 -3
  119. package/src/File/FileList.tsx +5 -3
  120. package/src/File/__snapshots__/FileGroup.test.tsx.snap +5 -3
  121. package/src/Form/Form.tsx +56 -4
  122. package/src/Form/FormBasedPreventNavigation.tsx +34 -18
  123. package/src/Form/__snapshots__/Form.test.tsx.snap +1 -0
  124. package/src/FormActions.tsx +8 -2
  125. package/src/FormDefaults.ts +1 -0
  126. package/src/Group.tsx +21 -6
  127. package/src/Input/IconInputGroup.tsx +7 -4
  128. package/src/Input/InputGroup.tsx +18 -5
  129. package/src/Input/MoneyInputGroup.tsx +6 -2
  130. package/src/Input/NumberInputGroup.tsx +6 -2
  131. package/src/Input/StringInputGroup.tsx +7 -3
  132. package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +4 -2
  133. package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +4 -2
  134. package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +4 -2
  135. package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +4 -2
  136. package/src/Normalization/normalizers.ts +2 -2
  137. package/src/Select/BooleanSelectGroup.tsx +1 -1
  138. package/src/Select/NumberSelectGroup.tsx +2 -2
  139. package/src/Select/SelectGroup.tsx +16 -4
  140. package/src/Select/__tests__/__snapshots__/BooleanSelectGroup.test.tsx.snap +3 -2
  141. package/src/Select/__tests__/__snapshots__/NumberSelectGroup.test.tsx.snap +6 -4
  142. package/src/Select/__tests__/__snapshots__/StringSelectGroup.test.tsx.snap +6 -4
  143. package/src/StandardFormActions.tsx +4 -1
  144. package/src/SubmitFormButton.tsx +9 -2
  145. package/src/TextArea/TextAreaGroup.tsx +13 -4
  146. package/src/Validation/validators.ts +16 -12
  147. package/src/__Tests__/FormTestBase.tsx +4 -4
  148. package/src/__Tests__/__snapshots__/StandardFormActions.test.tsx.snap +4 -2
  149. package/src/__Tests__/__snapshots__/SubmitFormButton.test.tsx.snap +3 -1
  150. package/src/index.ts +11 -10
  151. package/es/DatePicker/DateOnlyDatePickerGroup.d.ts +0 -10
  152. package/lib/DatePicker/DateOnlyDatePickerGroup.d.ts +0 -10
  153. package/src/DatePicker/DateOnlyDatePickerGroup.tsx +0 -24
package/README.md CHANGED
@@ -10,8 +10,8 @@ Base form package for envoc projects.
10
10
  Important naming conventions for our sanity while creating envoc-form types:
11
11
 
12
12
  - TForm = The type of the some form. e.g. LoginDto
13
- - TProp = The key / symbol of a indvidual property of some form. e.g. TProp would be literally "Username" for the prop of the same name for a LoginDto
14
- - TValue = The value of an indvidual property of some form. e.g. a "Username" property would probably have a TValue of string
13
+ - TProp = The key / symbol of a individual property of some form. e.g. TProp would be literally "Username" for the prop of the same name for a LoginDto
14
+ - TValue = The value of an individual property of some form. e.g. a "Username" property would probably have a TValue of string
15
15
  - Field = the abstract thing that deals with some specific TProp. Might represent several composed elements (e.g. label, input, helperText, etc) or may just be a direct component
16
16
  - TRenderComponent = The type of any 'Component' passed to a Field, e.g. 'StandardTextInputGroup' passed to Component means TRenderComponent is typeof(StandardTextInputGroup)
17
17
  - TComponentProps = For any 'Component' passed to a Field as a prop, this represents that Component's props
@@ -5,11 +5,11 @@ export interface AddressInputProps {
5
5
  name: string;
6
6
  }
7
7
  interface AddressDto {
8
- address1?: string;
9
- address2?: string;
10
- zipCode?: string;
11
- city?: string;
12
- state?: string;
8
+ address1?: string | null;
9
+ address2?: string | null;
10
+ zipCode?: string | null;
11
+ city?: string | null;
12
+ state?: string | null;
13
13
  }
14
14
  export default function AddressInput({ fieldBuilder: { Field }, name, }: AddressInputProps): JSX.Element;
15
15
  export {};
@@ -5,6 +5,8 @@ export interface ConfirmBaseFormProps {
5
5
  request: useAxiosRequestProps;
6
6
  style?: React.CSSProperties;
7
7
  title?: string;
8
+ confirmButtonText?: string;
9
+ confirmButtonClass?: string;
8
10
  children?: React.ReactNode;
9
11
  }
10
- export default function ConfirmBaseForm({ handleCancel, request, style, title, children, ...props }: ConfirmBaseFormProps): JSX.Element;
12
+ export default function ConfirmBaseForm({ handleCancel, request, style, title, confirmButtonText, confirmButtonClass, children, ...props }: ConfirmBaseFormProps): JSX.Element;
@@ -23,12 +23,13 @@ var __rest = (this && this.__rest) || function (s, e) {
23
23
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
24
  import classNames from 'classnames';
25
25
  import { useAxiosRequest } from 'envoc-request';
26
+ import { FormDefaults } from '../FormDefaults';
26
27
  // TODO: ask about how we should use 'children'
27
28
  export default function ConfirmBaseForm(_a) {
28
- var handleCancel = _a.handleCancel, request = _a.request, style = _a.style, title = _a.title, children = _a.children, props = __rest(_a, ["handleCancel", "request", "style", "title", "children"]);
29
+ var handleCancel = _a.handleCancel, request = _a.request, style = _a.style, title = _a.title, confirmButtonText = _a.confirmButtonText, confirmButtonClass = _a.confirmButtonClass, children = _a.children, props = __rest(_a, ["handleCancel", "request", "style", "title", "confirmButtonText", "confirmButtonClass", "children"]);
29
30
  var webRequest = useAxiosRequest(Object.assign({}, request, { autoExecute: false }));
30
31
  var onCancel = handleCancel !== null && handleCancel !== void 0 ? handleCancel : goBack;
31
- return (_jsxs("div", __assign({ style: __assign({ textAlign: 'center' }, style) }, props, { children: [_jsx("h3", { children: title }), children, _jsx("button", __assign({ className: classNames('confirm-base-form-yes-button'), type: "button", onClick: webRequest.submitRequest }, { children: "Yes" })), _jsx("button", __assign({ className: classNames('confirm-base-form-cancel-button'), type: "button", onClick: onCancel }, { children: "Cancel" }))] })));
32
+ return (_jsxs("div", __assign({ style: __assign({ textAlign: 'center' }, style) }, props, { children: [_jsx("h3", { children: title }), children, _jsx("button", __assign({ className: classNames(confirmButtonClass !== null && confirmButtonClass !== void 0 ? confirmButtonClass : FormDefaults.cssClassPrefix + 'confirm-base-form-confirm-button'), type: "button", onClick: webRequest.submitRequest }, { children: confirmButtonText !== null && confirmButtonText !== void 0 ? confirmButtonText : 'Confirm' })), _jsx("button", __assign({ className: classNames(FormDefaults.cssClassPrefix + 'confirm-base-form-cancel-button'), type: "button", onClick: onCancel }, { children: "Cancel" }))] })));
32
33
  function goBack() {
33
34
  window.history.back();
34
35
  }
@@ -24,6 +24,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
24
24
  import { useNavigate, useParams } from 'react-router-dom';
25
25
  import { toast } from 'react-toastify';
26
26
  import ConfirmBaseForm from '../ConfirmBaseForm/ConfirmBaseForm';
27
+ import { FormDefaults } from '../FormDefaults';
27
28
  export default function ConfirmDeleteForm(_a) {
28
29
  var successUrl = _a.successUrl, form = _a.form, title = _a.title, handleComplete = _a.handleComplete, handleError = _a.handleError, children = _a.children, props = __rest(_a, ["successUrl", "form", "title", "handleComplete", "handleError", "children"]);
29
30
  var navigate = useNavigate();
@@ -42,7 +43,7 @@ export default function ConfirmDeleteForm(_a) {
42
43
  onComplete: onComplete,
43
44
  onError: onError,
44
45
  };
45
- return (_jsx(ConfirmBaseForm, __assign({ request: request, handleCancel: goBack, title: title !== null && title !== void 0 ? title : 'Are you sure you want to delete this?' }, props, { children: children })));
46
+ return (_jsx(ConfirmBaseForm, __assign({ request: request, handleCancel: goBack, title: title !== null && title !== void 0 ? title : 'Are you sure you want to delete this?', confirmButtonText: "Yes", confirmButtonClass: FormDefaults.cssClassPrefix + 'confirm-delete-form-yes-button' }, props, { children: children })));
46
47
  function goBack() {
47
48
  if (successUrl) {
48
49
  navigate(successUrl);
@@ -2,7 +2,8 @@
2
2
  import { DatePickerProps } from 'react-date-picker/dist/entry.nostyle';
3
3
  import { InjectedFieldProps } from '../Field/InjectedFieldProps';
4
4
  import { GroupProps } from '../Group';
5
- export interface DatePickerGroupProps<T> extends InjectedFieldProps<T | undefined>, Omit<DatePickerProps, keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'>, Omit<GroupProps, keyof InjectedFieldProps<T> | 'children'> {
5
+ export interface DatePickerGroupProps<T> extends InjectedFieldProps<T | undefined | null>, Omit<DatePickerProps, keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'>, Omit<GroupProps, keyof InjectedFieldProps<T> | 'children'> {
6
6
  convert: (arg: Date) => T;
7
7
  }
8
- export default function DatePickerGroup<T>({ input, meta, label, helpText, className, disabled, convert, ...rest }: DatePickerGroupProps<T>): JSX.Element;
8
+ export default function DatePickerGroup<T>({ input, meta, label, helpText, className, required, disabled, convert, ...rest }: DatePickerGroupProps<T>): JSX.Element;
9
+ export declare function convertToTimeZoneInsensitiveISOString(date: Date): string;
@@ -21,15 +21,29 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  return t;
22
22
  };
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
- import { useState } from 'react';
24
+ import { useEffect, useState } from 'react';
25
25
  import DatePicker from 'react-date-picker/dist/entry.nostyle';
26
26
  import classnames from 'classnames';
27
27
  import parseISO from 'date-fns/parseISO';
28
+ import { FormDefaults } from '../FormDefaults';
28
29
  import Group from '../Group';
29
30
  export default function DatePickerGroup(_a) {
30
- var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, disabled = _a.disabled, convert = _a.convert, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "disabled", "convert"]);
31
+ 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"]);
31
32
  var _b = useState(null), displayDate = _b[0], setDisplayDate = _b[1];
32
- return (_jsx(Group, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: classnames(className, 'date-picker'), disabled: disabled }, { children: _jsx(DatePicker, __assign({}, rest, { className: classnames('date-picker', className), value: displayDate, onChange: handleChange })) })));
33
+ useEffect(function () {
34
+ if (!input.value) {
35
+ setDisplayDate(null);
36
+ }
37
+ else if (typeof input.value === 'string') {
38
+ if (input.value.indexOf('T') === -1) {
39
+ setDisplayDate(new Date("".concat(input.value, "T00:00:00.000")));
40
+ }
41
+ else {
42
+ setDisplayDate(new Date(input.value));
43
+ }
44
+ }
45
+ }, [setDisplayDate, input.value]);
46
+ return (_jsx(Group, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: classnames(className, FormDefaults.cssClassPrefix + 'date-picker'), required: required, disabled: disabled }, { children: _jsx(DatePicker, __assign({}, rest, { className: classnames(FormDefaults.cssClassPrefix + 'date-picker', className), value: displayDate, onChange: handleChange })) })));
33
47
  function handleChange(e) {
34
48
  var onChange = input.onChange;
35
49
  if (onChange === null) {
@@ -46,15 +60,23 @@ export default function DatePickerGroup(_a) {
46
60
  onChange(convert(parsedValue));
47
61
  }
48
62
  else if (e instanceof Date) {
49
- var parsedValue = parseISO(e.toISOString().split('T')[0]);
63
+ var parsedValue = parseISO(convertToTimeZoneInsensitiveISOString(e).split('T')[0]);
50
64
  setDisplayDate(parsedValue);
51
65
  onChange(convert(parsedValue));
52
66
  }
53
67
  else {
54
68
  // e is instanceof Date[]
55
- var parsedValue = parseISO(e[0].toISOString().split('T')[0]);
69
+ var parsedValue = parseISO(convertToTimeZoneInsensitiveISOString(e[0]).split('T')[0]);
56
70
  setDisplayDate(parsedValue);
57
71
  onChange(convert(parsedValue));
58
72
  }
59
73
  }
60
74
  }
75
+ export function convertToTimeZoneInsensitiveISOString(date) {
76
+ var year = new Intl.DateTimeFormat('en', { year: 'numeric' })
77
+ .format(date)
78
+ .padStart(4, '0');
79
+ var month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(date);
80
+ var day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(date);
81
+ return "".concat(year, "-").concat(month, "-").concat(day, "T00:00:00.000Z");
82
+ }
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { DatePickerHelper } from './DatePickerHelper';
3
+ export interface StringDateOnlyPickerGroupProps extends DatePickerHelper<string | undefined | null> {
4
+ }
5
+ export default function StringDatePickerGroup(props: StringDateOnlyPickerGroupProps): JSX.Element;
@@ -11,13 +11,14 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import DatePickerGroup from './DatePickerGroup';
14
- export default function DateOnlyDatePickerGroup(props) {
14
+ export default function StringDatePickerGroup(props) {
15
15
  return _jsx(DatePickerGroup, __assign({}, props, { convert: convertToDateOnly }));
16
16
  }
17
17
  function convertToDateOnly(arg) {
18
- return {
19
- year: arg.getFullYear(),
20
- month: arg.getMonth() + 1,
21
- day: arg.getDate(),
22
- };
18
+ var year = new Intl.DateTimeFormat('en', { year: 'numeric' })
19
+ .format(arg)
20
+ .padStart(4, '0');
21
+ var month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(arg);
22
+ var day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(arg);
23
+ return "".concat(year, "-").concat(month, "-").concat(day);
23
24
  }
@@ -1,5 +1,5 @@
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
5
  export default function StringDatePickerGroup(props: StringDatePickerGroupProps): JSX.Element;
@@ -2,8 +2,8 @@ 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>> ? TRenderComponent : never;
6
- export declare type RenderComponentProps<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue>> ? 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
9
  name: TProp;
@@ -17,6 +17,6 @@ export declare type FieldProps<TForm extends object, TProp extends keyof TForm,
17
17
  * Renders whatever Component is passed - injecting the formik values needed to finish wiring up that individual field.
18
18
  * Should no Component be used then the default will be provided by the default lookup based on typeof(TForm[TProp])
19
19
  */
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;
20
+ 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
21
  declare const _default: typeof Field;
22
22
  export default _default;
package/es/Field/Field.js CHANGED
@@ -24,22 +24,27 @@ import { jsx as _jsx } from "react/jsx-runtime";
24
24
  import React from 'react';
25
25
  import { FieldNameContext } from './FieldNameContext';
26
26
  import useStandardFormInput from './useStandardField';
27
+ import { required as requiredValidator } from '../Validation/validators';
27
28
  /**
28
29
  * Renders whatever Component is passed - injecting the formik values needed to finish wiring up that individual field.
29
30
  * Should no Component be used then the default will be provided by the default lookup based on typeof(TForm[TProp])
30
31
  */
31
32
  function Field(_a, ref) {
32
- 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"]);
33
+ 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"]);
33
34
  var _b = useStandardFormInput({
34
35
  name: String(name),
35
36
  id: id,
36
- normalize: normalize,
37
- validate: validate,
38
37
  disabled: disabled,
38
+ validate: validate,
39
+ normalize: normalize,
39
40
  }), input = _b[0], meta = _b[1];
41
+ var isRequired = (rest === null || rest === void 0 ? void 0 : rest.required) !== undefined
42
+ ? rest.required
43
+ : validate === requiredValidator ||
44
+ (Array.isArray(validate) && validate.includes(requiredValidator));
40
45
  // a bit of a hack so JSX is happy with us
41
46
  var Wrapped = Component;
42
- return (_jsx(FieldNameContext.Provider, __assign({ value: input.name }, { children: _jsx(Wrapped, __assign({}, rest, { ref: ref, id: id, input: input, meta: meta })) })));
47
+ return (_jsx(FieldNameContext.Provider, __assign({ value: input.name }, { children: _jsx(Wrapped, __assign({}, rest, { ref: ref, id: input.id, input: input, meta: meta, required: isRequired, disabled: disabled })) })));
43
48
  }
44
49
  // hack to get forwarded refs to work
45
50
  var FieldWithRef = React.forwardRef(Field);
@@ -1,14 +1,14 @@
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
5
  name: TProp;
6
6
  label?: string;
7
7
  disabled?: boolean;
8
8
  validate?: ValidationFunction<TForm[TProp]> | ValidationFunction<TForm[TProp]>[];
9
9
  children: (formBuilder: ArrayFormBuilderProp<TForm[TProp]>) => JSX.Element;
10
10
  } : never;
11
- export declare type ArrayFormBuilderProp<TValue extends Array<any> | undefined> = TValue extends Array<infer TForm> | undefined ? TForm extends object ? {
11
+ export declare type ArrayFormBuilderProp<TValue extends Array<any> | undefined | null> = TValue extends Array<infer TForm> | undefined | null ? TForm extends object ? {
12
12
  Field: <TProp extends keyof TForm, TRenderComponent extends ElementType>(props: FieldProps<TForm, TProp, TRenderComponent>) => JSX.Element;
13
13
  FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
14
14
  } : never : never;
@@ -34,26 +34,29 @@ import classNames from 'classnames';
34
34
  import Field from '../Field/Field';
35
35
  import { FieldNameContext } from '../Field/FieldNameContext';
36
36
  import useStandardFormInput from '../Field/useStandardField';
37
+ import { FormDefaults } from '../FormDefaults';
37
38
  export default function FieldArray(_a) {
39
+ var _b;
38
40
  var name = _a.name, label = _a.label, validate = _a.validate, disabled = _a.disabled, children = _a.children, rest = __rest(_a, ["name", "label", "validate", "disabled", "children"]);
39
- var _b = useStandardFormInput({
41
+ var input = useStandardFormInput({
40
42
  name: String(name),
41
43
  validate: validate,
42
44
  disabled: disabled,
43
- }), input = _b[0], meta = _b[1];
45
+ })[0];
44
46
  var values = !input.value
45
47
  ? []
46
48
  : Array.isArray(input.value)
47
49
  ? input.value
48
50
  : [];
49
- return (_jsxs("div", __assign({ className: "field-array" }, { children: [_jsxs("div", __assign({ className: "field-array-header" }, { children: [_jsx("div", __assign({ className: "field-array-title" }, { children: label })), _jsx("button", __assign({ className: classNames('add-array-item-button', { disabled: disabled }), title: "Add Item", type: "button", onClick: addItem }, { children: "+" }))] })), _jsx("div", __assign({ className: "field-array-body" }, { children: values.map(function (value, index) {
51
+ return (_jsxs("div", __assign({ className: FormDefaults.cssClassPrefix + 'field-array' }, { children: [_jsxs("div", __assign({ className: FormDefaults.cssClassPrefix + 'field-array-header' }, { children: [_jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'field-array-title' }, { children: label })), _jsx("button", __assign({ className: classNames(FormDefaults.cssClassPrefix + 'add-array-item-button', (_b = {}, _b[FormDefaults.cssClassPrefix + 'disabled'] = disabled, _b)), title: "Add Item", type: "button", onClick: addItem }, { children: "+" }))] })), _jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'field-array-body' }, { children: values.map(function (value, index) {
52
+ var _a, _b;
50
53
  var itemName = "".concat(input.name, "[").concat(index, "]");
51
- return (_jsxs("div", __assign({ className: classNames('field-array-item', {
52
- removed: value.isDeleted,
53
- }), role: "listitem" }, { children: [_jsx(FieldNameContext.Provider, __assign({ value: itemName }, { children: children({
54
+ return (_jsxs("div", __assign({ className: classNames(FormDefaults.cssClassPrefix + 'field-array-item', (_a = {},
55
+ _a[FormDefaults.cssClassPrefix + 'removed'] = value.isDeleted,
56
+ _a)), role: "listitem" }, { children: [_jsx(FieldNameContext.Provider, __assign({ value: itemName }, { children: children({
54
57
  Field: Field,
55
58
  FieldArray: FieldArray,
56
- }) })), _jsx("button", __assign({ className: classNames('remove-array-item-button', { disabled: disabled }), type: "button", title: "Remove Item", onClick: function () { return removeItem(value); } }, { children: "-" }))] }), (value && value['form-input-array-key']) ||
59
+ }) })), _jsx("button", __assign({ className: classNames(FormDefaults.cssClassPrefix + 'remove-array-item-button', (_b = {}, _b[FormDefaults.cssClassPrefix + 'disabled'] = disabled, _b)), type: "button", title: "Remove Item", onClick: function () { return removeItem(value); } }, { children: "-" }))] }), (value && value['form-input-array-key']) ||
57
60
  (value && value['id']) ||
58
61
  itemName));
59
62
  }) }))] })));
@@ -1,7 +1,7 @@
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
5
  multiple?: boolean | undefined;
6
6
  }
7
7
  declare const FileGroupWithRef: React.ComponentType<FileGroupProps>;
@@ -24,10 +24,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
24
  import React from 'react';
25
25
  import classNames from 'classnames';
26
26
  import FileList from './FileList';
27
+ import { FormDefaults } from '../FormDefaults';
27
28
  import Group from '../Group';
28
29
  function FileGroup(_a, ref) {
29
- 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"]);
30
- return (_jsxs(Group, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: classNames(className, { multiple: multiple }, 'file-group') }, { children: [_jsx("input", __assign({}, input, rest, { multiple: multiple, onChange: function (e) {
30
+ var _b;
31
+ 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"]);
32
+ return (_jsxs(Group, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: classNames(className, (_b = {}, _b[FormDefaults.cssClassPrefix + 'multiple'] = multiple, _b), FormDefaults.cssClassPrefix + 'file-group'), required: required, disabled: disabled }, { children: [_jsx("input", __assign({}, input, rest, { multiple: multiple, onChange: function (e) {
31
33
  var _a, _b;
32
34
  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)) {
33
35
  input.onChange(undefined);
@@ -44,7 +46,7 @@ function FileGroup(_a, ref) {
44
46
  input.onChange(files);
45
47
  }
46
48
  }
47
- }, value: undefined, ref: ref, type: "file", className: classNames(className, 'file-group') })), _jsx(FileList, { files: input.value })] })));
49
+ }, value: undefined, ref: ref, type: "file", className: classNames(className, FormDefaults.cssClassPrefix + 'file-group') })), _jsx(FileList, { files: input.value })] })));
48
50
  }
49
51
  var FileGroupWithRef = React.forwardRef(FileGroup);
50
52
  export 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;
@@ -10,9 +10,10 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { FormDefaults } from '../FormDefaults';
13
14
  export default function FileList(_a) {
14
15
  var files = _a.files, rejectedFiles = _a.rejectedFiles;
15
- return (_jsx("div", __assign({ className: "file-list" }, { children: !files ? null : Array.isArray(files) ? (files.map(function (x, i) { return _jsx(File, { file: x }, i); })) : (_jsx(File, { file: files })) })));
16
+ return (_jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'file-list' }, { children: !files ? null : Array.isArray(files) ? (files.map(function (x, i) { return _jsx(File, { file: x }, i); })) : (_jsx(File, { file: files })) })));
16
17
  }
17
18
  function File(_a) {
18
19
  var file = _a.file;
package/es/Form/Form.d.ts CHANGED
@@ -7,15 +7,20 @@ export declare type FormBuilderProp<TForm extends object> = {
7
7
  Field: <TProp extends keyof TForm, TRenderComponent extends ElementType>(props: FieldProps<TForm, TProp, TRenderComponent>) => JSX.Element;
8
8
  FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
9
9
  };
10
- export interface FormProps<TForm extends object> {
10
+ export interface FullFormProps<TForm extends object> {
11
11
  children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
12
- onSubmit: (formValues: FormData | TForm, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
12
+ onSubmit: (formValues: TForm, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
13
+ onFormDataSubmit: (formValues: FormData, formikBag: FormikHelpers<TForm>) => Promise<ValidatedApiResult>;
13
14
  className?: string;
14
15
  style?: CSSProperties;
15
16
  ignoreLostChanges?: boolean;
16
17
  initialValues?: TForm;
17
18
  }
18
- declare function Form<TForm extends object>({ children, className, style, ignoreLostChanges, onSubmit, initialValues, ...props }: FormProps<TForm>): JSX.Element;
19
+ declare type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
20
+ [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
21
+ }[Keys];
22
+ export declare type FormProps<TForm extends object> = RequireAtLeastOne<FullFormProps<TForm>, 'onSubmit' | 'onFormDataSubmit'>;
23
+ declare function Form<TForm extends object>({ children, className, style, ignoreLostChanges, onSubmit, onFormDataSubmit, initialValues, ...props }: FormProps<TForm>): JSX.Element;
19
24
  declare namespace Form {
20
25
  var DisplayFormState: () => JSX.Element;
21
26
  }
package/es/Form/Form.js CHANGED
@@ -22,16 +22,18 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  };
23
23
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
24
  import { useContext, useMemo, useState, } from 'react';
25
+ import classNames from 'classnames';
25
26
  import { Form as FormikFormWrapper, Formik, useFormikContext, } from 'formik';
26
27
  import FocusError from './FocusError';
27
28
  import FormBasedPreventNavigation from './FormBasedPreventNavigation';
28
29
  import { ServerErrorContext, } from './ServerErrorContext';
29
30
  import Field from '../Field/Field';
30
31
  import FieldArray from '../FieldArray/FieldArray';
32
+ import { FormDefaults } from '../FormDefaults';
31
33
  import objectContainsNonSerializableProperty from '../utils/objectContainsNonSerializableProperty';
32
34
  import objectToFormData from '../utils/objectToFormData';
33
35
  export default function Form(_a) {
34
- var children = _a.children, className = _a.className, style = _a.style, ignoreLostChanges = _a.ignoreLostChanges, onSubmit = _a.onSubmit, initialValues = _a.initialValues, props = __rest(_a, ["children", "className", "style", "ignoreLostChanges", "onSubmit", "initialValues"]);
36
+ 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"]);
35
37
  // formik resets all error on each blur (with our settings)
36
38
  // this means that ALL errors from the server disappear when any one field is blurred
37
39
  // So, we have to store server errors ourselves
@@ -51,13 +53,14 @@ export default function Form(_a) {
51
53
  _a)));
52
54
  },
53
55
  }); }, [serverErrors]);
54
- return (_jsx(Formik, __assign({ validateOnChange: false, validateOnBlur: true, validateOnMount: false, initialValues: initialValues || {}, onSubmit: handleSubmit }, props, { children: _jsx(ServerErrorContext.Provider, __assign({ value: serverErrorContextValue }, { children: _jsxs(FormikFormWrapper, __assign({ className: className, style: style }, { children: [_jsx(FocusError, { serverErrors: serverErrorContextValue }), _jsx(FormBasedPreventNavigation, { ignoreLostChanges: ignoreLostChanges }), children({
56
+ return (_jsx(Formik, __assign({ validateOnChange: false, validateOnBlur: true, validateOnMount: false, initialValues: initialValues || {}, onSubmit: handleSubmit }, props, { children: _jsx(ServerErrorContext.Provider, __assign({ value: serverErrorContextValue }, { children: _jsxs(FormikFormWrapper, __assign({ className: classNames(className, FormDefaults.cssClassPrefix + 'form'), style: style }, { children: [_jsx(FocusError, { serverErrors: serverErrorContextValue }), _jsx(FormBasedPreventNavigation, { ignoreLostChanges: ignoreLostChanges }), children({
55
57
  // hack for ref forwarding
56
58
  Field: Field,
57
59
  FieldArray: FieldArray,
58
60
  })] })) })) })));
59
61
  function handleSubmit(values, formikBag) {
60
62
  var formData = undefined;
63
+ var submitFunc;
61
64
  if (objectContainsNonSerializableProperty(values)) {
62
65
  formData = objectToFormData(values, {
63
66
  indices: true,
@@ -65,8 +68,34 @@ export default function Form(_a) {
65
68
  allowEmptyArrays: true,
66
69
  noFileListBrackets: true,
67
70
  });
71
+ if (onFormDataSubmit === undefined) {
72
+ throw new Error('No onFormDataSubmit supplied for non-serializable properties.');
73
+ }
74
+ submitFunc = function () {
75
+ return onFormDataSubmit(formData !== null && formData !== void 0 ? formData : new FormData(), formikBag);
76
+ };
77
+ }
78
+ else {
79
+ if (onSubmit === undefined) {
80
+ formData = objectToFormData(values, {
81
+ indices: true,
82
+ dotNotation: true,
83
+ allowEmptyArrays: true,
84
+ noFileListBrackets: true,
85
+ });
86
+ if (onFormDataSubmit === undefined) {
87
+ // This error should never occur, as this case is covered by RequireAtLeastOne type safety
88
+ throw new Error('No onFormDataSubmit supplied for non-serializable properties.');
89
+ }
90
+ submitFunc = function () {
91
+ return onFormDataSubmit(formData !== null && formData !== void 0 ? formData : new FormData(), formikBag);
92
+ };
93
+ }
94
+ else {
95
+ submitFunc = function () { return onSubmit(values, formikBag); };
96
+ }
68
97
  }
69
- return onSubmit(formData !== null && formData !== void 0 ? formData : values, formikBag)
98
+ return submitFunc()
70
99
  .then(function (response) {
71
100
  return response;
72
101
  })
@@ -22,26 +22,43 @@ export default function FormBasedPreventNavigation(_a) {
22
22
  if (!preventNavigate) {
23
23
  return;
24
24
  }
25
+ var unblock = function () { };
26
+ var push = navigator.push;
25
27
  // TODO: https://reactrouter.com/docs/en/v6/upgrading/v5#prompt-is-not-currently-supported
26
28
  // this is a workaround until we get native support for prompt on navigate
27
- var blocker = function (tx) {
28
- if (window.confirm(promptMessage)) {
29
- tx.retry();
30
- }
31
- };
32
- var unblock = navigator.block(function (tx) {
33
- var autoUnblockingTx = __assign(__assign({}, tx), { retry: function () {
34
- // Automatically unblock the transition so it can play all the way
35
- // through before retrying it. TODO: Figure out how to re-enable
36
- // this block if the transition is cancelled for some reason.
37
- unblock();
29
+ if (navigator.block) {
30
+ var blocker_1 = function (tx) {
31
+ if (window.confirm(promptMessage)) {
38
32
  tx.retry();
39
- } });
40
- blocker(autoUnblockingTx);
41
- });
33
+ }
34
+ };
35
+ unblock = navigator.block(function (tx) {
36
+ var autoUnblockingTx = __assign(__assign({}, tx), { retry: function () {
37
+ // Automatically unblock the transition so it can play all the way
38
+ // through before retrying it. TODO: Figure out how to re-enable
39
+ // this block if the transition is cancelled for some reason.
40
+ unblock();
41
+ tx.retry();
42
+ } });
43
+ blocker_1(autoUnblockingTx);
44
+ });
45
+ }
46
+ else {
47
+ //https://gist.github.com/MarksCode/64e438c82b0b2a1161e01c88ca0d0355
48
+ navigator.push = function () {
49
+ var args = [];
50
+ for (var _i = 0; _i < arguments.length; _i++) {
51
+ args[_i] = arguments[_i];
52
+ }
53
+ if (window.confirm(promptMessage)) {
54
+ push.apply(void 0, args);
55
+ }
56
+ };
57
+ }
42
58
  window.addEventListener('beforeunload', beforeUnload);
43
59
  return function () {
44
60
  unblock();
61
+ navigator.push = push;
45
62
  window.removeEventListener('beforeunload', beforeUnload);
46
63
  };
47
64
  function beforeUnload(e) {
package/es/FormActions.js CHANGED
@@ -10,12 +10,16 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { FormDefaults } from './FormDefaults';
13
14
  import { useFormikContext } from 'formik';
14
15
  import SubmitFormButton from './SubmitFormButton';
15
16
  export default function FormActions(_a) {
16
17
  var allowPristineSubmit = _a.allowPristineSubmit, handleCancel = _a.handleCancel, disabled = _a.disabled;
17
18
  var isSubmitting = useFormikContext().isSubmitting;
18
- return (_jsxs(_Fragment, { children: [_jsx(SubmitFormButton, { className: "form-actions", allowPristineSubmit: allowPristineSubmit, disabled: disabled }), _jsx("button", __assign({ type: "button", className: "form-actions cancel-form-button", disabled: isSubmitting || disabled, onClick: handleCancel || goBack }, { children: "Cancel" }))] }));
19
+ return (_jsxs(_Fragment, { children: [_jsx(SubmitFormButton, { className: FormDefaults.cssClassPrefix + 'form-actions', allowPristineSubmit: allowPristineSubmit, disabled: disabled }), _jsx("button", __assign({ type: "button", className: FormDefaults.cssClassPrefix +
20
+ 'form-actions ' +
21
+ FormDefaults.cssClassPrefix +
22
+ 'cancel-form-button', disabled: isSubmitting || disabled, onClick: handleCancel || goBack }, { children: "Cancel" }))] }));
19
23
  function goBack() {
20
24
  window.history.back();
21
25
  }
@@ -0,0 +1,3 @@
1
+ export declare const FormDefaults: {
2
+ cssClassPrefix: string;
3
+ };
@@ -0,0 +1 @@
1
+ export var FormDefaults = { cssClassPrefix: 'envoc-form-' };
package/es/Group.d.ts CHANGED
@@ -8,6 +8,7 @@ export interface GroupProps extends InjectedFieldProps<any> {
8
8
  /** simple helper text after the input*/
9
9
  helpText?: string | React.ReactNode;
10
10
  disabled?: boolean;
11
+ required?: boolean;
11
12
  }
12
13
  /** contains standard field bits like a label, helper text, error scroll target, validation message container, etc */
13
- export default function Group({ className, children, label, helpText, meta, input, disabled, }: GroupProps): JSX.Element;
14
+ export default function Group({ className, children, label, helpText, meta, input, disabled, required, }: GroupProps): JSX.Element;
package/es/Group.js CHANGED
@@ -11,12 +11,15 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import classNames from 'classnames';
14
+ import { FormDefaults } from './FormDefaults';
14
15
  import FieldErrorScrollTarget from './Field/FieldErrorScrollTarget';
15
16
  /** contains standard field bits like a label, helper text, error scroll target, validation message container, etc */
16
17
  export default function Group(_a) {
17
- var className = _a.className, children = _a.children, label = _a.label, helpText = _a.helpText, meta = _a.meta, input = _a.input, disabled = _a.disabled;
18
- return (_jsxs("div", __assign({ className: classNames(className, 'group', {
19
- 'is-invalid': meta.error,
20
- disabled: disabled,
21
- }) }, { children: [_jsx(FieldErrorScrollTarget, {}), meta.warning && _jsx("div", __assign({ className: "warning" }, { children: meta.warning })), _jsx("label", __assign({ htmlFor: input.id }, { children: label })), children, meta.error && _jsx("div", __assign({ className: "error" }, { children: meta.error })), helpText && _jsx("div", __assign({ className: "help" }, { children: helpText }))] })));
18
+ var _b;
19
+ var className = _a.className, children = _a.children, label = _a.label, helpText = _a.helpText, meta = _a.meta, input = _a.input, disabled = _a.disabled, required = _a.required;
20
+ return (_jsxs("div", __assign({ className: classNames(className, FormDefaults.cssClassPrefix + 'group', (_b = {},
21
+ _b[FormDefaults.cssClassPrefix + 'invalid'] = meta.error,
22
+ _b[FormDefaults.cssClassPrefix + 'disabled'] = disabled,
23
+ _b[FormDefaults.cssClassPrefix + 'required'] = required,
24
+ _b)) }, { children: [_jsx(FieldErrorScrollTarget, {}), meta.warning && (_jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'warning' }, { children: meta.warning }))), _jsx("label", __assign({ htmlFor: input.id }, { children: label })), children, meta.error && (_jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'error' }, { children: meta.error }))), helpText && (_jsx("div", __assign({ className: FormDefaults.cssClassPrefix + 'help' }, { children: helpText })))] })));
22
25
  }
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { InputGroupProps } from './InputGroup';
3
- export interface IconInputGroupProps extends Omit<InputGroupProps<string | undefined>, 'onChange' | 'type' | 'value'> {
3
+ export interface IconInputGroupProps extends Omit<InputGroupProps<string | undefined | null>, 'onChange' | 'type' | 'value'> {
4
4
  type?: 'color' | 'email' | 'search' | 'tel' | 'text' | 'url';
5
5
  icon: React.ReactNode;
6
6
  helpText?: string;
@@ -24,10 +24,12 @@ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
24
24
  import React from 'react';
25
25
  import classNames from 'classnames';
26
26
  import InputGroupWithRef from './InputGroup';
27
+ import { FormDefaults } from '../FormDefaults';
27
28
  function IconInputGroup(_a, ref) {
29
+ var _b;
28
30
  var icon = _a.icon, className = _a.className, rest = __rest(_a, ["icon", "className"]);
29
31
  var input = rest.input;
30
- return (_jsx(_Fragment, { children: _jsx(InputGroupWithRef, __assign({ icon: icon, ref: ref, className: classNames(className, 'icon-input-group'), value: input.value || '', onChange: function (e) {
32
+ return (_jsx(_Fragment, { children: _jsx(InputGroupWithRef, __assign({ icon: icon, ref: ref, className: classNames(className, FormDefaults.cssClassPrefix + 'icon-input-group'), value: (_b = input.value) !== null && _b !== void 0 ? _b : '', onChange: function (e) {
31
33
  if (!e.target.value) {
32
34
  input.onChange(undefined);
33
35
  }