@constructor-io/constructorio-ui-autocomplete 1.23.13 → 1.23.14

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.
@@ -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) => (react_1.default.createElement(SectionItem_1.default, { item: item, key: item === null || item === void 0 ? void 0 : item.id, displaySearchTermHighlights: section.displaySearchTermHighlights })))),
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' },
@@ -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.`;
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
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.23.13';
3
+ exports.default = '1.23.14';
@@ -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) => (React.createElement(SectionItem, { item: item, key: item?.id, displaySearchTermHighlights: section.displaySearchTermHighlights })))),
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' },
@@ -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.`;
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
@@ -1 +1 @@
1
- export default '1.23.13';
1
+ export default '1.23.14';
@@ -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.";
@@ -90,6 +90,10 @@ export type SectionConfiguration = {
90
90
  numResults?: number;
91
91
  displaySearchTermHighlights?: boolean;
92
92
  ref?: React.RefObject<HTMLElement>;
93
+ renderItem?: (props: {
94
+ item: Item;
95
+ query: string;
96
+ }) => ReactNode;
93
97
  };
94
98
  export interface AutocompleteSectionConfiguration extends SectionConfiguration {
95
99
  type?: 'autocomplete';
@@ -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;
@@ -1,2 +1,2 @@
1
- declare const _default: "1.23.13";
1
+ declare const _default: "1.23.14";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-autocomplete",
3
- "version": "1.23.13",
3
+ "version": "1.23.14",
4
4
  "description": "Constructor.io Autocomplete UI library for web applications",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",