envoc-form 5.0.3 → 5.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/README.md +163 -20
  2. package/es/ConfirmBaseForm/ConfirmBaseForm.js +2 -2
  3. package/es/DatePicker/DatePickerGroup.js +2 -2
  4. package/es/FieldArray/FieldArray.js +4 -4
  5. package/es/File/FileGroup.js +3 -3
  6. package/es/Form/Form.js +2 -2
  7. package/es/Group.js +3 -3
  8. package/es/Input/CheckboxGroup.d.ts +6 -0
  9. package/es/Input/CheckboxGroup.js +14 -0
  10. package/es/Input/CheckboxInputGroup.d.ts +13 -0
  11. package/es/Input/CheckboxInputGroup.js +41 -0
  12. package/es/Input/IconInputGroup.js +2 -2
  13. package/es/Input/InputGroup.js +2 -2
  14. package/es/Input/MoneyInputGroup.js +2 -2
  15. package/es/Input/NumberInputGroup.js +2 -2
  16. package/es/Input/PhoneNumberInputGroup.js +2 -2
  17. package/es/Input/StringInputGroup.js +2 -2
  18. package/es/Select/SelectGroup.js +3 -3
  19. package/es/StandardFormActions.js +3 -3
  20. package/es/SubmitFormButton.js +2 -2
  21. package/es/TextArea/TextAreaGroup.js +2 -2
  22. package/es/index.d.ts +2 -0
  23. package/es/index.js +1 -0
  24. package/lib/ConfirmBaseForm/ConfirmBaseForm.js +2 -5
  25. package/lib/DatePicker/DatePickerGroup.js +2 -2
  26. package/lib/FieldArray/FieldArray.js +4 -4
  27. package/lib/File/FileGroup.js +3 -3
  28. package/lib/Form/Form.js +2 -2
  29. package/lib/Group.js +3 -3
  30. package/lib/Input/CheckboxGroup.d.ts +6 -0
  31. package/lib/Input/CheckboxGroup.js +20 -0
  32. package/lib/Input/CheckboxInputGroup.d.ts +13 -0
  33. package/lib/Input/CheckboxInputGroup.js +46 -0
  34. package/lib/Input/IconInputGroup.js +2 -2
  35. package/lib/Input/InputGroup.js +2 -2
  36. package/lib/Input/MoneyInputGroup.js +2 -2
  37. package/lib/Input/NumberInputGroup.js +2 -2
  38. package/lib/Input/PhoneNumberInputGroup.js +2 -2
  39. package/lib/Input/StringInputGroup.js +2 -2
  40. package/lib/Select/SelectGroup.js +3 -3
  41. package/lib/StandardFormActions.js +3 -3
  42. package/lib/SubmitFormButton.js +2 -2
  43. package/lib/TextArea/TextAreaGroup.js +2 -2
  44. package/lib/index.d.ts +2 -0
  45. package/lib/index.js +3 -1
  46. package/package.json +111 -111
  47. package/src/AddressInput/AddressInput.test.tsx +27 -27
  48. package/src/AddressInput/AddressInput.tsx +82 -82
  49. package/src/AddressInput/UsStates.ts +55 -55
  50. package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +182 -182
  51. package/src/ConfirmBaseForm/ConfirmBaseForm.test.tsx +24 -24
  52. package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +74 -74
  53. package/src/ConfirmBaseForm/__snapshots__/ConfirmBaseForm.test.tsx.snap +23 -23
  54. package/src/ConfirmDeleteForm/ConfirmDeleteForm.test.tsx +24 -24
  55. package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +87 -87
  56. package/src/ConfirmDeleteForm/__snapshots__/ConfirmDeleteForm.test.tsx.snap +25 -25
  57. package/src/DatePicker/DatePicker.test.tsx +48 -48
  58. package/src/DatePicker/DatePickerGroup.tsx +109 -115
  59. package/src/DatePicker/DatePickerHelper.ts +4 -4
  60. package/src/DatePicker/StringDateOnlyPickerGroup.tsx +28 -28
  61. package/src/DatePicker/StringDatePickerGroup.tsx +20 -20
  62. package/src/DatePicker/__snapshots__/DatePicker.test.tsx.snap +152 -152
  63. package/src/Field/CustomFieldInputProps.ts +10 -10
  64. package/src/Field/CustomFieldMetaProps.ts +5 -5
  65. package/src/Field/Field.tsx +113 -113
  66. package/src/Field/FieldErrorScrollTarget.tsx +12 -12
  67. package/src/Field/FieldNameContext.ts +6 -6
  68. package/src/Field/FieldSection.tsx +18 -18
  69. package/src/Field/InjectedFieldProps.ts +8 -8
  70. package/src/Field/StandAloneInput.tsx +55 -55
  71. package/src/Field/useStandardField.ts +125 -125
  72. package/src/FieldArray/FieldArray.tsx +154 -154
  73. package/src/File/FileGroup.test.tsx +35 -35
  74. package/src/File/FileGroup.tsx +82 -85
  75. package/src/File/FileList.tsx +21 -21
  76. package/src/File/__snapshots__/FileGroup.test.tsx.snap +34 -34
  77. package/src/File/humanFileSize.ts +8 -8
  78. package/src/Form/FocusError.tsx +55 -55
  79. package/src/Form/Form.test.tsx +14 -14
  80. package/src/Form/Form.tsx +234 -237
  81. package/src/Form/FormBasedPreventNavigation.tsx +56 -56
  82. package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -77
  83. package/src/Form/NewFormBasedPreventNavigation.tsx +59 -59
  84. package/src/Form/ServerErrorContext.ts +18 -18
  85. package/src/Form/__snapshots__/Form.test.tsx.snap +10 -10
  86. package/src/FormActions.tsx +47 -47
  87. package/src/FormDefaults.ts +2 -2
  88. package/src/Group.tsx +62 -62
  89. package/src/Input/CheckboxGroup.tsx +60 -0
  90. package/src/Input/CheckboxInputGroup.tsx +78 -0
  91. package/src/Input/IconInputGroup.tsx +54 -54
  92. package/src/Input/InputGroup.tsx +66 -72
  93. package/src/Input/MoneyInputGroup.tsx +47 -50
  94. package/src/Input/NumberInputGroup.tsx +45 -48
  95. package/src/Input/PhoneNumberInputGroup.tsx +45 -45
  96. package/src/Input/StringInputGroup.tsx +50 -53
  97. package/src/Input/__Tests__/CheckboxInputGroup.test.tsx +26 -0
  98. package/src/Input/__Tests__/IconInputGroup.test.tsx +35 -35
  99. package/src/Input/__Tests__/MoneyInputGroup.test.tsx +37 -37
  100. package/src/Input/__Tests__/NumberInputGroup.test.tsx +35 -35
  101. package/src/Input/__Tests__/PhoneNumberInputGroup.test.tsx +36 -36
  102. package/src/Input/__Tests__/StringInputGroup.test.tsx +27 -27
  103. package/src/Input/__Tests__/__snapshots__/CheckboxInputGroup.test.tsx.snap +33 -0
  104. package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +32 -32
  105. package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +34 -34
  106. package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +32 -32
  107. package/src/Input/__Tests__/__snapshots__/PhoneNumberInputGroup.test.tsx.snap +33 -33
  108. package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +31 -31
  109. package/src/Normalization/NormalizationFunction.ts +4 -4
  110. package/src/Normalization/normalizers.ts +44 -44
  111. package/src/Select/BooleanSelectGroup.tsx +28 -28
  112. package/src/Select/NumberSelectGroup.tsx +16 -16
  113. package/src/Select/SelectGroup.tsx +124 -124
  114. package/src/Select/SelectGroupPropsHelper.ts +4 -4
  115. package/src/Select/StringSelectGroup.tsx +16 -16
  116. package/src/Select/__tests__/BooleanSelectGroup.test.tsx +35 -35
  117. package/src/Select/__tests__/NumberSelectGroup.test.tsx +87 -87
  118. package/src/Select/__tests__/StringSelectGroup.test.tsx +89 -89
  119. package/src/Select/__tests__/__snapshots__/BooleanSelectGroup.test.tsx.snap +98 -98
  120. package/src/Select/__tests__/__snapshots__/NumberSelectGroup.test.tsx.snap +195 -195
  121. package/src/Select/__tests__/__snapshots__/StringSelectGroup.test.tsx.snap +195 -195
  122. package/src/StandardFormActions.tsx +41 -41
  123. package/src/SubmitFormButton.tsx +54 -54
  124. package/src/TextArea/TextAreaGroup.tsx +64 -64
  125. package/src/Validation/ValidatedApiResult.ts +8 -8
  126. package/src/Validation/ValidationError.ts +6 -6
  127. package/src/Validation/ValidationFunction.ts +4 -4
  128. package/src/Validation/validators.test.tsx +81 -81
  129. package/src/Validation/validators.ts +97 -97
  130. package/src/__Tests__/FormTestBase.tsx +65 -64
  131. package/src/__Tests__/RealisticForm.test.tsx +82 -82
  132. package/src/__Tests__/StandardFormActions.test.tsx +17 -17
  133. package/src/__Tests__/SubmitFormButton.test.tsx +17 -17
  134. package/src/__Tests__/__snapshots__/StandardFormActions.test.tsx.snap +27 -27
  135. package/src/__Tests__/__snapshots__/SubmitFormButton.test.tsx.snap +20 -20
  136. package/src/__Tests__/index.ts +3 -3
  137. package/src/_variables.scss +11 -11
  138. package/src/index.ts +156 -153
  139. package/src/react-app-env.d.ts +1 -1
  140. package/src/setupTests.ts +1 -1
  141. package/src/utils/objectContainsNonSerializableProperty.test.tsx +49 -49
  142. package/src/utils/objectContainsNonSerializableProperty.ts +17 -17
  143. package/src/utils/objectToFormData.test.tsx +76 -76
  144. package/src/utils/objectToFormData.ts +105 -105
  145. package/src/utils/typeChecks.ts +18 -18
