@constructor-io/constructorio-ui-autocomplete 1.25.3 → 1.25.5

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.
@@ -17,7 +17,15 @@ function DefaultRenderInput({ getFormProps, getInputProps, getLabelProps, setQue
17
17
  react_1.default.createElement("div", { className: 'cio-icon' },
18
18
  react_1.default.createElement("svg", { stroke: 'currentColor', fill: 'currentColor', strokeWidth: '0', viewBox: '0 0 512 512', height: '1em', width: '1em', xmlns: 'http://www.w3.org/2000/svg' },
19
19
  react_1.default.createElement("path", { d: 'M289.94 256l95-95A24 24 0 00351 127l-95 95-95-95a24 24 0 00-34 34l95 95-95 95a24 24 0 1034 34l95-95 95 95a24 24 0 0034-34z' })))),
20
- react_1.default.createElement("button", { className: 'cio-submit-btn', "data-testid": 'cio-submit-btn', disabled: !inputProps.value, "data-cnstrc-search-submit-btn": true, type: 'submit', "aria-label": 'Submit Search' },
20
+ react_1.default.createElement("button", { className: 'cio-submit-btn', "data-testid": 'cio-submit-btn', "data-cnstrc-search-submit-btn": true, onClick: (e) => {
21
+ var _a;
22
+ if (!inputProps.value) {
23
+ e.preventDefault();
24
+ if (inputProps.id) {
25
+ (_a = document.getElementById(inputProps.id)) === null || _a === void 0 ? void 0 : _a.focus();
26
+ }
27
+ }
28
+ }, type: 'submit', "aria-label": 'Submit Search' },
21
29
  react_1.default.createElement("div", { className: 'cio-icon' },
22
30
  react_1.default.createElement("svg", { stroke: 'currentColor', fill: 'currentColor', strokeWidth: '0', viewBox: '0 0 512 512', height: '1em', width: '1em', xmlns: 'http://www.w3.org/2000/svg' },
23
31
  react_1.default.createElement("path", { d: 'M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z' }))))));
