@constructor-io/constructorio-ui-autocomplete 1.23.13 → 1.23.15
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/constructorio-ui-autocomplete-bundled.js +12 -12
- package/lib/cjs/components/Autocomplete/SectionItem/SearchSuggestionItem.js +22 -0
- package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js +11 -12
- package/lib/cjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +7 -2
- package/lib/cjs/constants.js +3 -1
- package/lib/cjs/hooks/useCioAutocomplete.js +2 -1
- package/lib/cjs/utils.js +9 -0
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/Autocomplete/SectionItem/SearchSuggestionItem.js +17 -0
- package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js +10 -11
- package/lib/mjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +7 -2
- package/lib/mjs/constants.js +2 -0
- package/lib/mjs/hooks/useCioAutocomplete.js +2 -1
- package/lib/mjs/utils.js +9 -0
- package/lib/mjs/version.js +1 -1
- package/lib/styles.css +8 -0
- package/lib/types/components/Autocomplete/CioAutocompleteProvider.d.ts +1 -0
- package/lib/types/components/Autocomplete/SectionItem/SearchSuggestionItem.d.ts +8 -0
- package/lib/types/constants.d.ts +1 -0
- package/lib/types/hooks/useCioAutocomplete.d.ts +1 -0
- package/lib/types/types.d.ts +5 -0
- package/lib/types/utils.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
|
+
const SectionItemText_1 = tslib_1.__importDefault(require("./SectionItemText"));
|
|
6
|
+
const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
|
|
7
|
+
function SearchSuggestionItem(props) {
|
|
8
|
+
var _a, _b, _c, _d;
|
|
9
|
+
const { item, displaySearchTermHighlights } = props;
|
|
10
|
+
const { advancedParameters, query, featureToggles } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
11
|
+
const { featureDisplaySearchSuggestionImages, featureDisplaySearchSuggestionResultCounts } = featureToggles;
|
|
12
|
+
const { displaySearchSuggestionImages = featureDisplaySearchSuggestionImages, displaySearchSuggestionResultCounts = featureDisplaySearchSuggestionResultCounts, } = advancedParameters || {};
|
|
13
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
14
|
+
displaySearchSuggestionImages && ((_a = item.data) === null || _a === void 0 ? void 0 : _a.image_url) && (react_1.default.createElement("img", { src: (_b = item.data) === null || _b === void 0 ? void 0 : _b.image_url, alt: item.value, className: 'cio-suggestion-image' })),
|
|
15
|
+
react_1.default.createElement("p", { className: 'cio-suggestion-text' },
|
|
16
|
+
react_1.default.createElement(SectionItemText_1.default, { item: item, query: query, highlightSearchTerm: displaySearchTermHighlights })),
|
|
17
|
+
displaySearchSuggestionResultCounts && ((_c = item.data) === null || _c === void 0 ? void 0 : _c.total_num_results) && (react_1.default.createElement("p", { className: 'cio-suggestion-count' },
|
|
18
|
+
"(", (_d = item.data) === null || _d === void 0 ? void 0 :
|
|
19
|
+
_d.total_num_results,
|
|
20
|
+
")"))));
|
|
21
|
+
}
|
|
22
|
+
exports.default = SearchSuggestionItem;
|
|
@@ -6,12 +6,12 @@ const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
|
|
|
6
6
|
const typeGuards_1 = require("../../../typeGuards");
|
|
7
7
|
const SectionItemText_1 = tslib_1.__importDefault(require("./SectionItemText"));
|
|
8
8
|
const utils_1 = require("../../../utils");
|
|
9
|
+
const SearchSuggestionItem_1 = tslib_1.__importDefault(require("./SearchSuggestionItem"));
|
|
9
10
|
function SectionItem(props) {
|
|
10
|
-
var _a, _b
|
|
11
|
+
var _a, _b;
|
|
11
12
|
const { item, children, displaySearchTermHighlights } = props;
|
|
12
|
-
const { getItemProps, advancedParameters, query,
|
|
13
|
-
const {
|
|
14
|
-
const { displaySearchSuggestionImages = featureDisplaySearchSuggestionImages, displaySearchSuggestionResultCounts = featureDisplaySearchSuggestionResultCounts, translations, } = advancedParameters || {};
|
|
13
|
+
const { getItemProps, advancedParameters, query, getSearchResultsUrl } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
14
|
+
const { translations } = advancedParameters || {};
|
|
15
15
|
let defaultChildren;
|
|
16
16
|
if ((0, typeGuards_1.isProduct)(item)) {
|
|
17
17
|
defaultChildren = (react_1.default.createElement("a", { href: (_a = item.data) === null || _a === void 0 ? void 0 : _a.url },
|
|
@@ -26,14 +26,13 @@ function SectionItem(props) {
|
|
|
26
26
|
react_1.default.createElement(SectionItemText_1.default, { item: item, query: query, highlightSearchTerm: displaySearchTermHighlights })));
|
|
27
27
|
}
|
|
28
28
|
else if ((0, typeGuards_1.isSearchSuggestion)(item)) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
")"))));
|
|
29
|
+
if (getSearchResultsUrl) {
|
|
30
|
+
defaultChildren = (react_1.default.createElement("a", { className: 'suggestion-link', href: getSearchResultsUrl(item) },
|
|
31
|
+
react_1.default.createElement(SearchSuggestionItem_1.default, { item: item, displaySearchTermHighlights: displaySearchTermHighlights })));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
defaultChildren = (react_1.default.createElement(SearchSuggestionItem_1.default, { item: item, displaySearchTermHighlights: displaySearchTermHighlights }));
|
|
35
|
+
}
|
|
37
36
|
}
|
|
38
37
|
else {
|
|
39
38
|
defaultChildren = (react_1.default.createElement("p", { className: 'cio-custom-text' },
|
|
@@ -8,7 +8,7 @@ const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
|
|
|
8
8
|
// eslint-disable-next-line func-names
|
|
9
9
|
const DefaultRenderSectionItemsList = function ({ section }) {
|
|
10
10
|
var _a, _b;
|
|
11
|
-
const { getSectionProps, getFormProps, advancedParameters } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
11
|
+
const { getSectionProps, query, getFormProps, advancedParameters } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
12
12
|
const { displayShowAllResultsButton, translations } = advancedParameters || {};
|
|
13
13
|
const { onSubmit } = getFormProps();
|
|
14
14
|
const { type, displayName } = section;
|
|
@@ -34,7 +34,12 @@ const DefaultRenderSectionItemsList = function ({ section }) {
|
|
|
34
34
|
// @deprecated `cio-sectionName` will be removed in the next major release
|
|
35
35
|
return (react_1.default.createElement("li", Object.assign({}, getSectionProps(section)),
|
|
36
36
|
react_1.default.createElement("h5", { className: 'cio-section-name cio-sectionName', "aria-hidden": true }, (0, utils_1.camelToStartCase)(sectionTitle)),
|
|
37
|
-
react_1.default.createElement("ul", { className: 'cio-section-items', role: 'none' }, (_b = section === null || section === void 0 ? void 0 : section.data) === null || _b === void 0 ? void 0 : _b.map((item) =>
|
|
37
|
+
react_1.default.createElement("ul", { className: 'cio-section-items', role: 'none' }, (_b = section === null || section === void 0 ? void 0 : section.data) === null || _b === void 0 ? void 0 : _b.map((item) => {
|
|
38
|
+
if (typeof (section === null || section === void 0 ? void 0 : section.renderItem) === 'function') {
|
|
39
|
+
return section.renderItem({ item, query });
|
|
40
|
+
}
|
|
41
|
+
return (react_1.default.createElement(SectionItem_1.default, { item: item, key: item === null || item === void 0 ? void 0 : item.id, displaySearchTermHighlights: section.displaySearchTermHighlights }));
|
|
42
|
+
})),
|
|
38
43
|
displayShowAllResultsButton &&
|
|
39
44
|
type === 'autocomplete' &&
|
|
40
45
|
section.indexSectionName === 'Products' && (react_1.default.createElement("div", { className: 'cio-section-footer' },
|
package/lib/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.displayShowAllResultsButtonDescription = exports.translationsDescription = exports.fetchZeroStateOnFocusDescription = exports.debounceDescription = exports.termsWithImagesAndCountsDescription = exports.filteredSuggestionsDescription = exports.termsWithGroupSuggestionsDescription = exports.advancedParametersDefaultDescription = exports.advancedParametersDescription = exports.customStylesDescription = exports.multipleSectionsDescription = exports.openOnFocusDescription = exports.zeroStateSectionsDescription = exports.onSubmitDefault = exports.onSubmitDescription = exports.onChangeDescription = exports.onFocusDescription = exports.customSectionDescription = exports.displaySearchTermHighlightsDescription = exports.recommendationsDescription = exports.sectionOrderDescription = exports.numResultsDescription = exports.contentDescription = exports.productsDescription = exports.searchSuggestionsDescription = exports.placeholderDescription = exports.cioJsClientOptionsDescription = exports.cioJsClientDescription = exports.apiKeyDescription = exports.fullFeaturedAndStyledExampleDescription = exports.zeroStateDescription = exports.userEventsDescription = exports.sectionsDescription = exports.hookDescription = exports.componentDescription = exports.apiKey = void 0;
|
|
3
|
+
exports.displayShowAllResultsButtonDescription = exports.customRenderItemDescription = exports.translationsDescription = exports.fetchZeroStateOnFocusDescription = exports.debounceDescription = exports.termsWithImagesAndCountsDescription = exports.filteredSuggestionsDescription = exports.termsWithGroupSuggestionsDescription = exports.advancedParametersDefaultDescription = exports.advancedParametersDescription = exports.customStylesDescription = exports.multipleSectionsDescription = exports.openOnFocusDescription = exports.zeroStateSectionsDescription = exports.onSubmitDefault = exports.onSubmitDescription = exports.onChangeDescription = exports.onFocusDescription = exports.customSectionDescription = exports.displaySearchTermHighlightsDescription = exports.recommendationsDescription = exports.sectionOrderDescription = exports.numResultsDescription = exports.contentDescription = exports.productsDescription = exports.searchSuggestionsDescription = exports.placeholderDescription = exports.cioJsClientOptionsDescription = exports.cioJsClientDescription = exports.apiKeyDescription = exports.fullFeaturedAndStyledExampleDescription = exports.zeroStateDescription = exports.userEventsDescription = exports.sectionsDescription = exports.hookDescription = exports.componentDescription = exports.apiKey = void 0;
|
|
4
4
|
// Autocomplete key index
|
|
5
5
|
exports.apiKey = 'key_M57QS8SMPdLdLx4x';
|
|
6
6
|
/// //////////////////////////////
|
|
@@ -239,4 +239,6 @@ exports.translationsDescription = `Pass a \`translations\` object to display tra
|
|
|
239
239
|
}
|
|
240
240
|
\`\`\`
|
|
241
241
|
`;
|
|
242
|
+
exports.customRenderItemDescription = `Customize the rendering of individual items within a Section by providing a \`renderItem\` function. This function allows you to define how each item should be rendered.
|
|
243
|
+
`;
|
|
242
244
|
exports.displayShowAllResultsButtonDescription = `Pass a boolean to \`displayShowAllResultsButton\` to display a button at the bottom of the Products section to show all results. This button will submit the form and trigger the \`onSubmit\` callback.`;
|
|
@@ -41,7 +41,7 @@ const convertLegacyParametersAndAddDefaults = (sections) => sections.map((config
|
|
|
41
41
|
const useCioAutocomplete = (options) => {
|
|
42
42
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
43
|
const memoizedOptions = (0, react_1.useMemo)(() => options, [JSON.stringify(options)]);
|
|
44
|
-
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', autocompleteClassName = 'cio-autocomplete', advancedParameters, defaultInput, } = memoizedOptions;
|
|
44
|
+
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', autocompleteClassName = 'cio-autocomplete', advancedParameters, defaultInput, getSearchResultsUrl, } = memoizedOptions;
|
|
45
45
|
let { sections = exports.defaultSections, zeroStateSections } = memoizedOptions;
|
|
46
46
|
sections = (0, react_1.useMemo)(() => {
|
|
47
47
|
if (sections) {
|
|
@@ -211,6 +211,7 @@ const useCioAutocomplete = (options) => {
|
|
|
211
211
|
autocompleteClassName,
|
|
212
212
|
selectedItem: items[highlightedIndex],
|
|
213
213
|
advancedParameters,
|
|
214
|
+
getSearchResultsUrl,
|
|
214
215
|
};
|
|
215
216
|
};
|
|
216
217
|
exports.default = useCioAutocomplete;
|
package/lib/cjs/utils.js
CHANGED
|
@@ -102,6 +102,15 @@ ${templateCode}
|
|
|
102
102
|
exports.getStoryParams = getStoryParams;
|
|
103
103
|
exports.functionStrings = {
|
|
104
104
|
onSubmit: `(submitEvent) => console.dir(submitEvent)`,
|
|
105
|
+
renderItem: `({ item, query }) => (
|
|
106
|
+
<div>
|
|
107
|
+
<a href={item.data?.url}>
|
|
108
|
+
<h3>{item.value}</h3>
|
|
109
|
+
<img src={item.data?.image_url} alt={item.value} />
|
|
110
|
+
</a>
|
|
111
|
+
<p>{item.data?.price}</p>
|
|
112
|
+
</div>
|
|
113
|
+
)`,
|
|
105
114
|
};
|
|
106
115
|
const stringifyWithDefaults = (obj) => {
|
|
107
116
|
// Stringify non-function values normally. Add a template block for functions to be replaced later
|
package/lib/cjs/version.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import SectionItemText from './SectionItemText';
|
|
3
|
+
import { CioAutocompleteContext } from '../CioAutocompleteProvider';
|
|
4
|
+
export default function SearchSuggestionItem(props) {
|
|
5
|
+
const { item, displaySearchTermHighlights } = props;
|
|
6
|
+
const { advancedParameters, query, featureToggles } = useContext(CioAutocompleteContext);
|
|
7
|
+
const { featureDisplaySearchSuggestionImages, featureDisplaySearchSuggestionResultCounts } = featureToggles;
|
|
8
|
+
const { displaySearchSuggestionImages = featureDisplaySearchSuggestionImages, displaySearchSuggestionResultCounts = featureDisplaySearchSuggestionResultCounts, } = advancedParameters || {};
|
|
9
|
+
return (React.createElement(React.Fragment, null,
|
|
10
|
+
displaySearchSuggestionImages && item.data?.image_url && (React.createElement("img", { src: item.data?.image_url, alt: item.value, className: 'cio-suggestion-image' })),
|
|
11
|
+
React.createElement("p", { className: 'cio-suggestion-text' },
|
|
12
|
+
React.createElement(SectionItemText, { item: item, query: query, highlightSearchTerm: displaySearchTermHighlights })),
|
|
13
|
+
displaySearchSuggestionResultCounts && item.data?.total_num_results && (React.createElement("p", { className: 'cio-suggestion-count' },
|
|
14
|
+
"(",
|
|
15
|
+
item.data?.total_num_results,
|
|
16
|
+
")"))));
|
|
17
|
+
}
|
|
@@ -3,11 +3,11 @@ import { CioAutocompleteContext } from '../CioAutocompleteProvider';
|
|
|
3
3
|
import { isProduct, isInGroupSuggestion, isSearchSuggestion } from '../../../typeGuards';
|
|
4
4
|
import SectionItemText from './SectionItemText';
|
|
5
5
|
import { translate } from '../../../utils';
|
|
6
|
+
import SearchSuggestionItem from './SearchSuggestionItem';
|
|
6
7
|
export default function SectionItem(props) {
|
|
7
8
|
const { item, children, displaySearchTermHighlights } = props;
|
|
8
|
-
const { getItemProps, advancedParameters, query,
|
|
9
|
-
const {
|
|
10
|
-
const { displaySearchSuggestionImages = featureDisplaySearchSuggestionImages, displaySearchSuggestionResultCounts = featureDisplaySearchSuggestionResultCounts, translations, } = advancedParameters || {};
|
|
9
|
+
const { getItemProps, advancedParameters, query, getSearchResultsUrl } = useContext(CioAutocompleteContext);
|
|
10
|
+
const { translations } = advancedParameters || {};
|
|
11
11
|
let defaultChildren;
|
|
12
12
|
if (isProduct(item)) {
|
|
13
13
|
defaultChildren = (React.createElement("a", { href: item.data?.url },
|
|
@@ -22,14 +22,13 @@ export default function SectionItem(props) {
|
|
|
22
22
|
React.createElement(SectionItemText, { item: item, query: query, highlightSearchTerm: displaySearchTermHighlights })));
|
|
23
23
|
}
|
|
24
24
|
else if (isSearchSuggestion(item)) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
")"))));
|
|
25
|
+
if (getSearchResultsUrl) {
|
|
26
|
+
defaultChildren = (React.createElement("a", { className: 'suggestion-link', href: getSearchResultsUrl(item) },
|
|
27
|
+
React.createElement(SearchSuggestionItem, { item: item, displaySearchTermHighlights: displaySearchTermHighlights })));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
defaultChildren = (React.createElement(SearchSuggestionItem, { item: item, displaySearchTermHighlights: displaySearchTermHighlights }));
|
|
31
|
+
}
|
|
33
32
|
}
|
|
34
33
|
else {
|
|
35
34
|
defaultChildren = (React.createElement("p", { className: 'cio-custom-text' },
|
|
@@ -4,7 +4,7 @@ import { camelToStartCase, translate } from '../../../utils';
|
|
|
4
4
|
import { CioAutocompleteContext } from '../CioAutocompleteProvider';
|
|
5
5
|
// eslint-disable-next-line func-names
|
|
6
6
|
const DefaultRenderSectionItemsList = function ({ section }) {
|
|
7
|
-
const { getSectionProps, getFormProps, advancedParameters } = useContext(CioAutocompleteContext);
|
|
7
|
+
const { getSectionProps, query, getFormProps, advancedParameters } = useContext(CioAutocompleteContext);
|
|
8
8
|
const { displayShowAllResultsButton, translations } = advancedParameters || {};
|
|
9
9
|
const { onSubmit } = getFormProps();
|
|
10
10
|
const { type, displayName } = section;
|
|
@@ -30,7 +30,12 @@ const DefaultRenderSectionItemsList = function ({ section }) {
|
|
|
30
30
|
// @deprecated `cio-sectionName` will be removed in the next major release
|
|
31
31
|
return (React.createElement("li", { ...getSectionProps(section) },
|
|
32
32
|
React.createElement("h5", { className: 'cio-section-name cio-sectionName', "aria-hidden": true }, camelToStartCase(sectionTitle)),
|
|
33
|
-
React.createElement("ul", { className: 'cio-section-items', role: 'none' }, section?.data?.map((item) =>
|
|
33
|
+
React.createElement("ul", { className: 'cio-section-items', role: 'none' }, section?.data?.map((item) => {
|
|
34
|
+
if (typeof section?.renderItem === 'function') {
|
|
35
|
+
return section.renderItem({ item, query });
|
|
36
|
+
}
|
|
37
|
+
return (React.createElement(SectionItem, { item: item, key: item?.id, displaySearchTermHighlights: section.displaySearchTermHighlights }));
|
|
38
|
+
})),
|
|
34
39
|
displayShowAllResultsButton &&
|
|
35
40
|
type === 'autocomplete' &&
|
|
36
41
|
section.indexSectionName === 'Products' && (React.createElement("div", { className: 'cio-section-footer' },
|
package/lib/mjs/constants.js
CHANGED
|
@@ -235,4 +235,6 @@ export const translationsDescription = `Pass a \`translations\` object to displa
|
|
|
235
235
|
}
|
|
236
236
|
\`\`\`
|
|
237
237
|
`;
|
|
238
|
+
export const customRenderItemDescription = `Customize the rendering of individual items within a Section by providing a \`renderItem\` function. This function allows you to define how each item should be rendered.
|
|
239
|
+
`;
|
|
238
240
|
export const displayShowAllResultsButtonDescription = `Pass a boolean to \`displayShowAllResultsButton\` to display a button at the bottom of the Products section to show all results. This button will submit the form and trigger the \`onSubmit\` callback.`;
|
|
@@ -37,7 +37,7 @@ const convertLegacyParametersAndAddDefaults = (sections) => sections.map((config
|
|
|
37
37
|
const useCioAutocomplete = (options) => {
|
|
38
38
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
39
39
|
const memoizedOptions = useMemo(() => options, [JSON.stringify(options)]);
|
|
40
|
-
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', autocompleteClassName = 'cio-autocomplete', advancedParameters, defaultInput, } = memoizedOptions;
|
|
40
|
+
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', autocompleteClassName = 'cio-autocomplete', advancedParameters, defaultInput, getSearchResultsUrl, } = memoizedOptions;
|
|
41
41
|
let { sections = defaultSections, zeroStateSections } = memoizedOptions;
|
|
42
42
|
sections = useMemo(() => {
|
|
43
43
|
if (sections) {
|
|
@@ -225,6 +225,7 @@ const useCioAutocomplete = (options) => {
|
|
|
225
225
|
autocompleteClassName,
|
|
226
226
|
selectedItem: items[highlightedIndex],
|
|
227
227
|
advancedParameters,
|
|
228
|
+
getSearchResultsUrl,
|
|
228
229
|
};
|
|
229
230
|
};
|
|
230
231
|
export default useCioAutocomplete;
|
package/lib/mjs/utils.js
CHANGED
|
@@ -86,6 +86,15 @@ ${templateCode}
|
|
|
86
86
|
};
|
|
87
87
|
export const functionStrings = {
|
|
88
88
|
onSubmit: `(submitEvent) => console.dir(submitEvent)`,
|
|
89
|
+
renderItem: `({ item, query }) => (
|
|
90
|
+
<div>
|
|
91
|
+
<a href={item.data?.url}>
|
|
92
|
+
<h3>{item.value}</h3>
|
|
93
|
+
<img src={item.data?.image_url} alt={item.value} />
|
|
94
|
+
</a>
|
|
95
|
+
<p>{item.data?.price}</p>
|
|
96
|
+
</div>
|
|
97
|
+
)`,
|
|
89
98
|
};
|
|
90
99
|
export const stringifyWithDefaults = (obj) => {
|
|
91
100
|
// Stringify non-function values normally. Add a template block for functions to be replaced later
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.23.
|
|
1
|
+
export default '1.23.15';
|
package/lib/styles.css
CHANGED
|
@@ -98,6 +98,14 @@
|
|
|
98
98
|
flex-direction: column;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
.cio-autocomplete .cio-item .suggestion-link {
|
|
102
|
+
display: flex;
|
|
103
|
+
flex-direction: row;
|
|
104
|
+
align-items: center;
|
|
105
|
+
width: 100%;
|
|
106
|
+
height: 100%;
|
|
107
|
+
}
|
|
108
|
+
|
|
101
109
|
.cio-autocomplete .cio-item[aria-selected='true'] {
|
|
102
110
|
background-color: hsl(0, 0%, 90%);
|
|
103
111
|
border-radius: 4px;
|
|
@@ -31,5 +31,6 @@ export declare const CioAutocompleteContext: React.Context<{
|
|
|
31
31
|
autocompleteClassName: string;
|
|
32
32
|
selectedItem: import("../../types").Item;
|
|
33
33
|
advancedParameters: import("../../types").AdvancedParameters | undefined;
|
|
34
|
+
getSearchResultsUrl: ((item: import("../../types").SearchSuggestion) => string) | undefined;
|
|
34
35
|
}>;
|
|
35
36
|
export default function CioAutocompleteProvider(props: CioAutocompleteProps): JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SearchSuggestion } from '../../../types';
|
|
3
|
+
interface SearchSuggestionItemProps {
|
|
4
|
+
item: SearchSuggestion;
|
|
5
|
+
displaySearchTermHighlights?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export default function SearchSuggestionItem(props: SearchSuggestionItemProps): JSX.Element;
|
|
8
|
+
export {};
|
package/lib/types/constants.d.ts
CHANGED
|
@@ -34,4 +34,5 @@ export declare const termsWithImagesAndCountsDescription = "Pass boolean flags f
|
|
|
34
34
|
export declare const debounceDescription = "Pass an integer to `debounce` to override the recommended, default delay employed for debouncing autocomplete network requests between keystrokes as your users type into the text input field. The default value is 250, which results in a debounce delay of 250 milliseconds.";
|
|
35
35
|
export declare const fetchZeroStateOnFocusDescription = "Pass a boolean to `fetchZeroStateOnFocus` to override the zero state fetching behavior from initial render to input focus.";
|
|
36
36
|
export declare const translationsDescription = "Pass a `translations` object to display translatable words in your preferred language.\n\n- Current translatable keys:\n```\n {\n \"in\": \"...\",\n \"show all results\": \"...\"\n }\n```\n";
|
|
37
|
+
export declare const customRenderItemDescription = "Customize the rendering of individual items within a Section by providing a `renderItem` function. This function allows you to define how each item should be rendered.\n";
|
|
37
38
|
export declare const displayShowAllResultsButtonDescription = "Pass a boolean to `displayShowAllResultsButton` to display a button at the bottom of the Products section to show all results. This button will submit the form and trigger the `onSubmit` callback.";
|
|
@@ -32,5 +32,6 @@ declare const useCioAutocomplete: (options: UseCioAutocompleteOptions) => {
|
|
|
32
32
|
autocompleteClassName: string;
|
|
33
33
|
selectedItem: Item;
|
|
34
34
|
advancedParameters: import("../types").AdvancedParameters | undefined;
|
|
35
|
+
getSearchResultsUrl: ((item: import("../types").SearchSuggestion) => string) | undefined;
|
|
35
36
|
};
|
|
36
37
|
export default useCioAutocomplete;
|
package/lib/types/types.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface AdvancedParametersBase {
|
|
|
21
21
|
export type AdvancedParameters = AdvancedParametersBase & Omit<IAutocompleteParameters, 'resultsPerSection'>;
|
|
22
22
|
export type CioAutocompleteProps = CioClientConfig & {
|
|
23
23
|
openOnFocus?: boolean;
|
|
24
|
+
getSearchResultsUrl?: (item: SearchSuggestion) => string;
|
|
24
25
|
onSubmit: OnSubmit;
|
|
25
26
|
onFocus?: () => void;
|
|
26
27
|
onChange?: (input: string) => void;
|
|
@@ -90,6 +91,10 @@ export type SectionConfiguration = {
|
|
|
90
91
|
numResults?: number;
|
|
91
92
|
displaySearchTermHighlights?: boolean;
|
|
92
93
|
ref?: React.RefObject<HTMLElement>;
|
|
94
|
+
renderItem?: (props: {
|
|
95
|
+
item: Item;
|
|
96
|
+
query: string;
|
|
97
|
+
}) => ReactNode;
|
|
93
98
|
};
|
|
94
99
|
export interface AutocompleteSectionConfiguration extends SectionConfiguration {
|
|
95
100
|
type?: 'autocomplete';
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export declare const getStoryParams: (storyCode: any, templateCode: any, importC
|
|
|
32
32
|
};
|
|
33
33
|
export declare const functionStrings: {
|
|
34
34
|
onSubmit: string;
|
|
35
|
+
renderItem: string;
|
|
35
36
|
};
|
|
36
37
|
export declare const stringifyWithDefaults: (obj: any) => string;
|
|
37
38
|
export declare const disableStoryActions: (story: any) => void;
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.23.
|
|
1
|
+
declare const _default: "1.23.15";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED