@constructor-io/constructorio-ui-autocomplete 1.20.2 → 1.20.3

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.
@@ -29,8 +29,9 @@ const DefaultRenderSectionItemsList = function ({ section }) {
29
29
  }
30
30
  if (!((_a = section === null || section === void 0 ? void 0 : section.data) === null || _a === void 0 ? void 0 : _a.length))
31
31
  return null;
32
+ // @deprecated `cio-sectionName` will be removed in the next major release
32
33
  return (react_1.default.createElement("li", Object.assign({}, getSectionProps(section)),
33
- react_1.default.createElement("h5", { className: 'cio-sectionName', "aria-hidden": true }, (0, utils_1.camelToStartCase)(sectionTitle)),
34
+ react_1.default.createElement("h5", { className: 'cio-section-name cio-sectionName', "aria-hidden": true }, (0, utils_1.camelToStartCase)(sectionTitle)),
34
35
  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 }))))));
35
36
  };
36
37
  function SectionItemsList(props) {
@@ -182,7 +182,7 @@ import '@constructor-io/constructorio-ui-autocomplete/styles.css';
182
182
  right: 24px;
183
183
  }
184
184
 
185
- .cio-autocomplete.custom-autocomplete-styles .cio-sectionName {
185
+ .cio-autocomplete.custom-autocomplete-styles .cio-section-name {
186
186
  margin: 5px 3px;
187
187
  }
188
188
 
@@ -79,7 +79,9 @@ const useCioAutocomplete = (options) => {
79
79
  getItemProps: (item) => {
80
80
  const { index, sectionId } = (0, utils_1.getItemPosition)({ item, items });
81
81
  const sectionItemTestId = `cio-item-${sectionId === null || sectionId === void 0 ? void 0 : sectionId.replace(' ', '')}`;
82
- return Object.assign(Object.assign({}, getItemProps({ item, index })), { className: `cio-item ${sectionItemTestId}`, 'data-testid': sectionItemTestId });
82
+ return Object.assign(Object.assign({}, getItemProps({ item, index })), {
83
+ // @deprecated `sectionItemTestId` will be removed as a className in the next major version
84
+ className: `cio-item ${sectionItemTestId}`, 'data-testid': sectionItemTestId });
83
85
  },
84
86
  getInputProps: () => (Object.assign(Object.assign({}, getInputProps({
85
87
  onChange: (e) => {
@@ -143,33 +145,46 @@ const useCioAutocomplete = (options) => {
143
145
  'data-testid': 'cio-form',
144
146
  }),
145
147
  getSectionProps: (section) => {
146
- var _a;
147
- const { type } = section;
148
- let sectionTitle;
149
- // Add the indexSectionName as a class to the section container to make sure it gets the styles
148
+ var _a, _b;
149
+ // @deprecated ClassNames derived from this fn will be removed in the next major version
150
+ const getDeprecatedClassNames = () => {
151
+ const { type } = section;
152
+ let sectionTitle;
153
+ const indexSectionName = type !== 'custom' && section.indexSectionName
154
+ ? (0, utils_1.toKebabCase)(section.indexSectionName)
155
+ : '';
156
+ switch (type) {
157
+ case 'recommendations':
158
+ sectionTitle = section.podId;
159
+ break;
160
+ case 'autocomplete':
161
+ sectionTitle = section.displayName || section.indexSectionName;
162
+ break;
163
+ case 'custom':
164
+ sectionTitle = section.displayName;
165
+ break;
166
+ default:
167
+ sectionTitle = section.displayName || section.indexSectionName;
168
+ break;
169
+ }
170
+ return `${sectionTitle} ${indexSectionName}`;
171
+ };
172
+ // Always add the indexSectionName (defaults to Products) as a class to the section container for the styles
150
173
  // Even if the section is a recommendation pod, if the results are "Products" or "Search Suggestions"
151
174
  // ... they should be styled accordingly
152
- const indexSectionName = type !== 'custom' && section.indexSectionName ? (0, utils_1.toKebabCase)(section.indexSectionName) : '';
153
- switch (type) {
154
- case 'recommendations':
155
- sectionTitle = section.podId;
156
- break;
157
- case 'autocomplete':
158
- sectionTitle = section.displayName || section.indexSectionName;
159
- break;
160
- case 'custom':
161
- sectionTitle = section.displayName;
162
- break;
163
- default:
164
- sectionTitle = section.displayName || section.indexSectionName;
165
- break;
166
- }
175
+ const sectionListingType = (0, typeGuards_1.isCustomSection)(section)
176
+ ? 'custom'
177
+ : (0, utils_1.toKebabCase)(section.indexSectionName || ((_a = section.data[0]) === null || _a === void 0 ? void 0 : _a.section) || 'Products');
167
178
  const attributes = {
168
- className: `${sectionTitle} cio-section ${indexSectionName}`,
179
+ className: `cio-section cio-section-${sectionListingType} ${getDeprecatedClassNames()}`,
169
180
  ref: section.ref,
170
181
  role: 'none',
171
- 'data-cnstrc-section': (_a = section.data[0]) === null || _a === void 0 ? void 0 : _a.section,
182
+ 'data-cnstrc-section': (_b = section.data[0]) === null || _b === void 0 ? void 0 : _b.section,
172
183
  };
184
+ if ((0, typeGuards_1.isCustomSection)(section)) {
185
+ attributes['data-cnstrc-custom-section'] = true;
186
+ attributes['data-cnstrc-custom-section-name'] = section.displayName;
187
+ }
173
188
  // Add data attributes for recommendations
174
189
  if ((0, typeGuards_1.isRecommendationsSection)(section)) {
175
190
  attributes['data-cnstrc-recommendations'] = true;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.20.2';
3
+ exports.default = '1.20.3';
@@ -25,8 +25,9 @@ const DefaultRenderSectionItemsList = function ({ section }) {
25
25
  }
26
26
  if (!section?.data?.length)
27
27
  return null;
28
+ // @deprecated `cio-sectionName` will be removed in the next major release
28
29
  return (React.createElement("li", { ...getSectionProps(section) },
29
- React.createElement("h5", { className: 'cio-sectionName', "aria-hidden": true }, camelToStartCase(sectionTitle)),
30
+ React.createElement("h5", { className: 'cio-section-name cio-sectionName', "aria-hidden": true }, camelToStartCase(sectionTitle)),
30
31
  React.createElement("ul", { className: 'cio-section-items', role: 'none' }, section?.data?.map((item) => (React.createElement(SectionItem, { item: item, key: item?.id, displaySearchTermHighlights: section.displaySearchTermHighlights }))))));
31
32
  };
32
33
  export default function SectionItemsList(props) {
@@ -178,7 +178,7 @@ import '@constructor-io/constructorio-ui-autocomplete/styles.css';
178
178
  right: 24px;
179
179
  }
180
180
 
181
- .cio-autocomplete.custom-autocomplete-styles .cio-sectionName {
181
+ .cio-autocomplete.custom-autocomplete-styles .cio-section-name {
182
182
  margin: 5px 3px;
183
183
  }
184
184
 
@@ -7,7 +7,7 @@ import { getItemPosition, getItemsForActiveSections, getFeatures, trackRecommend
7
7
  import useConsoleErrors from './useConsoleErrors';
8
8
  import useSections from './useSections';
9
9
  import useRecommendationsObserver from './useRecommendationsObserver';
10
- import { isAutocompleteSection, isRecommendationsSection } from '../typeGuards';
10
+ import { isAutocompleteSection, isCustomSection, isRecommendationsSection } from '../typeGuards';
11
11
  export const defaultSections = [
12
12
  {
13
13
  indexSectionName: 'Search Suggestions',
@@ -81,6 +81,7 @@ const useCioAutocomplete = (options) => {
81
81
  const sectionItemTestId = `cio-item-${sectionId?.replace(' ', '')}`;
82
82
  return {
83
83
  ...getItemProps({ item, index }),
84
+ // @deprecated `sectionItemTestId` will be removed as a className in the next major version
84
85
  className: `cio-item ${sectionItemTestId}`,
85
86
  'data-testid': sectionItemTestId,
86
87
  };
@@ -154,32 +155,45 @@ const useCioAutocomplete = (options) => {
154
155
  'data-testid': 'cio-form',
155
156
  }),
156
157
  getSectionProps: (section) => {
157
- const { type } = section;
158
- let sectionTitle;
159
- // Add the indexSectionName as a class to the section container to make sure it gets the styles
158
+ // @deprecated ClassNames derived from this fn will be removed in the next major version
159
+ const getDeprecatedClassNames = () => {
160
+ const { type } = section;
161
+ let sectionTitle;
162
+ const indexSectionName = type !== 'custom' && section.indexSectionName
163
+ ? toKebabCase(section.indexSectionName)
164
+ : '';
165
+ switch (type) {
166
+ case 'recommendations':
167
+ sectionTitle = section.podId;
168
+ break;
169
+ case 'autocomplete':
170
+ sectionTitle = section.displayName || section.indexSectionName;
171
+ break;
172
+ case 'custom':
173
+ sectionTitle = section.displayName;
174
+ break;
175
+ default:
176
+ sectionTitle = section.displayName || section.indexSectionName;
177
+ break;
178
+ }
179
+ return `${sectionTitle} ${indexSectionName}`;
180
+ };
181
+ // Always add the indexSectionName (defaults to Products) as a class to the section container for the styles
160
182
  // Even if the section is a recommendation pod, if the results are "Products" or "Search Suggestions"
161
183
  // ... they should be styled accordingly
162
- const indexSectionName = type !== 'custom' && section.indexSectionName ? toKebabCase(section.indexSectionName) : '';
163
- switch (type) {
164
- case 'recommendations':
165
- sectionTitle = section.podId;
166
- break;
167
- case 'autocomplete':
168
- sectionTitle = section.displayName || section.indexSectionName;
169
- break;
170
- case 'custom':
171
- sectionTitle = section.displayName;
172
- break;
173
- default:
174
- sectionTitle = section.displayName || section.indexSectionName;
175
- break;
176
- }
184
+ const sectionListingType = isCustomSection(section)
185
+ ? 'custom'
186
+ : toKebabCase(section.indexSectionName || section.data[0]?.section || 'Products');
177
187
  const attributes = {
178
- className: `${sectionTitle} cio-section ${indexSectionName}`,
188
+ className: `cio-section cio-section-${sectionListingType} ${getDeprecatedClassNames()}`,
179
189
  ref: section.ref,
180
190
  role: 'none',
181
191
  'data-cnstrc-section': section.data[0]?.section,
182
192
  };
193
+ if (isCustomSection(section)) {
194
+ attributes['data-cnstrc-custom-section'] = true;
195
+ attributes['data-cnstrc-custom-section-name'] = section.displayName;
196
+ }
183
197
  // Add data attributes for recommendations
184
198
  if (isRecommendationsSection(section)) {
185
199
  attributes['data-cnstrc-recommendations'] = true;
@@ -1 +1 @@
1
- export default '1.20.2';
1
+ export default '1.20.3';
package/lib/styles.css CHANGED
@@ -61,7 +61,9 @@
61
61
  margin-top: 5px;
62
62
  }
63
63
 
64
- .cio-autocomplete .cio-sectionName {
64
+ /* @deprecated in favor of .cio-section-name */
65
+ .cio-autocomplete .cio-sectionName,
66
+ .cio-autocomplete .cio-section-name {
65
67
  margin: 15px 0;
66
68
  font-size: 1rem;
67
69
  }
@@ -70,7 +72,9 @@
70
72
  padding: 0;
71
73
  }
72
74
 
73
- .cio-autocomplete .cio-item.cio-item-SearchSuggestions {
75
+ /* @deprecated in favor of .cio-section-search-suggestions */
76
+ .cio-autocomplete .cio-item.cio-item-SearchSuggestions,
77
+ .cio-autocomplete .cio-section-search-suggestions .cio-item {
74
78
  flex-direction: row;
75
79
  min-width: 160px;
76
80
  justify-content: space-between;
@@ -92,11 +96,15 @@
92
96
  border-radius: 4px;
93
97
  }
94
98
 
95
- .cio-autocomplete .products {
99
+ /* @deprecated in favor of .cio-section-products */
100
+ .cio-autocomplete .products,
101
+ .cio-autocomplete .cio-section-products {
96
102
  padding: 0 5px;
97
103
  }
98
104
 
99
- .cio-autocomplete .products .cio-item {
105
+ /* @deprecated in favor of .cio-section-products .cio-item */
106
+ .cio-autocomplete .products .cio-item,
107
+ .cio-autocomplete .cio-section-products .cio-item {
100
108
  display: inline-flex;
101
109
  align-items: center;
102
110
  width: 25%;
@@ -134,4 +142,4 @@
134
142
  .cio-autocomplete .cio-suggestion-count {
135
143
  font-size: 0.8rem;
136
144
  margin-left: 8px;
137
- }
145
+ }
@@ -25,7 +25,7 @@ export declare const onSubmitDefault: (submitEvent: AutocompleteSubmitEvent) =>
25
25
  export declare const zeroStateSectionsDescription = "Use `zeroStateSections` to show suggestions after a user applies focus to the search input field and before they start typing a query";
26
26
  export declare const openOnFocusDescription = "Use `openOnFocus: false` to show suggestions after a user clears their query, but not when they initially apply focus to the search input field";
27
27
  export declare const multipleSectionsDescription = "Use as many different `recommendations` and `custom` sections as you'd like and in whatever order you would like!";
28
- export declare const customStylesDescription = "\nBy default, importing react components or hooks from this library does not pull any css into your project.\n\nIf you wish to use some starter styles from this library, add an import statement similar to the example import statement below:\n\n`\nimport '@constructor-io/constructorio-ui-autocomplete/styles.css';\n`\n\n<i></i>\n\n- To opt out of all default styling, do not import the `styles.css` stylesheet.\n- The path and syntax in the example above may change depending on your module bundling strategy\n- These starter styles can be used as a foundation to build on top of, or just as a reference for you to replace completely.\n- All starter styles in this library are scoped within the `.cio-autocomplete` css selector.\n- These starter styles are intended to be extended by layering in your own css rules\n- If you like, you can override the container's className like so:\n`autocompleteClassName='custom-autocomplete-container'`\n- If you like, you can pass additional className(s) of your choosing like so:\n`autocompleteClassName='cio-autocomplete custom-autocomplete-container'`\n\n\n```css\n/* Custom Style Sheet */\n.cio-autocomplete.custom-autocomplete-styles form {\n height: 44px;\n width: 600px;\n border-radius: 8px;\n background-color: rgb(247, 247, 247);\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-input {\n font-weight: bold;\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-form button {\n width: 44px;\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-clear-btn {\n right: 24px;\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-sectionName {\n margin: 5px 3px;\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-results {\n width: 620px;\n max-height: 334px;\n overflow: hidden;\n border-radius: 0px 0px 8px 8px;\n color: rgb(51, 51, 51);\n}\n\n.cio-autocomplete.custom-autocomplete-styles .products p {\n padding: 5px 5px 0;\n}\n```\n";
28
+ export declare const customStylesDescription = "\nBy default, importing react components or hooks from this library does not pull any css into your project.\n\nIf you wish to use some starter styles from this library, add an import statement similar to the example import statement below:\n\n`\nimport '@constructor-io/constructorio-ui-autocomplete/styles.css';\n`\n\n<i></i>\n\n- To opt out of all default styling, do not import the `styles.css` stylesheet.\n- The path and syntax in the example above may change depending on your module bundling strategy\n- These starter styles can be used as a foundation to build on top of, or just as a reference for you to replace completely.\n- All starter styles in this library are scoped within the `.cio-autocomplete` css selector.\n- These starter styles are intended to be extended by layering in your own css rules\n- If you like, you can override the container's className like so:\n`autocompleteClassName='custom-autocomplete-container'`\n- If you like, you can pass additional className(s) of your choosing like so:\n`autocompleteClassName='cio-autocomplete custom-autocomplete-container'`\n\n\n```css\n/* Custom Style Sheet */\n.cio-autocomplete.custom-autocomplete-styles form {\n height: 44px;\n width: 600px;\n border-radius: 8px;\n background-color: rgb(247, 247, 247);\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-input {\n font-weight: bold;\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-form button {\n width: 44px;\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-clear-btn {\n right: 24px;\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-section-name {\n margin: 5px 3px;\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-results {\n width: 620px;\n max-height: 334px;\n overflow: hidden;\n border-radius: 0px 0px 8px 8px;\n color: rgb(51, 51, 51);\n}\n\n.cio-autocomplete.custom-autocomplete-styles .products p {\n padding: 5px 5px 0;\n}\n```\n";
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";
@@ -1,2 +1,2 @@
1
- declare const _default: "1.20.2";
1
+ declare const _default: "1.20.3";
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.20.2",
3
+ "version": "1.20.3",
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",