envoc-form 2.0.1-7 → 2.0.1
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 +7 -6
- package/es/ConfirmBaseForm/ConfirmBaseForm.js +3 -2
- package/es/ConfirmDeleteForm/ConfirmDeleteForm.js +2 -1
- package/es/DatePickerInput/DatePickerInput.js +22 -5
- package/es/FileInput/DefaultFileList.js +12 -8
- package/es/FileInput/DropzoneFileInput.js +24 -23
- package/es/FileInput/FileInput.js +31 -9
- package/es/Form/Form.js +4 -2
- package/es/FormGroupWrapper.js +2 -1
- package/es/FormInput/FormInput.js +12 -6
- 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/objectToFormData.js +10 -2
- package/lib/AddressInput/AddressInput.js +14 -8
- package/lib/ConfirmBaseForm/ConfirmBaseForm.js +4 -2
- package/lib/ConfirmDeleteForm/ConfirmDeleteForm.js +3 -1
- package/lib/DatePickerInput/DatePickerInput.js +25 -5
- package/lib/FileInput/DefaultFileList.js +20 -13
- package/lib/FileInput/DropzoneFileInput.js +25 -25
- package/lib/FileInput/FileInput.js +39 -10
- package/lib/Form/Form.js +11 -4
- package/lib/Form/FormBasedPreventNavigation.js +5 -1
- package/lib/FormGroupWrapper.js +3 -1
- package/lib/FormInput/FormInput.js +13 -6
- 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/objectToFormData.js +10 -2
- package/lib/validators/index.js +5 -1
- package/package.json +99 -93
- 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 +58 -46
- package/src/DatePickerInput/DatePickerInput.test.js +74 -74
- package/src/DatePickerInput/__snapshots__/DatePickerInput.test.js.snap +134 -134
- 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 -39
- package/src/FileInput/DropzoneFileInput.js +56 -59
- 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 -4
- package/src/Form/FocusError.js +48 -48
- package/src/Form/Form.js +139 -138
- 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 -144
- package/src/FormInput/FormInput.test.js +66 -66
- package/src/FormInput/__snapshots__/FormInput.test.js.snap +323 -316
- 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 -3
- package/src/utils/objectContainsNonSerializableProperty.js +15 -15
- package/src/utils/objectContainsNonSerializableProperty.test.js +49 -49
- package/src/utils/objectToFormData.js +89 -83
- package/src/utils/objectToFormData.test.js +76 -47
- package/src/utils/typeChecks.js +18 -18
- 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
@@ -1,12 +1,12 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { InputGroupAddon } from 'reactstrap';
|
3
|
-
|
4
|
-
const MoneyPrepend = <InputGroupAddon addonType="prepend">$</InputGroupAddon>;
|
5
|
-
const moneyInputProps = {
|
6
|
-
type: 'number',
|
7
|
-
step: '0.01',
|
8
|
-
min: '0',
|
9
|
-
prepend: MoneyPrepend,
|
10
|
-
className: 'money-input',
|
11
|
-
};
|
12
|
-
export default moneyInputProps;
|
1
|
+
import React from 'react';
|
2
|
+
import { InputGroupAddon } from 'reactstrap';
|
3
|
+
|
4
|
+
const MoneyPrepend = <InputGroupAddon addonType="prepend">$</InputGroupAddon>;
|
5
|
+
const moneyInputProps = {
|
6
|
+
type: 'number',
|
7
|
+
step: '0.01',
|
8
|
+
min: '0',
|
9
|
+
prepend: MoneyPrepend,
|
10
|
+
className: 'money-input',
|
11
|
+
};
|
12
|
+
export default moneyInputProps;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
|
3
|
-
// TODO: better name?
|
4
|
-
const NestedFormFieldContext = React.createContext();
|
5
|
-
|
6
|
-
export default NestedFormFieldContext;
|
1
|
+
import React from 'react';
|
2
|
+
|
3
|
+
// TODO: better name?
|
4
|
+
const NestedFormFieldContext = React.createContext();
|
5
|
+
|
6
|
+
export default NestedFormFieldContext;
|
@@ -1,120 +1,122 @@
|
|
1
|
-
import React, { useEffect, useRef } from 'react';
|
2
|
-
import { default as ReactSelect } from 'react-select';
|
3
|
-
|
4
|
-
export const overrideTheme = (theme) => {
|
5
|
-
return {
|
6
|
-
...theme,
|
7
|
-
borderRadius: 0,
|
8
|
-
spacing: Object.assign(
|
9
|
-
{},
|
10
|
-
{ ...theme.spacing },
|
11
|
-
{ baseUnit: 2, controlHeight: 35 }
|
12
|
-
),
|
13
|
-
};
|
14
|
-
};
|
15
|
-
|
16
|
-
const red = '#f86c6b';
|
17
|
-
const inputBorderColor = '#c2cfd6';
|
18
|
-
const inputBorderColorFocused = '#8ad4ee';
|
19
|
-
const inputBoxShadowFocused = '0 0 0 0.2rem rgba(32, 168, 216, 0.25)';
|
20
|
-
|
21
|
-
export const customStyles = {
|
22
|
-
control: (provided, { isFocused, selectProps }) => {
|
23
|
-
return {
|
24
|
-
...provided,
|
25
|
-
paddingLeft: '7px',
|
26
|
-
'&:hover': {
|
27
|
-
borderColor: isFocused ? inputBorderColorFocused : inputBorderColor,
|
28
|
-
},
|
29
|
-
borderColor: selectProps.hasErrors
|
30
|
-
? red
|
31
|
-
: isFocused
|
32
|
-
? inputBorderColorFocused
|
33
|
-
: inputBorderColor,
|
34
|
-
boxShadow: isFocused ? inputBoxShadowFocused : '',
|
35
|
-
};
|
36
|
-
},
|
37
|
-
menu: (provided) => ({ ...provided, zIndex: 3 }),
|
38
|
-
};
|
39
|
-
|
40
|
-
// internal to forms use only
|
41
|
-
export default function ReactSelectInput({
|
42
|
-
className,
|
43
|
-
meta,
|
44
|
-
disabled,
|
45
|
-
onSelected,
|
46
|
-
onChange,
|
47
|
-
onBlur,
|
48
|
-
value,
|
49
|
-
options,
|
50
|
-
defaultValue,
|
51
|
-
defaultIndex,
|
52
|
-
...props
|
53
|
-
}) {
|
54
|
-
const selectedItems = getSelectedItems();
|
55
|
-
const onSelectedRef = useRef(onSelected);
|
56
|
-
onSelectedRef.current = onSelected;
|
57
|
-
|
58
|
-
useEffect(() => {
|
59
|
-
onSelectedRef.current && onSelectedRef.current(selectedItems);
|
60
|
-
}, [selectedItems]);
|
61
|
-
|
62
|
-
return (
|
63
|
-
<ReactSelect
|
64
|
-
{...props}
|
65
|
-
options={options}
|
66
|
-
isDisabled={disabled}
|
67
|
-
hasErrors={meta.error}
|
68
|
-
getOptionLabel={(option) => option.label}
|
69
|
-
getOptionValue={getOptionValue}
|
70
|
-
value={selectedItems}
|
71
|
-
onChange={handleChange}
|
72
|
-
className="react-select-input"
|
73
|
-
theme={overrideTheme}
|
74
|
-
styles={customStyles}
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
return option
|
83
|
-
}
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
return value
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
onChange(
|
116
|
-
} else {
|
117
|
-
onChange(e.value);
|
118
|
-
}
|
119
|
-
|
120
|
-
}
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
2
|
+
import { default as ReactSelect } from 'react-select';
|
3
|
+
|
4
|
+
export const overrideTheme = (theme) => {
|
5
|
+
return {
|
6
|
+
...theme,
|
7
|
+
borderRadius: 0,
|
8
|
+
spacing: Object.assign(
|
9
|
+
{},
|
10
|
+
{ ...theme.spacing },
|
11
|
+
{ baseUnit: 2, controlHeight: 35 }
|
12
|
+
),
|
13
|
+
};
|
14
|
+
};
|
15
|
+
|
16
|
+
const red = '#f86c6b';
|
17
|
+
const inputBorderColor = '#c2cfd6';
|
18
|
+
const inputBorderColorFocused = '#8ad4ee';
|
19
|
+
const inputBoxShadowFocused = '0 0 0 0.2rem rgba(32, 168, 216, 0.25)';
|
20
|
+
|
21
|
+
export const customStyles = {
|
22
|
+
control: (provided, { isFocused, selectProps }) => {
|
23
|
+
return {
|
24
|
+
...provided,
|
25
|
+
paddingLeft: '7px',
|
26
|
+
'&:hover': {
|
27
|
+
borderColor: isFocused ? inputBorderColorFocused : inputBorderColor,
|
28
|
+
},
|
29
|
+
borderColor: selectProps.hasErrors
|
30
|
+
? red
|
31
|
+
: isFocused
|
32
|
+
? inputBorderColorFocused
|
33
|
+
: inputBorderColor,
|
34
|
+
boxShadow: isFocused ? inputBoxShadowFocused : '',
|
35
|
+
};
|
36
|
+
},
|
37
|
+
menu: (provided) => ({ ...provided, zIndex: 3 }),
|
38
|
+
};
|
39
|
+
|
40
|
+
// internal to forms use only
|
41
|
+
export default function ReactSelectInput({
|
42
|
+
className,
|
43
|
+
meta,
|
44
|
+
disabled,
|
45
|
+
onSelected,
|
46
|
+
onChange,
|
47
|
+
onBlur,
|
48
|
+
value,
|
49
|
+
options,
|
50
|
+
defaultValue,
|
51
|
+
defaultIndex,
|
52
|
+
...props
|
53
|
+
}) {
|
54
|
+
const selectedItems = getSelectedItems();
|
55
|
+
const onSelectedRef = useRef(onSelected);
|
56
|
+
onSelectedRef.current = onSelected;
|
57
|
+
|
58
|
+
useEffect(() => {
|
59
|
+
onSelectedRef.current && onSelectedRef.current(selectedItems);
|
60
|
+
}, [selectedItems]);
|
61
|
+
|
62
|
+
return (
|
63
|
+
<ReactSelect
|
64
|
+
{...props}
|
65
|
+
options={options}
|
66
|
+
isDisabled={disabled}
|
67
|
+
hasErrors={meta.error}
|
68
|
+
getOptionLabel={(option) => option.label}
|
69
|
+
getOptionValue={getOptionValue}
|
70
|
+
value={selectedItems}
|
71
|
+
onChange={handleChange}
|
72
|
+
className="react-select-input"
|
73
|
+
theme={overrideTheme}
|
74
|
+
styles={customStyles}
|
75
|
+
menuPortalTarget={document.body}
|
76
|
+
menuPlacement="auto"
|
77
|
+
/>
|
78
|
+
);
|
79
|
+
|
80
|
+
function getOptionValue(option) {
|
81
|
+
if (typeof props.getOptionValue === 'function') {
|
82
|
+
return props.getOptionValue(option);
|
83
|
+
} else {
|
84
|
+
return option.value;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
function getSelectedItems() {
|
89
|
+
if (defaultValue !== undefined && value === '') {
|
90
|
+
value = defaultValue;
|
91
|
+
onChange(defaultValue);
|
92
|
+
}
|
93
|
+
if (defaultIndex !== undefined && value === '') {
|
94
|
+
const item = options[defaultIndex];
|
95
|
+
onChange(getOptionValue(item));
|
96
|
+
return item;
|
97
|
+
}
|
98
|
+
|
99
|
+
const valueIsArray = Array.isArray(value);
|
100
|
+
const matches = options.filter((x) => {
|
101
|
+
if (valueIsArray) {
|
102
|
+
return value.includes(getOptionValue(x));
|
103
|
+
} else {
|
104
|
+
return value === getOptionValue(x);
|
105
|
+
}
|
106
|
+
});
|
107
|
+
if (matches.length < 1) {
|
108
|
+
return null;
|
109
|
+
}
|
110
|
+
return matches;
|
111
|
+
}
|
112
|
+
|
113
|
+
function handleChange(e) {
|
114
|
+
if (e == null) {
|
115
|
+
onChange(null);
|
116
|
+
} else if (Array.isArray(e)) {
|
117
|
+
onChange(e.map((x) => x.value));
|
118
|
+
} else {
|
119
|
+
onChange(e.value);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import ReactSelectField, {
|
2
|
-
overrideTheme,
|
3
|
-
customStyles,
|
4
|
-
} from './ReactSelectField';
|
5
|
-
|
6
|
-
export { ReactSelectField as default, overrideTheme, customStyles };
|
1
|
+
import ReactSelectField, {
|
2
|
+
overrideTheme,
|
3
|
+
customStyles,
|
4
|
+
} from './ReactSelectField';
|
5
|
+
|
6
|
+
export { ReactSelectField as default, overrideTheme, customStyles };
|
@@ -1,5 +1,5 @@
|
|
1
|
-
@import '../variables';
|
2
|
-
|
3
|
-
div.react-select-input.has-error {
|
4
|
-
border-color: $red;
|
5
|
-
}
|
1
|
+
@import '../variables';
|
2
|
+
|
3
|
+
div.react-select-input.has-error {
|
4
|
+
border-color: $red;
|
5
|
+
}
|
@@ -1,27 +1,27 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { Button } from 'reactstrap';
|
3
|
-
import { useFormikContext } from 'formik';
|
4
|
-
import SubmitFormButton from './SubmitFormButton';
|
5
|
-
|
6
|
-
export default function StandardFormActions({
|
7
|
-
allowPristineSubmit,
|
8
|
-
handleCancel,
|
9
|
-
}) {
|
10
|
-
const { isSubmitting } = useFormikContext();
|
11
|
-
return (
|
12
|
-
<>
|
13
|
-
<SubmitFormButton allowPristineSubmit={allowPristineSubmit} />
|
14
|
-
|
15
|
-
<Button
|
16
|
-
type="button"
|
17
|
-
color="link"
|
18
|
-
disabled={isSubmitting}
|
19
|
-
onClick={handleCancel || goBack}>
|
20
|
-
Cancel
|
21
|
-
</Button>
|
22
|
-
</>
|
23
|
-
);
|
24
|
-
function goBack() {
|
25
|
-
window.history.back();
|
26
|
-
}
|
27
|
-
}
|
1
|
+
import React from 'react';
|
2
|
+
import { Button } from 'reactstrap';
|
3
|
+
import { useFormikContext } from 'formik';
|
4
|
+
import SubmitFormButton from './SubmitFormButton';
|
5
|
+
|
6
|
+
export default function StandardFormActions({
|
7
|
+
allowPristineSubmit,
|
8
|
+
handleCancel,
|
9
|
+
}) {
|
10
|
+
const { isSubmitting } = useFormikContext();
|
11
|
+
return (
|
12
|
+
<>
|
13
|
+
<SubmitFormButton allowPristineSubmit={allowPristineSubmit} />
|
14
|
+
|
15
|
+
<Button
|
16
|
+
type="button"
|
17
|
+
color="link"
|
18
|
+
disabled={isSubmitting}
|
19
|
+
onClick={handleCancel || goBack}>
|
20
|
+
Cancel
|
21
|
+
</Button>
|
22
|
+
</>
|
23
|
+
);
|
24
|
+
function goBack() {
|
25
|
+
window.history.back();
|
26
|
+
}
|
27
|
+
}
|
package/src/SubmitFormButton.js
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { Button } from 'reactstrap';
|
3
|
-
import { useFormikContext } from 'formik';
|
4
|
-
|
5
|
-
export default function SubmitFormButton({
|
6
|
-
allowPristineSubmit,
|
7
|
-
children,
|
8
|
-
...props
|
9
|
-
}) {
|
10
|
-
const { isSubmitting, dirty } = useFormikContext();
|
11
|
-
const preventSubmit = (!dirty && !allowPristineSubmit) || isSubmitting;
|
12
|
-
return (
|
13
|
-
<Button
|
14
|
-
type="submit"
|
15
|
-
color="primary"
|
16
|
-
disabled={preventSubmit}
|
17
|
-
title={
|
18
|
-
isSubmitting
|
19
|
-
? 'Loading, please wait...'
|
20
|
-
: preventSubmit
|
21
|
-
? "You haven't made any changes"
|
22
|
-
: ''
|
23
|
-
}
|
24
|
-
{...props}>
|
25
|
-
{children || 'Submit'}
|
26
|
-
</Button>
|
27
|
-
);
|
28
|
-
}
|
1
|
+
import React from 'react';
|
2
|
+
import { Button } from 'reactstrap';
|
3
|
+
import { useFormikContext } from 'formik';
|
4
|
+
|
5
|
+
export default function SubmitFormButton({
|
6
|
+
allowPristineSubmit,
|
7
|
+
children,
|
8
|
+
...props
|
9
|
+
}) {
|
10
|
+
const { isSubmitting, dirty } = useFormikContext();
|
11
|
+
const preventSubmit = (!dirty && !allowPristineSubmit) || isSubmitting;
|
12
|
+
return (
|
13
|
+
<Button
|
14
|
+
type="submit"
|
15
|
+
color="primary"
|
16
|
+
disabled={preventSubmit}
|
17
|
+
title={
|
18
|
+
isSubmitting
|
19
|
+
? 'Loading, please wait...'
|
20
|
+
: preventSubmit
|
21
|
+
? "You haven't made any changes"
|
22
|
+
: ''
|
23
|
+
}
|
24
|
+
{...props}>
|
25
|
+
{children || 'Submit'}
|
26
|
+
</Button>
|
27
|
+
);
|
28
|
+
}
|
@@ -1,11 +1,14 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
2
|
+
import React from 'react';
|
3
|
+
import { HashRouter } from 'react-router-dom';
|
4
|
+
import Form from '../Form';
|
5
|
+
|
6
|
+
export default function FormTestBase({ children, initialValues }) {
|
7
|
+
return (
|
8
|
+
<HashRouter>
|
9
|
+
<Form onSubmit={() => {}} initialValues={initialValues}>
|
10
|
+
{children}
|
11
|
+
</Form>
|
12
|
+
</HashRouter>
|
13
|
+
);
|
14
|
+
}
|
@@ -1,23 +1,23 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { render } from '@testing-library/react';
|
3
|
-
import FormTestBase from './FormTestBase';
|
4
|
-
import IconInput from '../IconInput';
|
5
|
-
|
6
|
-
describe('IconInput', () => {
|
7
|
-
it('renders without crashing', () => {
|
8
|
-
render(
|
9
|
-
<FormTestBase>
|
10
|
-
<IconInput name="test" icon="fa fa-user" helpText="help text" />
|
11
|
-
</FormTestBase>
|
12
|
-
);
|
13
|
-
});
|
14
|
-
|
15
|
-
it('has matching snapshot', () => {
|
16
|
-
const renderResult = render(
|
17
|
-
<FormTestBase>
|
18
|
-
<IconInput name="test" icon="fa fa-user" helpText="help text" />
|
19
|
-
</FormTestBase>
|
20
|
-
);
|
21
|
-
expect(renderResult.asFragment()).toMatchSnapshot();
|
22
|
-
});
|
23
|
-
});
|
1
|
+
import React from 'react';
|
2
|
+
import { render } from '@testing-library/react';
|
3
|
+
import FormTestBase from './FormTestBase';
|
4
|
+
import IconInput from '../IconInput';
|
5
|
+
|
6
|
+
describe('IconInput', () => {
|
7
|
+
it('renders without crashing', () => {
|
8
|
+
render(
|
9
|
+
<FormTestBase>
|
10
|
+
<IconInput name="test" icon="fa fa-user" helpText="help text" />
|
11
|
+
</FormTestBase>
|
12
|
+
);
|
13
|
+
});
|
14
|
+
|
15
|
+
it('has matching snapshot', () => {
|
16
|
+
const renderResult = render(
|
17
|
+
<FormTestBase>
|
18
|
+
<IconInput name="test" icon="fa fa-user" helpText="help text" />
|
19
|
+
</FormTestBase>
|
20
|
+
);
|
21
|
+
expect(renderResult.asFragment()).toMatchSnapshot();
|
22
|
+
});
|
23
|
+
});
|
@@ -1,23 +1,23 @@
|
|
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(
|
9
|
-
<FormTestBase>
|
10
|
-
<StandardFormActions />
|
11
|
-
</FormTestBase>
|
12
|
-
);
|
13
|
-
});
|
14
|
-
|
15
|
-
it('has matching snapshot', () => {
|
16
|
-
const renderResult = render(
|
17
|
-
<FormTestBase>
|
18
|
-
<StandardFormActions />
|
19
|
-
</FormTestBase>
|
20
|
-
);
|
21
|
-
expect(renderResult.asFragment()).toMatchSnapshot();
|
22
|
-
});
|
23
|
-
});
|
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(
|
9
|
+
<FormTestBase>
|
10
|
+
<StandardFormActions />
|
11
|
+
</FormTestBase>
|
12
|
+
);
|
13
|
+
});
|
14
|
+
|
15
|
+
it('has matching snapshot', () => {
|
16
|
+
const renderResult = render(
|
17
|
+
<FormTestBase>
|
18
|
+
<StandardFormActions />
|
19
|
+
</FormTestBase>
|
20
|
+
);
|
21
|
+
expect(renderResult.asFragment()).toMatchSnapshot();
|
22
|
+
});
|
23
|
+
});
|
@@ -1,23 +1,23 @@
|
|
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(
|
9
|
-
<FormTestBase>
|
10
|
-
<SubmitFormButton />
|
11
|
-
</FormTestBase>
|
12
|
-
);
|
13
|
-
});
|
14
|
-
|
15
|
-
it('has matching snapshot', () => {
|
16
|
-
const renderResult = render(
|
17
|
-
<FormTestBase>
|
18
|
-
<SubmitFormButton />
|
19
|
-
</FormTestBase>
|
20
|
-
);
|
21
|
-
expect(renderResult.asFragment()).toMatchSnapshot();
|
22
|
-
});
|
23
|
-
});
|
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(
|
9
|
+
<FormTestBase>
|
10
|
+
<SubmitFormButton />
|
11
|
+
</FormTestBase>
|
12
|
+
);
|
13
|
+
});
|
14
|
+
|
15
|
+
it('has matching snapshot', () => {
|
16
|
+
const renderResult = render(
|
17
|
+
<FormTestBase>
|
18
|
+
<SubmitFormButton />
|
19
|
+
</FormTestBase>
|
20
|
+
);
|
21
|
+
expect(renderResult.asFragment()).toMatchSnapshot();
|
22
|
+
});
|
23
|
+
});
|
@@ -1,38 +1,38 @@
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
-
|
3
|
-
exports[`IconInput has matching snapshot 1`] = `
|
4
|
-
<DocumentFragment>
|
5
|
-
<form
|
6
|
-
action="#"
|
7
|
-
>
|
8
|
-
<div
|
9
|
-
class="input-group"
|
10
|
-
>
|
11
|
-
<div
|
12
|
-
class="input-group-prepend"
|
13
|
-
>
|
14
|
-
<span
|
15
|
-
class="input-group-text"
|
16
|
-
>
|
17
|
-
<i
|
18
|
-
class="fa fa-user"
|
19
|
-
/>
|
20
|
-
</span>
|
21
|
-
</div>
|
22
|
-
<input
|
23
|
-
aria-invalid="false"
|
24
|
-
class="form-control"
|
25
|
-
id="test"
|
26
|
-
name="test"
|
27
|
-
type="text"
|
28
|
-
value=""
|
29
|
-
/>
|
30
|
-
<div
|
31
|
-
class="invalid-feedback"
|
32
|
-
>
|
33
|
-
help text
|
34
|
-
</div>
|
35
|
-
</div>
|
36
|
-
</form>
|
37
|
-
</DocumentFragment>
|
38
|
-
`;
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`IconInput has matching snapshot 1`] = `
|
4
|
+
<DocumentFragment>
|
5
|
+
<form
|
6
|
+
action="#"
|
7
|
+
>
|
8
|
+
<div
|
9
|
+
class="input-group"
|
10
|
+
>
|
11
|
+
<div
|
12
|
+
class="input-group-prepend"
|
13
|
+
>
|
14
|
+
<span
|
15
|
+
class="input-group-text"
|
16
|
+
>
|
17
|
+
<i
|
18
|
+
class="fa fa-user"
|
19
|
+
/>
|
20
|
+
</span>
|
21
|
+
</div>
|
22
|
+
<input
|
23
|
+
aria-invalid="false"
|
24
|
+
class="form-control"
|
25
|
+
id="test"
|
26
|
+
name="test"
|
27
|
+
type="text"
|
28
|
+
value=""
|
29
|
+
/>
|
30
|
+
<div
|
31
|
+
class="invalid-feedback"
|
32
|
+
>
|
33
|
+
help text
|
34
|
+
</div>
|
35
|
+
</div>
|
36
|
+
</form>
|
37
|
+
</DocumentFragment>
|
38
|
+
`;
|