@itcase/forms 1.1.27 → 1.1.28
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/dist/itcase-forms.cjs.js +48 -48
- package/dist/itcase-forms.esm.js +143 -143
- package/package.json +1 -1
package/dist/itcase-forms.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var libphonenumberJs = require('libphonenumber-js');
|
|
4
|
-
var React
|
|
4
|
+
var React = require('react');
|
|
5
5
|
var finalForm = require('final-form');
|
|
6
6
|
var reactFinalForm = require('react-final-form');
|
|
7
7
|
var clsx = require('clsx');
|
|
@@ -40,7 +40,7 @@ var createDecorator = require('final-form-focus');
|
|
|
40
40
|
|
|
41
41
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
42
42
|
|
|
43
|
-
var React__default = /*#__PURE__*/_interopDefault(React
|
|
43
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
44
44
|
var clsx__default = /*#__PURE__*/_interopDefault(clsx);
|
|
45
45
|
var camelCase__default = /*#__PURE__*/_interopDefault(camelCase);
|
|
46
46
|
var snakeCase__default = /*#__PURE__*/_interopDefault(snakeCase);
|
|
@@ -124,7 +124,7 @@ const makeValidate = schema => {
|
|
|
124
124
|
};
|
|
125
125
|
};
|
|
126
126
|
function useYupValidationSchema(schema, language) {
|
|
127
|
-
const validate = React
|
|
127
|
+
const validate = React.useMemo(() => schema && makeValidate(schema), [schema, language]);
|
|
128
128
|
return validate;
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -143,7 +143,7 @@ function useFieldValidationState(props) {
|
|
|
143
143
|
const successKey = 'success';
|
|
144
144
|
|
|
145
145
|
// Determines if the field is in an error state based on various conditions.
|
|
146
|
-
const isErrorState = React
|
|
146
|
+
const isErrorState = React.useMemo(() => {
|
|
147
147
|
if (fieldProps.showErrorsOnSubmit) {
|
|
148
148
|
return Boolean(meta.submitFailed && meta.touched && (meta.error || submitError));
|
|
149
149
|
} else {
|
|
@@ -152,12 +152,12 @@ function useFieldValidationState(props) {
|
|
|
152
152
|
}, [fieldProps.showErrorsOnSubmit, meta.submitFailed, meta.touched, meta.error, submitError]);
|
|
153
153
|
|
|
154
154
|
// Determines if the field's input state is valid
|
|
155
|
-
const isValidState = React
|
|
155
|
+
const isValidState = React.useMemo(() => {
|
|
156
156
|
const hasValue = Array.isArray(input?.value) ? input?.value.length : input?.value;
|
|
157
157
|
const isModifiedAfterSubmit = meta.modifiedSinceLastSubmit && !meta.error && submitError;
|
|
158
158
|
return Boolean(hasValue && (meta.valid || isModifiedAfterSubmit));
|
|
159
159
|
}, [input?.value, meta.valid, meta.error, submitError, meta.modifiedSinceLastSubmit]);
|
|
160
|
-
const errorMessage = React
|
|
160
|
+
const errorMessage = React.useMemo(() => {
|
|
161
161
|
// If final-form field has error in "meta" render-property.
|
|
162
162
|
// If field not modified after last form submit - use submit error
|
|
163
163
|
const error = meta.error || submitError || false;
|
|
@@ -195,7 +195,7 @@ function useValidationAppearanceInputProps(props) {
|
|
|
195
195
|
} = props;
|
|
196
196
|
|
|
197
197
|
// TODO: need to add props that can change during errors in this field
|
|
198
|
-
const validationAppearanceInputProps = React
|
|
198
|
+
const validationAppearanceInputProps = React.useMemo(() => {
|
|
199
199
|
// const resultAppearanceProps = {
|
|
200
200
|
// messageTextColor: props.errorMessageTextColor,
|
|
201
201
|
// messageTextSize: props.errorMessageTextSize,
|
|
@@ -314,8 +314,8 @@ function FieldWrapperBase(props) {
|
|
|
314
314
|
isValidState,
|
|
315
315
|
children
|
|
316
316
|
} = props;
|
|
317
|
-
const formFieldClass = React
|
|
318
|
-
const fieldClass = React
|
|
317
|
+
const formFieldClass = React.useMemo(() => clsx__default.default(className, isValidState && 'form__item_state_success', isRequired && 'form__item_state_required', isDisabled && 'form__item_state_disabled', metaActive && 'form__item_state_focus', inputValue && 'form__item_state_filled', isErrorState && `form__item_state_${errorKey}`), [className, isErrorState, isValidState, isRequired, metaActive, inputValue, isDisabled, metaError]);
|
|
318
|
+
const fieldClass = React.useMemo(() => clsx__default.default(fieldClassName, isValidState && `${fieldClassName}_state_success`, metaActive && `${fieldClassName}_state_focus`, inputValue && `${fieldClassName}_state_filled`, isDisabled && `${fieldClassName}_state_disabled`, isErrorState && `${fieldClassName}_state_${errorKey}`), [fieldClassName, isErrorState, isValidState, metaActive, inputValue, isDisabled, metaError]);
|
|
319
319
|
const sizeClass = useDeviceTargetClass.useDeviceTargetClass(props, {
|
|
320
320
|
prefix: 'form-field_size_',
|
|
321
321
|
propsKey: 'size'
|
|
@@ -413,7 +413,7 @@ function FieldWrapper(props) {
|
|
|
413
413
|
change
|
|
414
414
|
} = reactFinalForm.useForm(); // , mutators
|
|
415
415
|
|
|
416
|
-
React
|
|
416
|
+
React.useEffect(() => {
|
|
417
417
|
return () => {
|
|
418
418
|
change(inputName, undefined);
|
|
419
419
|
};
|
|
@@ -465,10 +465,10 @@ const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function File
|
|
|
465
465
|
const {
|
|
466
466
|
change
|
|
467
467
|
} = reactFinalForm.useForm();
|
|
468
|
-
const [fileError, setFileError] = React
|
|
469
|
-
const [fileIsLoading, setFileIsLoading] = React
|
|
470
|
-
const filesList = React
|
|
471
|
-
const changeFormState = React
|
|
468
|
+
const [fileError, setFileError] = React.useState('');
|
|
469
|
+
const [fileIsLoading, setFileIsLoading] = React.useState(false);
|
|
470
|
+
const filesList = React.useMemo(() => inputValue ? castArray__default.default(inputValue) : [], [inputValue]);
|
|
471
|
+
const changeFormState = React.useCallback(newFiles => {
|
|
472
472
|
// If max files in dropzone is 1 - return file as it self, else as array of files
|
|
473
473
|
// ps: for old projects compatibility
|
|
474
474
|
const toSave = dropzoneProps.maxFiles == 1 ? newFiles[0] : newFiles;
|
|
@@ -480,7 +480,7 @@ const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function File
|
|
|
480
480
|
[dropzoneProps, change]);
|
|
481
481
|
|
|
482
482
|
//
|
|
483
|
-
const convertFiledValueAndSaveAsFiles = React
|
|
483
|
+
const convertFiledValueAndSaveAsFiles = React.useCallback(async currentFilesList => {
|
|
484
484
|
setFileIsLoading(true);
|
|
485
485
|
const newFiles = [];
|
|
486
486
|
for (const fileItem of currentFilesList) {
|
|
@@ -498,7 +498,7 @@ const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function File
|
|
|
498
498
|
}, [isPreviews, changeFormState]);
|
|
499
499
|
|
|
500
500
|
// Delete file from dropzone
|
|
501
|
-
const removeFile = React
|
|
501
|
+
const removeFile = React.useCallback((event, index) => {
|
|
502
502
|
event.stopPropagation();
|
|
503
503
|
event.preventDefault();
|
|
504
504
|
const newFiles = [...filesList];
|
|
@@ -573,7 +573,7 @@ const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function File
|
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
575
|
});
|
|
576
|
-
React
|
|
576
|
+
React.useEffect(() => {
|
|
577
577
|
const currentFilesList = castArray__default.default(inputValue);
|
|
578
578
|
const isNeedToConvert = currentFilesList.some(fileItem => typeof fileItem === 'string');
|
|
579
579
|
if (isNeedToConvert) {
|
|
@@ -1073,7 +1073,7 @@ const FormFieldCheckbox = /*#__PURE__*/React__default.default.memo(function Form
|
|
|
1073
1073
|
* custom React Hook function.
|
|
1074
1074
|
*/
|
|
1075
1075
|
|
|
1076
|
-
const onChangeField = React
|
|
1076
|
+
const onChangeField = React.useCallback(event => {
|
|
1077
1077
|
input.onChange(event);
|
|
1078
1078
|
if (onChange) {
|
|
1079
1079
|
onChange(event.target.checked, input.name);
|
|
@@ -1149,12 +1149,12 @@ function FormFieldChips(props) {
|
|
|
1149
1149
|
} = reactFinalForm.useForm();
|
|
1150
1150
|
|
|
1151
1151
|
// Callback for value changes
|
|
1152
|
-
const onChangeSomeInput = React
|
|
1152
|
+
const onChangeSomeInput = React.useCallback((inputValue, newOptionValue) => {
|
|
1153
1153
|
const updatedValues = inputValue.includes(newOptionValue) ? inputValue.filter(selectedValue => selectedValue !== newOptionValue) : [...inputValue, newOptionValue];
|
|
1154
1154
|
change(name, updatedValues);
|
|
1155
1155
|
onChange && onChange(updatedValues);
|
|
1156
1156
|
}, [change, name, onChange]);
|
|
1157
|
-
React
|
|
1157
|
+
React.useEffect(() => {
|
|
1158
1158
|
initialValue && change(name, initialValue);
|
|
1159
1159
|
// update the form value only when the initialValue changes, so use disable eslint to ignore the warning
|
|
1160
1160
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -1180,7 +1180,7 @@ function FormFieldChips(props) {
|
|
|
1180
1180
|
inputProps: inputProps,
|
|
1181
1181
|
validationStateKey: isErrorState ? errorKey : 'success'
|
|
1182
1182
|
});
|
|
1183
|
-
const activeOptionsList = React
|
|
1183
|
+
const activeOptionsList = React.useMemo(() => {
|
|
1184
1184
|
const emptyOptionsList = [{
|
|
1185
1185
|
label: null,
|
|
1186
1186
|
value: null
|
|
@@ -1251,7 +1251,7 @@ const FormFieldChoice = /*#__PURE__*/React__default.default.memo(function FormFi
|
|
|
1251
1251
|
const {
|
|
1252
1252
|
change
|
|
1253
1253
|
} = reactFinalForm.useForm();
|
|
1254
|
-
const setActiveSegment = React
|
|
1254
|
+
const setActiveSegment = React.useCallback((option, isChecked) => {
|
|
1255
1255
|
change(name, isChecked && option.value);
|
|
1256
1256
|
if (onChange) {
|
|
1257
1257
|
onChange(option.value, name, isChecked);
|
|
@@ -1270,7 +1270,7 @@ const FormFieldChoice = /*#__PURE__*/React__default.default.memo(function FormFi
|
|
|
1270
1270
|
* React Hooks must be called in a React function component or a
|
|
1271
1271
|
* custom React Hook function.
|
|
1272
1272
|
*/
|
|
1273
|
-
const activeOption = React
|
|
1273
|
+
const activeOption = React.useMemo(() => {
|
|
1274
1274
|
const emptyOption = {
|
|
1275
1275
|
value: null,
|
|
1276
1276
|
label: null
|
|
@@ -1503,7 +1503,7 @@ function FormFieldDatePicker(props) {
|
|
|
1503
1503
|
* custom React Hook function.
|
|
1504
1504
|
*/
|
|
1505
1505
|
|
|
1506
|
-
const onChangeField = React
|
|
1506
|
+
const onChangeField = React.useCallback((startDate, endDate) => {
|
|
1507
1507
|
if (!datePickerProps.selectsRange) {
|
|
1508
1508
|
// When we need to save single date, value is date
|
|
1509
1509
|
// TODO: make object with one date? need to check all forms with FormFieldDatePicker
|
|
@@ -1605,7 +1605,7 @@ const FormFieldInput = /*#__PURE__*/React__default.default.memo(function FormFie
|
|
|
1605
1605
|
* custom React Hook function.
|
|
1606
1606
|
*/
|
|
1607
1607
|
|
|
1608
|
-
const onChangeField = React
|
|
1608
|
+
const onChangeField = React.useCallback(event => {
|
|
1609
1609
|
input.onChange(event);
|
|
1610
1610
|
if (onChange) {
|
|
1611
1611
|
onChange(event.target.value, input.name);
|
|
@@ -1689,11 +1689,11 @@ const FormFieldPassword = /*#__PURE__*/React__default.default.memo(function Form
|
|
|
1689
1689
|
isRequired,
|
|
1690
1690
|
onChange
|
|
1691
1691
|
} = props;
|
|
1692
|
-
const [isRevealed, setIsRevealed] = React
|
|
1693
|
-
const inputType = React
|
|
1692
|
+
const [isRevealed, setIsRevealed] = React.useState(false);
|
|
1693
|
+
const inputType = React.useMemo(() => {
|
|
1694
1694
|
return isRevealed ? 'text' : 'password';
|
|
1695
1695
|
}, [isRevealed]);
|
|
1696
|
-
const onClickIconReveal = React
|
|
1696
|
+
const onClickIconReveal = React.useCallback(event => {
|
|
1697
1697
|
event.preventDefault();
|
|
1698
1698
|
setIsRevealed(prev => !prev);
|
|
1699
1699
|
}, []);
|
|
@@ -1712,7 +1712,7 @@ const FormFieldPassword = /*#__PURE__*/React__default.default.memo(function Form
|
|
|
1712
1712
|
* custom React Hook function.
|
|
1713
1713
|
*/
|
|
1714
1714
|
|
|
1715
|
-
const onChangeField = React
|
|
1715
|
+
const onChangeField = React.useCallback(event => {
|
|
1716
1716
|
input.onChange(event);
|
|
1717
1717
|
if (onChange) {
|
|
1718
1718
|
onChange(event.target.value, input.name);
|
|
@@ -1787,7 +1787,7 @@ function FormFieldSegmented(props) {
|
|
|
1787
1787
|
const {
|
|
1788
1788
|
change
|
|
1789
1789
|
} = reactFinalForm.useForm();
|
|
1790
|
-
const setActiveSegment = React
|
|
1790
|
+
const setActiveSegment = React.useCallback(option => {
|
|
1791
1791
|
change(name, option.value);
|
|
1792
1792
|
}, [change]);
|
|
1793
1793
|
return /*#__PURE__*/React__default.default.createElement(reactFinalForm.Field, {
|
|
@@ -1803,7 +1803,7 @@ function FormFieldSegmented(props) {
|
|
|
1803
1803
|
* custom React Hook function.
|
|
1804
1804
|
*/
|
|
1805
1805
|
|
|
1806
|
-
const activeOption = React
|
|
1806
|
+
const activeOption = React.useMemo(() => {
|
|
1807
1807
|
const emptyOption = {
|
|
1808
1808
|
label: null,
|
|
1809
1809
|
value: null
|
|
@@ -1901,8 +1901,8 @@ const FormFieldSelect = /*#__PURE__*/React__default.default.memo(function FormFi
|
|
|
1901
1901
|
* React Hooks must be called in a React function component or a
|
|
1902
1902
|
* custom React Hook function.
|
|
1903
1903
|
*/
|
|
1904
|
-
const [selectedOptions, setSelectedOptions] = React
|
|
1905
|
-
const defaultValue = React
|
|
1904
|
+
const [selectedOptions, setSelectedOptions] = React.useState(null);
|
|
1905
|
+
const defaultValue = React.useMemo(() => {
|
|
1906
1906
|
const optionsValues = getDefaultValue(options, input.value);
|
|
1907
1907
|
if (!optionsValues.length && input.value?.length) {
|
|
1908
1908
|
optionsValues.push({
|
|
@@ -1912,18 +1912,18 @@ const FormFieldSelect = /*#__PURE__*/React__default.default.memo(function FormFi
|
|
|
1912
1912
|
}
|
|
1913
1913
|
return optionsValues;
|
|
1914
1914
|
}, [input.value]);
|
|
1915
|
-
const onChangeField = React
|
|
1915
|
+
const onChangeField = React.useCallback(value => {
|
|
1916
1916
|
input.onChange(value);
|
|
1917
1917
|
if (onChange) {
|
|
1918
1918
|
onChange(value, input.name);
|
|
1919
1919
|
}
|
|
1920
1920
|
}, [onChange, input.onChange]);
|
|
1921
|
-
const onChangeValue = React
|
|
1921
|
+
const onChangeValue = React.useCallback((option, actionMeta) => {
|
|
1922
1922
|
const value = Array.isArray(option) ? option.map(o => o.value) : option?.value || null;
|
|
1923
1923
|
setSelectedOptions(option);
|
|
1924
1924
|
onChangeField(value);
|
|
1925
1925
|
}, [onChangeField]);
|
|
1926
|
-
React
|
|
1926
|
+
React.useEffect(() => {
|
|
1927
1927
|
setSelectedOptions(defaultValue);
|
|
1928
1928
|
}, [defaultValue]);
|
|
1929
1929
|
const {
|
|
@@ -1996,7 +1996,7 @@ const FormFieldSwitch = /*#__PURE__*/React__default.default.memo(function FormFi
|
|
|
1996
1996
|
* custom React Hook function.
|
|
1997
1997
|
*/
|
|
1998
1998
|
|
|
1999
|
-
const onChangeField = React
|
|
1999
|
+
const onChangeField = React.useCallback(event => {
|
|
2000
2000
|
input.onChange(event);
|
|
2001
2001
|
if (onChange) {
|
|
2002
2002
|
onChange(event.target.checked, input.name);
|
|
@@ -2160,7 +2160,7 @@ const FormFieldMaskedInput = /*#__PURE__*/React__default.default.memo(function F
|
|
|
2160
2160
|
}
|
|
2161
2161
|
}
|
|
2162
2162
|
});
|
|
2163
|
-
React
|
|
2163
|
+
React.useEffect(() => {
|
|
2164
2164
|
if (input.value !== unmaskedValue) {
|
|
2165
2165
|
setUnmaskedValue(input.value.replace(unmasked, ''));
|
|
2166
2166
|
}
|
|
@@ -2222,8 +2222,8 @@ function RadioGroupInput(props) {
|
|
|
2222
2222
|
value,
|
|
2223
2223
|
onChange
|
|
2224
2224
|
} = props;
|
|
2225
|
-
const onChangeField = React
|
|
2226
|
-
return /*#__PURE__*/
|
|
2225
|
+
const onChangeField = React.useCallback(event => onChange(event.target.value), [onChange]);
|
|
2226
|
+
return /*#__PURE__*/React__default.default.createElement(Input.Input, Object.assign({
|
|
2227
2227
|
name: input.name,
|
|
2228
2228
|
autoComplete: "nope",
|
|
2229
2229
|
value: value,
|
|
@@ -2240,12 +2240,12 @@ function RadioGroupItem(props) {
|
|
|
2240
2240
|
option,
|
|
2241
2241
|
onChange
|
|
2242
2242
|
} = props;
|
|
2243
|
-
const onChangeField = React
|
|
2243
|
+
const onChangeField = React.useCallback(event => {
|
|
2244
2244
|
if (event.target.checked) {
|
|
2245
2245
|
onChange(option.value);
|
|
2246
2246
|
}
|
|
2247
2247
|
}, [onChange]);
|
|
2248
|
-
return /*#__PURE__*/
|
|
2248
|
+
return /*#__PURE__*/React__default.default.createElement(Radio.Radio, Object.assign({
|
|
2249
2249
|
className: "form-radio__item",
|
|
2250
2250
|
type: "radio",
|
|
2251
2251
|
name: input.name,
|
|
@@ -2266,14 +2266,14 @@ function RadioGroupList(props) {
|
|
|
2266
2266
|
options,
|
|
2267
2267
|
onChange
|
|
2268
2268
|
} = props;
|
|
2269
|
-
const [editableValue, setEditableValue] = React
|
|
2269
|
+
const [editableValue, setEditableValue] = React.useState(() => {
|
|
2270
2270
|
const isRadioValue = options.find(option => option.value === input.value);
|
|
2271
2271
|
if (!isRadioValue) {
|
|
2272
2272
|
return input.value;
|
|
2273
2273
|
}
|
|
2274
2274
|
return '';
|
|
2275
2275
|
});
|
|
2276
|
-
React
|
|
2276
|
+
React.useEffect(() => {
|
|
2277
2277
|
// When a new value from outside enters the form
|
|
2278
2278
|
if (input.value) {
|
|
2279
2279
|
// Check value for radio type
|
|
@@ -2287,7 +2287,7 @@ function RadioGroupList(props) {
|
|
|
2287
2287
|
}, [input.value]);
|
|
2288
2288
|
|
|
2289
2289
|
// Callback for value changes
|
|
2290
|
-
const onChangeSomeInput = React
|
|
2290
|
+
const onChangeSomeInput = React.useCallback(value => {
|
|
2291
2291
|
// Save to form values
|
|
2292
2292
|
input.onChange(value);
|
|
2293
2293
|
if (onChange) {
|
|
@@ -2297,13 +2297,13 @@ function RadioGroupList(props) {
|
|
|
2297
2297
|
}, [input, onChange]);
|
|
2298
2298
|
|
|
2299
2299
|
// Handle for radio inputs
|
|
2300
|
-
const onChangeRadio = React
|
|
2300
|
+
const onChangeRadio = React.useCallback(value => {
|
|
2301
2301
|
setEditableValue('');
|
|
2302
2302
|
onChangeSomeInput(value);
|
|
2303
2303
|
}, [onChangeSomeInput]);
|
|
2304
2304
|
|
|
2305
2305
|
// Handle for text input
|
|
2306
|
-
const onChangeEditable = React
|
|
2306
|
+
const onChangeEditable = React.useCallback(value => {
|
|
2307
2307
|
setEditableValue(value);
|
|
2308
2308
|
onChangeSomeInput(value);
|
|
2309
2309
|
}, [onChangeSomeInput]);
|
|
@@ -2717,7 +2717,7 @@ const FinalForm = /*#__PURE__*/React__default.default.forwardRef(function FinalF
|
|
|
2717
2717
|
onSubmit
|
|
2718
2718
|
} = props;
|
|
2719
2719
|
const validate = useYupValidationSchema(validationSchema, language);
|
|
2720
|
-
const onRefFormInstance = React
|
|
2720
|
+
const onRefFormInstance = React.useCallback(formInstance => {
|
|
2721
2721
|
if (ref) {
|
|
2722
2722
|
ref.current = formInstance;
|
|
2723
2723
|
}
|