envoc-form 5.0.2 → 5.0.5

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 (113) hide show
  1. package/README.md +158 -15
  2. package/es/Input/CheckboxGroup.d.ts +6 -0
  3. package/es/Input/CheckboxGroup.js +14 -0
  4. package/es/Input/CheckboxInputGroup.d.ts +13 -0
  5. package/es/Input/CheckboxInputGroup.js +41 -0
  6. package/es/index.d.ts +2 -0
  7. package/es/index.js +1 -0
  8. package/lib/Input/CheckboxGroup.d.ts +6 -0
  9. package/lib/Input/CheckboxGroup.js +20 -0
  10. package/lib/Input/CheckboxInputGroup.d.ts +13 -0
  11. package/lib/Input/CheckboxInputGroup.js +46 -0
  12. package/lib/index.d.ts +2 -0
  13. package/lib/index.js +3 -1
  14. package/package.json +111 -111
  15. package/src/AddressInput/AddressInput.test.tsx +27 -27
  16. package/src/AddressInput/AddressInput.tsx +82 -82
  17. package/src/AddressInput/UsStates.ts +55 -55
  18. package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +182 -182
  19. package/src/ConfirmBaseForm/ConfirmBaseForm.test.tsx +24 -24
  20. package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +74 -74
  21. package/src/ConfirmBaseForm/__snapshots__/ConfirmBaseForm.test.tsx.snap +23 -23
  22. package/src/ConfirmDeleteForm/ConfirmDeleteForm.test.tsx +24 -24
  23. package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +87 -87
  24. package/src/ConfirmDeleteForm/__snapshots__/ConfirmDeleteForm.test.tsx.snap +25 -25
  25. package/src/DatePicker/DatePicker.test.tsx +48 -48
  26. package/src/DatePicker/DatePickerGroup.tsx +115 -115
  27. package/src/DatePicker/DatePickerHelper.ts +4 -4
  28. package/src/DatePicker/StringDateOnlyPickerGroup.tsx +28 -28
  29. package/src/DatePicker/StringDatePickerGroup.tsx +20 -20
  30. package/src/DatePicker/__snapshots__/DatePicker.test.tsx.snap +152 -152
  31. package/src/Field/CustomFieldInputProps.ts +10 -10
  32. package/src/Field/CustomFieldMetaProps.ts +5 -5
  33. package/src/Field/Field.tsx +113 -113
  34. package/src/Field/FieldErrorScrollTarget.tsx +12 -12
  35. package/src/Field/FieldNameContext.ts +6 -6
  36. package/src/Field/FieldSection.tsx +18 -18
  37. package/src/Field/InjectedFieldProps.ts +8 -8
  38. package/src/Field/StandAloneInput.tsx +55 -55
  39. package/src/Field/useStandardField.ts +125 -125
  40. package/src/FieldArray/FieldArray.tsx +154 -154
  41. package/src/File/FileGroup.test.tsx +35 -35
  42. package/src/File/FileGroup.tsx +85 -85
  43. package/src/File/FileList.tsx +21 -21
  44. package/src/File/__snapshots__/FileGroup.test.tsx.snap +34 -34
  45. package/src/File/humanFileSize.ts +8 -8
  46. package/src/Form/FocusError.tsx +55 -55
  47. package/src/Form/Form.test.tsx +14 -14
  48. package/src/Form/Form.tsx +237 -237
  49. package/src/Form/FormBasedPreventNavigation.tsx +56 -56
  50. package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -77
  51. package/src/Form/NewFormBasedPreventNavigation.tsx +59 -59
  52. package/src/Form/ServerErrorContext.ts +18 -18
  53. package/src/Form/__snapshots__/Form.test.tsx.snap +10 -10
  54. package/src/FormActions.tsx +47 -47
  55. package/src/FormDefaults.ts +2 -2
  56. package/src/Group.tsx +62 -62
  57. package/src/Input/CheckboxGroup.tsx +60 -0
  58. package/src/Input/CheckboxInputGroup.tsx +78 -0
  59. package/src/Input/IconInputGroup.tsx +54 -54
  60. package/src/Input/InputGroup.tsx +72 -72
  61. package/src/Input/MoneyInputGroup.tsx +50 -50
  62. package/src/Input/NumberInputGroup.tsx +48 -48
  63. package/src/Input/PhoneNumberInputGroup.tsx +45 -45
  64. package/src/Input/StringInputGroup.tsx +53 -53
  65. package/src/Input/__Tests__/CheckboxInputGroup.test.tsx +26 -0
  66. package/src/Input/__Tests__/IconInputGroup.test.tsx +35 -35
  67. package/src/Input/__Tests__/MoneyInputGroup.test.tsx +37 -37
  68. package/src/Input/__Tests__/NumberInputGroup.test.tsx +35 -35
  69. package/src/Input/__Tests__/PhoneNumberInputGroup.test.tsx +36 -36
  70. package/src/Input/__Tests__/StringInputGroup.test.tsx +27 -27
  71. package/src/Input/__Tests__/__snapshots__/CheckboxInputGroup.test.tsx.snap +33 -0
  72. package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +32 -32
  73. package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +34 -34
  74. package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +32 -32
  75. package/src/Input/__Tests__/__snapshots__/PhoneNumberInputGroup.test.tsx.snap +33 -33
  76. package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +31 -31
  77. package/src/Normalization/NormalizationFunction.ts +4 -4
  78. package/src/Normalization/normalizers.ts +44 -44
  79. package/src/Select/BooleanSelectGroup.tsx +28 -28
  80. package/src/Select/NumberSelectGroup.tsx +16 -16
  81. package/src/Select/SelectGroup.tsx +124 -124
  82. package/src/Select/SelectGroupPropsHelper.ts +4 -4
  83. package/src/Select/StringSelectGroup.tsx +16 -16
  84. package/src/Select/__tests__/BooleanSelectGroup.test.tsx +35 -35
  85. package/src/Select/__tests__/NumberSelectGroup.test.tsx +87 -87
  86. package/src/Select/__tests__/StringSelectGroup.test.tsx +89 -89
  87. package/src/Select/__tests__/__snapshots__/BooleanSelectGroup.test.tsx.snap +98 -98
  88. package/src/Select/__tests__/__snapshots__/NumberSelectGroup.test.tsx.snap +195 -195
  89. package/src/Select/__tests__/__snapshots__/StringSelectGroup.test.tsx.snap +195 -195
  90. package/src/StandardFormActions.tsx +41 -41
  91. package/src/SubmitFormButton.tsx +54 -54
  92. package/src/TextArea/TextAreaGroup.tsx +64 -64
  93. package/src/Validation/ValidatedApiResult.ts +8 -8
  94. package/src/Validation/ValidationError.ts +6 -6
  95. package/src/Validation/ValidationFunction.ts +4 -4
  96. package/src/Validation/validators.test.tsx +81 -81
  97. package/src/Validation/validators.ts +97 -97
  98. package/src/__Tests__/FormTestBase.tsx +65 -64
  99. package/src/__Tests__/RealisticForm.test.tsx +82 -82
  100. package/src/__Tests__/StandardFormActions.test.tsx +17 -17
  101. package/src/__Tests__/SubmitFormButton.test.tsx +17 -17
  102. package/src/__Tests__/__snapshots__/StandardFormActions.test.tsx.snap +27 -27
  103. package/src/__Tests__/__snapshots__/SubmitFormButton.test.tsx.snap +20 -20
  104. package/src/__Tests__/index.ts +3 -3
  105. package/src/_variables.scss +11 -11
  106. package/src/index.ts +156 -153
  107. package/src/react-app-env.d.ts +1 -1
  108. package/src/setupTests.ts +1 -1
  109. package/src/utils/objectContainsNonSerializableProperty.test.tsx +49 -49
  110. package/src/utils/objectContainsNonSerializableProperty.ts +17 -17
  111. package/src/utils/objectToFormData.test.tsx +76 -76
  112. package/src/utils/objectToFormData.ts +105 -105
  113. package/src/utils/typeChecks.ts +18 -18
