@itwin/core-react 5.19.0 → 5.21.0
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/CHANGELOG.md +4 -0
- package/lib/core-react/UiCore.js +2 -1
- package/lib/core-react/UiCore.js.map +1 -1
- package/lib/core-react/autosuggest/AutoSuggest.js +86 -86
- package/lib/core-react/autosuggest/AutoSuggest.js.map +1 -1
- package/lib/core-react/contextmenu/ContextMenu.js +272 -269
- package/lib/core-react/contextmenu/ContextMenu.js.map +1 -1
- package/lib/core-react/contextmenu/ContextMenuItem.js +57 -55
- package/lib/core-react/contextmenu/ContextMenuItem.js.map +1 -1
- package/lib/core-react/contextmenu/ContextSubMenu.js +70 -67
- package/lib/core-react/contextmenu/ContextSubMenu.js.map +1 -1
- package/lib/core-react/contextmenu/GlobalContextMenu.js +23 -22
- package/lib/core-react/contextmenu/GlobalContextMenu.js.map +1 -1
- package/lib/core-react/contextmenu/TildeFinder.js +52 -52
- package/lib/core-react/contextmenu/TildeFinder.js.map +1 -1
- package/lib/core-react/dialog/Dialog.js +29 -29
- package/lib/core-react/dialog/Dialog.js.map +1 -1
- package/lib/core-react/dialog/GlobalDialog.js +24 -23
- package/lib/core-react/dialog/GlobalDialog.js.map +1 -1
- package/lib/core-react/expandable/ExpandableList.js +15 -15
- package/lib/core-react/expandable/ExpandableList.js.map +1 -1
- package/lib/core-react/focus/ItemKeyboardNavigator.js +7 -3
- package/lib/core-react/focus/ItemKeyboardNavigator.js.map +1 -1
- package/lib/core-react/hocs/withIsPressed.js +14 -17
- package/lib/core-react/hocs/withIsPressed.js.map +1 -1
- package/lib/core-react/hocs/withOnOutsideClick.js +38 -41
- package/lib/core-react/hocs/withOnOutsideClick.js.map +1 -1
- package/lib/core-react/hocs/withTimeout.js +2 -5
- package/lib/core-react/hocs/withTimeout.js.map +1 -1
- package/lib/core-react/icons/ConditionalIconItem.js +3 -0
- package/lib/core-react/icons/ConditionalIconItem.js.map +1 -1
- package/lib/core-react/imagecheckbox/ImageCheckBox.js +15 -18
- package/lib/core-react/imagecheckbox/ImageCheckBox.js.map +1 -1
- package/lib/core-react/loading/LoadingBar.js +3 -3
- package/lib/core-react/loading/LoadingBar.js.map +1 -1
- package/lib/core-react/loading/LoadingPrompt.js +9 -9
- package/lib/core-react/loading/LoadingPrompt.js.map +1 -1
- package/lib/core-react/loading/LoadingSpinner.js +3 -3
- package/lib/core-react/loading/LoadingSpinner.js.map +1 -1
- package/lib/core-react/loading/LoadingStatus.js +4 -4
- package/lib/core-react/loading/LoadingStatus.js.map +1 -1
- package/lib/core-react/messagebox/MessageBox.js +6 -6
- package/lib/core-react/messagebox/MessageBox.js.map +1 -1
- package/lib/core-react/popup/Popup.js +209 -209
- package/lib/core-react/popup/Popup.js.map +1 -1
- package/lib/core-react/radialmenu/Annulus.js +19 -2
- package/lib/core-react/radialmenu/Annulus.js.map +1 -1
- package/lib/core-react/radialmenu/RadialMenu.js +56 -56
- package/lib/core-react/radialmenu/RadialMenu.js.map +1 -1
- package/lib/core-react/searchbox/SearchBox.js +60 -60
- package/lib/core-react/searchbox/SearchBox.js.map +1 -1
- package/lib/core-react/settings/SettingsManager.js +20 -22
- package/lib/core-react/settings/SettingsManager.js.map +1 -1
- package/lib/core-react/tabs/Tabs.js +14 -13
- package/lib/core-react/tabs/Tabs.js.map +1 -1
- package/lib/core-react/tree/Node.js +18 -18
- package/lib/core-react/tree/Node.js.map +1 -1
- package/lib/core-react/tree/Tree.js +1 -4
- package/lib/core-react/tree/Tree.js.map +1 -1
- package/lib/core-react/uistate/LocalStateStorage.js +1 -0
- package/lib/core-react/uistate/LocalStateStorage.js.map +1 -1
- package/lib/core-react/uistate/UiStateEntry.js +5 -0
- package/lib/core-react/uistate/UiStateEntry.js.map +1 -1
- package/lib/core-react/utils/Point.js +2 -0
- package/lib/core-react/utils/Point.js.map +1 -1
- package/lib/core-react/utils/Rectangle.js +4 -0
- package/lib/core-react/utils/Rectangle.js.map +1 -1
- package/lib/core-react/utils/ScrollPositionMaintainer.js +1 -0
- package/lib/core-react/utils/ScrollPositionMaintainer.js.map +1 -1
- package/lib/core-react/utils/Timer.js +5 -2
- package/lib/core-react/utils/Timer.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/lib/core-react/UiCore.js
CHANGED
|
@@ -17,6 +17,8 @@ import { Logger } from "@itwin/core-bentley";
|
|
|
17
17
|
* @deprecated in 4.16.0. `@itwin/core-react` package is deprecated, see used modules for suggested replacements.
|
|
18
18
|
*/
|
|
19
19
|
export class UiCore {
|
|
20
|
+
static _initialized = false;
|
|
21
|
+
static _localization;
|
|
20
22
|
/**
|
|
21
23
|
* Registers the Localization service namespace for UiCore.
|
|
22
24
|
* @param localization The internationalization service created by the host application.
|
|
@@ -65,5 +67,4 @@ export class UiCore {
|
|
|
65
67
|
return `${UiCore.packageName}.${name}`;
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
|
-
UiCore._initialized = false;
|
|
69
70
|
//# sourceMappingURL=UiCore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UiCore.js","sourceRoot":"","sources":["../../src/core-react/UiCore.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,4EAA4E;AAC5E,OAAO,oBAAoB,CAAC;AAC5B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,yBAAyB,CAAC;AACjC,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,qDAAqD;AAErD;;;GAGG;AACH,MAAM,OAAO,MAAM;
|
|
1
|
+
{"version":3,"file":"UiCore.js","sourceRoot":"","sources":["../../src/core-react/UiCore.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,4EAA4E;AAC5E,OAAO,oBAAoB,CAAC;AAC5B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,yBAAyB,CAAC;AACjC,OAAO,gBAAgB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,OAAO,MAAM,CAAC,aAAa,CAAC,kBAAkB,CAC5C,GAAG,MAAM,CAAC,qBAAqB,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CACjD,CAAC;IACJ,CAAC;IAED,gBAAgB;IACT,MAAM,KAAK,WAAW;QAC3B,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,gBAAgB;IACT,MAAM,CAAC,cAAc,CAAC,IAAY;QACvC,OAAO,GAAG,MAAM,CAAC,WAAW,IAAI,IAAI,EAAE,CAAC;IACzC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Utilities\n */\n\n/** Import color variables, layout variables and Sass classes barrel file */\nimport \"./colorthemes.scss\";\nimport \"./colorvariables.scss\";\nimport \"./layout-variables.scss\";\nimport \"./classes.scss\";\n\nimport { Logger } from \"@itwin/core-bentley\";\nimport type { Localization } from \"@itwin/core-common\";\n\n/* eslint-disable @typescript-eslint/no-deprecated */\n\n/** Manages the Localization service for the core-react package.\n * @public\n * @deprecated in 4.16.0. `@itwin/core-react` package is deprecated, see used modules for suggested replacements.\n */\nexport class UiCore {\n private static _initialized = false;\n private static _localization?: Localization;\n\n /**\n * Registers the Localization service namespace for UiCore.\n * @param localization The internationalization service created by the host application.\n */\n public static async initialize(localization: Localization): Promise<void> {\n if (UiCore._initialized) {\n Logger.logInfo(\n UiCore.loggerCategory(\"UiCore\"),\n `UiCore.initialize already called`\n );\n return;\n }\n\n UiCore._localization = localization;\n await UiCore._localization.registerNamespace(UiCore.localizationNamespace);\n\n UiCore._initialized = true;\n }\n\n /** Unregisters the UiCore localization namespace */\n public static terminate() {\n if (UiCore._localization)\n UiCore._localization.unregisterNamespace(UiCore.localizationNamespace);\n UiCore._localization = undefined;\n\n UiCore._initialized = false;\n }\n\n /** Determines if UiCore has been initialized */\n public static get initialized(): boolean {\n return UiCore._initialized;\n }\n\n /** The internationalization service namespace. */\n public static get localizationNamespace(): string {\n return \"UiCore\";\n }\n\n /** Calls localization.getLocalizedString with the \"UiCore\" namespace. Do NOT include the namespace in the key.\n * @deprecated in 4.12.0. Do not use this internally, this is replaced by `useTranslation`.\n * @internal\n */\n public static translate(key: string | string[]): string {\n if (!UiCore._localization) {\n Logger.logError(\n UiCore.loggerCategory(\"UiCore\"),\n `translate: UiCore must be initialize with a localization provider. Returning blank string.`\n );\n return \"\";\n }\n return UiCore._localization.getLocalizedString(\n `${UiCore.localizationNamespace}:${String(key)}`\n );\n }\n\n /** @internal */\n public static get packageName(): string {\n return \"core-react\";\n }\n\n /** @internal */\n public static loggerCategory(name: string): string {\n return `${UiCore.packageName}.${name}`;\n }\n}\n"]}
|
|
@@ -17,94 +17,9 @@ import { UiCore } from "../UiCore.js";
|
|
|
17
17
|
* @deprecated in 4.16.0. Use {@link https://itwinui.bentley.com/ iTwinUI components} instead.
|
|
18
18
|
*/
|
|
19
19
|
export class AutoSuggest extends React.PureComponent {
|
|
20
|
+
_isMounted = false;
|
|
20
21
|
constructor(props) {
|
|
21
22
|
super(props);
|
|
22
|
-
this._isMounted = false;
|
|
23
|
-
this._onChange = (e) => {
|
|
24
|
-
let newValue = "";
|
|
25
|
-
if (e.target.tagName === "LI" && e.target.textContent)
|
|
26
|
-
newValue = e.target.textContent;
|
|
27
|
-
else if (e.target.value)
|
|
28
|
-
newValue = e.target.value;
|
|
29
|
-
this.setState({
|
|
30
|
-
inputValue: newValue,
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
this._onFocus = (e) => {
|
|
34
|
-
if (this.props.onInputFocus)
|
|
35
|
-
this.props.onInputFocus(e);
|
|
36
|
-
};
|
|
37
|
-
/** Autosuggest will call this function every time you need to update suggestions. */
|
|
38
|
-
this._onSuggestionsFetchRequested = async (request) => {
|
|
39
|
-
const value = request.value;
|
|
40
|
-
const suggestions = await this._getSuggestions(value);
|
|
41
|
-
if (this._isMounted)
|
|
42
|
-
this.setState({ suggestions });
|
|
43
|
-
};
|
|
44
|
-
/** Autosuggest will call this function every time you need to clear suggestions. */
|
|
45
|
-
this._onSuggestionsClearRequested = () => {
|
|
46
|
-
this.setState({ suggestions: [] });
|
|
47
|
-
this.props.onSuggestionsClearRequested &&
|
|
48
|
-
this.props.onSuggestionsClearRequested();
|
|
49
|
-
};
|
|
50
|
-
this._onSuggestionSelected = (_event, data) => {
|
|
51
|
-
this.props.onSuggestionSelected(data.suggestion);
|
|
52
|
-
};
|
|
53
|
-
/** Teach Autosuggest how to calculate suggestions for any given input value. */
|
|
54
|
-
this._getSuggestions = async (value) => {
|
|
55
|
-
if (typeof this.props.options === "function")
|
|
56
|
-
return Promise.resolve(this.props.options(value));
|
|
57
|
-
if (this.props.getSuggestions)
|
|
58
|
-
return this.props.getSuggestions(value);
|
|
59
|
-
if (this.props.options === undefined) {
|
|
60
|
-
Logger.logError(UiCore.loggerCategory("AutoSuggest"), `props.options or props.getSuggestions should be provided`);
|
|
61
|
-
return Promise.resolve([]);
|
|
62
|
-
}
|
|
63
|
-
const inputValue = value.trim().toLowerCase();
|
|
64
|
-
const inputLength = inputValue.length;
|
|
65
|
-
return Promise.resolve(inputLength === 0
|
|
66
|
-
? []
|
|
67
|
-
: this.props.options.filter((data) => {
|
|
68
|
-
return (data.label.toLowerCase().includes(inputValue) ||
|
|
69
|
-
data.value.toLowerCase().includes(inputValue));
|
|
70
|
-
}));
|
|
71
|
-
};
|
|
72
|
-
/** When suggestion is clicked, Autosuggest needs to populate the input based on the clicked suggestion. */
|
|
73
|
-
this._getSuggestionValue = (suggestion) => suggestion.label;
|
|
74
|
-
/** Render each suggestion. */
|
|
75
|
-
this._renderSuggestion = (suggestion) => (React.createElement("span", null, suggestion.label));
|
|
76
|
-
this._handleKeyDown = (e) => {
|
|
77
|
-
switch (e.key) {
|
|
78
|
-
case Key.Enter.valueOf():
|
|
79
|
-
if (this.props.onPressEnter)
|
|
80
|
-
this.props.onPressEnter(e);
|
|
81
|
-
break;
|
|
82
|
-
case Key.Escape.valueOf():
|
|
83
|
-
if (this.props.onPressEscape)
|
|
84
|
-
this.props.onPressEscape(e);
|
|
85
|
-
break;
|
|
86
|
-
case Key.Tab.valueOf():
|
|
87
|
-
if (this.props.onPressTab)
|
|
88
|
-
this.props.onPressTab(e);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
this._theme = {
|
|
93
|
-
container: "uicore-autosuggest__container",
|
|
94
|
-
containerOpen: "uicore-autosuggest__container--open",
|
|
95
|
-
input: "uicore-autosuggest__input",
|
|
96
|
-
inputOpen: "uicore-autosuggest__input--open",
|
|
97
|
-
inputFocused: "uicore-autosuggest__input--focused",
|
|
98
|
-
suggestionsContainer: "uicore-autosuggest__suggestions-container",
|
|
99
|
-
suggestionsContainerOpen: "uicore-autosuggest__suggestions-container--open",
|
|
100
|
-
suggestionsList: "uicore-autosuggest__suggestions-list",
|
|
101
|
-
suggestion: "uicore-autosuggest__suggestion",
|
|
102
|
-
suggestionFirst: "uicore-autosuggest__suggestion--first",
|
|
103
|
-
suggestionHighlighted: "uicore-autosuggest__suggestion--highlighted",
|
|
104
|
-
sectionContainer: "uicore-autosuggest__section-container",
|
|
105
|
-
sectionContainerFirst: "uicore-autosuggest__section-container--first",
|
|
106
|
-
sectionTitle: "uicore-autosuggest__section-title",
|
|
107
|
-
};
|
|
108
23
|
// Autosuggest is a controlled component.
|
|
109
24
|
// This means that you need to provide an input value
|
|
110
25
|
// and an onChange handler that updates this value (see below).
|
|
@@ -130,6 +45,59 @@ export class AutoSuggest extends React.PureComponent {
|
|
|
130
45
|
}));
|
|
131
46
|
}
|
|
132
47
|
}
|
|
48
|
+
_onChange = (e) => {
|
|
49
|
+
let newValue = "";
|
|
50
|
+
if (e.target.tagName === "LI" && e.target.textContent)
|
|
51
|
+
newValue = e.target.textContent;
|
|
52
|
+
else if (e.target.value)
|
|
53
|
+
newValue = e.target.value;
|
|
54
|
+
this.setState({
|
|
55
|
+
inputValue: newValue,
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
_onFocus = (e) => {
|
|
59
|
+
if (this.props.onInputFocus)
|
|
60
|
+
this.props.onInputFocus(e);
|
|
61
|
+
};
|
|
62
|
+
/** Autosuggest will call this function every time you need to update suggestions. */
|
|
63
|
+
_onSuggestionsFetchRequested = async (request) => {
|
|
64
|
+
const value = request.value;
|
|
65
|
+
const suggestions = await this._getSuggestions(value);
|
|
66
|
+
if (this._isMounted)
|
|
67
|
+
this.setState({ suggestions });
|
|
68
|
+
};
|
|
69
|
+
/** Autosuggest will call this function every time you need to clear suggestions. */
|
|
70
|
+
_onSuggestionsClearRequested = () => {
|
|
71
|
+
this.setState({ suggestions: [] });
|
|
72
|
+
this.props.onSuggestionsClearRequested &&
|
|
73
|
+
this.props.onSuggestionsClearRequested();
|
|
74
|
+
};
|
|
75
|
+
_onSuggestionSelected = (_event, data) => {
|
|
76
|
+
this.props.onSuggestionSelected(data.suggestion);
|
|
77
|
+
};
|
|
78
|
+
/** Teach Autosuggest how to calculate suggestions for any given input value. */
|
|
79
|
+
_getSuggestions = async (value) => {
|
|
80
|
+
if (typeof this.props.options === "function")
|
|
81
|
+
return Promise.resolve(this.props.options(value));
|
|
82
|
+
if (this.props.getSuggestions)
|
|
83
|
+
return this.props.getSuggestions(value);
|
|
84
|
+
if (this.props.options === undefined) {
|
|
85
|
+
Logger.logError(UiCore.loggerCategory("AutoSuggest"), `props.options or props.getSuggestions should be provided`);
|
|
86
|
+
return Promise.resolve([]);
|
|
87
|
+
}
|
|
88
|
+
const inputValue = value.trim().toLowerCase();
|
|
89
|
+
const inputLength = inputValue.length;
|
|
90
|
+
return Promise.resolve(inputLength === 0
|
|
91
|
+
? []
|
|
92
|
+
: this.props.options.filter((data) => {
|
|
93
|
+
return (data.label.toLowerCase().includes(inputValue) ||
|
|
94
|
+
data.value.toLowerCase().includes(inputValue));
|
|
95
|
+
}));
|
|
96
|
+
};
|
|
97
|
+
/** When suggestion is clicked, Autosuggest needs to populate the input based on the clicked suggestion. */
|
|
98
|
+
_getSuggestionValue = (suggestion) => suggestion.label;
|
|
99
|
+
/** Render each suggestion. */
|
|
100
|
+
_renderSuggestion = (suggestion) => (React.createElement("span", null, suggestion.label));
|
|
133
101
|
getLabel(value) {
|
|
134
102
|
let label = "";
|
|
135
103
|
if (this.props.getLabel) {
|
|
@@ -145,6 +113,38 @@ export class AutoSuggest extends React.PureComponent {
|
|
|
145
113
|
}
|
|
146
114
|
return label;
|
|
147
115
|
}
|
|
116
|
+
_handleKeyDown = (e) => {
|
|
117
|
+
switch (e.key) {
|
|
118
|
+
case Key.Enter.valueOf():
|
|
119
|
+
if (this.props.onPressEnter)
|
|
120
|
+
this.props.onPressEnter(e);
|
|
121
|
+
break;
|
|
122
|
+
case Key.Escape.valueOf():
|
|
123
|
+
if (this.props.onPressEscape)
|
|
124
|
+
this.props.onPressEscape(e);
|
|
125
|
+
break;
|
|
126
|
+
case Key.Tab.valueOf():
|
|
127
|
+
if (this.props.onPressTab)
|
|
128
|
+
this.props.onPressTab(e);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
_theme = {
|
|
133
|
+
container: "uicore-autosuggest__container",
|
|
134
|
+
containerOpen: "uicore-autosuggest__container--open",
|
|
135
|
+
input: "uicore-autosuggest__input",
|
|
136
|
+
inputOpen: "uicore-autosuggest__input--open",
|
|
137
|
+
inputFocused: "uicore-autosuggest__input--focused",
|
|
138
|
+
suggestionsContainer: "uicore-autosuggest__suggestions-container",
|
|
139
|
+
suggestionsContainerOpen: "uicore-autosuggest__suggestions-container--open",
|
|
140
|
+
suggestionsList: "uicore-autosuggest__suggestions-list",
|
|
141
|
+
suggestion: "uicore-autosuggest__suggestion",
|
|
142
|
+
suggestionFirst: "uicore-autosuggest__suggestion--first",
|
|
143
|
+
suggestionHighlighted: "uicore-autosuggest__suggestion--highlighted",
|
|
144
|
+
sectionContainer: "uicore-autosuggest__section-container",
|
|
145
|
+
sectionContainerFirst: "uicore-autosuggest__section-container--first",
|
|
146
|
+
sectionTitle: "uicore-autosuggest__section-title",
|
|
147
|
+
};
|
|
148
148
|
render() {
|
|
149
149
|
const { inputValue, suggestions } = this.state;
|
|
150
150
|
const { value, onChange, placeholder, options, onSuggestionSelected, setFocus, alwaysRenderSuggestions, onPressEnter, onPressEscape, onPressTab, onInputFocus, getLabel, getSuggestions, renderInputComponent, renderSuggestionsContainer, onSuggestionsClearRequested, ...props } = this.props;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoSuggest.js","sourceRoot":"","sources":["../../../src/core-react/autosuggest/AutoSuggest.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,gBAAgB,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AA6EtC;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK,CAAC,aAGtC;IAGC,YAAY,KAAuB;QACjC,KAAK,CAAC,KAAK,CAAC,CAAC;QAHP,eAAU,GAAG,KAAK,CAAC;QAoCnB,cAAS,GAAG,CAAC,CAAsC,EAAE,EAAE;YAC7D,IAAI,QAAQ,GAAG,EAAE,CAAC;YAElB,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,WAAW;gBACnD,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;iBAC7B,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK;gBAAE,QAAQ,G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sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module AutoSuggest\n */\n\nimport \"./AutoSuggest.scss\";\nimport * as React from \"react\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport ReactAutosuggest from \"react-autosuggest\";\nimport { Key } from \"ts-key-enum\";\nimport type { CommonProps } from \"../utils/Props.js\";\nimport { UiCore } from \"../UiCore.js\";\n\n/* eslint-disable @typescript-eslint/no-deprecated */\n\n/** Data for the [[AutoSuggest]] options\n * @public\n * @deprecated in 4.16.0. Used in a deprecated interface {@link AutoSuggestProps}.\n */\nexport interface AutoSuggestData {\n /** Value of [[AutoSuggest]] option. */\n value: string;\n /** Label of [[AutoSuggest]] option. This is shown in the dropdown. */\n label: string;\n}\n\n/** Prototype for function returning AutoSuggestData\n * @public\n * @deprecated in 4.16.0. Used in a deprecated interface {@link AutoSuggestProps}.\n */\nexport type GetAutoSuggestDataFunc = (value: string) => AutoSuggestData[];\n\n/** Prototype for async function returning AutoSuggestData\n * @public\n * @deprecated in 4.16.0. Used in a deprecated interface {@link AutoSuggestProps}.\n */\nexport type AsyncGetAutoSuggestDataFunc = (\n value: string\n) => Promise<AutoSuggestData[]>;\n\n/** Properties for the [[AutoSuggest]] component.\n * @public\n * @deprecated in 4.16.0. Props of deprecated {@link AutoSuggest} component.\n */\nexport interface AutoSuggestProps\n extends React.InputHTMLAttributes<HTMLInputElement>,\n CommonProps {\n /** Optional input value override. */\n value?: string;\n /** Options for dropdown. */\n options?: AutoSuggestData[] | GetAutoSuggestDataFunc;\n /** Asynchronously calculate suggestions for any given input value. */\n getSuggestions?: AsyncGetAutoSuggestDataFunc;\n /** Gets a label associated with a given value */\n getLabel?: (value: string | undefined) => string;\n /** Handler for when suggested selected. */\n onSuggestionSelected: (selected: AutoSuggestData) => void;\n /** Handler for Enter key. */\n onPressEnter?: (e: React.KeyboardEvent<HTMLInputElement>) => void;\n /** Handler for Escape key. */\n onPressEscape?: (e: React.KeyboardEvent<HTMLInputElement>) => void;\n /** Handler for Tab key. */\n onPressTab?: (e: React.KeyboardEvent<HTMLInputElement>) => void;\n /** Handler for input receiving focus. */\n onInputFocus?: (e: React.FocusEvent<HTMLInputElement>) => void;\n /** Called every time you need to clear suggestions. */\n onSuggestionsClearRequested?: () => void;\n /** Indicates whether to set focus to the input element */\n setFocus?: boolean;\n\n /** Use it only if you need to customize the rendering of the input.\n * @internal\n */\n renderInputComponent?: any; // ReactAutosuggest.RenderInputComponent<AutoSuggestData>; NOTE: changed to \"any\" because build was failing with RenderInputComponent is not generic?\n /** Use it if you want to customize things inside the suggestions container beyond rendering the suggestions themselves.\n * @internal\n */\n renderSuggestionsContainer?: ReactAutosuggest.RenderSuggestionsContainer;\n\n /** @internal */\n alwaysRenderSuggestions?: boolean;\n}\n\ninterface AutoSuggestState {\n inputValue: string;\n suggestions: AutoSuggestData[];\n}\n\n/** Auto Suggest React component. Uses the react-autosuggest component internally.\n * @public\n * @deprecated in 4.16.0. Use {@link https://itwinui.bentley.com/ iTwinUI components} instead.\n */\nexport class AutoSuggest extends React.PureComponent<\n AutoSuggestProps,\n AutoSuggestState\n> {\n private _isMounted = false;\n\n constructor(props: AutoSuggestProps) {\n super(props);\n\n // Autosuggest is a controlled component.\n // This means that you need to provide an input value\n // and an onChange handler that updates this value (see below).\n // Suggestions also need to be provided to the Autosuggest,\n // and they are initially empty because the Autosuggest is closed.\n this.state = {\n inputValue: this.getLabel(props.value),\n suggestions: [],\n };\n }\n\n public override componentDidMount() {\n this._isMounted = true;\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: AutoSuggestProps) {\n if (\n this.props.value !== prevProps.value ||\n this.props.options !== prevProps.options\n ) {\n this.setState((_prevState, props) => ({\n inputValue: this.getLabel(props.value),\n }));\n }\n }\n\n private _onChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n let newValue = \"\";\n\n if (e.target.tagName === \"LI\" && e.target.textContent)\n newValue = e.target.textContent;\n else if (e.target.value) newValue = e.target.value;\n\n this.setState({\n inputValue: newValue,\n });\n };\n\n private _onFocus = (e: React.FocusEvent<HTMLInputElement>) => {\n if (this.props.onInputFocus) this.props.onInputFocus(e);\n };\n\n /** Autosuggest will call this function every time you need to update suggestions. */\n private _onSuggestionsFetchRequested = async (\n request: ReactAutosuggest.SuggestionsFetchRequestedParams\n ): Promise<void> => {\n const value = request.value;\n const suggestions = await this._getSuggestions(value);\n\n if (this._isMounted) this.setState({ suggestions });\n };\n\n /** Autosuggest will call this function every time you need to clear suggestions. */\n private _onSuggestionsClearRequested = () => {\n this.setState({ suggestions: [] });\n this.props.onSuggestionsClearRequested &&\n this.props.onSuggestionsClearRequested();\n };\n\n private _onSuggestionSelected = (\n _event: React.FormEvent<any>,\n data: ReactAutosuggest.SuggestionSelectedEventData<AutoSuggestData>\n ): void => {\n this.props.onSuggestionSelected(data.suggestion);\n };\n\n /** Teach Autosuggest how to calculate suggestions for any given input value. */\n private _getSuggestions = async (\n value: string\n ): Promise<AutoSuggestData[]> => {\n if (typeof this.props.options === \"function\")\n return Promise.resolve(this.props.options(value));\n\n if (this.props.getSuggestions) return this.props.getSuggestions(value);\n\n if (this.props.options === undefined) {\n Logger.logError(\n UiCore.loggerCategory(\"AutoSuggest\"),\n `props.options or props.getSuggestions should be provided`\n );\n return Promise.resolve([]);\n }\n\n const inputValue = value.trim().toLowerCase();\n const inputLength = inputValue.length;\n\n return Promise.resolve(\n inputLength === 0\n ? []\n : this.props.options.filter((data: AutoSuggestData) => {\n return (\n data.label.toLowerCase().includes(inputValue) ||\n data.value.toLowerCase().includes(inputValue)\n );\n })\n );\n };\n\n /** When suggestion is clicked, Autosuggest needs to populate the input based on the clicked suggestion. */\n private _getSuggestionValue = (suggestion: AutoSuggestData) =>\n suggestion.label;\n\n /** Render each suggestion. */\n private _renderSuggestion = (suggestion: AutoSuggestData) => (\n <span>{suggestion.label}</span>\n );\n\n private getLabel(value: string | undefined): string {\n let label = \"\";\n\n if (this.props.getLabel) {\n label = this.props.getLabel(value);\n } else if (this.props.options instanceof Array) {\n const entry = this.props.options.find(\n (data: AutoSuggestData) => data.value === value\n );\n if (entry) label = entry.label;\n } else {\n Logger.logError(\n UiCore.loggerCategory(\"AutoSuggest\"),\n `props.getLabel should be provided when props.options is a function`\n );\n }\n\n return label;\n }\n\n private _handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n switch (e.key) {\n case Key.Enter.valueOf():\n if (this.props.onPressEnter) this.props.onPressEnter(e);\n break;\n case Key.Escape.valueOf():\n if (this.props.onPressEscape) this.props.onPressEscape(e);\n break;\n case Key.Tab.valueOf():\n if (this.props.onPressTab) this.props.onPressTab(e);\n break;\n }\n };\n\n private _theme = {\n container: \"uicore-autosuggest__container\",\n containerOpen: \"uicore-autosuggest__container--open\",\n input: \"uicore-autosuggest__input\",\n inputOpen: \"uicore-autosuggest__input--open\",\n inputFocused: \"uicore-autosuggest__input--focused\",\n suggestionsContainer: \"uicore-autosuggest__suggestions-container\",\n suggestionsContainerOpen: \"uicore-autosuggest__suggestions-container--open\",\n suggestionsList: \"uicore-autosuggest__suggestions-list\",\n suggestion: \"uicore-autosuggest__suggestion\",\n suggestionFirst: \"uicore-autosuggest__suggestion--first\",\n suggestionHighlighted: \"uicore-autosuggest__suggestion--highlighted\",\n sectionContainer: \"uicore-autosuggest__section-container\",\n sectionContainerFirst: \"uicore-autosuggest__section-container--first\",\n sectionTitle: \"uicore-autosuggest__section-title\",\n };\n\n public override render(): React.ReactElement {\n const { inputValue, suggestions } = this.state;\n const {\n value,\n onChange,\n placeholder,\n options,\n onSuggestionSelected,\n setFocus,\n alwaysRenderSuggestions,\n onPressEnter,\n onPressEscape,\n onPressTab,\n onInputFocus,\n getLabel,\n getSuggestions,\n renderInputComponent,\n renderSuggestionsContainer,\n onSuggestionsClearRequested,\n ...props\n } = this.props;\n const inputPlaceholder = !inputValue ? placeholder : undefined;\n\n const inputProps: ReactAutosuggest.InputProps<AutoSuggestData> = {\n ...props,\n value: inputValue,\n onChange: this._onChange,\n onFocus: this._onFocus,\n placeholder: inputPlaceholder,\n autoFocus: setFocus,\n };\n\n const defaultRenderInputComponent: React.ComponentProps<\n typeof ReactAutosuggest\n >[\"renderInputComponent\"] = (renderInputProps) => {\n const { size, ...other } = renderInputProps;\n return <Input {...other} />;\n };\n return (\n // The onKeyDown event handler is only being used to capture bubbled events\n // eslint-disable-next-line jsx-a11y/no-static-element-interactions\n <div\n className={this.props.className}\n style={this.props.style}\n onKeyDown={this._handleKeyDown}\n >\n <ReactAutosuggest\n theme={this._theme}\n suggestions={suggestions}\n onSuggestionsFetchRequested={this._onSuggestionsFetchRequested}\n onSuggestionsClearRequested={this._onSuggestionsClearRequested}\n getSuggestionValue={this._getSuggestionValue}\n renderSuggestion={this._renderSuggestion}\n inputProps={inputProps}\n onSuggestionSelected={this._onSuggestionSelected}\n alwaysRenderSuggestions={alwaysRenderSuggestions}\n renderInputComponent={\n renderInputComponent || defaultRenderInputComponent\n }\n renderSuggestionsContainer={renderSuggestionsContainer}\n />\n </div>\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AutoSuggest.js","sourceRoot":"","sources":["../../../src/core-react/autosuggest/AutoSuggest.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,gBAAgB,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,cAA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,EAAE,IAAI,CAAC,MAAM,EAClB,WAAW,EAAE,WAAW,EACxB,2BAA2B,EAAE,IAAI,CAAC,4BAA4B,EAC9D,2BAA2B,EAAE,IAAI,CAAC,4BAA4B,EAC9D,kBAAkB,EAAE,IAAI,CAAC,mBAAmB,EAC5C,gBAAgB,EAAE,IAAI,CAAC,iBAAiB,EACxC,UAAU,EAAE,UAAU,EACtB,oBAAoB,EAAE,IAAI,CAAC,qBAAqB,EAChD,uBAAuB,EAAE,uBAAuB,EAChD,oBAAoB,EAClB,oBAAoB,IAAI,2BAA2B,EAErD,0BAA0B,EAAE,0BAA0B,GACtD,CACE,CACP,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module AutoSuggest\n */\n\nimport \"./AutoSuggest.scss\";\nimport * as React from \"react\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport ReactAutosuggest from \"react-autosuggest\";\nimport { Key } from \"ts-key-enum\";\nimport type { CommonProps } from \"../utils/Props.js\";\nimport { UiCore } from \"../UiCore.js\";\n\n/* eslint-disable @typescript-eslint/no-deprecated */\n\n/** Data for the [[AutoSuggest]] options\n * @public\n * @deprecated in 4.16.0. Used in a deprecated interface {@link AutoSuggestProps}.\n */\nexport interface AutoSuggestData {\n /** Value of [[AutoSuggest]] option. */\n value: string;\n /** Label of [[AutoSuggest]] option. This is shown in the dropdown. */\n label: string;\n}\n\n/** Prototype for function returning AutoSuggestData\n * @public\n * @deprecated in 4.16.0. Used in a deprecated interface {@link AutoSuggestProps}.\n */\nexport type GetAutoSuggestDataFunc = (value: string) => AutoSuggestData[];\n\n/** Prototype for async function returning AutoSuggestData\n * @public\n * @deprecated in 4.16.0. Used in a deprecated interface {@link AutoSuggestProps}.\n */\nexport type AsyncGetAutoSuggestDataFunc = (\n value: string\n) => Promise<AutoSuggestData[]>;\n\n/** Properties for the [[AutoSuggest]] component.\n * @public\n * @deprecated in 4.16.0. Props of deprecated {@link AutoSuggest} component.\n */\nexport interface AutoSuggestProps\n extends React.InputHTMLAttributes<HTMLInputElement>,\n CommonProps {\n /** Optional input value override. */\n value?: string;\n /** Options for dropdown. */\n options?: AutoSuggestData[] | GetAutoSuggestDataFunc;\n /** Asynchronously calculate suggestions for any given input value. */\n getSuggestions?: AsyncGetAutoSuggestDataFunc;\n /** Gets a label associated with a given value */\n getLabel?: (value: string | undefined) => string;\n /** Handler for when suggested selected. */\n onSuggestionSelected: (selected: AutoSuggestData) => void;\n /** Handler for Enter key. */\n onPressEnter?: (e: React.KeyboardEvent<HTMLInputElement>) => void;\n /** Handler for Escape key. */\n onPressEscape?: (e: React.KeyboardEvent<HTMLInputElement>) => void;\n /** Handler for Tab key. */\n onPressTab?: (e: React.KeyboardEvent<HTMLInputElement>) => void;\n /** Handler for input receiving focus. */\n onInputFocus?: (e: React.FocusEvent<HTMLInputElement>) => void;\n /** Called every time you need to clear suggestions. */\n onSuggestionsClearRequested?: () => void;\n /** Indicates whether to set focus to the input element */\n setFocus?: boolean;\n\n /** Use it only if you need to customize the rendering of the input.\n * @internal\n */\n renderInputComponent?: any; // ReactAutosuggest.RenderInputComponent<AutoSuggestData>; NOTE: changed to \"any\" because build was failing with RenderInputComponent is not generic?\n /** Use it if you want to customize things inside the suggestions container beyond rendering the suggestions themselves.\n * @internal\n */\n renderSuggestionsContainer?: ReactAutosuggest.RenderSuggestionsContainer;\n\n /** @internal */\n alwaysRenderSuggestions?: boolean;\n}\n\ninterface AutoSuggestState {\n inputValue: string;\n suggestions: AutoSuggestData[];\n}\n\n/** Auto Suggest React component. Uses the react-autosuggest component internally.\n * @public\n * @deprecated in 4.16.0. Use {@link https://itwinui.bentley.com/ iTwinUI components} instead.\n */\nexport class AutoSuggest extends React.PureComponent<\n AutoSuggestProps,\n AutoSuggestState\n> {\n private _isMounted = false;\n\n constructor(props: AutoSuggestProps) {\n super(props);\n\n // Autosuggest is a controlled component.\n // This means that you need to provide an input value\n // and an onChange handler that updates this value (see below).\n // Suggestions also need to be provided to the Autosuggest,\n // and they are initially empty because the Autosuggest is closed.\n this.state = {\n inputValue: this.getLabel(props.value),\n suggestions: [],\n };\n }\n\n public override componentDidMount() {\n this._isMounted = true;\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: AutoSuggestProps) {\n if (\n this.props.value !== prevProps.value ||\n this.props.options !== prevProps.options\n ) {\n this.setState((_prevState, props) => ({\n inputValue: this.getLabel(props.value),\n }));\n }\n }\n\n private _onChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n let newValue = \"\";\n\n if (e.target.tagName === \"LI\" && e.target.textContent)\n newValue = e.target.textContent;\n else if (e.target.value) newValue = e.target.value;\n\n this.setState({\n inputValue: newValue,\n });\n };\n\n private _onFocus = (e: React.FocusEvent<HTMLInputElement>) => {\n if (this.props.onInputFocus) this.props.onInputFocus(e);\n };\n\n /** Autosuggest will call this function every time you need to update suggestions. */\n private _onSuggestionsFetchRequested = async (\n request: ReactAutosuggest.SuggestionsFetchRequestedParams\n ): Promise<void> => {\n const value = request.value;\n const suggestions = await this._getSuggestions(value);\n\n if (this._isMounted) this.setState({ suggestions });\n };\n\n /** Autosuggest will call this function every time you need to clear suggestions. */\n private _onSuggestionsClearRequested = () => {\n this.setState({ suggestions: [] });\n this.props.onSuggestionsClearRequested &&\n this.props.onSuggestionsClearRequested();\n };\n\n private _onSuggestionSelected = (\n _event: React.FormEvent<any>,\n data: ReactAutosuggest.SuggestionSelectedEventData<AutoSuggestData>\n ): void => {\n this.props.onSuggestionSelected(data.suggestion);\n };\n\n /** Teach Autosuggest how to calculate suggestions for any given input value. */\n private _getSuggestions = async (\n value: string\n ): Promise<AutoSuggestData[]> => {\n if (typeof this.props.options === \"function\")\n return Promise.resolve(this.props.options(value));\n\n if (this.props.getSuggestions) return this.props.getSuggestions(value);\n\n if (this.props.options === undefined) {\n Logger.logError(\n UiCore.loggerCategory(\"AutoSuggest\"),\n `props.options or props.getSuggestions should be provided`\n );\n return Promise.resolve([]);\n }\n\n const inputValue = value.trim().toLowerCase();\n const inputLength = inputValue.length;\n\n return Promise.resolve(\n inputLength === 0\n ? []\n : this.props.options.filter((data: AutoSuggestData) => {\n return (\n data.label.toLowerCase().includes(inputValue) ||\n data.value.toLowerCase().includes(inputValue)\n );\n })\n );\n };\n\n /** When suggestion is clicked, Autosuggest needs to populate the input based on the clicked suggestion. */\n private _getSuggestionValue = (suggestion: AutoSuggestData) =>\n suggestion.label;\n\n /** Render each suggestion. */\n private _renderSuggestion = (suggestion: AutoSuggestData) => (\n <span>{suggestion.label}</span>\n );\n\n private getLabel(value: string | undefined): string {\n let label = \"\";\n\n if (this.props.getLabel) {\n label = this.props.getLabel(value);\n } else if (this.props.options instanceof Array) {\n const entry = this.props.options.find(\n (data: AutoSuggestData) => data.value === value\n );\n if (entry) label = entry.label;\n } else {\n Logger.logError(\n UiCore.loggerCategory(\"AutoSuggest\"),\n `props.getLabel should be provided when props.options is a function`\n );\n }\n\n return label;\n }\n\n private _handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n switch (e.key) {\n case Key.Enter.valueOf():\n if (this.props.onPressEnter) this.props.onPressEnter(e);\n break;\n case Key.Escape.valueOf():\n if (this.props.onPressEscape) this.props.onPressEscape(e);\n break;\n case Key.Tab.valueOf():\n if (this.props.onPressTab) this.props.onPressTab(e);\n break;\n }\n };\n\n private _theme = {\n container: \"uicore-autosuggest__container\",\n containerOpen: \"uicore-autosuggest__container--open\",\n input: \"uicore-autosuggest__input\",\n inputOpen: \"uicore-autosuggest__input--open\",\n inputFocused: \"uicore-autosuggest__input--focused\",\n suggestionsContainer: \"uicore-autosuggest__suggestions-container\",\n suggestionsContainerOpen: \"uicore-autosuggest__suggestions-container--open\",\n suggestionsList: \"uicore-autosuggest__suggestions-list\",\n suggestion: \"uicore-autosuggest__suggestion\",\n suggestionFirst: \"uicore-autosuggest__suggestion--first\",\n suggestionHighlighted: \"uicore-autosuggest__suggestion--highlighted\",\n sectionContainer: \"uicore-autosuggest__section-container\",\n sectionContainerFirst: \"uicore-autosuggest__section-container--first\",\n sectionTitle: \"uicore-autosuggest__section-title\",\n };\n\n public override render(): React.ReactElement {\n const { inputValue, suggestions } = this.state;\n const {\n value,\n onChange,\n placeholder,\n options,\n onSuggestionSelected,\n setFocus,\n alwaysRenderSuggestions,\n onPressEnter,\n onPressEscape,\n onPressTab,\n onInputFocus,\n getLabel,\n getSuggestions,\n renderInputComponent,\n renderSuggestionsContainer,\n onSuggestionsClearRequested,\n ...props\n } = this.props;\n const inputPlaceholder = !inputValue ? placeholder : undefined;\n\n const inputProps: ReactAutosuggest.InputProps<AutoSuggestData> = {\n ...props,\n value: inputValue,\n onChange: this._onChange,\n onFocus: this._onFocus,\n placeholder: inputPlaceholder,\n autoFocus: setFocus,\n };\n\n const defaultRenderInputComponent: React.ComponentProps<\n typeof ReactAutosuggest\n >[\"renderInputComponent\"] = (renderInputProps) => {\n const { size, ...other } = renderInputProps;\n return <Input {...other} />;\n };\n return (\n // The onKeyDown event handler is only being used to capture bubbled events\n // eslint-disable-next-line jsx-a11y/no-static-element-interactions\n <div\n className={this.props.className}\n style={this.props.style}\n onKeyDown={this._handleKeyDown}\n >\n <ReactAutosuggest\n theme={this._theme}\n suggestions={suggestions}\n onSuggestionsFetchRequested={this._onSuggestionsFetchRequested}\n onSuggestionsClearRequested={this._onSuggestionsClearRequested}\n getSuggestionValue={this._getSuggestionValue}\n renderSuggestion={this._renderSuggestion}\n inputProps={inputProps}\n onSuggestionSelected={this._onSuggestionSelected}\n alwaysRenderSuggestions={alwaysRenderSuggestions}\n renderInputComponent={\n renderInputComponent || defaultRenderInputComponent\n }\n renderSuggestionsContainer={renderSuggestionsContainer}\n />\n </div>\n );\n }\n}\n"]}
|