@constructor-io/constructorio-ui-autocomplete 1.23.24 → 1.23.25

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.
@@ -0,0 +1,8 @@
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 NoResults() {
6
+ return react_1.default.createElement("div", { className: 'cio-no-results-message' }, "No Results Found");
7
+ }
8
+ exports.default = NoResults;
@@ -5,13 +5,14 @@ const react_1 = tslib_1.__importStar(require("react"));
5
5
  const SectionItem_1 = tslib_1.__importDefault(require("../SectionItem/SectionItem"));
6
6
  const utils_1 = require("../../../utils");
7
7
  const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
8
+ const NoResults_1 = tslib_1.__importDefault(require("../AutocompleteResults/NoResults"));
8
9
  // eslint-disable-next-line func-names
9
10
  const DefaultRenderSectionItemsList = function ({ section }) {
10
- var _a, _b;
11
+ var _a, _b, _c;
11
12
  const { getSectionProps, query, getFormProps, advancedParameters, getItemProps } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
12
13
  const { displayShowAllResultsButton, translations } = advancedParameters || {};
13
14
  const { onSubmit } = getFormProps();
14
- const { type, displayName } = section;
15
+ const { type, displayName, displayNoResultsMessage } = section;
15
16
  let sectionTitle = displayName;
16
17
  if (!sectionTitle) {
17
18
  switch (type) {
@@ -29,12 +30,17 @@ const DefaultRenderSectionItemsList = function ({ section }) {
29
30
  break;
30
31
  }
31
32
  }
32
- if (!((_a = section === null || section === void 0 ? void 0 : section.data) === null || _a === void 0 ? void 0 : _a.length))
33
+ // Display no results message
34
+ if (!((_a = section === null || section === void 0 ? void 0 : section.data) === null || _a === void 0 ? void 0 : _a.length) && displayNoResultsMessage)
35
+ return (react_1.default.createElement("li", Object.assign({}, getSectionProps(section)),
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(NoResults_1.default, null)));
38
+ if (!((_b = section === null || section === void 0 ? void 0 : section.data) === null || _b === void 0 ? void 0 : _b.length))
33
39
  return null;
34
40
  // @deprecated `cio-sectionName` will be removed in the next major release
35
41
  return (react_1.default.createElement("li", Object.assign({}, getSectionProps(section)),
36
42
  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) => {
43
+ react_1.default.createElement("ul", { className: 'cio-section-items', role: 'none' }, (_c = section === null || section === void 0 ? void 0 : section.data) === null || _c === void 0 ? void 0 : _c.map((item) => {
38
44
  if (typeof (section === null || section === void 0 ? void 0 : section.renderItem) === 'function') {
39
45
  return section.renderItem({ item, query, getItemProps });
40
46
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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.onIsOpenChangeDescription = 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.onIsOpenChangeDescription = exports.onChangeDescription = exports.onFocusDescription = exports.customSectionDescription = exports.displayNoResultsMessageDescription = 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
  /// //////////////////////////////
@@ -128,6 +128,7 @@ exports.numResultsDescription = `Override default \`numResults\` to only suggest
128
128
  exports.sectionOrderDescription = `Override default \`numResults\` to suggest products, then terms`;
129
129
  exports.recommendationsDescription = `Use constructor's recommendations service, with \`"type": "recommendations"\``;
130
130
  exports.displaySearchTermHighlightsDescription = `Use constructor's auto highlighting of words that match the search keyword, with \`"displaySearchTermHighlights": true\``;
131
+ exports.displayNoResultsMessageDescription = `Display a no results message for this section, with \`"displayNoResultsMessage": true\``;
131
132
  exports.customSectionDescription = `Use a custom section, by managing and passing your own data, with \`"type": "custom"\` and \`"data":[{...}]\``;
132
133
  exports.onFocusDescription = `Pass an \`onFocus\` callback function to execute some code each time the user applies focus to the text input field`;
133
134
  exports.onChangeDescription = `Pass an \`onChange\` callback function to execute some code each time the user changes the value of the text input field`;
@@ -49,7 +49,7 @@ const useCioAutocomplete = (options) => {
49
49
  totalNumResultsPerSection,
50
50
  request,
51
51
  featureToggles: features,
52
- isOpen: isOpen && (items === null || items === void 0 ? void 0 : items.length) > 0,
52
+ isOpen,
53
53
  getMenuProps: () => (Object.assign(Object.assign({}, getMenuProps()), { className: 'cio-results', 'data-testid': 'cio-results', 'data-cnstrc-autosuggest': '' })),
54
54
  getLabelProps,
55
55
  openMenu,
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.23.24';
3
+ exports.default = '1.23.25';
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export default function NoResults() {
3
+ return React.createElement("div", { className: 'cio-no-results-message' }, "No Results Found");
4
+ }
@@ -2,12 +2,13 @@ import React, { useContext } from 'react';
2
2
  import SectionItem from '../SectionItem/SectionItem';
3
3
  import { camelToStartCase, translate } from '../../../utils';
4
4
  import { CioAutocompleteContext } from '../CioAutocompleteProvider';
5
+ import NoResults from '../AutocompleteResults/NoResults';
5
6
  // eslint-disable-next-line func-names
6
7
  const DefaultRenderSectionItemsList = function ({ section }) {
7
8
  const { getSectionProps, query, getFormProps, advancedParameters, getItemProps } = useContext(CioAutocompleteContext);
8
9
  const { displayShowAllResultsButton, translations } = advancedParameters || {};
9
10
  const { onSubmit } = getFormProps();
10
- const { type, displayName } = section;
11
+ const { type, displayName, displayNoResultsMessage } = section;
11
12
  let sectionTitle = displayName;
12
13
  if (!sectionTitle) {
13
14
  switch (type) {
@@ -25,6 +26,11 @@ const DefaultRenderSectionItemsList = function ({ section }) {
25
26
  break;
26
27
  }
27
28
  }
29
+ // Display no results message
30
+ if (!section?.data?.length && displayNoResultsMessage)
31
+ return (React.createElement("li", { ...getSectionProps(section) },
32
+ React.createElement("h5", { className: 'cio-section-name cio-sectionName', "aria-hidden": true }, camelToStartCase(sectionTitle)),
33
+ React.createElement(NoResults, null)));
28
34
  if (!section?.data?.length)
29
35
  return null;
30
36
  // @deprecated `cio-sectionName` will be removed in the next major release
@@ -125,6 +125,7 @@ export const numResultsDescription = `Override default \`numResults\` to only su
125
125
  export const sectionOrderDescription = `Override default \`numResults\` to suggest products, then terms`;
126
126
  export const recommendationsDescription = `Use constructor's recommendations service, with \`"type": "recommendations"\``;
127
127
  export const displaySearchTermHighlightsDescription = `Use constructor's auto highlighting of words that match the search keyword, with \`"displaySearchTermHighlights": true\``;
128
+ export const displayNoResultsMessageDescription = `Display a no results message for this section, with \`"displayNoResultsMessage": true\``;
128
129
  export const customSectionDescription = `Use a custom section, by managing and passing your own data, with \`"type": "custom"\` and \`"data":[{...}]\``;
129
130
  export const onFocusDescription = `Pass an \`onFocus\` callback function to execute some code each time the user applies focus to the text input field`;
130
131
  export const onChangeDescription = `Pass an \`onChange\` callback function to execute some code each time the user changes the value of the text input field`;
@@ -48,7 +48,7 @@ const useCioAutocomplete = (options) => {
48
48
  totalNumResultsPerSection,
49
49
  request,
50
50
  featureToggles: features,
51
- isOpen: isOpen && items?.length > 0,
51
+ isOpen,
52
52
  getMenuProps: () => ({
53
53
  ...getMenuProps(),
54
54
  className: 'cio-results',
@@ -1 +1 @@
1
- export default '1.23.24';
1
+ export default '1.23.25';
package/lib/styles.css CHANGED
@@ -191,4 +191,9 @@
191
191
  cursor: pointer;
192
192
  width: 15px;
193
193
  height: 15px;
194
- }
194
+ }
195
+
196
+ .cio-autocomplete .cio-section-search-suggestions .cio-no-results-message {
197
+ min-width: 160px;
198
+ margin: 15px 3px;
199
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function NoResults(): JSX.Element;
@@ -17,6 +17,7 @@ export declare const numResultsDescription = "Override default `numResults` to o
17
17
  export declare const sectionOrderDescription = "Override default `numResults` to suggest products, then terms";
18
18
  export declare const recommendationsDescription = "Use constructor's recommendations service, with `\"type\": \"recommendations\"`";
19
19
  export declare const displaySearchTermHighlightsDescription = "Use constructor's auto highlighting of words that match the search keyword, with `\"displaySearchTermHighlights\": true`";
20
+ export declare const displayNoResultsMessageDescription = "Display a no results message for this section, with `\"displayNoResultsMessage\": true`";
20
21
  export declare const customSectionDescription = "Use a custom section, by managing and passing your own data, with `\"type\": \"custom\"` and `\"data\":[{...}]`";
21
22
  export declare const onFocusDescription = "Pass an `onFocus` callback function to execute some code each time the user applies focus to the text input field";
22
23
  export declare const onChangeDescription = "Pass an `onChange` callback function to execute some code each time the user changes the value of the text input field";
@@ -94,6 +94,7 @@ export type SectionConfiguration = {
94
94
  displayName?: string;
95
95
  numResults?: number;
96
96
  displaySearchTermHighlights?: boolean;
97
+ displayNoResultsMessage?: boolean;
97
98
  ref?: React.RefObject<HTMLElement>;
98
99
  renderItem?: (props: {
99
100
  item: Item;
@@ -1,2 +1,2 @@
1
- declare const _default: "1.23.24";
1
+ declare const _default: "1.23.25";
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.24",
3
+ "version": "1.23.25",
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",