@tripian/react 9.1.52 → 9.1.53
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/components/PoiSearchAutoComplete/PoiSearchAutoComplete.d.ts +2 -0
- package/index.js +60 -7
- package/index.js.map +1 -1
- package/min.css +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import Model from '@tripian/model';
|
|
2
3
|
import { RSelectOption } from '../base/RSelect/RSelect';
|
|
3
4
|
interface IPoiSearchAutoComplete {
|
|
4
5
|
inputValue: string;
|
|
@@ -11,6 +12,7 @@ interface IPoiSearchAutoComplete {
|
|
|
11
12
|
placeHolder?: string;
|
|
12
13
|
isDisabled?: boolean;
|
|
13
14
|
isLoading?: boolean;
|
|
15
|
+
t: (value: Model.TranslationKey) => string;
|
|
14
16
|
}
|
|
15
17
|
declare const PoiSearchAutoComplete: React.FC<IPoiSearchAutoComplete>;
|
|
16
18
|
export default PoiSearchAutoComplete;
|
package/index.js
CHANGED
|
@@ -19864,7 +19864,7 @@ var index_641ee5b8_esm = __webpack_require__(8);
|
|
|
19864
19864
|
// EXTERNAL MODULE: ./node_modules/@emotion/react/dist/emotion-react.esm.js
|
|
19865
19865
|
var emotion_react_esm = __webpack_require__(5);
|
|
19866
19866
|
|
|
19867
|
-
// EXTERNAL MODULE: ./node_modules/memoize-one/dist/memoize-one.esm.js
|
|
19867
|
+
// EXTERNAL MODULE: ./node_modules/react-select/node_modules/memoize-one/dist/memoize-one.esm.js
|
|
19868
19868
|
var memoize_one_esm = __webpack_require__(123);
|
|
19869
19869
|
|
|
19870
19870
|
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js + 1 modules
|
|
@@ -87671,23 +87671,76 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
87671
87671
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
87672
87672
|
};
|
|
87673
87673
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
87674
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
87674
87675
|
const react_1 = __importStar(__webpack_require__(0));
|
|
87675
87676
|
const creatable_1 = __importDefault(__webpack_require__(1112));
|
|
87676
87677
|
const PoiSearchAutoComplete_scss_1 = __importDefault(__webpack_require__(1020));
|
|
87677
|
-
const
|
|
87678
|
+
const ITEM_HEIGHT = 35;
|
|
87679
|
+
const WINDOW_SIZE = 10;
|
|
87680
|
+
const BUFFER_SIZE = Math.ceil(WINDOW_SIZE * 0.5);
|
|
87681
|
+
const VirtualizedMenuList = ({ children: childrenProp, maxHeight }) => {
|
|
87682
|
+
const menuRef = (0, react_1.useRef)(null);
|
|
87683
|
+
const [scrollTop, setScrollTop] = react_1.default.useState(0);
|
|
87684
|
+
const children = react_1.default.Children.toArray(childrenProp);
|
|
87685
|
+
const handleScroll = (0, react_1.useCallback)((e) => {
|
|
87686
|
+
setScrollTop(e.currentTarget.scrollTop);
|
|
87687
|
+
}, []);
|
|
87688
|
+
const isNoOptionsMessage = (child) => {
|
|
87689
|
+
if (!react_1.default.isValidElement(child) || !('props' in child))
|
|
87690
|
+
return false;
|
|
87691
|
+
const props = child.props;
|
|
87692
|
+
return Array.isArray(props.options) && props.options.length === 0;
|
|
87693
|
+
};
|
|
87694
|
+
const totalHeight = children.length * ITEM_HEIGHT;
|
|
87695
|
+
const startIndex = Math.max(0, Math.floor(scrollTop / ITEM_HEIGHT) - BUFFER_SIZE);
|
|
87696
|
+
const endIndex = Math.min(startIndex + WINDOW_SIZE + BUFFER_SIZE * 2, children.length);
|
|
87697
|
+
const visibleChildren = children.slice(startIndex, endIndex);
|
|
87698
|
+
const offsetY = startIndex * ITEM_HEIGHT;
|
|
87699
|
+
if (children.length === 1 && isNoOptionsMessage(children[0])) {
|
|
87700
|
+
return (react_1.default.createElement("div", { ref: menuRef, style: {
|
|
87701
|
+
maxHeight: 300,
|
|
87702
|
+
height: 'auto',
|
|
87703
|
+
overflow: 'auto',
|
|
87704
|
+
position: 'relative',
|
|
87705
|
+
} }, children));
|
|
87706
|
+
}
|
|
87707
|
+
return (react_1.default.createElement("div", { ref: menuRef, style: {
|
|
87708
|
+
height: children.length === 1 && isNoOptionsMessage(children[0]) ? 'auto' : maxHeight,
|
|
87709
|
+
overflow: 'auto',
|
|
87710
|
+
position: 'relative',
|
|
87711
|
+
margin: children.length === 1 && isNoOptionsMessage(children[0]) ? '0' : '1rem 0',
|
|
87712
|
+
}, onScroll: handleScroll },
|
|
87713
|
+
react_1.default.createElement("div", { style: { height: totalHeight, position: 'relative' } },
|
|
87714
|
+
react_1.default.createElement("div", { style: {
|
|
87715
|
+
position: 'absolute',
|
|
87716
|
+
top: offsetY,
|
|
87717
|
+
left: 0,
|
|
87718
|
+
right: 0,
|
|
87719
|
+
} },
|
|
87720
|
+
react_1.default.createElement("div", { className: "visible-children" }, visibleChildren)))));
|
|
87721
|
+
};
|
|
87722
|
+
const PoiSearchAutoComplete = ({ inputValue, options, selectedOptionValues, onSelectedOptionChange, onInputChange, onKeyDown, onCreateOption, placeHolder, isDisabled = false, isLoading = false, t }) => {
|
|
87678
87723
|
const [localOptions, setLocalOptions] = react_1.default.useState([]);
|
|
87679
87724
|
(0, react_1.useEffect)(() => {
|
|
87680
87725
|
if (Array.isArray(options) && options.length > 0) {
|
|
87681
87726
|
setLocalOptions(options);
|
|
87682
87727
|
}
|
|
87683
87728
|
}, [options]);
|
|
87684
|
-
const selectedOptions = (0, react_1.useMemo)(() =>
|
|
87685
|
-
|
|
87686
|
-
|
|
87729
|
+
const selectedOptions = (0, react_1.useMemo)(() => {
|
|
87730
|
+
if (!selectedOptionValues.length)
|
|
87731
|
+
return [];
|
|
87732
|
+
return localOptions.filter((option) => selectedOptionValues.includes(option.value));
|
|
87733
|
+
}, [selectedOptionValues, localOptions]);
|
|
87734
|
+
const availableOptions = (0, react_1.useMemo)(() => {
|
|
87735
|
+
if (!selectedOptionValues.length)
|
|
87736
|
+
return localOptions;
|
|
87737
|
+
return localOptions.filter((option) => !selectedOptionValues.includes(option.value));
|
|
87738
|
+
}, [localOptions, selectedOptionValues]);
|
|
87739
|
+
const handleChange = (0, react_1.useCallback)((newSelectedOptions) => {
|
|
87687
87740
|
onSelectedOptionChange(newSelectedOptions);
|
|
87688
|
-
};
|
|
87741
|
+
}, [onSelectedOptionChange]);
|
|
87689
87742
|
return (react_1.default.createElement("div", { className: PoiSearchAutoComplete_scss_1.default.poiSearchAutoComplete },
|
|
87690
|
-
react_1.default.createElement(creatable_1.default, { className: "trpReactCreatableSelectMulti", classNamePrefix: "trpReactCreatableSelectMulti", onCreateOption: onCreateOption, isMulti: true, options: availableOptions, value: selectedOptions, isClearable: false, isSearchable: true, onChange: handleChange, controlShouldRenderValue: false, inputValue: inputValue || '', placeholder: placeHolder, onInputChange: onInputChange, formatCreateLabel: (userInput) => userInput, onKeyDown: onKeyDown, isDisabled: isDisabled, isLoading: isLoading, loadingMessage: () => '
|
|
87743
|
+
react_1.default.createElement(creatable_1.default, { className: "trpReactCreatableSelectMulti", classNamePrefix: "trpReactCreatableSelectMulti", onCreateOption: onCreateOption, isMulti: true, options: availableOptions, value: selectedOptions, isClearable: false, isSearchable: true, onChange: handleChange, controlShouldRenderValue: false, inputValue: inputValue || '', placeholder: placeHolder, onInputChange: onInputChange, formatCreateLabel: (userInput) => userInput, onKeyDown: onKeyDown, isDisabled: isDisabled, isLoading: isLoading, loadingMessage: () => `${t('trips.myTrips.itinerary.offers.qrWriter.loading')}...`, noOptionsMessage: () => react_1.default.createElement("div", { "data-no-options-message": true }, t('trips.myTrips.exploreMore.noResultsFound')), maxMenuHeight: 300, menuPlacement: "bottom", menuShouldScrollIntoView: true, menuShouldBlockScroll: true, components: { MenuList: VirtualizedMenuList } })));
|
|
87691
87744
|
};
|
|
87692
87745
|
exports.default = PoiSearchAutoComplete;
|
|
87693
87746
|
|