@@ -1,77 +1,77 @@
1
- import type { History, Blocker, Transition } from 'history';
2
- import { useEffect } from 'react';
3
- // see: https://gist.github.com/rmorse/426ffcc579922a82749934826fa9f743
4
- import { Navigator as BaseNavigator } from 'react-router-dom';
5
-
6
- interface Navigator extends BaseNavigator {
7
- block?: History['block'];
8
- }
9
-
10
- export interface FormBasedPreventNavigationProps {
11
- promptMessage?: string;
12
- preventNavigate: boolean;
13
- navigator: Navigator;
14
- }
15
- /** Only use this if the project uses `<BrowserRouter/>` or any router that does not support the new
16
- * [react-router Data API](https://reactrouter.com/en/main/routers/picking-a-router#using-v64-data-apis)
17
- *
18
- * Legacy function to prevent the user from navigating away from a form if there are any changes.
19
- */
20
- export default function LegacyFormBasedPreventNavigation({
21
- promptMessage = 'Changes you made may not be saved.',
22
- preventNavigate,
23
- navigator,
24
- }: FormBasedPreventNavigationProps) {
25
- useEffect(() => {
26
- if (!preventNavigate) {
27
- return;
28
- }
29
- let unblock = () => {};
30
- const push = navigator.push;
31
-
32
- // TODO: https://reactrouter.com/docs/en/v6/upgrading/v5#prompt-is-not-currently-supported
33
- // this is a workaround until we get native support for prompt on navigate
34
- if (navigator.block) {
35
- const blocker: Blocker = (tx) => {
36
- if (window.confirm(promptMessage)) {
37
- tx.retry();
38
- }
39
- };
40
- unblock = navigator.block((tx: Transition) => {
41
- const autoUnblockingTx = {
42
- ...tx,
43
- retry() {
44
- // Automatically unblock the transition so it can play all the way
45
- // through before retrying it. TODO: Figure out how to re-enable
46
- // this block if the transition is cancelled for some reason.
47
- unblock();
48
- tx.retry();
49
- },
50
- };
51
-
52
- blocker(autoUnblockingTx);
53
- });
54
- } else {
55
- //https://gist.github.com/MarksCode/64e438c82b0b2a1161e01c88ca0d0355
56
- navigator.push = (...args: Parameters<typeof push>) => {
57
- if (window.confirm(promptMessage)) {
58
- push(...args);
59
- }
60
- };
61
- }
62
-
63
- window.addEventListener('beforeunload', beforeUnload);
64
- return () => {
65
- unblock();
66
- navigator.push = push;
67
- window.removeEventListener('beforeunload', beforeUnload);
68
- };
69
-
70
- function beforeUnload(e: BeforeUnloadEvent) {
71
- e.preventDefault();
72
- e.returnValue = promptMessage;
73
- }
74
- }, [preventNavigate, promptMessage, navigator]);
75
-
76
- return null;
77
- }
1
+ import type { History, Blocker, Transition } from 'history';
2
+ import { useEffect } from 'react';
3
+ // see: https://gist.github.com/rmorse/426ffcc579922a82749934826fa9f743
4
+ import { Navigator as BaseNavigator } from 'react-router-dom';
5
+
6
+ interface Navigator extends BaseNavigator {
7
+ block?: History['block'];
8
+ }
9
+
10
+ export interface FormBasedPreventNavigationProps {
11
+ promptMessage?: string;
12
+ preventNavigate: boolean;
13
+ navigator: Navigator;
14
+ }
15
+ /** Only use this if the project uses `<BrowserRouter/>` or any router that does not support the new
16
+ * [react-router Data API](https://reactrouter.com/en/main/routers/picking-a-router#using-v64-data-apis)
17
+ *
18
+ * Legacy function to prevent the user from navigating away from a form if there are any changes.
19
+ */
20
+ export default function LegacyFormBasedPreventNavigation({
21
+ promptMessage = 'Changes you made may not be saved.',
22
+ preventNavigate,
23
+ navigator,
24
+ }: FormBasedPreventNavigationProps) {
25
+ useEffect(() => {
26
+ if (!preventNavigate) {
27
+ return;
28
+ }
29
+ let unblock = () => {};
30
+ const push = navigator.push;
31
+
32
+ // TODO: https://reactrouter.com/docs/en/v6/upgrading/v5#prompt-is-not-currently-supported
33
+ // this is a workaround until we get native support for prompt on navigate
34
+ if (navigator.block) {
35
+ const blocker: Blocker = (tx) => {
36
+ if (window.confirm(promptMessage)) {
37
+ tx.retry();
38
+ }
39
+ };
40
+ unblock = navigator.block((tx: Transition) => {
41
+ const autoUnblockingTx = {
42
+ ...tx,
43
+ retry() {
44
+ // Automatically unblock the transition so it can play all the way
45
+ // through before retrying it. TODO: Figure out how to re-enable
46
+ // this block if the transition is cancelled for some reason.
47
+ unblock();
48
+ tx.retry();
49
+ },
50
+ };
51
+
52
+ blocker(autoUnblockingTx);
53
+ });
54
+ } else {
55
+ //https://gist.github.com/MarksCode/64e438c82b0b2a1161e01c88ca0d0355
56
+ navigator.push = (...args: Parameters<typeof push>) => {
57
+ if (window.confirm(promptMessage)) {
58
+ push(...args);
59
+ }
60
+ };
61
+ }
62
+
63
+ window.addEventListener('beforeunload', beforeUnload);
64
+ return () => {
65
+ unblock();
66
+ navigator.push = push;
67
+ window.removeEventListener('beforeunload', beforeUnload);
68
+ };
69
+
70
+ function beforeUnload(e: BeforeUnloadEvent) {
71
+ e.preventDefault();
72
+ e.returnValue = promptMessage;
73
+ }
74
+ }, [preventNavigate, promptMessage, navigator]);
75
+
76
+ return null;
77
+ }
@@ -1,59 +1,59 @@
1
- import type { History, Blocker, Transition } from 'history';
2
- import { useEffect } from 'react';
3
- import {
4
- Navigator as BaseNavigator,
5
- unstable_usePrompt as usePrompt,
6
- } from 'react-router-dom';
7
-
8
- interface Navigator extends BaseNavigator {
9
- block?: History['block'];
10
- location: Location;
11
- }
12
-
13
- interface FormBasedPreventNavigationProps {
14
- promptMessage?: string;
15
- preventNavigate: boolean;
16
- navigator: Navigator;
17
- }
18
-
19
- /** Temporary function to allow backwards compatibility with routers that do not use the new Data API */
20
- export default function NewFormBasedPreventNavigation({
21
- promptMessage = 'Changes you made may not be saved.',
22
- preventNavigate,
23
- navigator,
24
- }: FormBasedPreventNavigationProps) {
25
- usePrompt({
26
- when: preventNavigate,
27
- message: promptMessage,
28
- });
29
-
30
- // TODO: Once react-router fully supports usePrompt and when we do not want to support routers
31
- // that do not support the react-router Data API we can remove this.
32
- useEffect(() => {
33
- if (!preventNavigate) {
34
- return;
35
- }
36
- let unblock = () => {};
37
- const push = navigator.push;
38
-
39
- navigator.push = (...args: Parameters<typeof push>) => {
40
- if (window.confirm(promptMessage)) {
41
- push(...args);
42
- }
43
- };
44
-
45
- window.addEventListener('beforeunload', beforeUnload);
46
- return () => {
47
- unblock();
48
- navigator.push = push;
49
- window.removeEventListener('beforeunload', beforeUnload);
50
- };
51
-
52
- function beforeUnload(e: BeforeUnloadEvent) {
53
- e.preventDefault();
54
- e.returnValue = promptMessage;
55
- }
56
- }, [preventNavigate, promptMessage, navigator]);
57
-
58
- return null;
59
- }
1
+ import type { History, Blocker, Transition } from 'history';
2
+ import { useEffect } from 'react';
3
+ import {
4
+ Navigator as BaseNavigator,
5
+ unstable_usePrompt as usePrompt,
6
+ } from 'react-router-dom';
7
+
8
+ interface Navigator extends BaseNavigator {
9
+ block?: History['block'];
10
+ location: Location;
11
+ }
12
+
13
+ interface FormBasedPreventNavigationProps {
14
+ promptMessage?: string;
15
+ preventNavigate: boolean;
16
+ navigator: Navigator;
17
+ }
18
+
19
+ /** Temporary function to allow backwards compatibility with routers that do not use the new Data API */
20
+ export default function NewFormBasedPreventNavigation({
21
+ promptMessage = 'Changes you made may not be saved.',
22
+ preventNavigate,
23
+ navigator,
24
+ }: FormBasedPreventNavigationProps) {
25
+ usePrompt({
26
+ when: preventNavigate,
27
+ message: promptMessage,
28
+ });
29
+
30
+ // TODO: Once react-router fully supports usePrompt and when we do not want to support routers
31
+ // that do not support the react-router Data API we can remove this.
32
+ useEffect(() => {
33
+ if (!preventNavigate) {
34
+ return;
35
+ }
36
+ let unblock = () => {};
37
+ const push = navigator.push;
38
+
39
+ navigator.push = (...args: Parameters<typeof push>) => {
40
+ if (window.confirm(promptMessage)) {
41
+ push(...args);
42
+ }
43
+ };
44
+
45
+ window.addEventListener('beforeunload', beforeUnload);
46
+ return () => {
47
+ unblock();
48
+ navigator.push = push;
49
+ window.removeEventListener('beforeunload', beforeUnload);
50
+ };
51
+
52
+ function beforeUnload(e: BeforeUnloadEvent) {
53
+ e.preventDefault();
54
+ e.returnValue = promptMessage;
55
+ }
56
+ }, [preventNavigate, promptMessage, navigator]);
57
+
58
+ return null;
59
+ }
@@ -1,18 +1,18 @@
1
- import React from 'react';
2
-
3
- export interface ServerErrors {
4
- [path: string]: string;
5
- }
6
- export interface ServerErrorContextProps {
7
- errors: ServerErrors;
8
- getError: (path: string) => string | undefined;
9
- setError: (path: string, errorMessage: string | undefined) => void;
10
- }
11
- /** Context to store the API errors from the server for the form. */
12
- export const ServerErrorContext = React.createContext<ServerErrorContextProps>({
13
- errors: {},
14
- getError: (path: string) => {
15
- return undefined;
16
- },
17
- setError: (path: string, errorMessage: string | undefined) => {},
18
- });
1
+ import React from 'react';
2
+
3
+ export interface ServerErrors {
4
+ [path: string]: string;
5
+ }
6
+ export interface ServerErrorContextProps {
7
+ errors: ServerErrors;
8
+ getError: (path: string) => string | undefined;
9
+ setError: (path: string, errorMessage: string | undefined) => void;
10
+ }
11
+ /** Context to store the API errors from the server for the form. */
12
+ export const ServerErrorContext = React.createContext<ServerErrorContextProps>({
13
+ errors: {},
14
+ getError: (path: string) => {
15
+ return undefined;
16
+ },
17
+ setError: (path: string, errorMessage: string | undefined) => {},
18
+ });
@@ -1,10 +1,10 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`FormTestBase has matching snapshot 1`] = `
4
- <DocumentFragment>
5
- <form
6
- action="#"
7
- class="envoc-form-form"
8
- />
9
- </DocumentFragment>
10
- `;
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`FormTestBase has matching snapshot 1`] = `
4
+ <DocumentFragment>
5
+ <form
6
+ action="#"
7
+ class="envoc-form-form"
8
+ />
9
+ </DocumentFragment>
10
+ `;
@@ -1,47 +1,47 @@
1
- import { FormDefaults } from './FormDefaults';
2
- import { useFormikContext } from 'formik';
3
- import SubmitFormButton from './SubmitFormButton';
4
-
5
- export interface FormActionsProps {
6
- /** Allow the form to be submitted without any changes. By default this is not allowed. */
7
- allowPristineSubmit?: boolean;
8
- /** The cancel button's `onClick`.
9
- * @defaultValue `window.history.back()`
10
- */
11
- handleCancel?: () => void;
12
- /** Whether both buttons should be disabled. */
13
- disabled?: boolean;
14
- }
15
-
16
- /** Standard cancel and submit buttons. */
17
- export default function FormActions({
18
- allowPristineSubmit,
19
- handleCancel,
20
- disabled,
21
- }: FormActionsProps) {
22
- const { isSubmitting } = useFormikContext();
23
- return (
24
- <>
25
- <SubmitFormButton
26
- className={FormDefaults.cssClassPrefix + 'form-actions'}
27
- allowPristineSubmit={allowPristineSubmit}
28
- disabled={disabled}
29
- />
30
- <button
31
- type="button"
32
- className={
33
- FormDefaults.cssClassPrefix +
34
- 'form-actions ' +
35
- FormDefaults.cssClassPrefix +
36
- 'cancel-form-button'
37
- }
38
- disabled={isSubmitting || disabled}
39
- onClick={handleCancel || goBack}>
40
- Cancel
41
- </button>
42
- </>
43
- );
44
- function goBack() {
45
- window.history.back();
46
- }
47
- }
1
+ import { FormDefaults } from './FormDefaults';
2
+ import { useFormikContext } from 'formik';
3
+ import SubmitFormButton from './SubmitFormButton';
4
+
5
+ export interface FormActionsProps {
6
+ /** Allow the form to be submitted without any changes. By default this is not allowed. */
7
+ allowPristineSubmit?: boolean;
8
+ /** The cancel button's `onClick`.
9
+ * @defaultValue `window.history.back()`
10
+ */
11
+ handleCancel?: () => void;
12
+ /** Whether both buttons should be disabled. */
13
+ disabled?: boolean;
14
+ }
15
+
16
+ /** Standard cancel and submit buttons. */
17
+ export default function FormActions({
18
+ allowPristineSubmit,
19
+ handleCancel,
20
+ disabled,
21
+ }: FormActionsProps) {
22
+ const { isSubmitting } = useFormikContext();
23
+ return (
24
+ <>
25
+ <SubmitFormButton
26
+ className={FormDefaults.cssClassPrefix + 'form-actions'}
27
+ allowPristineSubmit={allowPristineSubmit}
28
+ disabled={disabled}
29
+ />
30
+ <button
31
+ type="button"
32
+ className={
33
+ FormDefaults.cssClassPrefix +
34
+ 'form-actions ' +
35
+ FormDefaults.cssClassPrefix +
36
+ 'cancel-form-button'
37
+ }
38
+ disabled={isSubmitting || disabled}
39
+ onClick={handleCancel || goBack}>
40
+ Cancel
41
+ </button>
42
+ </>
43
+ );
44
+ function goBack() {
45
+ window.history.back();
46
+ }
47
+ }
@@ -1,2 +1,2 @@
1
- /** `envoc-form-` CSS class prefix */
2
- export const FormDefaults = { cssClassPrefix: 'envoc-form-' };
1
+ /** `envoc-form-` CSS class prefix */
2
+ export const FormDefaults = { cssClassPrefix: 'envoc-form-' };
package/src/Group.tsx CHANGED
@@ -1,62 +1,62 @@
1
- import classNames from 'classnames';
2
- import { FormDefaults } from './FormDefaults';
3
- import FieldErrorScrollTarget from './Field/FieldErrorScrollTarget';
4
- import { InjectedFieldProps } from './Field/InjectedFieldProps';
5
-
6
- export interface GroupProps extends InjectedFieldProps<any> {
7
- /** Extra class names to apply. */
8
- className?: string;
9
-
10
- children: React.ReactNode;
11
-
12
- /** Simple text label before the input. */
13
- label?: string;
14
-
15
- /** Simple helper text after the input. */
16
- helpText?: string | React.ReactNode;
17
-
18
- /** Whether the field should be disabled. */
19
- disabled?: boolean;
20
-
21
- required?: boolean;
22
- }
23
-
24
- /** Contains standard field bits like a label, helper text, error scroll target, validation message container, etc. */
25
- export default function Group({
26
- className,
27
- children,
28
- label,
29
- helpText,
30
- meta,
31
- input,
32
- disabled,
33
- required,
34
- }: GroupProps) {
35
- return (
36
- <div
37
- className={classNames(className, FormDefaults.cssClassPrefix + 'group', {
38
- [FormDefaults.cssClassPrefix + 'invalid']: meta.error,
39
- [FormDefaults.cssClassPrefix + 'disabled']: disabled,
40
- [FormDefaults.cssClassPrefix + 'required']: required,
41
- })}>
42
- <FieldErrorScrollTarget />
43
- {meta.warning && (
44
- <div className={FormDefaults.cssClassPrefix + 'warning'}>
45
- {meta.warning}
46
- </div>
47
- )}
48
- <label htmlFor={input.id}>{label}</label>
49
- {children}
50
- {meta.error && (
51
- <div
52
- id={`${input.id}-error`}
53
- className={FormDefaults.cssClassPrefix + 'error'}>
54
- {meta.error}
55
- </div>
56
- )}
57
- {helpText && (
58
- <div className={FormDefaults.cssClassPrefix + 'help'}>{helpText}</div>
59
- )}
60
- </div>
61
- );
62
- }
1
+ import { clsx } from 'clsx';
2
+ import FieldErrorScrollTarget from './Field/FieldErrorScrollTarget';
3
+ import { InjectedFieldProps } from './Field/InjectedFieldProps';
4
+ import { FormDefaults } from './FormDefaults';
5
+
6
+ export interface GroupProps extends InjectedFieldProps<any> {
7
+ /** Extra class names to apply. */
8
+ className?: string;
9
+
10
+ children: React.ReactNode;
11
+
12
+ /** Simple text label before the input. */
13
+ label?: string;
14
+
15
+ /** Simple helper text after the input. */
16
+ helpText?: string | React.ReactNode;
17
+
18
+ /** Whether the field should be disabled. */
19
+ disabled?: boolean;
20
+
21
+ required?: boolean;
22
+ }
23
+
24
+ /** Contains standard field bits like a label, helper text, error scroll target, validation message container, etc. */
25
+ export default function Group({
26
+ className,
27
+ children,
28
+ label,
29
+ helpText,
30
+ meta,
31
+ input,
32
+ disabled,
33
+ required,
34
+ }: GroupProps) {
35
+ return (
36
+ <div
37
+ className={clsx(className, FormDefaults.cssClassPrefix + 'group', {
38
+ [FormDefaults.cssClassPrefix + 'invalid']: meta.error,
39
+ [FormDefaults.cssClassPrefix + 'disabled']: disabled,
40
+ [FormDefaults.cssClassPrefix + 'required']: required,
41
+ })}>
42
+ <FieldErrorScrollTarget />
43
+ {meta.warning && (
44
+ <div className={FormDefaults.cssClassPrefix + 'warning'}>
45
+ {meta.warning}
46
+ </div>
47
+ )}
48
+ <label htmlFor={input.id}>{label}</label>
49
+ {children}
50
+ {meta.error && (
51
+ <div
52
+ id={`${input.id}-error`}
53
+ className={FormDefaults.cssClassPrefix + 'error'}>
54
+ {meta.error}
55
+ </div>
56
+ )}
57
+ {helpText && (
58
+ <div className={FormDefaults.cssClassPrefix + 'help'}>{helpText}</div>
59
+ )}
60
+ </div>
61
+ );
62
+ }
@@ -0,0 +1,60 @@
1
+ import { clsx } from 'clsx';
2
+ import FieldErrorScrollTarget from '../Field/FieldErrorScrollTarget';
3
+ import { FormDefaults } from '../FormDefaults';
4
+ import { GroupProps } from '../Group';
5
+
6
+ export interface CheckboxGroupProps extends GroupProps {
7
+ labelOnLeft?: boolean;
8
+ }
9
+
10
+ /** Contains standard field bits like a label, helper text, error scroll target, validation message container, etc. */
11
+ export default function CheckboxGroup({
12
+ className,
13
+ children,
14
+ label,
15
+ helpText,
16
+ meta,
17
+ input,
18
+ disabled,
19
+ required,
20
+ labelOnLeft,
21
+ }: CheckboxGroupProps) {
22
+ return (
23
+ <div
24
+ className={clsx(className, FormDefaults.cssClassPrefix + 'group', {
25
+ [FormDefaults.cssClassPrefix + 'invalid']: meta.error,
26
+ [FormDefaults.cssClassPrefix + 'disabled']: disabled,
27
+ [FormDefaults.cssClassPrefix + 'required']: required,
28
+ })}>
29
+ <FieldErrorScrollTarget />
30
+ {meta.warning && (
31
+ <div className={FormDefaults.cssClassPrefix + 'warning'}>
32
+ {meta.warning}
33
+ </div>
34
+ )}
35
+ <div className={FormDefaults.cssClassPrefix + 'checkbox-group-input'}>
36
+ {labelOnLeft ? (
37
+ <>
38
+ <label htmlFor={input.id}>{label}</label>
39
+ {children}
40
+ </>
41
+ ) : (
42
+ <>
43
+ {children}
44
+ <label htmlFor={input.id}>{label}</label>
45
+ </>
46
+ )}
47
+ </div>
48
+ {meta.error && (
49
+ <div
50
+ id={`${input.id}-error`}
51
+ className={FormDefaults.cssClassPrefix + 'error'}>
52
+ {meta.error}
53
+ </div>
54
+ )}
55
+ {helpText && (
56
+ <div className={FormDefaults.cssClassPrefix + 'help'}>{helpText}</div>
57
+ )}
58
+ </div>
59
+ );
60
+ }