@constructor-io/constructorio-ui-autocomplete 1.23.9 → 1.23.11
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 +9 -9
- package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js +7 -7
- package/lib/cjs/hooks/useCioAutocomplete.js +7 -5
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js +1 -1
- package/lib/mjs/hooks/useCioAutocomplete.js +9 -2
- package/lib/mjs/version.js +1 -1
- package/lib/styles.css +8 -0
- package/lib/types/components/Autocomplete/AutocompleteResults/AutocompleteResults.d.ts +2 -2
- package/lib/types/components/Autocomplete/CioAutocompleteProvider.d.ts +2 -1
- package/lib/types/hooks/useCioAutocomplete.d.ts +4 -3
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -7,15 +7,15 @@ const typeGuards_1 = require("../../../typeGuards");
|
|
|
7
7
|
const SectionItemText_1 = tslib_1.__importDefault(require("./SectionItemText"));
|
|
8
8
|
const utils_1 = require("../../../utils");
|
|
9
9
|
function SectionItem(props) {
|
|
10
|
-
var _a, _b, _c, _d, _e;
|
|
10
|
+
var _a, _b, _c, _d, _e, _f;
|
|
11
11
|
const { item, children, displaySearchTermHighlights } = props;
|
|
12
12
|
const { getItemProps, advancedParameters, query, featureToggles } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
13
13
|
const { featureDisplaySearchSuggestionImages, featureDisplaySearchSuggestionResultCounts } = featureToggles;
|
|
14
14
|
const { displaySearchSuggestionImages = featureDisplaySearchSuggestionImages, displaySearchSuggestionResultCounts = featureDisplaySearchSuggestionResultCounts, translations, } = advancedParameters || {};
|
|
15
15
|
let defaultChildren;
|
|
16
16
|
if ((0, typeGuards_1.isProduct)(item)) {
|
|
17
|
-
defaultChildren = (react_1.default.createElement(
|
|
18
|
-
react_1.default.createElement("img", { "data-testid": 'cio-img', src: (
|
|
17
|
+
defaultChildren = (react_1.default.createElement("a", { href: (_a = item.data) === null || _a === void 0 ? void 0 : _a.url },
|
|
18
|
+
react_1.default.createElement("img", { "data-testid": 'cio-img', src: (_b = item.data) === null || _b === void 0 ? void 0 : _b.image_url, alt: item.value, className: 'cio-product-image' }),
|
|
19
19
|
react_1.default.createElement("p", { "data-testid": 'cio-text', className: 'cio-product-text' },
|
|
20
20
|
react_1.default.createElement(SectionItemText_1.default, { item: item, query: query, highlightSearchTerm: displaySearchTermHighlights }))));
|
|
21
21
|
}
|
|
@@ -27,12 +27,12 @@ function SectionItem(props) {
|
|
|
27
27
|
}
|
|
28
28
|
else if ((0, typeGuards_1.isSearchSuggestion)(item)) {
|
|
29
29
|
defaultChildren = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
30
|
-
displaySearchSuggestionImages && ((
|
|
30
|
+
displaySearchSuggestionImages && ((_c = item.data) === null || _c === void 0 ? void 0 : _c.image_url) && (react_1.default.createElement("img", { src: (_d = item.data) === null || _d === void 0 ? void 0 : _d.image_url, alt: item.value, className: 'cio-suggestion-image' })),
|
|
31
31
|
react_1.default.createElement("p", { className: 'cio-suggestion-text' },
|
|
32
32
|
react_1.default.createElement(SectionItemText_1.default, { item: item, query: query, highlightSearchTerm: displaySearchTermHighlights })),
|
|
33
|
-
displaySearchSuggestionResultCounts && ((
|
|
34
|
-
"(", (
|
|
35
|
-
|
|
33
|
+
displaySearchSuggestionResultCounts && ((_e = item.data) === null || _e === void 0 ? void 0 : _e.total_num_results) && (react_1.default.createElement("p", { className: 'cio-suggestion-count' },
|
|
34
|
+
"(", (_f = item.data) === null || _f === void 0 ? void 0 :
|
|
35
|
+
_f.total_num_results,
|
|
36
36
|
")"))));
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
@@ -63,7 +63,7 @@ const useCioAutocomplete = (options) => {
|
|
|
63
63
|
const features = (0, react_1.useMemo)(() => (0, utils_1.getFeatures)(request), [request]);
|
|
64
64
|
// Get dropdown items array from active sections (autocomplete + recommendations + custom)
|
|
65
65
|
const items = (0, react_1.useMemo)(() => (0, utils_1.getItemsForActiveSections)(activeSectionsWithData), [activeSectionsWithData]);
|
|
66
|
-
const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu, highlightedIndex, getInputProps, getItemProps, } = (0, useDownShift_1.default)({ setQuery, items, onSubmit, cioClient, previousQuery });
|
|
66
|
+
const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu, highlightedIndex, getInputProps, getItemProps: getItemPropsDownShift, } = (0, useDownShift_1.default)({ setQuery, items, onSubmit, cioClient, previousQuery });
|
|
67
67
|
// Log console errors
|
|
68
68
|
(0, useConsoleErrors_1.default)(sections, activeSections);
|
|
69
69
|
// Track recommendation view
|
|
@@ -75,16 +75,17 @@ const useCioAutocomplete = (options) => {
|
|
|
75
75
|
request,
|
|
76
76
|
featureToggles: features,
|
|
77
77
|
isOpen: isOpen && (items === null || items === void 0 ? void 0 : items.length) > 0,
|
|
78
|
-
getMenuProps: () => (Object.assign(Object.assign({}, getMenuProps()), { className: 'cio-results', 'data-testid': 'cio-results' })),
|
|
78
|
+
getMenuProps: () => (Object.assign(Object.assign({}, getMenuProps()), { className: 'cio-results', 'data-testid': 'cio-results', 'data-cnstrc-autosuggest': '' })),
|
|
79
79
|
getLabelProps,
|
|
80
80
|
openMenu,
|
|
81
81
|
closeMenu,
|
|
82
82
|
getItemProps: (item) => {
|
|
83
|
+
var _a;
|
|
83
84
|
const { index, sectionId } = (0, utils_1.getItemPosition)({ item, items });
|
|
84
85
|
const sectionItemTestId = `cio-item-${sectionId === null || sectionId === void 0 ? void 0 : sectionId.replace(' ', '')}`;
|
|
85
|
-
return Object.assign(Object.assign({},
|
|
86
|
+
return Object.assign(Object.assign({}, getItemPropsDownShift({ item, index })), {
|
|
86
87
|
// @deprecated `sectionItemTestId` will be removed as a className in the next major version
|
|
87
|
-
className: `cio-item ${sectionItemTestId}`, 'data-testid': sectionItemTestId });
|
|
88
|
+
className: `cio-item ${sectionItemTestId}`, 'data-testid': sectionItemTestId, 'data-cnstrc-item-section': item.section, 'data-cnstrc-item-group': item.groupId, 'data-cnstrc-item-name': item.value, 'data-cnstrc-item-id': (_a = item.data) === null || _a === void 0 ? void 0 : _a.id });
|
|
88
89
|
},
|
|
89
90
|
getInputProps: () => (Object.assign(Object.assign({}, getInputProps({
|
|
90
91
|
onChange: (e) => {
|
|
@@ -116,7 +117,7 @@ const useCioAutocomplete = (options) => {
|
|
|
116
117
|
// eslint-disable-next-line no-console
|
|
117
118
|
console.log(error);
|
|
118
119
|
}
|
|
119
|
-
}, className: 'cio-input', 'data-testid': 'cio-input', placeholder, onKeyDownCapture: ({ code, key, nativeEvent }) => {
|
|
120
|
+
}, className: 'cio-input', 'data-testid': 'cio-input', 'data-cnstrc-search-input': '', placeholder, onKeyDownCapture: ({ code, key, nativeEvent }) => {
|
|
120
121
|
const isEnter = code === 'Enter' || key === 'Enter';
|
|
121
122
|
const isHome = code === 'Home' || key === 'Home';
|
|
122
123
|
const isEnd = code === 'End' || key === 'End';
|
|
@@ -155,6 +156,7 @@ const useCioAutocomplete = (options) => {
|
|
|
155
156
|
},
|
|
156
157
|
className: 'cio-form',
|
|
157
158
|
'data-testid': 'cio-form',
|
|
159
|
+
'data-cnstrc-search-form': '',
|
|
158
160
|
}),
|
|
159
161
|
getSectionProps: (section) => {
|
|
160
162
|
var _a, _b;
|
package/lib/cjs/version.js
CHANGED
|
@@ -10,7 +10,7 @@ export default function SectionItem(props) {
|
|
|
10
10
|
const { displaySearchSuggestionImages = featureDisplaySearchSuggestionImages, displaySearchSuggestionResultCounts = featureDisplaySearchSuggestionResultCounts, translations, } = advancedParameters || {};
|
|
11
11
|
let defaultChildren;
|
|
12
12
|
if (isProduct(item)) {
|
|
13
|
-
defaultChildren = (React.createElement(
|
|
13
|
+
defaultChildren = (React.createElement("a", { href: item.data?.url },
|
|
14
14
|
React.createElement("img", { "data-testid": 'cio-img', src: item.data?.image_url, alt: item.value, className: 'cio-product-image' }),
|
|
15
15
|
React.createElement("p", { "data-testid": 'cio-text', className: 'cio-product-text' },
|
|
16
16
|
React.createElement(SectionItemText, { item: item, query: query, highlightSearchTerm: displaySearchTermHighlights }))));
|
|
@@ -59,7 +59,7 @@ const useCioAutocomplete = (options) => {
|
|
|
59
59
|
const features = useMemo(() => getFeatures(request), [request]);
|
|
60
60
|
// Get dropdown items array from active sections (autocomplete + recommendations + custom)
|
|
61
61
|
const items = useMemo(() => getItemsForActiveSections(activeSectionsWithData), [activeSectionsWithData]);
|
|
62
|
-
const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu, highlightedIndex, getInputProps, getItemProps, } = useDownShift({ setQuery, items, onSubmit, cioClient, previousQuery });
|
|
62
|
+
const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu, highlightedIndex, getInputProps, getItemProps: getItemPropsDownShift, } = useDownShift({ setQuery, items, onSubmit, cioClient, previousQuery });
|
|
63
63
|
// Log console errors
|
|
64
64
|
useConsoleErrors(sections, activeSections);
|
|
65
65
|
// Track recommendation view
|
|
@@ -75,6 +75,7 @@ const useCioAutocomplete = (options) => {
|
|
|
75
75
|
...getMenuProps(),
|
|
76
76
|
className: 'cio-results',
|
|
77
77
|
'data-testid': 'cio-results',
|
|
78
|
+
'data-cnstrc-autosuggest': '',
|
|
78
79
|
}),
|
|
79
80
|
getLabelProps,
|
|
80
81
|
openMenu,
|
|
@@ -83,10 +84,14 @@ const useCioAutocomplete = (options) => {
|
|
|
83
84
|
const { index, sectionId } = getItemPosition({ item, items });
|
|
84
85
|
const sectionItemTestId = `cio-item-${sectionId?.replace(' ', '')}`;
|
|
85
86
|
return {
|
|
86
|
-
...
|
|
87
|
+
...getItemPropsDownShift({ item, index }),
|
|
87
88
|
// @deprecated `sectionItemTestId` will be removed as a className in the next major version
|
|
88
89
|
className: `cio-item ${sectionItemTestId}`,
|
|
89
90
|
'data-testid': sectionItemTestId,
|
|
91
|
+
'data-cnstrc-item-section': item.section,
|
|
92
|
+
'data-cnstrc-item-group': item.groupId,
|
|
93
|
+
'data-cnstrc-item-name': item.value,
|
|
94
|
+
'data-cnstrc-item-id': item.data?.id,
|
|
90
95
|
};
|
|
91
96
|
},
|
|
92
97
|
getInputProps: () => ({
|
|
@@ -124,6 +129,7 @@ const useCioAutocomplete = (options) => {
|
|
|
124
129
|
},
|
|
125
130
|
className: 'cio-input',
|
|
126
131
|
'data-testid': 'cio-input',
|
|
132
|
+
'data-cnstrc-search-input': '',
|
|
127
133
|
placeholder,
|
|
128
134
|
onKeyDownCapture: ({ code, key, nativeEvent }) => {
|
|
129
135
|
const isEnter = code === 'Enter' || key === 'Enter';
|
|
@@ -165,6 +171,7 @@ const useCioAutocomplete = (options) => {
|
|
|
165
171
|
},
|
|
166
172
|
className: 'cio-form',
|
|
167
173
|
'data-testid': 'cio-form',
|
|
174
|
+
'data-cnstrc-search-form': '',
|
|
168
175
|
}),
|
|
169
176
|
getSectionProps: (section) => {
|
|
170
177
|
// @deprecated ClassNames derived from this fn will be removed in the next major version
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.23.
|
|
1
|
+
export default '1.23.11';
|
package/lib/styles.css
CHANGED
|
@@ -91,6 +91,13 @@
|
|
|
91
91
|
border-bottom: 3px solid transparent;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
.cio-autocomplete .cio-item a {
|
|
95
|
+
color: inherit;
|
|
96
|
+
display: inline-flex;
|
|
97
|
+
text-decoration: inherit;
|
|
98
|
+
flex-direction: column;
|
|
99
|
+
}
|
|
100
|
+
|
|
94
101
|
.cio-autocomplete .cio-item[aria-selected='true'] {
|
|
95
102
|
background-color: hsl(0, 0%, 90%);
|
|
96
103
|
border-radius: 4px;
|
|
@@ -122,6 +129,7 @@
|
|
|
122
129
|
width: 100%;
|
|
123
130
|
max-width: 100px;
|
|
124
131
|
max-height: 100px;
|
|
132
|
+
align-self: center;
|
|
125
133
|
}
|
|
126
134
|
|
|
127
135
|
.cio-autocomplete .cio-term-in-group {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Item, Section } from '../../../types';
|
|
3
3
|
export type RenderResults = (renderResultsArguments: {
|
|
4
4
|
sections: Section[];
|
|
5
|
-
getItemProps:
|
|
5
|
+
getItemProps: (item: Item) => any;
|
|
6
6
|
}) => ReactNode;
|
|
7
7
|
type AutocompleteResultsProps = {
|
|
8
8
|
children?: RenderResults | ReactNode;
|
|
@@ -15,7 +15,7 @@ export declare const CioAutocompleteContext: React.Context<{
|
|
|
15
15
|
getLabelProps: (options?: import("downshift").UseComboboxGetLabelPropsOptions | undefined) => any;
|
|
16
16
|
openMenu: () => void;
|
|
17
17
|
closeMenu: () => void;
|
|
18
|
-
getItemProps: (item:
|
|
18
|
+
getItemProps: (item: import("../../types").Item) => any;
|
|
19
19
|
getInputProps: () => any;
|
|
20
20
|
getFormProps: () => {
|
|
21
21
|
onSubmit: (event: any) => {
|
|
@@ -23,6 +23,7 @@ export declare const CioAutocompleteContext: React.Context<{
|
|
|
23
23
|
};
|
|
24
24
|
className: string;
|
|
25
25
|
'data-testid': string;
|
|
26
|
+
'data-cnstrc-search-form': string;
|
|
26
27
|
};
|
|
27
28
|
getSectionProps: (section: import("../../types").Section) => import("../../types").HTMLPropsWithCioDataAttributes<any>;
|
|
28
29
|
setQuery: React.Dispatch<React.SetStateAction<string>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CioAutocompleteProps, Section, UserDefinedSection, HTMLPropsWithCioDataAttributes } from '../types';
|
|
1
|
+
import { CioAutocompleteProps, Section, UserDefinedSection, HTMLPropsWithCioDataAttributes, Item } from '../types';
|
|
2
2
|
export declare const defaultSections: UserDefinedSection[];
|
|
3
3
|
export type UseCioAutocompleteOptions = Omit<CioAutocompleteProps, 'children'>;
|
|
4
4
|
declare const useCioAutocomplete: (options: UseCioAutocompleteOptions) => {
|
|
@@ -16,7 +16,7 @@ declare const useCioAutocomplete: (options: UseCioAutocompleteOptions) => {
|
|
|
16
16
|
getLabelProps: (options?: import("downshift").UseComboboxGetLabelPropsOptions | undefined) => any;
|
|
17
17
|
openMenu: () => void;
|
|
18
18
|
closeMenu: () => void;
|
|
19
|
-
getItemProps: (item:
|
|
19
|
+
getItemProps: (item: Item) => any;
|
|
20
20
|
getInputProps: () => any;
|
|
21
21
|
getFormProps: () => {
|
|
22
22
|
onSubmit: (event: any) => {
|
|
@@ -24,12 +24,13 @@ declare const useCioAutocomplete: (options: UseCioAutocompleteOptions) => {
|
|
|
24
24
|
};
|
|
25
25
|
className: string;
|
|
26
26
|
'data-testid': string;
|
|
27
|
+
'data-cnstrc-search-form': string;
|
|
27
28
|
};
|
|
28
29
|
getSectionProps: (section: Section) => HTMLPropsWithCioDataAttributes<any>;
|
|
29
30
|
setQuery: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
30
31
|
cioClient: import("@constructor-io/constructorio-client-javascript").Nullable<import("@constructor-io/constructorio-client-javascript/lib/types/constructorio")>;
|
|
31
32
|
autocompleteClassName: string;
|
|
32
|
-
selectedItem:
|
|
33
|
+
selectedItem: Item;
|
|
33
34
|
advancedParameters: import("../types").AdvancedParameters | undefined;
|
|
34
35
|
};
|
|
35
36
|
export default useCioAutocomplete;
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.23.
|
|
1
|
+
declare const _default: "1.23.11";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED