envoc-form 2.0.1-1 → 2.0.1-13
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.
- package/README.md +7 -7
- package/dist/css/envoc-form-styles.css +43 -5
- package/dist/css/envoc-form-styles.css.map +1 -1
- package/es/AddressInput/AddressInput.js +8 -7
- package/es/ConfirmBaseForm/ConfirmBaseForm.js +3 -2
- package/es/ConfirmDeleteForm/ConfirmDeleteForm.js +3 -2
- package/es/DatePickerInput/DatePickerInput.js +3 -2
- package/es/FileInput/DefaultFileList.js +36 -0
- package/es/FileInput/DropzoneFileInput.js +58 -0
- package/es/FileInput/FileInput.js +31 -9
- package/es/FileInput/index.js +2 -1
- package/es/Form/Form.js +11 -33
- package/es/Form/FormBasedPreventNavigation.js +1 -1
- package/es/FormGroupWrapper.js +2 -1
- package/es/FormInput/FormInput.js +29 -10
- package/es/FormInputArray/FormInputArray.js +39 -24
- package/es/IconInput.js +2 -1
- package/es/ReactSelectField/ReactSelectField.js +6 -3
- package/es/SubmitFormButton.js +2 -1
- package/es/__Tests__/FormTestBase.js +5 -2
- package/es/normalizers.js +10 -5
- package/es/useStandardFormInput.js +4 -2
- package/es/utils/index.js +3 -0
- package/es/utils/objectContainsNonSerializableProperty.js +16 -0
- package/es/utils/objectToFormData.js +65 -0
- package/es/utils/typeChecks.js +25 -0
- package/lib/AddressInput/AddressInput.js +15 -9
- package/lib/ConfirmBaseForm/ConfirmBaseForm.js +4 -2
- package/lib/ConfirmDeleteForm/ConfirmDeleteForm.js +6 -4
- package/lib/DatePickerInput/DatePickerInput.js +4 -2
- package/lib/FileInput/DefaultFileList.js +47 -0
- package/lib/FileInput/DropzoneFileInput.js +75 -0
- package/lib/FileInput/FileInput.js +39 -10
- package/lib/FileInput/index.js +13 -3
- package/lib/Form/Form.js +19 -39
- package/lib/Form/FormBasedPreventNavigation.js +7 -3
- package/lib/FormGroupWrapper.js +3 -1
- package/lib/FormInput/FormInput.js +31 -11
- package/lib/FormInputArray/FormInputArray.js +47 -26
- package/lib/FormSection.js +5 -1
- package/lib/IconInput.js +3 -1
- package/lib/ReactSelectField/ReactSelectField.js +13 -5
- package/lib/ReactSelectField/index.js +6 -2
- package/lib/SubmitFormButton.js +3 -1
- package/lib/__Tests__/FormTestBase.js +6 -2
- package/lib/index.js +7 -3
- package/lib/normalizers.js +10 -5
- package/lib/useStandardFormInput.js +5 -2
- package/lib/utils/index.js +23 -0
- package/lib/utils/objectContainsNonSerializableProperty.js +24 -0
- package/lib/utils/objectToFormData.js +73 -0
- package/lib/utils/typeChecks.js +58 -0
- package/lib/validators/index.js +5 -1
- package/package.json +99 -90
- package/src/AddressInput/AddesssInput.test.js +23 -23
- package/src/AddressInput/AddressInput.js +73 -73
- package/src/AddressInput/UsStates.js +53 -53
- package/src/AddressInput/__snapshots__/AddesssInput.test.js.snap +207 -207
- package/src/AddressInput/index.js +2 -2
- package/src/BoolInput/BoolInput.js +7 -7
- package/src/BoolInput/BoolInput.test.js +23 -23
- package/src/BoolInput/InlineBoolInput.js +7 -7
- package/src/BoolInput/__snapshots__/BoolInput.test.js.snap +89 -89
- package/src/BoolInput/boolOptions.js +6 -6
- package/src/BoolInput/index.js +4 -4
- package/src/ConfirmBaseForm/ConfirmBaseForm.js +37 -37
- package/src/ConfirmBaseForm/ConfirmBaseForm.test.js +14 -14
- package/src/ConfirmBaseForm/__snapshots__/ConfirmBaseForm.test.js.snap +23 -23
- package/src/ConfirmBaseForm/index.js +1 -1
- package/src/ConfirmDeleteForm/ConfirmDeleteForm.js +39 -39
- package/src/ConfirmDeleteForm/ConfirmDeleteForm.test.js +24 -24
- package/src/ConfirmDeleteForm/__snapshots__/ConfirmDeleteForm.test.js.snap +25 -25
- package/src/ConfirmDeleteForm/index.js +1 -1
- package/src/DatePickerInput/DatePickerInput.js +46 -46
- package/src/DatePickerInput/DatePickerInput.test.js +74 -74
- package/src/DatePickerInput/__snapshots__/DatePickerInput.test.js.snap +134 -131
- package/src/DatePickerInput/date-picker-input.scss +42 -42
- package/src/DatePickerInput/index.js +3 -3
- package/src/ErrorScrollTarget.js +6 -6
- package/src/FileInput/DefaultFileList.js +39 -0
- package/src/FileInput/DropzoneFileInput.js +56 -0
- package/src/FileInput/DropzoneFileInput.test.js +24 -0
- package/src/FileInput/FileInput.js +77 -49
- package/src/FileInput/FileInput.test.js +24 -15
- package/src/FileInput/__snapshots__/DropzoneFileInput.test.js.snap +57 -0
- package/src/FileInput/__snapshots__/FileInput.test.js.snap +58 -22
- package/src/FileInput/file-input.scss +58 -17
- package/src/FileInput/index.js +4 -3
- package/src/Form/FocusError.js +48 -48
- package/src/Form/Form.js +139 -161
- package/src/Form/Form.test.js +23 -23
- package/src/Form/FormBasedPreventNavigation.js +25 -25
- package/src/Form/ServerErrorContext.js +7 -7
- package/src/Form/__snapshots__/Form.test.js.snap +9 -9
- package/src/Form/index.js +3 -3
- package/src/FormGroup.js +30 -30
- package/src/FormGroupWrapper.js +28 -28
- package/src/FormInput/FormInput.js +144 -136
- package/src/FormInput/FormInput.test.js +66 -66
- package/src/FormInput/__snapshots__/FormInput.test.js.snap +323 -313
- package/src/FormInput/form-input.scss +9 -9
- package/src/FormInput/index.js +2 -2
- package/src/FormInputArray/FormInputArray.js +224 -210
- package/src/FormInputArray/FormInputArray.test.js +108 -59
- package/src/FormInputArray/__snapshots__/FormInputArray.test.js.snap +52 -40
- package/src/FormInputArray/form-input-array.scss +13 -8
- package/src/FormInputArray/index.js +2 -2
- package/src/FormSection.js +13 -13
- package/src/IconInput.js +31 -31
- package/src/InlineFormInput/InlineFormInput.js +6 -6
- package/src/InlineFormInput/InlineFormInput.test.js +23 -23
- package/src/InlineFormInput/__snapshots__/InlineFormInput.test.js.snap +26 -26
- package/src/InlineFormInput/index.js +3 -3
- package/src/InlineFormInput/inline-form-input.scss +3 -3
- package/src/MoneyInput/InlineMoneyInput.js +7 -7
- package/src/MoneyInput/MoneyInput.js +7 -7
- package/src/MoneyInput/MoneyInputs.test.js +43 -43
- package/src/MoneyInput/__snapshots__/MoneyInputs.test.js.snap +81 -81
- package/src/MoneyInput/index.js +4 -4
- package/src/MoneyInput/money-input.scss +3 -3
- package/src/MoneyInput/moneyInputProps.js +12 -12
- package/src/NestedFormFieldContext.js +6 -6
- package/src/ReactSelectField/ReactSelectField.js +122 -120
- package/src/ReactSelectField/index.js +6 -6
- package/src/ReactSelectField/react-select-field.scss +5 -5
- package/src/StandardFormActions.js +27 -27
- package/src/SubmitFormButton.js +28 -28
- package/src/__Tests__/FormTestBase.js +14 -11
- package/src/__Tests__/IconInput.test.js +23 -23
- package/src/__Tests__/StandardFormActions.test.js +23 -23
- package/src/__Tests__/SubmitFormButton.test.js +23 -23
- package/src/__Tests__/__snapshots__/IconInput.test.js.snap +38 -38
- package/src/__Tests__/__snapshots__/StandardFormActions.test.js.snap +25 -25
- package/src/__Tests__/__snapshots__/SubmitFormButton.test.js.snap +18 -18
- package/src/__Tests__/index.js +2 -2
- package/src/_variables.scss +11 -11
- package/src/index.js +33 -33
- package/src/normalizers.js +42 -32
- package/src/selectors.js +3 -3
- package/src/styles.scss +7 -7
- package/src/useStandardFormInput.js +118 -118
- package/src/utils/index.js +3 -0
- package/src/utils/objectContainsNonSerializableProperty.js +15 -0
- package/src/utils/objectContainsNonSerializableProperty.test.js +49 -0
- package/src/utils/objectToFormData.js +89 -0
- package/src/utils/objectToFormData.test.js +76 -0
- package/src/utils/typeChecks.js +18 -0
- package/src/validators/index.js +2 -2
- package/src/validators/validators.js +93 -93
- package/src/validators/validators.test.js +79 -79
- package/CHANGELOG.json +0 -95
- package/CHANGELOG.md +0 -58
- package/es/FormInput/utilities.js +0 -71
- package/lib/FormInput/utilities.js +0 -86
- package/src/FormInput/utilities.js +0 -26
package/src/Form/Form.js
CHANGED
@@ -1,161 +1,139 @@
|
|
1
|
-
import React, { useState, useMemo, useContext } from 'react';
|
2
|
-
import PropTypes from 'prop-types';
|
3
|
-
import FocusError from './FocusError';
|
4
|
-
import { Formik, Form as FormikFormWrapper, useFormikContext } from 'formik';
|
5
|
-
import FormBasedPreventNavigation from './FormBasedPreventNavigation';
|
6
|
-
import ServerErrorContext from './ServerErrorContext';
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
const lowered = path.toLowerCase();
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
{
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
fd.append(formKey, obj[property].toISOString());
|
141
|
-
} else if (
|
142
|
-
typeof obj[property] === 'object' &&
|
143
|
-
!(obj[property] instanceof File) &&
|
144
|
-
!(obj[property] instanceof Blob)
|
145
|
-
) {
|
146
|
-
objectToFormData(obj[property], fd, formKey);
|
147
|
-
} else {
|
148
|
-
// if it's a string or a File object
|
149
|
-
fd.append(formKey, obj[property]);
|
150
|
-
}
|
151
|
-
}
|
152
|
-
}
|
153
|
-
|
154
|
-
return fd;
|
155
|
-
};
|
156
|
-
|
157
|
-
Form.propTypes = {
|
158
|
-
ignoreLostChanges: PropTypes.bool,
|
159
|
-
onSubmit: PropTypes.func.isRequired,
|
160
|
-
initialValues: PropTypes.object,
|
161
|
-
};
|
1
|
+
import React, { useState, useMemo, useContext } from 'react';
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
import FocusError from './FocusError';
|
4
|
+
import { Formik, Form as FormikFormWrapper, useFormikContext } from 'formik';
|
5
|
+
import FormBasedPreventNavigation from './FormBasedPreventNavigation';
|
6
|
+
import ServerErrorContext from './ServerErrorContext';
|
7
|
+
import {
|
8
|
+
objectToFormData,
|
9
|
+
objectContainsNonSerializableProperty,
|
10
|
+
} from '../utils';
|
11
|
+
|
12
|
+
export default function Form({
|
13
|
+
children,
|
14
|
+
className,
|
15
|
+
style,
|
16
|
+
ignoreLostChanges,
|
17
|
+
onSubmit,
|
18
|
+
initialValues,
|
19
|
+
...props
|
20
|
+
}) {
|
21
|
+
// formik resets all error on each blur (with our settings)
|
22
|
+
// this means that ALL errors from the server disappear when any one field is blurred
|
23
|
+
// So, we have to store server errors ourselves
|
24
|
+
// Since we only use useStandardFormInput, that means there is only one consumer
|
25
|
+
const [serverErrors, setServerErrors] = useState(null);
|
26
|
+
const serverErrorContextValue = useMemo(
|
27
|
+
() => ({
|
28
|
+
errors: serverErrors,
|
29
|
+
getError: (path) => {
|
30
|
+
const lowered = path.toLowerCase();
|
31
|
+
return serverErrors && serverErrors[lowered];
|
32
|
+
},
|
33
|
+
setError: (path, errorMessage) => {
|
34
|
+
const lowered = path.toLowerCase();
|
35
|
+
setServerErrors(
|
36
|
+
Object.assign({}, serverErrors, {
|
37
|
+
[lowered]: !errorMessage ? undefined : errorMessage,
|
38
|
+
})
|
39
|
+
);
|
40
|
+
},
|
41
|
+
}),
|
42
|
+
[serverErrors]
|
43
|
+
);
|
44
|
+
|
45
|
+
return (
|
46
|
+
<Formik
|
47
|
+
validateOnChange={false}
|
48
|
+
validateOnBlur={true}
|
49
|
+
validateOnMount={false}
|
50
|
+
initialValues={initialValues || {}}
|
51
|
+
onSubmit={handleSubmit}
|
52
|
+
{...props}>
|
53
|
+
<ServerErrorContext.Provider value={serverErrorContextValue}>
|
54
|
+
<FormikFormWrapper className={className} style={style}>
|
55
|
+
<FocusError serverErrors={serverErrorContextValue} />
|
56
|
+
<FormBasedPreventNavigation ignoreLostChanges={ignoreLostChanges} />
|
57
|
+
{typeof children === 'function' ? children(props) : children}
|
58
|
+
</FormikFormWrapper>
|
59
|
+
</ServerErrorContext.Provider>
|
60
|
+
</Formik>
|
61
|
+
);
|
62
|
+
|
63
|
+
function handleSubmit(values, formikBag) {
|
64
|
+
let formData = null;
|
65
|
+
if (objectContainsNonSerializableProperty(values)) {
|
66
|
+
formData = objectToFormData(values, {
|
67
|
+
indices: true,
|
68
|
+
dotNotation: true,
|
69
|
+
allowEmptyArrays: true,
|
70
|
+
noFileListBrackets: true,
|
71
|
+
});
|
72
|
+
}
|
73
|
+
|
74
|
+
return Promise.resolve(onSubmit(formData || values))
|
75
|
+
.then((response) => {
|
76
|
+
return response;
|
77
|
+
})
|
78
|
+
.catch((err) => {
|
79
|
+
//this is an http error
|
80
|
+
if (
|
81
|
+
err &&
|
82
|
+
err.response &&
|
83
|
+
err.response.data &&
|
84
|
+
err.response.data.validationFailures
|
85
|
+
) {
|
86
|
+
try {
|
87
|
+
const serverErrors = err.response.data.validationFailures
|
88
|
+
.map((error) => ({
|
89
|
+
// case insensitive path
|
90
|
+
path: error.propertyName.toLowerCase(),
|
91
|
+
errorMessage: error.errorMessage,
|
92
|
+
}))
|
93
|
+
.reduce((acc, value) => {
|
94
|
+
// for simplicity, just keep it to one server error at a time per path
|
95
|
+
acc[value.path] = value.errorMessage;
|
96
|
+
return acc;
|
97
|
+
}, {});
|
98
|
+
setServerErrors(serverErrors);
|
99
|
+
} catch (err) {
|
100
|
+
console.error('Failure to getErrorObject');
|
101
|
+
console.error(err);
|
102
|
+
throw err;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
throw err;
|
106
|
+
});
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
Form.DisplayFormState = DisplayFormState;
|
111
|
+
function DisplayFormState() {
|
112
|
+
const formState = useFormikContext();
|
113
|
+
const serverErrorContext = useContext(ServerErrorContext);
|
114
|
+
return (
|
115
|
+
<div style={{ margin: '1rem 0' }}>
|
116
|
+
<pre
|
117
|
+
style={{
|
118
|
+
background: '#f6f8fa',
|
119
|
+
fontSize: '.65rem',
|
120
|
+
padding: '.5rem',
|
121
|
+
}}>
|
122
|
+
{serverErrorContext && serverErrorContext.errors && (
|
123
|
+
<div>
|
124
|
+
<strong>serverErrors = </strong>
|
125
|
+
{JSON.stringify(serverErrorContext.errors, null, 2)}
|
126
|
+
</div>
|
127
|
+
)}
|
128
|
+
<strong>formState = </strong>
|
129
|
+
{JSON.stringify(formState, null, 2)}
|
130
|
+
</pre>
|
131
|
+
</div>
|
132
|
+
);
|
133
|
+
}
|
134
|
+
|
135
|
+
Form.propTypes = {
|
136
|
+
ignoreLostChanges: PropTypes.bool,
|
137
|
+
onSubmit: PropTypes.func.isRequired,
|
138
|
+
initialValues: PropTypes.object,
|
139
|
+
};
|
package/src/Form/Form.test.js
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { render } from '@testing-library/react';
|
3
|
-
import { HashRouter } from 'react-router-dom';
|
4
|
-
import Form from './Form';
|
5
|
-
|
6
|
-
describe('MoneyInput', () => {
|
7
|
-
it('renders without crashing', () => {
|
8
|
-
render(
|
9
|
-
<HashRouter>
|
10
|
-
<Form onSubmit={() => {}} />
|
11
|
-
</HashRouter>
|
12
|
-
);
|
13
|
-
});
|
14
|
-
|
15
|
-
it('has matching snapshot', () => {
|
16
|
-
const renderResult = render(
|
17
|
-
<HashRouter>
|
18
|
-
<Form onSubmit={() => {}} />
|
19
|
-
</HashRouter>
|
20
|
-
);
|
21
|
-
expect(renderResult.asFragment()).toMatchSnapshot();
|
22
|
-
});
|
23
|
-
});
|
1
|
+
import React from 'react';
|
2
|
+
import { render } from '@testing-library/react';
|
3
|
+
import { HashRouter } from 'react-router-dom';
|
4
|
+
import Form from './Form';
|
5
|
+
|
6
|
+
describe('MoneyInput', () => {
|
7
|
+
it('renders without crashing', () => {
|
8
|
+
render(
|
9
|
+
<HashRouter>
|
10
|
+
<Form onSubmit={() => {}} />
|
11
|
+
</HashRouter>
|
12
|
+
);
|
13
|
+
});
|
14
|
+
|
15
|
+
it('has matching snapshot', () => {
|
16
|
+
const renderResult = render(
|
17
|
+
<HashRouter>
|
18
|
+
<Form onSubmit={() => {}} />
|
19
|
+
</HashRouter>
|
20
|
+
);
|
21
|
+
expect(renderResult.asFragment()).toMatchSnapshot();
|
22
|
+
});
|
23
|
+
});
|
@@ -1,25 +1,25 @@
|
|
1
|
-
import React, { useEffect } from 'react';
|
2
|
-
import { Prompt } from 'react-router';
|
3
|
-
import { useFormikContext } from 'formik';
|
4
|
-
|
5
|
-
export default function FormBasedPreventNavigation({
|
6
|
-
ignoreLostChanges,
|
7
|
-
promptMessage = 'Changes you made may not be saved.',
|
8
|
-
}) {
|
9
|
-
const { dirty, isSubmitting } = useFormikContext();
|
10
|
-
const preventNavigate = !ignoreLostChanges && dirty && !isSubmitting;
|
11
|
-
useEffect(() => {
|
12
|
-
if (!preventNavigate) {
|
13
|
-
return;
|
14
|
-
}
|
15
|
-
window.addEventListener('beforeunload', beforeUnload);
|
16
|
-
return () => {
|
17
|
-
window.removeEventListener('beforeunload', beforeUnload);
|
18
|
-
};
|
19
|
-
function beforeUnload(e) {
|
20
|
-
e.preventDefault();
|
21
|
-
e.returnValue = promptMessage;
|
22
|
-
}
|
23
|
-
}, [preventNavigate, promptMessage]);
|
24
|
-
return <Prompt when={preventNavigate} message={promptMessage} />;
|
25
|
-
}
|
1
|
+
import React, { useEffect } from 'react';
|
2
|
+
import { Prompt } from 'react-router-dom';
|
3
|
+
import { useFormikContext } from 'formik';
|
4
|
+
|
5
|
+
export default function FormBasedPreventNavigation({
|
6
|
+
ignoreLostChanges,
|
7
|
+
promptMessage = 'Changes you made may not be saved.',
|
8
|
+
}) {
|
9
|
+
const { dirty, isSubmitting } = useFormikContext();
|
10
|
+
const preventNavigate = !ignoreLostChanges && dirty && !isSubmitting;
|
11
|
+
useEffect(() => {
|
12
|
+
if (!preventNavigate) {
|
13
|
+
return;
|
14
|
+
}
|
15
|
+
window.addEventListener('beforeunload', beforeUnload);
|
16
|
+
return () => {
|
17
|
+
window.removeEventListener('beforeunload', beforeUnload);
|
18
|
+
};
|
19
|
+
function beforeUnload(e) {
|
20
|
+
e.preventDefault();
|
21
|
+
e.returnValue = promptMessage;
|
22
|
+
}
|
23
|
+
}, [preventNavigate, promptMessage]);
|
24
|
+
return <Prompt when={preventNavigate} message={promptMessage} />;
|
25
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
|
3
|
-
const ServerErrorContext = React.createContext({
|
4
|
-
getError: (path) => {},
|
5
|
-
setError: (path, errorMessage) => {},
|
6
|
-
});
|
7
|
-
export default ServerErrorContext;
|
1
|
+
import React from 'react';
|
2
|
+
|
3
|
+
const ServerErrorContext = React.createContext({
|
4
|
+
getError: (path) => {},
|
5
|
+
setError: (path, errorMessage) => {},
|
6
|
+
});
|
7
|
+
export default ServerErrorContext;
|
@@ -1,9 +1,9 @@
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
-
|
3
|
-
exports[`MoneyInput has matching snapshot 1`] = `
|
4
|
-
<DocumentFragment>
|
5
|
-
<form
|
6
|
-
action="#"
|
7
|
-
/>
|
8
|
-
</DocumentFragment>
|
9
|
-
`;
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`MoneyInput has matching snapshot 1`] = `
|
4
|
+
<DocumentFragment>
|
5
|
+
<form
|
6
|
+
action="#"
|
7
|
+
/>
|
8
|
+
</DocumentFragment>
|
9
|
+
`;
|
package/src/Form/index.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import Form from './Form';
|
2
|
-
import ServerErrorContext from './ServerErrorContext';
|
3
|
-
export { Form as default, ServerErrorContext };
|
1
|
+
import Form from './Form';
|
2
|
+
import ServerErrorContext from './ServerErrorContext';
|
3
|
+
export { Form as default, ServerErrorContext };
|
package/src/FormGroup.js
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import {
|
3
|
-
FormGroup as BootstrapFormGroup,
|
4
|
-
Label,
|
5
|
-
FormFeedback,
|
6
|
-
FormText,
|
7
|
-
Alert,
|
8
|
-
} from 'reactstrap';
|
9
|
-
|
10
|
-
const FormGroup = ({
|
11
|
-
label,
|
12
|
-
id,
|
13
|
-
helpText,
|
14
|
-
className,
|
15
|
-
style,
|
16
|
-
children,
|
17
|
-
meta,
|
18
|
-
}) => {
|
19
|
-
return (
|
20
|
-
<BootstrapFormGroup className={className} style={style}>
|
21
|
-
{!!meta.warning && <Alert color="warning">{meta.warning}</Alert>}
|
22
|
-
{label && <Label htmlFor={id}>{label}</Label>}
|
23
|
-
{children}
|
24
|
-
{meta.error && <FormFeedback>{meta.error}</FormFeedback>}
|
25
|
-
{helpText && <FormText>{helpText}</FormText>}
|
26
|
-
</BootstrapFormGroup>
|
27
|
-
);
|
28
|
-
};
|
29
|
-
|
30
|
-
export default FormGroup;
|
1
|
+
import React from 'react';
|
2
|
+
import {
|
3
|
+
FormGroup as BootstrapFormGroup,
|
4
|
+
Label,
|
5
|
+
FormFeedback,
|
6
|
+
FormText,
|
7
|
+
Alert,
|
8
|
+
} from 'reactstrap';
|
9
|
+
|
10
|
+
const FormGroup = ({
|
11
|
+
label,
|
12
|
+
id,
|
13
|
+
helpText,
|
14
|
+
className,
|
15
|
+
style,
|
16
|
+
children,
|
17
|
+
meta,
|
18
|
+
}) => {
|
19
|
+
return (
|
20
|
+
<BootstrapFormGroup className={className} style={style}>
|
21
|
+
{!!meta.warning && <Alert color="warning">{meta.warning}</Alert>}
|
22
|
+
{label && <Label htmlFor={id}>{label}</Label>}
|
23
|
+
{children}
|
24
|
+
{meta.error && <FormFeedback>{meta.error}</FormFeedback>}
|
25
|
+
{helpText && <FormText>{helpText}</FormText>}
|
26
|
+
</BootstrapFormGroup>
|
27
|
+
);
|
28
|
+
};
|
29
|
+
|
30
|
+
export default FormGroup;
|
package/src/FormGroupWrapper.js
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { InputGroup } from 'reactstrap';
|
3
|
-
import FormGroup from './FormGroup';
|
4
|
-
import ErrorScrollTarget from './ErrorScrollTarget';
|
5
|
-
|
6
|
-
export default function FormGroupWrapper({
|
7
|
-
prepend,
|
8
|
-
append,
|
9
|
-
Component,
|
10
|
-
helpText,
|
11
|
-
...props
|
12
|
-
}) {
|
13
|
-
const { meta } = props;
|
14
|
-
return (
|
15
|
-
<FormGroup meta={meta} helpText={helpText} {...props}>
|
16
|
-
<ErrorScrollTarget name={props.name} />
|
17
|
-
{prepend || append ? (
|
18
|
-
<InputGroup>
|
19
|
-
{prepend}
|
20
|
-
<Component {...props} />
|
21
|
-
{append}
|
22
|
-
</InputGroup>
|
23
|
-
) : (
|
24
|
-
<Component {...props} />
|
25
|
-
)}
|
26
|
-
</FormGroup>
|
27
|
-
);
|
28
|
-
}
|
1
|
+
import React from 'react';
|
2
|
+
import { InputGroup } from 'reactstrap';
|
3
|
+
import FormGroup from './FormGroup';
|
4
|
+
import ErrorScrollTarget from './ErrorScrollTarget';
|
5
|
+
|
6
|
+
export default function FormGroupWrapper({
|
7
|
+
prepend,
|
8
|
+
append,
|
9
|
+
Component,
|
10
|
+
helpText,
|
11
|
+
...props
|
12
|
+
}) {
|
13
|
+
const { meta } = props;
|
14
|
+
return (
|
15
|
+
<FormGroup meta={meta} helpText={helpText} {...props}>
|
16
|
+
<ErrorScrollTarget name={props.name} />
|
17
|
+
{prepend || append ? (
|
18
|
+
<InputGroup>
|
19
|
+
{prepend}
|
20
|
+
<Component {...props} />
|
21
|
+
{append}
|
22
|
+
</InputGroup>
|
23
|
+
) : (
|
24
|
+
<Component {...props} />
|
25
|
+
)}
|
26
|
+
</FormGroup>
|
27
|
+
);
|
28
|
+
}
|