@@ -60,12 +60,26 @@ const useCioAutocomplete = (options) => {
60
60
  openMenu,
61
61
  closeMenu,
62
62
  getItemProps: (item) => {
63
- var _a;
63
+ var _a, _b;
64
64
  const { index, sectionId } = (0, helpers_1.getItemPosition)({ item, items });
65
65
  const sectionItemTestId = `cio-item-${sectionId === null || sectionId === void 0 ? void 0 : sectionId.replace(' ', '')}`;
66
- return Object.assign(Object.assign({}, getItemPropsDownShift({ item, index })), {
66
+ // Products always have links, Search Suggestions with getSearchResultsUrl have links
67
+ const hasLink = ((_a = item.data) === null || _a === void 0 ? void 0 : _a.url) || (item.section === 'Search Suggestions' && getSearchResultsUrl) || false;
68
+ const nonInteractiveItemsProps = {
69
+ tabIndex: 0,
70
+ onKeyDown: (event) => {
71
+ const { code, key } = event;
72
+ const isEnter = code === 'Enter' || key === 'Enter';
73
+ if (isEnter) {
74
+ event.preventDefault();
75
+ // Trigger default click behavior
76
+ getItemPropsDownShift({ item, index }).onClick(event);
77
+ }
78
+ },
79
+ };
80
+ return Object.assign(Object.assign(Object.assign({}, getItemPropsDownShift({ item, index })), {
67
81
  // @deprecated `sectionItemTestId` will be removed as a className in the next major version
68
- 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 });
82
+ 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': (_b = item.data) === null || _b === void 0 ? void 0 : _b.id }), (hasLink ? {} : nonInteractiveItemsProps));
69
83
  },
70
84
  getInputProps: () => (Object.assign(Object.assign({}, getInputProps({
71
85
  onChange: (e) => {
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.25.3';
3
+ exports.default = '1.25.5';
@@ -14,7 +14,14 @@ function DefaultRenderInput({ getFormProps, getInputProps, getLabelProps, setQue
14
14
  React.createElement("div", { className: 'cio-icon' },
15
15
  React.createElement("svg", { stroke: 'currentColor', fill: 'currentColor', strokeWidth: '0', viewBox: '0 0 512 512', height: '1em', width: '1em', xmlns: 'http://www.w3.org/2000/svg' },
16
16
  React.createElement("path", { d: 'M289.94 256l95-95A24 24 0 00351 127l-95 95-95-95a24 24 0 00-34 34l95 95-95 95a24 24 0 1034 34l95-95 95 95a24 24 0 0034-34z' })))),
17
- React.createElement("button", { className: 'cio-submit-btn', "data-testid": 'cio-submit-btn', disabled: !inputProps.value, "data-cnstrc-search-submit-btn": true, type: 'submit', "aria-label": 'Submit Search' },
17
+ React.createElement("button", { className: 'cio-submit-btn', "data-testid": 'cio-submit-btn', "data-cnstrc-search-submit-btn": true, onClick: (e) => {
18
+ if (!inputProps.value) {
19
+ e.preventDefault();
20
+ if (inputProps.id) {
21
+ document.getElementById(inputProps.id)?.focus();
22
+ }
23
+ }
24
+ }, type: 'submit', "aria-label": 'Submit Search' },
18
25
  React.createElement("div", { className: 'cio-icon' },
19
26
  React.createElement("svg", { stroke: 'currentColor', fill: 'currentColor', strokeWidth: '0', viewBox: '0 0 512 512', height: '1em', width: '1em', xmlns: 'http://www.w3.org/2000/svg' },
20
27
  React.createElement("path", { d: 'M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z' }))))));
@@ -66,6 +66,20 @@ const useCioAutocomplete = (options) => {
66
66
  getItemProps: (item) => {
67
67
  const { index, sectionId } = getItemPosition({ item, items });
68
68
  const sectionItemTestId = `cio-item-${sectionId?.replace(' ', '')}`;
69
+ // Products always have links, Search Suggestions with getSearchResultsUrl have links
70
+ const hasLink = item.data?.url || (item.section === 'Search Suggestions' && getSearchResultsUrl) || false;
71
+ const nonInteractiveItemsProps = {
72
+ tabIndex: 0,
73
+ onKeyDown: (event) => {
74
+ const { code, key } = event;
75
+ const isEnter = code === 'Enter' || key === 'Enter';
76
+ if (isEnter) {
77
+ event.preventDefault();
78
+ // Trigger default click behavior
79
+ getItemPropsDownShift({ item, index }).onClick(event);
80
+ }
81
+ },
82
+ };
69
83
  return {
70
84
  ...getItemPropsDownShift({ item, index }),
71
85
  // @deprecated `sectionItemTestId` will be removed as a className in the next major version
@@ -75,6 +89,7 @@ const useCioAutocomplete = (options) => {
75
89
  'data-cnstrc-item-group': item.groupId,
76
90
  'data-cnstrc-item-name': item.value,
77
91
  'data-cnstrc-item-id': item.data?.id,
92
+ ...(hasLink ? {} : nonInteractiveItemsProps),
78
93
  };
79
94
  },
80
95
  getInputProps: () => ({
@@ -1 +1 @@
1
- export default '1.25.3';
1
+ export default '1.25.5';
package/lib/styles.css CHANGED
@@ -31,9 +31,6 @@
31
31
  cursor: pointer;
32
32
  }
33
33
 
34
- .cio-autocomplete button:disabled {
35
- cursor: not-allowed;
36
- }
37
34
 
38
35
  .cio-autocomplete .cio-submit-btn {
39
36
  right: -21px;
@@ -4,8 +4,17 @@ import ConstructorIOClient from '@constructor-io/constructorio-client-javascript
4
4
  import { IAutocompleteParameters, SearchSuggestion as SearchSuggestionFromClient, Product as ProductFromClient, Item as ItemBase, AutocompleteRequestType, ConstructorClientOptions, RecommendationsParameters } from '@constructor-io/constructorio-client-javascript/lib/types';
5
5
  export type { IAutocompleteParameters } from '@constructor-io/constructorio-client-javascript/lib/types';
6
6
  export type CioClientConfig = {
7
+ /**
8
+ * Your Constructor API key. Either `apiKey` or `cioJsClient` are required
9
+ */
7
10
  apiKey?: string;
11
+ /**
12
+ * Optional custom constructor instance. Either `apiKey` or `cioJsClient` are required
13
+ */
8
14
  cioJsClient?: ConstructorIOClient;
15
+ /**
16
+ * Pass a `cioJsClientOptions` object to customize the client's configurations w/o creating a new instance of `ConstructorIOClient`. You can learn more about the possible values [Here](https://constructor-io.github.io/constructorio-client-javascript/ConstructorIO.html)
17
+ */
9
18
  cioJsClientOptions?: ConstructorClientOptions;
10
19
  };
11
20
  export interface AdvancedParametersBase {
@@ -24,17 +33,58 @@ type OptionalItemsComboboxProps<Item> = Partial<UseComboboxProps<Item>> & {
24
33
  };
25
34
  export type UseCioAutocompleteOptions = Omit<CioAutocompleteProps, 'children'>;
26
35
  export type CioAutocompleteProps = CioClientConfig & OptionalItemsComboboxProps<Item> & {
36
+ /**
37
+ * Set to `false` to show suggestions only after a user clears their query,
38
+ * but not when they initially select the input
39
+ */
27
40
  openOnFocus?: boolean;
41
+ /**
42
+ * Transforms a `SearchSuggestion` into the desired URL string to be used when rendering anchor tags
43
+ * i.e. <a href=getSearchResultsUrl([selected_search_suggestion])>[Search Suggestion]</a>
44
+ */
28
45
  getSearchResultsUrl?: (item: SearchSuggestion) => string;
46
+ /**
47
+ * Callback function that runs when the user submits a search.
48
+ * Usually used to trigger a redirect
49
+ */
29
50
  onSubmit: OnSubmit;
51
+ /**
52
+ * Callback function that runs when the user focuses on the input
53
+ */
30
54
  onFocus?: () => void;
55
+ /**
56
+ * Callback function that runs when the user modifies input
57
+ */
31
58
  onChange?: (input: string) => void;
59
+ /**
60
+ * Search input placeholder
61
+ */
32
62
  placeholder?: string;
63
+ /**
64
+ * Children to be rendered according to the RenderProps pattern
65
+ */
33
66
  children?: ReactNode;
67
+ /**
68
+ * Configure the sections rendered, based on the user's input. This can be either Constructor-powered sections,
69
+ * or your own custom sections. Defaults to Products and Search Suggestion sections powered by Constructor
70
+ */
34
71
  sections?: UserDefinedSection[];
72
+ /**
73
+ * Configure either Constructor-powered sections or power your own custom sections,
74
+ * to be rendered for [Autocomplete Zero-State](link-tbd)
75
+ */
35
76
  zeroStateSections?: UserDefinedSection[];
77
+ /**
78
+ * Configure the parent container's class. Defaults to `cio-autocomplete`
79
+ */
36
80
  autocompleteClassName?: string;
81
+ /**
82
+ * See Advanced Parameters
83
+ */
37
84
  advancedParameters?: AdvancedParameters;
85
+ /**
86
+ * Search input default value
87
+ */
38
88
  defaultInput?: string;
39
89
  };
40
90
  /**
@@ -1,2 +1,2 @@
1
- declare const _default: "1.25.3";
1
+ declare const _default: "1.25.5";
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.25.3",
3
+ "version": "1.25.5",
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",
@@ -36,9 +36,11 @@
36
36
  "test-storybook": "test-storybook",
37
37
  "test-storybook:watch": "test-storybook --watch",
38
38
  "test-storybook:ci": "start-server-and-test storybook:ci http://localhost:6006 test-storybook",
39
- "build-storybook": "storybook build -o 'docs'",
39
+ "build-storybook": "storybook build --docs -o 'docs'",
40
+ "storybook-docs-dev": "storybook dev --docs -p 6007",
40
41
  "serve-built-storybook": "npx http-server docs",
41
- "compile": "rm -rf lib && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && npm run copy-styles && vite build"
42
+ "compile": "rm -rf lib && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && npm run copy-styles && vite build",
43
+ "doctoc-readme": "doctoc README.md --title '## 📌 Table of Contents'"
42
44
  },
43
45
  "author": "Constructor.io Corporation",
44
46
  "license": "MIT",
@@ -84,6 +86,7 @@
84
86
  "@types/react-dom": "^18.0.6",
85
87
  "@typescript-eslint/eslint-plugin": "^5.38.0",
86
88
  "@typescript-eslint/parser": "^5.38.0",
89
+ "doctoc": "^2.2.1",
87
90
  "eslint": "^8.23.1",
88
91
  "eslint-config-airbnb": "^19.0.4",
89
92
  "eslint-config-airbnb-typescript": "^17.0.0",