@itcase/forms 1.1.26 → 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.
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
&-inner {
|
|
4
4
|
position: relative;
|
|
5
5
|
display: flex;
|
|
6
|
+
& > input {
|
|
7
|
+
width: 100%;
|
|
8
|
+
}
|
|
6
9
|
}
|
|
7
10
|
}
|
|
8
11
|
&__message {
|
|
9
12
|
&-item {
|
|
10
|
-
height: var(--form-field-
|
|
11
|
-
line-height: var(--form-field-
|
|
12
|
-
padding: var(--form-field-
|
|
13
|
+
height: var(--form-field-help-text-height);
|
|
14
|
+
line-height: var(--form-field-help-text-line-height);
|
|
15
|
+
padding: var(--form-field-help-text-padding);
|
|
13
16
|
display: block;
|
|
14
17
|
}
|
|
15
18
|
}
|
|
@@ -24,7 +27,7 @@
|
|
|
24
27
|
}
|
|
25
28
|
.form {
|
|
26
29
|
&^&-field_type_float {
|
|
27
|
-
padding:
|
|
30
|
+
padding: 12px 0 12px 0;
|
|
28
31
|
margin: var(--form-field_type_float-margin);
|
|
29
32
|
position: relative;
|
|
30
33
|
gap: var(--form-field_type_float-gap);
|
|
@@ -42,11 +45,16 @@
|
|
|
42
45
|
opacity: 100%;
|
|
43
46
|
}
|
|
44
47
|
}
|
|
48
|
+
& .textarea {
|
|
49
|
+
&::placeholder {
|
|
50
|
+
opacity: 100%;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
45
53
|
}
|
|
46
54
|
& .form {
|
|
47
55
|
&-field {
|
|
48
56
|
&__label {
|
|
49
|
-
background:
|
|
57
|
+
background: #fff;
|
|
50
58
|
padding: 0 4px;
|
|
51
59
|
position: absolute;
|
|
52
60
|
display: flex;
|
|
@@ -58,7 +66,7 @@
|
|
|
58
66
|
transform-origin: top left;
|
|
59
67
|
}
|
|
60
68
|
&__message {
|
|
61
|
-
padding:
|
|
69
|
+
padding: 0 0 0 12px;
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
}
|
|
@@ -68,15 +76,21 @@
|
|
|
68
76
|
opacity: 0%;
|
|
69
77
|
}
|
|
70
78
|
}
|
|
79
|
+
& .textarea {
|
|
80
|
+
&::placeholder {
|
|
81
|
+
transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
82
|
+
opacity: 0%;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
71
85
|
}
|
|
72
86
|
}
|
|
73
87
|
.form-field {
|
|
74
88
|
&_type {
|
|
75
89
|
&_classic {
|
|
76
|
-
padding: var(--form-
|
|
77
|
-
margin: var(--form-
|
|
90
|
+
padding: var(--form-field_type_classic-padding);
|
|
91
|
+
margin: var(--form-field_type_classic-margin);
|
|
78
92
|
position: relative;
|
|
79
|
-
gap: var(--form-
|
|
93
|
+
gap: var(--form-field_type_classic-gap);
|
|
80
94
|
}
|
|
81
95
|
}
|
|
82
96
|
}
|
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');
|
|
@@ -27,6 +27,7 @@ var Code = require('@itcase/ui/components/Code');
|
|
|
27
27
|
var Icon = require('@itcase/ui/components/Icon');
|
|
28
28
|
var DatePicker = require('@itcase/ui/components/DatePicker');
|
|
29
29
|
var Input = require('@itcase/ui/components/Input');
|
|
30
|
+
var _default = require('@itcase/icons/default');
|
|
30
31
|
var Segmented = require('@itcase/ui/components/Segmented');
|
|
31
32
|
var Select = require('@itcase/ui/components/Select');
|
|
32
33
|
var Switch = require('@itcase/ui/components/Switch');
|
|
@@ -39,7 +40,7 @@ var createDecorator = require('final-form-focus');
|
|
|
39
40
|
|
|
40
41
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
41
42
|
|
|
42
|
-
var React__default = /*#__PURE__*/_interopDefault(React
|
|
43
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
43
44
|
var clsx__default = /*#__PURE__*/_interopDefault(clsx);
|
|
44
45
|
var camelCase__default = /*#__PURE__*/_interopDefault(camelCase);
|
|
45
46
|
var snakeCase__default = /*#__PURE__*/_interopDefault(snakeCase);
|
|
@@ -123,7 +124,7 @@ const makeValidate = schema => {
|
|
|
123
124
|
};
|
|
124
125
|
};
|
|
125
126
|
function useYupValidationSchema(schema, language) {
|
|
126
|
-
const validate = React
|
|
127
|
+
const validate = React.useMemo(() => schema && makeValidate(schema), [schema, language]);
|
|
127
128
|
return validate;
|
|
128
129
|
}
|
|
129
130
|
|
|
@@ -142,7 +143,7 @@ function useFieldValidationState(props) {
|
|
|
142
143
|
const successKey = 'success';
|
|
143
144
|
|
|
144
145
|
// Determines if the field is in an error state based on various conditions.
|
|
145
|
-
const isErrorState = React
|
|
146
|
+
const isErrorState = React.useMemo(() => {
|
|
146
147
|
if (fieldProps.showErrorsOnSubmit) {
|
|
147
148
|
return Boolean(meta.submitFailed && meta.touched && (meta.error || submitError));
|
|
148
149
|
} else {
|
|
@@ -151,12 +152,12 @@ function useFieldValidationState(props) {
|
|
|
151
152
|
}, [fieldProps.showErrorsOnSubmit, meta.submitFailed, meta.touched, meta.error, submitError]);
|
|
152
153
|
|
|
153
154
|
// Determines if the field's input state is valid
|
|
154
|
-
const isValidState = React
|
|
155
|
+
const isValidState = React.useMemo(() => {
|
|
155
156
|
const hasValue = Array.isArray(input?.value) ? input?.value.length : input?.value;
|
|
156
157
|
const isModifiedAfterSubmit = meta.modifiedSinceLastSubmit && !meta.error && submitError;
|
|
157
158
|
return Boolean(hasValue && (meta.valid || isModifiedAfterSubmit));
|
|
158
159
|
}, [input?.value, meta.valid, meta.error, submitError, meta.modifiedSinceLastSubmit]);
|
|
159
|
-
const errorMessage = React
|
|
160
|
+
const errorMessage = React.useMemo(() => {
|
|
160
161
|
// If final-form field has error in "meta" render-property.
|
|
161
162
|
// If field not modified after last form submit - use submit error
|
|
162
163
|
const error = meta.error || submitError || false;
|
|
@@ -194,7 +195,7 @@ function useValidationAppearanceInputProps(props) {
|
|
|
194
195
|
} = props;
|
|
195
196
|
|
|
196
197
|
// TODO: need to add props that can change during errors in this field
|
|
197
|
-
const validationAppearanceInputProps = React
|
|
198
|
+
const validationAppearanceInputProps = React.useMemo(() => {
|
|
198
199
|
// const resultAppearanceProps = {
|
|
199
200
|
// messageTextColor: props.errorMessageTextColor,
|
|
200
201
|
// messageTextSize: props.errorMessageTextSize,
|
|
@@ -313,8 +314,8 @@ function FieldWrapperBase(props) {
|
|
|
313
314
|
isValidState,
|
|
314
315
|
children
|
|
315
316
|
} = props;
|
|
316
|
-
const formFieldClass = React
|
|
317
|
-
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]);
|
|
318
319
|
const sizeClass = useDeviceTargetClass.useDeviceTargetClass(props, {
|
|
319
320
|
prefix: 'form-field_size_',
|
|
320
321
|
propsKey: 'size'
|
|
@@ -412,7 +413,7 @@ function FieldWrapper(props) {
|
|
|
412
413
|
change
|
|
413
414
|
} = reactFinalForm.useForm(); // , mutators
|
|
414
415
|
|
|
415
|
-
React
|
|
416
|
+
React.useEffect(() => {
|
|
416
417
|
return () => {
|
|
417
418
|
change(inputName, undefined);
|
|
418
419
|
};
|
|
@@ -464,10 +465,10 @@ const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function File
|
|
|
464
465
|
const {
|
|
465
466
|
change
|
|
466
467
|
} = reactFinalForm.useForm();
|
|
467
|
-
const [fileError, setFileError] = React
|
|
468
|
-
const [fileIsLoading, setFileIsLoading] = React
|
|
469
|
-
const filesList = React
|
|
470
|
-
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 => {
|
|
471
472
|
// If max files in dropzone is 1 - return file as it self, else as array of files
|
|
472
473
|
// ps: for old projects compatibility
|
|
473
474
|
const toSave = dropzoneProps.maxFiles == 1 ? newFiles[0] : newFiles;
|
|
@@ -479,7 +480,7 @@ const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function File
|
|
|
479
480
|
[dropzoneProps, change]);
|
|
480
481
|
|
|
481
482
|
//
|
|
482
|
-
const convertFiledValueAndSaveAsFiles = React
|
|
483
|
+
const convertFiledValueAndSaveAsFiles = React.useCallback(async currentFilesList => {
|
|
483
484
|
setFileIsLoading(true);
|
|
484
485
|
const newFiles = [];
|
|
485
486
|
for (const fileItem of currentFilesList) {
|
|
@@ -497,7 +498,7 @@ const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function File
|
|
|
497
498
|
}, [isPreviews, changeFormState]);
|
|
498
499
|
|
|
499
500
|
// Delete file from dropzone
|
|
500
|
-
const removeFile = React
|
|
501
|
+
const removeFile = React.useCallback((event, index) => {
|
|
501
502
|
event.stopPropagation();
|
|
502
503
|
event.preventDefault();
|
|
503
504
|
const newFiles = [...filesList];
|
|
@@ -572,7 +573,7 @@ const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function File
|
|
|
572
573
|
}
|
|
573
574
|
}
|
|
574
575
|
});
|
|
575
|
-
React
|
|
576
|
+
React.useEffect(() => {
|
|
576
577
|
const currentFilesList = castArray__default.default(inputValue);
|
|
577
578
|
const isNeedToConvert = currentFilesList.some(fileItem => typeof fileItem === 'string');
|
|
578
579
|
if (isNeedToConvert) {
|
|
@@ -1072,7 +1073,7 @@ const FormFieldCheckbox = /*#__PURE__*/React__default.default.memo(function Form
|
|
|
1072
1073
|
* custom React Hook function.
|
|
1073
1074
|
*/
|
|
1074
1075
|
|
|
1075
|
-
const onChangeField = React
|
|
1076
|
+
const onChangeField = React.useCallback(event => {
|
|
1076
1077
|
input.onChange(event);
|
|
1077
1078
|
if (onChange) {
|
|
1078
1079
|
onChange(event.target.checked, input.name);
|
|
@@ -1148,12 +1149,12 @@ function FormFieldChips(props) {
|
|
|
1148
1149
|
} = reactFinalForm.useForm();
|
|
1149
1150
|
|
|
1150
1151
|
// Callback for value changes
|
|
1151
|
-
const onChangeSomeInput = React
|
|
1152
|
+
const onChangeSomeInput = React.useCallback((inputValue, newOptionValue) => {
|
|
1152
1153
|
const updatedValues = inputValue.includes(newOptionValue) ? inputValue.filter(selectedValue => selectedValue !== newOptionValue) : [...inputValue, newOptionValue];
|
|
1153
1154
|
change(name, updatedValues);
|
|
1154
1155
|
onChange && onChange(updatedValues);
|
|
1155
1156
|
}, [change, name, onChange]);
|
|
1156
|
-
React
|
|
1157
|
+
React.useEffect(() => {
|
|
1157
1158
|
initialValue && change(name, initialValue);
|
|
1158
1159
|
// update the form value only when the initialValue changes, so use disable eslint to ignore the warning
|
|
1159
1160
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -1179,7 +1180,7 @@ function FormFieldChips(props) {
|
|
|
1179
1180
|
inputProps: inputProps,
|
|
1180
1181
|
validationStateKey: isErrorState ? errorKey : 'success'
|
|
1181
1182
|
});
|
|
1182
|
-
const activeOptionsList = React
|
|
1183
|
+
const activeOptionsList = React.useMemo(() => {
|
|
1183
1184
|
const emptyOptionsList = [{
|
|
1184
1185
|
label: null,
|
|
1185
1186
|
value: null
|
|
@@ -1250,7 +1251,7 @@ const FormFieldChoice = /*#__PURE__*/React__default.default.memo(function FormFi
|
|
|
1250
1251
|
const {
|
|
1251
1252
|
change
|
|
1252
1253
|
} = reactFinalForm.useForm();
|
|
1253
|
-
const setActiveSegment = React
|
|
1254
|
+
const setActiveSegment = React.useCallback((option, isChecked) => {
|
|
1254
1255
|
change(name, isChecked && option.value);
|
|
1255
1256
|
if (onChange) {
|
|
1256
1257
|
onChange(option.value, name, isChecked);
|
|
@@ -1269,7 +1270,7 @@ const FormFieldChoice = /*#__PURE__*/React__default.default.memo(function FormFi
|
|
|
1269
1270
|
* React Hooks must be called in a React function component or a
|
|
1270
1271
|
* custom React Hook function.
|
|
1271
1272
|
*/
|
|
1272
|
-
const activeOption = React
|
|
1273
|
+
const activeOption = React.useMemo(() => {
|
|
1273
1274
|
const emptyOption = {
|
|
1274
1275
|
value: null,
|
|
1275
1276
|
label: null
|
|
@@ -1502,7 +1503,7 @@ function FormFieldDatePicker(props) {
|
|
|
1502
1503
|
* custom React Hook function.
|
|
1503
1504
|
*/
|
|
1504
1505
|
|
|
1505
|
-
const onChangeField = React
|
|
1506
|
+
const onChangeField = React.useCallback((startDate, endDate) => {
|
|
1506
1507
|
if (!datePickerProps.selectsRange) {
|
|
1507
1508
|
// When we need to save single date, value is date
|
|
1508
1509
|
// TODO: make object with one date? need to check all forms with FormFieldDatePicker
|
|
@@ -1582,33 +1583,13 @@ const FormFieldInput = /*#__PURE__*/React__default.default.memo(function FormFie
|
|
|
1582
1583
|
clearIconShape,
|
|
1583
1584
|
clearIconSize,
|
|
1584
1585
|
fieldProps = {},
|
|
1585
|
-
iconFill,
|
|
1586
|
-
iconFillHover,
|
|
1587
|
-
iconRevealableHide,
|
|
1588
|
-
iconRevealableShow,
|
|
1589
|
-
iconShape,
|
|
1590
|
-
iconSize,
|
|
1591
1586
|
inputProps = {},
|
|
1592
1587
|
parse,
|
|
1593
1588
|
showMessage,
|
|
1594
|
-
isPassword,
|
|
1595
1589
|
isRequired,
|
|
1596
|
-
isRevealable,
|
|
1597
1590
|
onChange,
|
|
1598
1591
|
onClickClearIcon
|
|
1599
1592
|
} = props;
|
|
1600
|
-
const [isRevealed, setIsRevealed] = React$1.useState(false);
|
|
1601
|
-
const inputType = React$1.useMemo(() => {
|
|
1602
|
-
if (isPassword) {
|
|
1603
|
-
return isRevealed ? 'text' : 'password';
|
|
1604
|
-
} else {
|
|
1605
|
-
return 'text';
|
|
1606
|
-
}
|
|
1607
|
-
}, [isRevealed, isPassword]);
|
|
1608
|
-
const onClickIconReveal = React$1.useCallback(event => {
|
|
1609
|
-
event.preventDefault();
|
|
1610
|
-
setIsRevealed(prev => !prev);
|
|
1611
|
-
}, []);
|
|
1612
1593
|
return /*#__PURE__*/React__default.default.createElement(reactFinalForm.Field, {
|
|
1613
1594
|
name: name,
|
|
1614
1595
|
initialValue: initialValue,
|
|
@@ -1624,7 +1605,7 @@ const FormFieldInput = /*#__PURE__*/React__default.default.memo(function FormFie
|
|
|
1624
1605
|
* custom React Hook function.
|
|
1625
1606
|
*/
|
|
1626
1607
|
|
|
1627
|
-
const onChangeField = React
|
|
1608
|
+
const onChangeField = React.useCallback(event => {
|
|
1628
1609
|
input.onChange(event);
|
|
1629
1610
|
if (onChange) {
|
|
1630
1611
|
onChange(event.target.value, input.name);
|
|
@@ -1644,7 +1625,6 @@ const FormFieldInput = /*#__PURE__*/React__default.default.memo(function FormFie
|
|
|
1644
1625
|
inputProps: inputProps,
|
|
1645
1626
|
validationStateKey: isErrorState ? errorKey : 'success'
|
|
1646
1627
|
});
|
|
1647
|
-
const isIconRevealableString = typeof iconRevealableHide === 'string' && typeof iconRevealableShow === 'string';
|
|
1648
1628
|
return /*#__PURE__*/React__default.default.createElement(FieldWrapper, Object.assign({
|
|
1649
1629
|
className: clsx__default.default('form-field_type_input', 'form__item_type_input', classNameGroupItem),
|
|
1650
1630
|
errorKey: errorKey,
|
|
@@ -1652,7 +1632,7 @@ const FormFieldInput = /*#__PURE__*/React__default.default.memo(function FormFie
|
|
|
1652
1632
|
isErrorState: isErrorState,
|
|
1653
1633
|
metaError: meta.error,
|
|
1654
1634
|
isDisabled: isDisabled,
|
|
1655
|
-
fieldClassName:
|
|
1635
|
+
fieldClassName: "form-input",
|
|
1656
1636
|
inputName: input.name,
|
|
1657
1637
|
inputValue: input.value || '',
|
|
1658
1638
|
metaActive: meta.active,
|
|
@@ -1662,7 +1642,7 @@ const FormFieldInput = /*#__PURE__*/React__default.default.memo(function FormFie
|
|
|
1662
1642
|
}, fieldProps), /*#__PURE__*/React__default.default.createElement(Input.Input, Object.assign({
|
|
1663
1643
|
dataTestId: `${input.name}FieldInput`,
|
|
1664
1644
|
className: clsx__default.default(meta.active && 'input_state_focus', meta.error && meta.touched && `input_state_${errorKey}`),
|
|
1665
|
-
type:
|
|
1645
|
+
type: "text",
|
|
1666
1646
|
name: input.name,
|
|
1667
1647
|
isDisabled: isDisabled,
|
|
1668
1648
|
autoComplete: "nope",
|
|
@@ -1670,16 +1650,7 @@ const FormFieldInput = /*#__PURE__*/React__default.default.memo(function FormFie
|
|
|
1670
1650
|
onBlur: input.onBlur,
|
|
1671
1651
|
onChange: onChangeField,
|
|
1672
1652
|
onFocus: input.onFocus
|
|
1673
|
-
}, updatedInputProps)),
|
|
1674
|
-
className: "form-field__icon",
|
|
1675
|
-
size: iconSize,
|
|
1676
|
-
iconFill: iconFill,
|
|
1677
|
-
iconFillHover: iconFillHover,
|
|
1678
|
-
imageSrc: isRevealed && isIconRevealableString ? iconRevealableHide : iconRevealableShow,
|
|
1679
|
-
shape: iconShape,
|
|
1680
|
-
SvgImage: isRevealed && !isIconRevealableString ? iconRevealableHide : iconRevealableShow,
|
|
1681
|
-
onClick: onClickIconReveal
|
|
1682
|
-
}), clearIcon && /*#__PURE__*/React__default.default.createElement(Icon.Icon, {
|
|
1653
|
+
}, updatedInputProps)), clearIcon && /*#__PURE__*/React__default.default.createElement(Icon.Icon, {
|
|
1683
1654
|
className: "form-field__icon",
|
|
1684
1655
|
size: clearIconSize,
|
|
1685
1656
|
iconFill: clearIconFill,
|
|
@@ -1692,6 +1663,110 @@ const FormFieldInput = /*#__PURE__*/React__default.default.memo(function FormFie
|
|
|
1692
1663
|
});
|
|
1693
1664
|
});
|
|
1694
1665
|
|
|
1666
|
+
const defaultPasswordProps = {
|
|
1667
|
+
appearance: 'sizeM defaultSecondary solid rounded',
|
|
1668
|
+
iconRevealableHide: _default.icons24.View.HideValue,
|
|
1669
|
+
iconRevealableShow: _default.icons24.View.ShowValue,
|
|
1670
|
+
iconFill: 'surfaceItemQuaternary'
|
|
1671
|
+
};
|
|
1672
|
+
|
|
1673
|
+
const FormFieldPassword = /*#__PURE__*/React__default.default.memo(function FormFieldPassword(props) {
|
|
1674
|
+
const {
|
|
1675
|
+
name,
|
|
1676
|
+
initialValue,
|
|
1677
|
+
isDisabled,
|
|
1678
|
+
classNameGroupItem,
|
|
1679
|
+
fieldProps,
|
|
1680
|
+
iconFill,
|
|
1681
|
+
iconFillHover,
|
|
1682
|
+
iconRevealableHide,
|
|
1683
|
+
iconRevealableShow,
|
|
1684
|
+
iconShape,
|
|
1685
|
+
iconSize,
|
|
1686
|
+
inputProps,
|
|
1687
|
+
parse,
|
|
1688
|
+
showMessage,
|
|
1689
|
+
isRequired,
|
|
1690
|
+
onChange
|
|
1691
|
+
} = props;
|
|
1692
|
+
const [isRevealed, setIsRevealed] = React.useState(false);
|
|
1693
|
+
const inputType = React.useMemo(() => {
|
|
1694
|
+
return isRevealed ? 'text' : 'password';
|
|
1695
|
+
}, [isRevealed]);
|
|
1696
|
+
const onClickIconReveal = React.useCallback(event => {
|
|
1697
|
+
event.preventDefault();
|
|
1698
|
+
setIsRevealed(prev => !prev);
|
|
1699
|
+
}, []);
|
|
1700
|
+
return /*#__PURE__*/React__default.default.createElement(reactFinalForm.Field, {
|
|
1701
|
+
name: name,
|
|
1702
|
+
initialValue: initialValue,
|
|
1703
|
+
parse: parse
|
|
1704
|
+
}, function Render({
|
|
1705
|
+
input,
|
|
1706
|
+
meta
|
|
1707
|
+
}) {
|
|
1708
|
+
/** Note:
|
|
1709
|
+
* Create "Render" function by "eslint-react-hooks/rules-of-hooks":
|
|
1710
|
+
* React Hooks cannot be called inside a callback.
|
|
1711
|
+
* React Hooks must be called in a React function component or a
|
|
1712
|
+
* custom React Hook function.
|
|
1713
|
+
*/
|
|
1714
|
+
|
|
1715
|
+
const onChangeField = React.useCallback(event => {
|
|
1716
|
+
input.onChange(event);
|
|
1717
|
+
if (onChange) {
|
|
1718
|
+
onChange(event.target.value, input.name);
|
|
1719
|
+
}
|
|
1720
|
+
}, [onChange, input.onChange]);
|
|
1721
|
+
const {
|
|
1722
|
+
isErrorState,
|
|
1723
|
+
isValidState,
|
|
1724
|
+
errorKey,
|
|
1725
|
+
errorMessage
|
|
1726
|
+
} = useFieldValidationState({
|
|
1727
|
+
fieldProps: fieldProps,
|
|
1728
|
+
input: input,
|
|
1729
|
+
meta: meta
|
|
1730
|
+
});
|
|
1731
|
+
const updatedInputProps = useValidationAppearanceInputProps({
|
|
1732
|
+
inputProps: inputProps,
|
|
1733
|
+
validationStateKey: isErrorState ? errorKey : 'success'
|
|
1734
|
+
});
|
|
1735
|
+
return /*#__PURE__*/React__default.default.createElement(FieldWrapper, Object.assign({
|
|
1736
|
+
className: clsx__default.default('form-field_type_input', 'form__item_type_input', classNameGroupItem),
|
|
1737
|
+
errorKey: errorKey,
|
|
1738
|
+
errorMessage: errorMessage,
|
|
1739
|
+
isErrorState: isErrorState,
|
|
1740
|
+
metaError: meta.error,
|
|
1741
|
+
isDisabled: isDisabled,
|
|
1742
|
+
fieldClassName: "form-password",
|
|
1743
|
+
inputName: input.name,
|
|
1744
|
+
inputValue: input.value || '',
|
|
1745
|
+
metaActive: meta.active,
|
|
1746
|
+
showMessage: showMessage,
|
|
1747
|
+
isRequired: isRequired,
|
|
1748
|
+
isValidState: isValidState
|
|
1749
|
+
}, fieldProps), /*#__PURE__*/React__default.default.createElement(Input.Input, Object.assign({
|
|
1750
|
+
dataTestId: `${input.name}FieldInputPassword`,
|
|
1751
|
+
className: clsx__default.default(meta.active && 'input_state_focus', meta.error && meta.touched && `input_state_${errorKey}`),
|
|
1752
|
+
type: inputType,
|
|
1753
|
+
name: input.name,
|
|
1754
|
+
isDisabled: isDisabled,
|
|
1755
|
+
autoComplete: "nope",
|
|
1756
|
+
value: input.value || '',
|
|
1757
|
+
onBlur: input.onBlur,
|
|
1758
|
+
onChange: onChangeField,
|
|
1759
|
+
onFocus: input.onFocus
|
|
1760
|
+
}, updatedInputProps)), /*#__PURE__*/React__default.default.createElement(Icon.Icon, {
|
|
1761
|
+
className: "form-field__icon",
|
|
1762
|
+
size: inputProps.iconSize,
|
|
1763
|
+
iconFill: inputProps.iconFill,
|
|
1764
|
+
SvgImage: isRevealed ? inputProps.iconRevealableHide : inputProps.iconRevealableShow,
|
|
1765
|
+
onClick: onClickIconReveal
|
|
1766
|
+
}));
|
|
1767
|
+
});
|
|
1768
|
+
});
|
|
1769
|
+
|
|
1695
1770
|
const defaultSegmentedProps = {
|
|
1696
1771
|
appearance: 'defaultPrimary sizeM solid rounded',
|
|
1697
1772
|
width: 'fill',
|
|
@@ -1712,7 +1787,7 @@ function FormFieldSegmented(props) {
|
|
|
1712
1787
|
const {
|
|
1713
1788
|
change
|
|
1714
1789
|
} = reactFinalForm.useForm();
|
|
1715
|
-
const setActiveSegment = React
|
|
1790
|
+
const setActiveSegment = React.useCallback(option => {
|
|
1716
1791
|
change(name, option.value);
|
|
1717
1792
|
}, [change]);
|
|
1718
1793
|
return /*#__PURE__*/React__default.default.createElement(reactFinalForm.Field, {
|
|
@@ -1728,7 +1803,7 @@ function FormFieldSegmented(props) {
|
|
|
1728
1803
|
* custom React Hook function.
|
|
1729
1804
|
*/
|
|
1730
1805
|
|
|
1731
|
-
const activeOption = React
|
|
1806
|
+
const activeOption = React.useMemo(() => {
|
|
1732
1807
|
const emptyOption = {
|
|
1733
1808
|
label: null,
|
|
1734
1809
|
value: null
|
|
@@ -1826,8 +1901,8 @@ const FormFieldSelect = /*#__PURE__*/React__default.default.memo(function FormFi
|
|
|
1826
1901
|
* React Hooks must be called in a React function component or a
|
|
1827
1902
|
* custom React Hook function.
|
|
1828
1903
|
*/
|
|
1829
|
-
const [selectedOptions, setSelectedOptions] = React
|
|
1830
|
-
const defaultValue = React
|
|
1904
|
+
const [selectedOptions, setSelectedOptions] = React.useState(null);
|
|
1905
|
+
const defaultValue = React.useMemo(() => {
|
|
1831
1906
|
const optionsValues = getDefaultValue(options, input.value);
|
|
1832
1907
|
if (!optionsValues.length && input.value?.length) {
|
|
1833
1908
|
optionsValues.push({
|
|
@@ -1837,18 +1912,18 @@ const FormFieldSelect = /*#__PURE__*/React__default.default.memo(function FormFi
|
|
|
1837
1912
|
}
|
|
1838
1913
|
return optionsValues;
|
|
1839
1914
|
}, [input.value]);
|
|
1840
|
-
const onChangeField = React
|
|
1915
|
+
const onChangeField = React.useCallback(value => {
|
|
1841
1916
|
input.onChange(value);
|
|
1842
1917
|
if (onChange) {
|
|
1843
1918
|
onChange(value, input.name);
|
|
1844
1919
|
}
|
|
1845
1920
|
}, [onChange, input.onChange]);
|
|
1846
|
-
const onChangeValue = React
|
|
1921
|
+
const onChangeValue = React.useCallback((option, actionMeta) => {
|
|
1847
1922
|
const value = Array.isArray(option) ? option.map(o => o.value) : option?.value || null;
|
|
1848
1923
|
setSelectedOptions(option);
|
|
1849
1924
|
onChangeField(value);
|
|
1850
1925
|
}, [onChangeField]);
|
|
1851
|
-
React
|
|
1926
|
+
React.useEffect(() => {
|
|
1852
1927
|
setSelectedOptions(defaultValue);
|
|
1853
1928
|
}, [defaultValue]);
|
|
1854
1929
|
const {
|
|
@@ -1921,7 +1996,7 @@ const FormFieldSwitch = /*#__PURE__*/React__default.default.memo(function FormFi
|
|
|
1921
1996
|
* custom React Hook function.
|
|
1922
1997
|
*/
|
|
1923
1998
|
|
|
1924
|
-
const onChangeField = React
|
|
1999
|
+
const onChangeField = React.useCallback(event => {
|
|
1925
2000
|
input.onChange(event);
|
|
1926
2001
|
if (onChange) {
|
|
1927
2002
|
onChange(event.target.checked, input.name);
|
|
@@ -2027,10 +2102,12 @@ const FormFieldTextarea = /*#__PURE__*/React__default.default.memo(function Form
|
|
|
2027
2102
|
isRequired: isRequired,
|
|
2028
2103
|
isValidState: isValidState
|
|
2029
2104
|
}, fieldProps), /*#__PURE__*/React__default.default.createElement(Textarea.Textarea, Object.assign({
|
|
2105
|
+
dataTestId: `${input.name}FieldTextarea`,
|
|
2106
|
+
className: clsx__default.default(meta.active && 'textarea_state_focus', meta.error && meta.touched && `textarea_state_${errorKey}`),
|
|
2030
2107
|
name: input.name,
|
|
2031
2108
|
isDisabled: isDisabled,
|
|
2032
2109
|
autoComplete: "nope",
|
|
2033
|
-
value: input.value,
|
|
2110
|
+
value: input.value || '',
|
|
2034
2111
|
onBlur: input.onBlur,
|
|
2035
2112
|
onChange: input.onChange,
|
|
2036
2113
|
onFocus: input.onFocus
|
|
@@ -2083,7 +2160,7 @@ const FormFieldMaskedInput = /*#__PURE__*/React__default.default.memo(function F
|
|
|
2083
2160
|
}
|
|
2084
2161
|
}
|
|
2085
2162
|
});
|
|
2086
|
-
React
|
|
2163
|
+
React.useEffect(() => {
|
|
2087
2164
|
if (input.value !== unmaskedValue) {
|
|
2088
2165
|
setUnmaskedValue(input.value.replace(unmasked, ''));
|
|
2089
2166
|
}
|
|
@@ -2145,8 +2222,8 @@ function RadioGroupInput(props) {
|
|
|
2145
2222
|
value,
|
|
2146
2223
|
onChange
|
|
2147
2224
|
} = props;
|
|
2148
|
-
const onChangeField = React
|
|
2149
|
-
return /*#__PURE__*/
|
|
2225
|
+
const onChangeField = React.useCallback(event => onChange(event.target.value), [onChange]);
|
|
2226
|
+
return /*#__PURE__*/React__default.default.createElement(Input.Input, Object.assign({
|
|
2150
2227
|
name: input.name,
|
|
2151
2228
|
autoComplete: "nope",
|
|
2152
2229
|
value: value,
|
|
@@ -2163,12 +2240,12 @@ function RadioGroupItem(props) {
|
|
|
2163
2240
|
option,
|
|
2164
2241
|
onChange
|
|
2165
2242
|
} = props;
|
|
2166
|
-
const onChangeField = React
|
|
2243
|
+
const onChangeField = React.useCallback(event => {
|
|
2167
2244
|
if (event.target.checked) {
|
|
2168
2245
|
onChange(option.value);
|
|
2169
2246
|
}
|
|
2170
2247
|
}, [onChange]);
|
|
2171
|
-
return /*#__PURE__*/
|
|
2248
|
+
return /*#__PURE__*/React__default.default.createElement(Radio.Radio, Object.assign({
|
|
2172
2249
|
className: "form-radio__item",
|
|
2173
2250
|
type: "radio",
|
|
2174
2251
|
name: input.name,
|
|
@@ -2189,14 +2266,14 @@ function RadioGroupList(props) {
|
|
|
2189
2266
|
options,
|
|
2190
2267
|
onChange
|
|
2191
2268
|
} = props;
|
|
2192
|
-
const [editableValue, setEditableValue] = React
|
|
2269
|
+
const [editableValue, setEditableValue] = React.useState(() => {
|
|
2193
2270
|
const isRadioValue = options.find(option => option.value === input.value);
|
|
2194
2271
|
if (!isRadioValue) {
|
|
2195
2272
|
return input.value;
|
|
2196
2273
|
}
|
|
2197
2274
|
return '';
|
|
2198
2275
|
});
|
|
2199
|
-
React
|
|
2276
|
+
React.useEffect(() => {
|
|
2200
2277
|
// When a new value from outside enters the form
|
|
2201
2278
|
if (input.value) {
|
|
2202
2279
|
// Check value for radio type
|
|
@@ -2210,7 +2287,7 @@ function RadioGroupList(props) {
|
|
|
2210
2287
|
}, [input.value]);
|
|
2211
2288
|
|
|
2212
2289
|
// Callback for value changes
|
|
2213
|
-
const onChangeSomeInput = React
|
|
2290
|
+
const onChangeSomeInput = React.useCallback(value => {
|
|
2214
2291
|
// Save to form values
|
|
2215
2292
|
input.onChange(value);
|
|
2216
2293
|
if (onChange) {
|
|
@@ -2220,13 +2297,13 @@ function RadioGroupList(props) {
|
|
|
2220
2297
|
}, [input, onChange]);
|
|
2221
2298
|
|
|
2222
2299
|
// Handle for radio inputs
|
|
2223
|
-
const onChangeRadio = React
|
|
2300
|
+
const onChangeRadio = React.useCallback(value => {
|
|
2224
2301
|
setEditableValue('');
|
|
2225
2302
|
onChangeSomeInput(value);
|
|
2226
2303
|
}, [onChangeSomeInput]);
|
|
2227
2304
|
|
|
2228
2305
|
// Handle for text input
|
|
2229
|
-
const onChangeEditable = React
|
|
2306
|
+
const onChangeEditable = React.useCallback(value => {
|
|
2230
2307
|
setEditableValue(value);
|
|
2231
2308
|
onChangeSomeInput(value);
|
|
2232
2309
|
}, [onChangeSomeInput]);
|
|
@@ -2398,6 +2475,12 @@ function generateField(field, config, props) {
|
|
|
2398
2475
|
key: config.key
|
|
2399
2476
|
}, field, props));
|
|
2400
2477
|
}
|
|
2478
|
+
case formTypes.password:
|
|
2479
|
+
{
|
|
2480
|
+
return /*#__PURE__*/React__default.default.createElement(FormFieldPassword, Object.assign({
|
|
2481
|
+
key: config.key
|
|
2482
|
+
}, field, props));
|
|
2483
|
+
}
|
|
2401
2484
|
case formTypes.textarea:
|
|
2402
2485
|
{
|
|
2403
2486
|
return /*#__PURE__*/React__default.default.createElement(FormFieldTextarea, Object.assign({
|
|
@@ -2634,7 +2717,7 @@ const FinalForm = /*#__PURE__*/React__default.default.forwardRef(function FinalF
|
|
|
2634
2717
|
onSubmit
|
|
2635
2718
|
} = props;
|
|
2636
2719
|
const validate = useYupValidationSchema(validationSchema, language);
|
|
2637
|
-
const onRefFormInstance = React
|
|
2720
|
+
const onRefFormInstance = React.useCallback(formInstance => {
|
|
2638
2721
|
if (ref) {
|
|
2639
2722
|
ref.current = formInstance;
|
|
2640
2723
|
}
|
|
@@ -3021,6 +3104,7 @@ exports.FormFieldCustom = FormFieldCustom;
|
|
|
3021
3104
|
exports.FormFieldDatePicker = FormFieldDatePicker;
|
|
3022
3105
|
exports.FormFieldInput = FormFieldInput;
|
|
3023
3106
|
exports.FormFieldMaskedInput = FormFieldMaskedInput;
|
|
3107
|
+
exports.FormFieldPassword = FormFieldPassword;
|
|
3024
3108
|
exports.FormFieldSegmented = FormFieldSegmented;
|
|
3025
3109
|
exports.FormFieldSelect = FormFieldSelect;
|
|
3026
3110
|
exports.FormFieldSwitch = FormFieldSwitch;
|
|
@@ -3039,6 +3123,7 @@ exports.defaultFieldSizeM = defaultFieldSizeM;
|
|
|
3039
3123
|
exports.defaultFieldSizeXL = defaultFieldSizeXL;
|
|
3040
3124
|
exports.defaultGroupProps = defaultGroupProps;
|
|
3041
3125
|
exports.defaultInputProps = defaultInputProps;
|
|
3126
|
+
exports.defaultPasswordProps = defaultPasswordProps;
|
|
3042
3127
|
exports.defaultRadioProps = defaultRadioProps;
|
|
3043
3128
|
exports.defaultSegmentedProps = defaultSegmentedProps;
|
|
3044
3129
|
exports.defaultSelectProps = defaultSelectProps;
|