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

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.
@@ -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 = typeof children === 'function' ? children({ sections, getItemProps }) : children;
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;
@@ -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, _c, _d, _e, _f;
11
+ var _a, _b;
11
12
  const { item, children, displaySearchTermHighlights } = props;
12
- const { getItemProps, advancedParameters, query, featureToggles } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
13
- const { featureDisplaySearchSuggestionImages, featureDisplaySearchSuggestionResultCounts } = featureToggles;
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
- defaultChildren = (react_1.default.createElement(react_1.default.Fragment, null,
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
- react_1.default.createElement("p", { className: 'cio-suggestion-text' },
32
- react_1.default.createElement(SectionItemText_1.default, { item: item, query: query, highlightSearchTerm: displaySearchTermHighlights })),
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
- ")"))));
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' },
@@ -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;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.23.14';
3
+ exports.default = '1.23.16';
@@ -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 = typeof children === 'function' ? children({ sections, getItemProps }) : children;
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
+ }
@@ -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, featureToggles } = useContext(CioAutocompleteContext);
9
- const { featureDisplaySearchSuggestionImages, featureDisplaySearchSuggestionResultCounts } = featureToggles;
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
- defaultChildren = (React.createElement(React.Fragment, null,
26
- displaySearchSuggestionImages && item.data?.image_url && (React.createElement("img", { src: item.data?.image_url, alt: item.value, className: 'cio-suggestion-image' })),
27
- React.createElement("p", { className: 'cio-suggestion-text' },
28
- React.createElement(SectionItemText, { item: item, query: query, highlightSearchTerm: displaySearchTermHighlights })),
29
- displaySearchSuggestionResultCounts && item.data?.total_num_results && (React.createElement("p", { className: 'cio-suggestion-count' },
30
- "(",
31
- item.data?.total_num_results,
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' },
@@ -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;
@@ -1 +1 @@
1
- export default '1.23.14';
1
+ export default '1.23.16';
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;
@@ -174,4 +182,13 @@
174
182
 
175
183
  .cio-autocomplete .cio-section-footer .cio-show-all-results-button:hover {
176
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;
177
194
  }
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function CloseIcon(props: any): JSX.Element;
@@ -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 {};
@@ -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;
@@ -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;
@@ -1,2 +1,2 @@
1
- declare const _default: "1.23.14";
1
+ declare const _default: "1.23.16";
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.14",
3
+ "version": "1.23.16",
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",