intelicoreact 1.1.49 → 1.1.50
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.
|
@@ -83,30 +83,20 @@ var InputAddress = function InputAddress(_ref) {
|
|
|
83
83
|
isLoading = _useState8[0],
|
|
84
84
|
setIsLoading = _useState8[1];
|
|
85
85
|
|
|
86
|
-
var _useState9 = (0, _react.useState)(
|
|
86
|
+
var _useState9 = (0, _react.useState)(null),
|
|
87
87
|
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
hightlightedIndex = _useState10[0],
|
|
89
|
+
setHightlightedIndex = _useState10[1];
|
|
90
90
|
|
|
91
91
|
var _useState11 = (0, _react.useState)(false),
|
|
92
92
|
_useState12 = (0, _slicedToArray2.default)(_useState11, 2),
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
isFocused = _useState12[0],
|
|
94
|
+
setIsFocused = _useState12[1];
|
|
95
95
|
|
|
96
|
-
var _useState13 = (0, _react.useState)(
|
|
96
|
+
var _useState13 = (0, _react.useState)(false),
|
|
97
97
|
_useState14 = (0, _slicedToArray2.default)(_useState13, 2),
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
var _useState15 = (0, _react.useState)(false),
|
|
102
|
-
_useState16 = (0, _slicedToArray2.default)(_useState15, 2),
|
|
103
|
-
isFocused = _useState16[0],
|
|
104
|
-
setIsFocused = _useState16[1];
|
|
105
|
-
|
|
106
|
-
var _useState17 = (0, _react.useState)(false),
|
|
107
|
-
_useState18 = (0, _slicedToArray2.default)(_useState17, 2),
|
|
108
|
-
isListVisible = _useState18[0],
|
|
109
|
-
setIsListVisible = _useState18[1];
|
|
98
|
+
isListVisible = _useState14[0],
|
|
99
|
+
setIsListVisible = _useState14[1];
|
|
110
100
|
|
|
111
101
|
var isWrongAddress = (0, _react.useMemo)(function () {
|
|
112
102
|
var _query$street;
|
|
@@ -120,7 +110,6 @@ var InputAddress = function InputAddress(_ref) {
|
|
|
120
110
|
|
|
121
111
|
var setQueryAsItem = function setQueryAsItem(e, item) {
|
|
122
112
|
if (e) e === null || e === void 0 ? void 0 : e.stopPropagation();
|
|
123
|
-
setIsSelectedFromList(true);
|
|
124
113
|
setTimeout(function () {
|
|
125
114
|
return setQuery(item);
|
|
126
115
|
}, 1);
|
|
@@ -161,19 +150,18 @@ var InputAddress = function InputAddress(_ref) {
|
|
|
161
150
|
setHightlightedIndex(null);
|
|
162
151
|
inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.blur();
|
|
163
152
|
} else {
|
|
164
|
-
var _listRef$current, _listRef$current$getB, _listRef$current2,
|
|
153
|
+
var _listRef$current, _listRef$current$getB, _listRef$current2, _newHightlightedEleme;
|
|
165
154
|
|
|
166
|
-
var prevHightlightedIndex = hightlightedIndex;
|
|
167
155
|
var newHightlightedIndex = null;
|
|
168
156
|
var listItemsElements = document.getElementsByClassName('input-address__list--item');
|
|
169
|
-
var
|
|
170
|
-
var
|
|
171
|
-
var
|
|
157
|
+
var listHeight = listRef === null || listRef === void 0 ? void 0 : (_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : (_listRef$current$getB = _listRef$current.getBoundingClientRect()) === null || _listRef$current$getB === void 0 ? void 0 : _listRef$current$getB.height;
|
|
158
|
+
var listScrollTop = (listRef === null || listRef === void 0 ? void 0 : (_listRef$current2 = listRef.current) === null || _listRef$current2 === void 0 ? void 0 : _listRef$current2.scrollTop) || 0;
|
|
159
|
+
var lastItemIndex = parseInt(listItems === null || listItems === void 0 ? void 0 : listItems.length) - 1;
|
|
172
160
|
/** Arrows Controllers **/
|
|
173
161
|
|
|
174
162
|
if (keyCode === 40) {
|
|
175
163
|
// Down Key Controller
|
|
176
|
-
if (hightlightedIndex === null || hightlightedIndex ===
|
|
164
|
+
if (hightlightedIndex === null || hightlightedIndex === lastItemIndex) {
|
|
177
165
|
newHightlightedIndex = 0;
|
|
178
166
|
} else if (hightlightedIndex + 1 < (listItems === null || listItems === void 0 ? void 0 : listItems.length)) {
|
|
179
167
|
newHightlightedIndex = hightlightedIndex + 1;
|
|
@@ -181,7 +169,7 @@ var InputAddress = function InputAddress(_ref) {
|
|
|
181
169
|
} else if (keyCode === 38) {
|
|
182
170
|
// Up Key Controller
|
|
183
171
|
if (hightlightedIndex === null || hightlightedIndex === 0) {
|
|
184
|
-
newHightlightedIndex =
|
|
172
|
+
newHightlightedIndex = lastItemIndex;
|
|
185
173
|
} else if (hightlightedIndex - 1 >= 0) {
|
|
186
174
|
newHightlightedIndex = hightlightedIndex - 1;
|
|
187
175
|
}
|
|
@@ -194,23 +182,23 @@ var InputAddress = function InputAddress(_ref) {
|
|
|
194
182
|
|
|
195
183
|
if (newHightlightedElementTopInList + newHightlightedElementHeight > listScrollTop + listHeight) {
|
|
196
184
|
if (Math.abs(newHightlightedElementTopInList + newHightlightedElementHeight - (listScrollTop + listHeight)) <= newHightlightedElementHeight) {
|
|
197
|
-
var _listRef$
|
|
185
|
+
var _listRef$current3;
|
|
198
186
|
|
|
199
|
-
listRef === null || listRef === void 0 ? void 0 : (_listRef$
|
|
187
|
+
listRef === null || listRef === void 0 ? void 0 : (_listRef$current3 = listRef.current) === null || _listRef$current3 === void 0 ? void 0 : _listRef$current3.scrollTo(0, listScrollTop + newHightlightedElementHeight);
|
|
200
188
|
} else {
|
|
201
|
-
var _listRef$
|
|
189
|
+
var _listRef$current4;
|
|
202
190
|
|
|
203
|
-
listRef === null || listRef === void 0 ? void 0 : (_listRef$
|
|
191
|
+
listRef === null || listRef === void 0 ? void 0 : (_listRef$current4 = listRef.current) === null || _listRef$current4 === void 0 ? void 0 : _listRef$current4.scrollTo(0, newHightlightedElementTopInList);
|
|
204
192
|
}
|
|
205
193
|
} else if (newHightlightedElementTopInList < listScrollTop) {
|
|
206
194
|
if (Math.abs(newHightlightedElementTopInList - listScrollTop) < newHightlightedElementHeight) {
|
|
207
|
-
var _listRef$
|
|
195
|
+
var _listRef$current5;
|
|
208
196
|
|
|
209
|
-
listRef === null || listRef === void 0 ? void 0 : (_listRef$
|
|
197
|
+
listRef === null || listRef === void 0 ? void 0 : (_listRef$current5 = listRef.current) === null || _listRef$current5 === void 0 ? void 0 : _listRef$current5.scrollTo(0, listScrollTop - newHightlightedElementHeight);
|
|
210
198
|
} else {
|
|
211
|
-
var _listRef$
|
|
199
|
+
var _listRef$current6;
|
|
212
200
|
|
|
213
|
-
listRef === null || listRef === void 0 ? void 0 : (_listRef$
|
|
201
|
+
listRef === null || listRef === void 0 ? void 0 : (_listRef$current6 = listRef.current) === null || _listRef$current6 === void 0 ? void 0 : _listRef$current6.scrollTo(0, newHightlightedElementTopInList);
|
|
214
202
|
}
|
|
215
203
|
}
|
|
216
204
|
|
|
@@ -220,23 +208,6 @@ var InputAddress = function InputAddress(_ref) {
|
|
|
220
208
|
|
|
221
209
|
var onChangeInternal = function onChangeInternal(value) {
|
|
222
210
|
setQuery(value);
|
|
223
|
-
setIsSelectedFromList(false);
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
var onFocus = function onFocus() {
|
|
227
|
-
setIsFocused(true);
|
|
228
|
-
setInternalError(false);
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
var onBlur = function onBlur() {
|
|
232
|
-
if (typeof query === 'string' && isWrongAddress) {
|
|
233
|
-
onChange('');
|
|
234
|
-
setInternalError(true);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
setTimeout(function () {
|
|
238
|
-
return setIsFocused(false);
|
|
239
|
-
}, 50);
|
|
240
211
|
};
|
|
241
212
|
|
|
242
213
|
var getHintMessage = function getHintMessage() {
|
|
@@ -247,13 +218,13 @@ var InputAddress = function InputAddress(_ref) {
|
|
|
247
218
|
var getSelectedItemLabel = function getSelectedItemLabel() {
|
|
248
219
|
var _query$street2;
|
|
249
220
|
|
|
250
|
-
if (typeof query ===
|
|
221
|
+
if (typeof query === 'string') return query;
|
|
251
222
|
if (!renderSelectedItem || typeof renderSelectedItem !== 'function') return "".concat((query === null || query === void 0 ? void 0 : query.streetNumber) || '', " ").concat((query === null || query === void 0 ? void 0 : (_query$street2 = query.street) === null || _query$street2 === void 0 ? void 0 : _query$street2.fullName) || '');
|
|
252
223
|
return renderSelectedItem(query);
|
|
253
224
|
};
|
|
254
225
|
|
|
255
226
|
var getListItemLabel = function getListItemLabel(item) {
|
|
256
|
-
if (typeof item ===
|
|
227
|
+
if (typeof item === 'string') return item;
|
|
257
228
|
if (!renderListItem || typeof renderListItem !== 'function') return item === null || item === void 0 ? void 0 : item.fullPrediction;
|
|
258
229
|
return renderListItem(item);
|
|
259
230
|
};
|
|
@@ -297,8 +268,12 @@ var InputAddress = function InputAddress(_ref) {
|
|
|
297
268
|
className: (0, _classnames.default)('input-address__input', className),
|
|
298
269
|
value: value,
|
|
299
270
|
onChange: onChangeInternal,
|
|
300
|
-
onFocus: onFocus
|
|
301
|
-
|
|
271
|
+
onFocus: function onFocus() {
|
|
272
|
+
return setIsFocused(true);
|
|
273
|
+
},
|
|
274
|
+
onBlur: function onBlur() {
|
|
275
|
+
return setIsFocused(false);
|
|
276
|
+
},
|
|
302
277
|
onKeyDown: onKeyDown
|
|
303
278
|
}), isWrongAddress && /*#__PURE__*/_react.default.createElement("div", {
|
|
304
279
|
className: (0, _classnames.default)('input-address__alert', {
|
|
@@ -351,7 +326,7 @@ var InputAddress = function InputAddress(_ref) {
|
|
|
351
326
|
|
|
352
327
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
353
328
|
className: (0, _classnames.default)('input-address', {
|
|
354
|
-
'input-address--error': error ||
|
|
329
|
+
'input-address--error': error || isWrongAddress && !isFocused
|
|
355
330
|
})
|
|
356
331
|
}, renderInput(), isListVisible && renderList());
|
|
357
332
|
};
|