@@ -1,82 +1,82 @@
1
- import { render, screen, waitFor } from '@testing-library/react';
2
- import user from '@testing-library/user-event';
3
- import FormTestBase from './FormTestBase';
4
- import { Form, StringInputGroup, ValidatedApiResult } from '../';
5
- import { PersonDto } from '../__Tests__/FormTestBase';
6
- import StandardFormActions from '../StandardFormActions';
7
- import { validators } from '../';
8
-
9
- const handleSubmitMock = jest.fn((value: PersonDto | FormData) => {
10
- //return value;
11
- return new Promise<ValidatedApiResult>((res, rej) => {
12
- setTimeout(() => {
13
- res({});
14
- }, 15);
15
- });
16
- });
17
-
18
- describe('Realistic Form', () => {
19
- it('Validates, resolves validation, submits values', async () => {
20
- global.scrollTo = jest.fn();
21
- const fullForm = (
22
- <FormTestBase handleSubmit={handleSubmitMock}>
23
- {({ Field }) => (
24
- <>
25
- <Field name="name" label="name" Component={StringInputGroup} />
26
- <Field
27
- name="nameWithIcon"
28
- label="Name with Icon"
29
- Component={StringInputGroup}
30
- validate={validators.required}
31
- />
32
- <StandardFormActions />
33
- <Form.DisplayFormState />
34
- </>
35
- )}
36
- </FormTestBase>
37
- );
38
-
39
- render(fullForm);
40
- const nameInput = screen.getByLabelText('name');
41
- const formSubmitButton = screen.getByRole('button', {
42
- name: 'Submit',
43
- });
44
- //The form should start off with the submit button disabled
45
- expect(formSubmitButton).toBeDisabled();
46
-
47
- //Enter a name into the name input
48
- user.click(nameInput);
49
- user.type(nameInput, 'Travis Overmier');
50
- expect(nameInput).toHaveValue('Travis Overmier');
51
-
52
- //Submit should be enabled, click submit
53
- expect(formSubmitButton).toBeEnabled();
54
- user.click(formSubmitButton);
55
-
56
- //Submit should disable while 'submitting' then re-enable
57
- expect(formSubmitButton).toBeDisabled();
58
- await waitFor(() => {
59
- expect(formSubmitButton).toBeEnabled();
60
- });
61
-
62
- //Validation message should appear
63
- const nameWithIconInput = screen.getByLabelText('Name with Icon');
64
- expect(nameWithIconInput).toHaveErrorMessage('Required');
65
-
66
- //Fill in field, error message goes away
67
- user.type(nameWithIconInput, 'Kyle Joiner');
68
- user.tab();
69
- await waitFor(() => {
70
- expect(nameWithIconInput).not.toHaveErrorMessage();
71
- });
72
-
73
- //Click the submit button
74
- user.click(formSubmitButton);
75
- await waitFor(() => {
76
- expect(handleSubmitMock).toHaveBeenCalled();
77
- expect(JSON.stringify(handleSubmitMock.mock.calls[0][0])).toBe(
78
- `{"name":"Travis Overmier","nameWithIcon":"Kyle Joiner"}`
79
- );
80
- });
81
- });
82
- });
1
+ import { render, screen, waitFor } from '@testing-library/react';
2
+ import user from '@testing-library/user-event';
3
+ import FormTestBase from './FormTestBase';
4
+ import { Form, StringInputGroup, ValidatedApiResult } from '../';
5
+ import { PersonDto } from '../__Tests__/FormTestBase';
6
+ import StandardFormActions from '../StandardFormActions';
7
+ import { validators } from '../';
8
+
9
+ const handleSubmitMock = jest.fn((value: PersonDto | FormData) => {
10
+ //return value;
11
+ return new Promise<ValidatedApiResult>((res, rej) => {
12
+ setTimeout(() => {
13
+ res({});
14
+ }, 15);
15
+ });
16
+ });
17
+
18
+ describe('Realistic Form', () => {
19
+ it('Validates, resolves validation, submits values', async () => {
20
+ global.scrollTo = jest.fn();
21
+ const fullForm = (
22
+ <FormTestBase handleSubmit={handleSubmitMock}>
23
+ {({ Field }) => (
24
+ <>
25
+ <Field name="name" label="name" Component={StringInputGroup} />
26
+ <Field
27
+ name="nameWithIcon"
28
+ label="Name with Icon"
29
+ Component={StringInputGroup}
30
+ validate={validators.required}
31
+ />
32
+ <StandardFormActions />
33
+ <Form.DisplayFormState />
34
+ </>
35
+ )}
36
+ </FormTestBase>
37
+ );
38
+
39
+ render(fullForm);
40
+ const nameInput = screen.getByLabelText('name');
41
+ const formSubmitButton = screen.getByRole('button', {
42
+ name: 'Submit',
43
+ });
44
+ //The form should start off with the submit button disabled
45
+ expect(formSubmitButton).toBeDisabled();
46
+
47
+ //Enter a name into the name input
48
+ user.click(nameInput);
49
+ user.type(nameInput, 'Travis Overmier');
50
+ expect(nameInput).toHaveValue('Travis Overmier');
51
+
52
+ //Submit should be enabled, click submit
53
+ expect(formSubmitButton).toBeEnabled();
54
+ user.click(formSubmitButton);
55
+
56
+ //Submit should disable while 'submitting' then re-enable
57
+ expect(formSubmitButton).toBeDisabled();
58
+ await waitFor(() => {
59
+ expect(formSubmitButton).toBeEnabled();
60
+ });
61
+
62
+ //Validation message should appear
63
+ const nameWithIconInput = screen.getByLabelText('Name with Icon');
64
+ expect(nameWithIconInput).toHaveErrorMessage('Required');
65
+
66
+ //Fill in field, error message goes away
67
+ user.type(nameWithIconInput, 'Kyle Joiner');
68
+ user.tab();
69
+ await waitFor(() => {
70
+ expect(nameWithIconInput).not.toHaveErrorMessage();
71
+ });
72
+
73
+ //Click the submit button
74
+ user.click(formSubmitButton);
75
+ await waitFor(() => {
76
+ expect(handleSubmitMock).toHaveBeenCalled();
77
+ expect(JSON.stringify(handleSubmitMock.mock.calls[0][0])).toBe(
78
+ `{"name":"Travis Overmier","nameWithIcon":"Kyle Joiner"}`
79
+ );
80
+ });
81
+ });
82
+ });
@@ -1,17 +1,17 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import FormTestBase from './FormTestBase';
4
- import StandardFormActions from '../StandardFormActions';
5
-
6
- describe('StandardFormActions', () => {
7
- it('renders without crashing', () => {
8
- render(<FormTestBase>{() => <StandardFormActions />}</FormTestBase>);
9
- });
10
-
11
- it('has matching snapshot', () => {
12
- const renderResult = render(
13
- <FormTestBase>{() => <StandardFormActions />}</FormTestBase>
14
- );
15
- expect(renderResult.asFragment()).toMatchSnapshot();
16
- });
17
- });
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import FormTestBase from './FormTestBase';
4
+ import StandardFormActions from '../StandardFormActions';
5
+
6
+ describe('StandardFormActions', () => {
7
+ it('renders without crashing', () => {
8
+ render(<FormTestBase>{() => <StandardFormActions />}</FormTestBase>);
9
+ });
10
+
11
+ it('has matching snapshot', () => {
12
+ const renderResult = render(
13
+ <FormTestBase>{() => <StandardFormActions />}</FormTestBase>
14
+ );
15
+ expect(renderResult.asFragment()).toMatchSnapshot();
16
+ });
17
+ });
@@ -1,17 +1,17 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import FormTestBase from './FormTestBase';
4
- import SubmitFormButton from '../SubmitFormButton';
5
-
6
- describe('SubmitFormButton', () => {
7
- it('renders without crashing', () => {
8
- render(<FormTestBase>{() => <SubmitFormButton />}</FormTestBase>);
9
- });
10
-
11
- it('has matching snapshot', () => {
12
- const renderResult = render(
13
- <FormTestBase>{() => <SubmitFormButton />}</FormTestBase>
14
- );
15
- expect(renderResult.asFragment()).toMatchSnapshot();
16
- });
17
- });
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import FormTestBase from './FormTestBase';
4
+ import SubmitFormButton from '../SubmitFormButton';
5
+
6
+ describe('SubmitFormButton', () => {
7
+ it('renders without crashing', () => {
8
+ render(<FormTestBase>{() => <SubmitFormButton />}</FormTestBase>);
9
+ });
10
+
11
+ it('has matching snapshot', () => {
12
+ const renderResult = render(
13
+ <FormTestBase>{() => <SubmitFormButton />}</FormTestBase>
14
+ );
15
+ expect(renderResult.asFragment()).toMatchSnapshot();
16
+ });
17
+ });
@@ -1,27 +1,27 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`StandardFormActions has matching snapshot 1`] = `
4
- <DocumentFragment>
5
- <form
6
- action="#"
7
- class="envoc-form-form"
8
- >
9
- <button
10
- aria-label="Submit"
11
- class="envoc-form-submit-form-button"
12
- disabled=""
13
- title="You haven't made any changes"
14
- type="submit"
15
- >
16
- Submit
17
- </button>
18
-  
19
- <button
20
- class="envoc-form-standard-form-actions-cancel-button"
21
- type="button"
22
- >
23
- Cancel
24
- </button>
25
- </form>
26
- </DocumentFragment>
27
- `;
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`StandardFormActions has matching snapshot 1`] = `
4
+ <DocumentFragment>
5
+ <form
6
+ action="#"
7
+ class="envoc-form-form"
8
+ >
9
+ <button
10
+ aria-label="Submit"
11
+ class="envoc-form-submit-form-button"
12
+ disabled=""
13
+ title="You haven't made any changes"
14
+ type="submit"
15
+ >
16
+ Submit
17
+ </button>
18
+  
19
+ <button
20
+ class="envoc-form-standard-form-actions-cancel-button"
21
+ type="button"
22
+ >
23
+ Cancel
24
+ </button>
25
+ </form>
26
+ </DocumentFragment>
27
+ `;
@@ -1,20 +1,20 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`SubmitFormButton has matching snapshot 1`] = `
4
- <DocumentFragment>
5
- <form
6
- action="#"
7
- class="envoc-form-form"
8
- >
9
- <button
10
- aria-label="Submit"
11
- class="envoc-form-submit-form-button"
12
- disabled=""
13
- title="You haven't made any changes"
14
- type="submit"
15
- >
16
- Submit
17
- </button>
18
- </form>
19
- </DocumentFragment>
20
- `;
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`SubmitFormButton has matching snapshot 1`] = `
4
+ <DocumentFragment>
5
+ <form
6
+ action="#"
7
+ class="envoc-form-form"
8
+ >
9
+ <button
10
+ aria-label="Submit"
11
+ class="envoc-form-submit-form-button"
12
+ disabled=""
13
+ title="You haven't made any changes"
14
+ type="submit"
15
+ >
16
+ Submit
17
+ </button>
18
+ </form>
19
+ </DocumentFragment>
20
+ `;
@@ -1,3 +1,3 @@
1
- import FormTestBase from './FormTestBase';
2
-
3
- export { FormTestBase };
1
+ import FormTestBase from './FormTestBase';
2
+
3
+ export { FormTestBase };
@@ -1,11 +1,11 @@
1
- //These variables are normally in the template directly,
2
-
3
- $red: #f86c6b;
4
- // Couldn't find these variables directly from coreui/bootstrap
5
- $input-border-color: #c2cfd6;
6
- $input-border-color--focused: #8ad4ee;
7
- $input-box-shadow--focused: 0 0 0 0.2rem rgba(32, 168, 216, 0.25);
8
-
9
- //Taken from react-select because it fit better in the color scheme and is more readable.
10
- $input-disabled-background-color: hsl(0, 0%, 95%);
11
- $input-disabled-border-color: hsl(0, 0%, 90%);
1
+ //These variables are normally in the template directly,
2
+
3
+ $red: #f86c6b;
4
+ // Couldn't find these variables directly from coreui/bootstrap
5
+ $input-border-color: #c2cfd6;
6
+ $input-border-color--focused: #8ad4ee;
7
+ $input-box-shadow--focused: 0 0 0 0.2rem rgba(32, 168, 216, 0.25);
8
+
9
+ //Taken from react-select because it fit better in the color scheme and is more readable.
10
+ $input-disabled-background-color: hsl(0, 0%, 95%);
11
+ $input-disabled-border-color: hsl(0, 0%, 90%);