@constructor-io/constructorio-ui-autocomplete 1.23.15 → 1.23.17
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 +6 -6
- package/lib/cjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js +5 -2
- package/lib/cjs/components/Autocomplete/AutocompleteResults/CloseIcon.js +10 -0
- package/lib/cjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +2 -2
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/utils.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js +5 -2
- package/lib/mjs/components/Autocomplete/AutocompleteResults/CloseIcon.js +6 -0
- package/lib/mjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +2 -2
- package/lib/mjs/constants.js +2 -1
- package/lib/mjs/utils.js +2 -2
- package/lib/mjs/version.js +1 -1
- package/lib/styles.css +9 -0
- package/lib/types/components/Autocomplete/AutocompleteResults/CloseIcon.d.ts +2 -0
- package/lib/types/constants.d.ts +2 -2
- package/lib/types/types.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ const react_1 = tslib_1.__importStar(require("react"));
|
|
|
5
5
|
const utils_1 = require("../../../utils");
|
|
6
6
|
const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
|
|
7
7
|
const SectionItemsList_1 = tslib_1.__importDefault(require("../SectionItemsList/SectionItemsList"));
|
|
8
|
+
const CloseIcon_1 = tslib_1.__importDefault(require("./CloseIcon"));
|
|
8
9
|
const DefaultRenderResults = ({ sections }) => sections === null || sections === void 0 ? void 0 : sections.map((section) => {
|
|
9
10
|
const { type } = section;
|
|
10
11
|
let key = section.displayName;
|
|
@@ -26,12 +27,14 @@ const DefaultRenderResults = ({ sections }) => sections === null || sections ===
|
|
|
26
27
|
});
|
|
27
28
|
function AutocompleteResults(props) {
|
|
28
29
|
const { children = DefaultRenderResults } = props;
|
|
29
|
-
const { sections, isOpen, getMenuProps, getItemProps } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
30
|
+
const { sections, isOpen, getMenuProps, getItemProps, closeMenu } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
30
31
|
const hasResults = sections && sections.some((section) => { var _a; return (_a = section === null || section === void 0 ? void 0 : section.data) === null || _a === void 0 ? void 0 : _a.length; });
|
|
31
32
|
const menuProps = Object.assign({}, getMenuProps());
|
|
32
33
|
let content;
|
|
33
34
|
if (isOpen && hasResults) {
|
|
34
|
-
content =
|
|
35
|
+
content = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
36
|
+
react_1.default.createElement(CloseIcon_1.default, { onClick: () => closeMenu() }),
|
|
37
|
+
typeof children === 'function' ? children({ sections, getItemProps }) : children));
|
|
35
38
|
}
|
|
36
39
|
else {
|
|
37
40
|
content = null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
|
+
function CloseIcon(props) {
|
|
6
|
+
return (react_1.default.createElement("svg", Object.assign({}, props, { className: 'cio-close', version: '1.1', id: 'Layer_1', xmlns: 'http://www.w3.org/2000/svg', x: '0px', y: '0px', width: '122.878px', height: '122.88px', viewBox: '0 0 122.878 122.88', enableBackground: 'new 0 0 122.878 122.88', xmlSpace: 'preserve' }),
|
|
7
|
+
react_1.default.createElement("g", null,
|
|
8
|
+
react_1.default.createElement("path", { d: 'M1.426,8.313c-1.901-1.901-1.901-4.984,0-6.886c1.901-1.902,4.984-1.902,6.886,0l53.127,53.127l53.127-53.127 c1.901-1.902,4.984-1.902,6.887,0c1.901,1.901,1.901,4.985,0,6.886L68.324,61.439l53.128,53.128c1.901,1.901,1.901,4.984,0,6.886 c-1.902,1.902-4.985,1.902-6.887,0L61.438,68.326L8.312,121.453c-1.901,1.902-4.984,1.902-6.886,0 c-1.901-1.901-1.901-4.984,0-6.886l53.127-53.128L1.426,8.313L1.426,8.313z' }))));
|
|
9
|
+
}
|
|
10
|
+
exports.default = CloseIcon;
|
|
@@ -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, query, getFormProps, advancedParameters } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
11
|
+
const { getSectionProps, query, getFormProps, advancedParameters, getItemProps } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
12
12
|
const { displayShowAllResultsButton, translations } = advancedParameters || {};
|
|
13
13
|
const { onSubmit } = getFormProps();
|
|
14
14
|
const { type, displayName } = section;
|
|
@@ -36,7 +36,7 @@ const DefaultRenderSectionItemsList = function ({ section }) {
|
|
|
36
36
|
react_1.default.createElement("h5", { className: 'cio-section-name cio-sectionName', "aria-hidden": true }, (0, utils_1.camelToStartCase)(sectionTitle)),
|
|
37
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
38
|
if (typeof (section === null || section === void 0 ? void 0 : section.renderItem) === 'function') {
|
|
39
|
-
return section.renderItem({ item, query });
|
|
39
|
+
return section.renderItem({ item, query, getItemProps });
|
|
40
40
|
}
|
|
41
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
42
|
})),
|
package/lib/cjs/constants.js
CHANGED
|
@@ -215,7 +215,7 @@ To see this in action:
|
|
|
215
215
|
3. Then use the Controls to adjust the values of \`numTermsWithGroupSuggestions\` to \`3\` and \`numGroupsSuggestedPerTerm\` to \`1\`
|
|
216
216
|
4. Next, type "pan" in the example autocomplete input field.
|
|
217
217
|
- Notice how the user is presented with three different search terms that have a maximum of one "in {group}" suggestion each`;
|
|
218
|
-
exports.filteredSuggestionsDescription = `Pass a \`filters\` object under \`advancedParameters\` to apply filters to the suggestions. Any parameter supported by <a href="https://docs.constructor.
|
|
218
|
+
exports.filteredSuggestionsDescription = `Pass a \`filters\` object under \`advancedParameters\` to apply filters to the suggestions. Any parameter supported by <a href="https://docs.constructor.com/reference/autocomplete-autocomplete-results" target="__blank">our autocomplete endpoint</a> can be passed under \`advancedParameters\`.
|
|
219
219
|
|
|
220
220
|
To see this in action:
|
|
221
221
|
1. Type "short" in the example below.
|
|
@@ -240,5 +240,6 @@ exports.translationsDescription = `Pass a \`translations\` object to display tra
|
|
|
240
240
|
\`\`\`
|
|
241
241
|
`;
|
|
242
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
|
+
- Make sure to call \`getItemProps(item)\` and spread like this \`<div {...getItemProps(item)}/>\` on the container of each custom rendered item or else tracking will not work.
|
|
243
244
|
`;
|
|
244
245
|
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.`;
|
package/lib/cjs/utils.js
CHANGED
|
@@ -102,8 +102,8 @@ ${templateCode}
|
|
|
102
102
|
exports.getStoryParams = getStoryParams;
|
|
103
103
|
exports.functionStrings = {
|
|
104
104
|
onSubmit: `(submitEvent) => console.dir(submitEvent)`,
|
|
105
|
-
renderItem: `({ item, query }) => (
|
|
106
|
-
<div>
|
|
105
|
+
renderItem: `({ item, query, getItemProps }) => (
|
|
106
|
+
<div {...getItemProps(item)}>
|
|
107
107
|
<a href={item.data?.url}>
|
|
108
108
|
<h3>{item.value}</h3>
|
|
109
109
|
<img src={item.data?.image_url} alt={item.value} />
|
package/lib/cjs/version.js
CHANGED
|
@@ -2,6 +2,7 @@ import React, { useContext } from 'react';
|
|
|
2
2
|
import { toKebabCase } from '../../../utils';
|
|
3
3
|
import { CioAutocompleteContext } from '../CioAutocompleteProvider';
|
|
4
4
|
import SectionItemsList from '../SectionItemsList/SectionItemsList';
|
|
5
|
+
import CloseIcon from './CloseIcon';
|
|
5
6
|
const DefaultRenderResults = ({ sections }) => sections?.map((section) => {
|
|
6
7
|
const { type } = section;
|
|
7
8
|
let key = section.displayName;
|
|
@@ -23,14 +24,16 @@ const DefaultRenderResults = ({ sections }) => sections?.map((section) => {
|
|
|
23
24
|
});
|
|
24
25
|
export default function AutocompleteResults(props) {
|
|
25
26
|
const { children = DefaultRenderResults } = props;
|
|
26
|
-
const { sections, isOpen, getMenuProps, getItemProps } = useContext(CioAutocompleteContext);
|
|
27
|
+
const { sections, isOpen, getMenuProps, getItemProps, closeMenu } = useContext(CioAutocompleteContext);
|
|
27
28
|
const hasResults = sections && sections.some((section) => section?.data?.length);
|
|
28
29
|
const menuProps = {
|
|
29
30
|
...getMenuProps(),
|
|
30
31
|
};
|
|
31
32
|
let content;
|
|
32
33
|
if (isOpen && hasResults) {
|
|
33
|
-
content =
|
|
34
|
+
content = (React.createElement(React.Fragment, null,
|
|
35
|
+
React.createElement(CloseIcon, { onClick: () => closeMenu() }),
|
|
36
|
+
typeof children === 'function' ? children({ sections, getItemProps }) : children));
|
|
34
37
|
}
|
|
35
38
|
else {
|
|
36
39
|
content = null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export default function CloseIcon(props) {
|
|
3
|
+
return (React.createElement("svg", { ...props, className: 'cio-close', version: '1.1', id: 'Layer_1', xmlns: 'http://www.w3.org/2000/svg', x: '0px', y: '0px', width: '122.878px', height: '122.88px', viewBox: '0 0 122.878 122.88', enableBackground: 'new 0 0 122.878 122.88', xmlSpace: 'preserve' },
|
|
4
|
+
React.createElement("g", null,
|
|
5
|
+
React.createElement("path", { d: 'M1.426,8.313c-1.901-1.901-1.901-4.984,0-6.886c1.901-1.902,4.984-1.902,6.886,0l53.127,53.127l53.127-53.127 c1.901-1.902,4.984-1.902,6.887,0c1.901,1.901,1.901,4.985,0,6.886L68.324,61.439l53.128,53.128c1.901,1.901,1.901,4.984,0,6.886 c-1.902,1.902-4.985,1.902-6.887,0L61.438,68.326L8.312,121.453c-1.901,1.902-4.984,1.902-6.886,0 c-1.901-1.901-1.901-4.984,0-6.886l53.127-53.128L1.426,8.313L1.426,8.313z' }))));
|
|
6
|
+
}
|
|
@@ -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, query, getFormProps, advancedParameters } = useContext(CioAutocompleteContext);
|
|
7
|
+
const { getSectionProps, query, getFormProps, advancedParameters, getItemProps } = useContext(CioAutocompleteContext);
|
|
8
8
|
const { displayShowAllResultsButton, translations } = advancedParameters || {};
|
|
9
9
|
const { onSubmit } = getFormProps();
|
|
10
10
|
const { type, displayName } = section;
|
|
@@ -32,7 +32,7 @@ const DefaultRenderSectionItemsList = function ({ section }) {
|
|
|
32
32
|
React.createElement("h5", { className: 'cio-section-name cio-sectionName', "aria-hidden": true }, camelToStartCase(sectionTitle)),
|
|
33
33
|
React.createElement("ul", { className: 'cio-section-items', role: 'none' }, section?.data?.map((item) => {
|
|
34
34
|
if (typeof section?.renderItem === 'function') {
|
|
35
|
-
return section.renderItem({ item, query });
|
|
35
|
+
return section.renderItem({ item, query, getItemProps });
|
|
36
36
|
}
|
|
37
37
|
return (React.createElement(SectionItem, { item: item, key: item?.id, displaySearchTermHighlights: section.displaySearchTermHighlights }));
|
|
38
38
|
})),
|
package/lib/mjs/constants.js
CHANGED
|
@@ -211,7 +211,7 @@ To see this in action:
|
|
|
211
211
|
3. Then use the Controls to adjust the values of \`numTermsWithGroupSuggestions\` to \`3\` and \`numGroupsSuggestedPerTerm\` to \`1\`
|
|
212
212
|
4. Next, type "pan" in the example autocomplete input field.
|
|
213
213
|
- Notice how the user is presented with three different search terms that have a maximum of one "in {group}" suggestion each`;
|
|
214
|
-
export const filteredSuggestionsDescription = `Pass a \`filters\` object under \`advancedParameters\` to apply filters to the suggestions. Any parameter supported by <a href="https://docs.constructor.
|
|
214
|
+
export const filteredSuggestionsDescription = `Pass a \`filters\` object under \`advancedParameters\` to apply filters to the suggestions. Any parameter supported by <a href="https://docs.constructor.com/reference/autocomplete-autocomplete-results" target="__blank">our autocomplete endpoint</a> can be passed under \`advancedParameters\`.
|
|
215
215
|
|
|
216
216
|
To see this in action:
|
|
217
217
|
1. Type "short" in the example below.
|
|
@@ -236,5 +236,6 @@ export const translationsDescription = `Pass a \`translations\` object to displa
|
|
|
236
236
|
\`\`\`
|
|
237
237
|
`;
|
|
238
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
|
+
- Make sure to call \`getItemProps(item)\` and spread like this \`<div {...getItemProps(item)}/>\` on the container of each custom rendered item or else tracking will not work.
|
|
239
240
|
`;
|
|
240
241
|
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.`;
|
package/lib/mjs/utils.js
CHANGED
|
@@ -86,8 +86,8 @@ ${templateCode}
|
|
|
86
86
|
};
|
|
87
87
|
export const functionStrings = {
|
|
88
88
|
onSubmit: `(submitEvent) => console.dir(submitEvent)`,
|
|
89
|
-
renderItem: `({ item, query }) => (
|
|
90
|
-
<div>
|
|
89
|
+
renderItem: `({ item, query, getItemProps }) => (
|
|
90
|
+
<div {...getItemProps(item)}>
|
|
91
91
|
<a href={item.data?.url}>
|
|
92
92
|
<h3>{item.value}</h3>
|
|
93
93
|
<img src={item.data?.image_url} alt={item.value} />
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.23.
|
|
1
|
+
export default '1.23.17';
|
package/lib/styles.css
CHANGED
|
@@ -182,4 +182,13 @@
|
|
|
182
182
|
|
|
183
183
|
.cio-autocomplete .cio-section-footer .cio-show-all-results-button:hover {
|
|
184
184
|
background-color: hsl(0, 0%, 90%);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.cio-autocomplete .cio-close {
|
|
188
|
+
position: absolute;
|
|
189
|
+
top: 20px;
|
|
190
|
+
right: 20px;
|
|
191
|
+
cursor: pointer;
|
|
192
|
+
width: 15px;
|
|
193
|
+
height: 15px;
|
|
185
194
|
}
|
package/lib/types/constants.d.ts
CHANGED
|
@@ -29,10 +29,10 @@ export declare const customStylesDescription = "\nBy default, importing react co
|
|
|
29
29
|
export declare const advancedParametersDescription = "The stories below show how optional fields within this `advancedParameters` object that can be used to fine-tune the autosuggest data returned from constructor's servers.";
|
|
30
30
|
export declare const advancedParametersDefaultDescription = "Passing an `advancedParameters` object is optional. Passing an empty object for the `advancedParameters` field behaves the same as not passing an `advancedParameters` object at all.";
|
|
31
31
|
export declare const termsWithGroupSuggestionsDescription = "Pass integers for the `numTermsWithGroupSuggestions` and `numGroupsSuggestedPerTerm` fields to add suggested group filters to search term suggestions. Not all suggested search terms will have group filters, so these integers are upper limits, used to specify the maximum number of terms with group filters and the maximum number of suggested group filters per term.\n\nTo see this in action:\n1. Type \"pan\" in the example below.\n - Notice how the user is presented with a search term of \"all week flex pant\" as well as \"all week flex pant in Chinos\" and \"all week flex pant baby in Athleisure Pants & Joggers\"\n2. Navigate to the \"Terms With Group Suggestions\" story (using the navigation menu to the left)\n3. Then use the Controls to adjust the values of `numTermsWithGroupSuggestions` to `3` and `numGroupsSuggestedPerTerm` to `1`\n4. Next, type \"pan\" in the example autocomplete input field.\n - Notice how the user is presented with three different search terms that have a maximum of one \"in {group}\" suggestion each";
|
|
32
|
-
export declare const filteredSuggestionsDescription = "Pass a `filters` object under `advancedParameters` to apply filters to the suggestions. Any parameter supported by <a href=\"https://docs.constructor.
|
|
32
|
+
export declare const filteredSuggestionsDescription = "Pass a `filters` object under `advancedParameters` to apply filters to the suggestions. Any parameter supported by <a href=\"https://docs.constructor.com/reference/autocomplete-autocomplete-results\" target=\"__blank\">our autocomplete endpoint</a> can be passed under `advancedParameters`.\n\nTo see this in action:\n1. Type \"short\" in the example below.\n - Notice how the user is presented with only short pants as results.\n - This is because the results are currently filtered to belong to the \"Shorts\" group.\n2. Navigate to the \"Filtered Suggestions\" story (using the navigation menu to the left)\n3. Then use the Controls to adjust the values of `\"group_id\"` to `\"1030\"`.\n4. Next, type \"short\" in the example autocomplete input field.\n - Notice how the user is presented with only short sleeved items as results.\n - This is because we are filtering to the \"Shirts\" group";
|
|
33
33
|
export declare const termsWithImagesAndCountsDescription = "Pass boolean flags for `displaySearchSuggestionImages` and `displaySearchSuggestionResultCounts` fields to display images and counts for search suggestions. These fields need to be made displayable before they can be used. Please contact your Constructor Integration Engineer for details.";
|
|
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
|
+
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- Make sure to call `getItemProps(item)` and spread like this `<div {...getItemProps(item)}/>` on the container of each custom rendered item or else tracking will not work.\n";
|
|
38
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.";
|
package/lib/types/types.d.ts
CHANGED
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.23.
|
|
1
|
+
declare const _default: "1.23.17";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED