@constructor-io/constructorio-ui-autocomplete
Advanced tools
Comparing version 1.23.22 to 1.23.23
@@ -71,2 +71,3 @@ "use strict"; | ||
- each recommendation section object must have a \`podId\` | ||
- passing displayName in the sectionConfiguration will override the displayName set by Merchandisers on the Customer Dashboard for the recommendation section | ||
- each custom section object must have a \`displayName\` | ||
@@ -110,2 +111,3 @@ - each section object can specify a \`type\` | ||
- each recommendation section object must have a \`podId\` | ||
- passing displayName in the sectionConfiguration will override the displayName set by Merchandisers on the Customer Dashboard for the recommendation section | ||
- each custom section object must have a \`displayName\` | ||
@@ -112,0 +114,0 @@ - each section object can specify a \`type\` |
@@ -28,3 +28,3 @@ "use strict"; | ||
// Return current active sections populated with data from the API response sectionsResults | ||
const activeSectionsWithData = (0, useActiveSectionsWithData_1.default)(sectionsResults, activeSections, sectionsRefs, query); | ||
const activeSectionsWithData = (0, useActiveSectionsWithData_1.default)(sectionsResults, activeSections, sectionsRefs, query, recommendations.podsData); | ||
return { | ||
@@ -31,0 +31,0 @@ fetchRecommendationResults: recommendations.fetchRecommendationResults, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* eslint-disable max-params */ | ||
const react_1 = require("react"); | ||
const utils_1 = require("../../utils"); | ||
function useActiveSectionsWithData(sectionsResults, activeSections, sectionsRefs, query) { | ||
function useActiveSectionsWithData(sectionsResults, activeSections, sectionsRefs, query, podsData) { | ||
const [activeSectionsWithData, setActiveSectionsWithData] = (0, react_1.useState)([]); | ||
// Add to active sections the results data and refs when autocomplete results or recommendation results fetched | ||
(0, react_1.useEffect)(() => { | ||
const activeSectionsWithDataValue = (0, utils_1.getActiveSectionsWithData)(activeSections, sectionsResults, sectionsRefs); | ||
const activeSectionsWithDataValue = (0, utils_1.getActiveSectionsWithData)(activeSections, sectionsResults, sectionsRefs, podsData); | ||
if (activeSectionsWithDataValue.length || !query) { | ||
setActiveSectionsWithData(activeSectionsWithDataValue); | ||
} | ||
}, [activeSections, sectionsResults, sectionsRefs, query]); | ||
}, [activeSections, sectionsResults, sectionsRefs, query, podsData]); | ||
return activeSectionsWithData; | ||
} | ||
exports.default = useActiveSectionsWithData; |
@@ -147,3 +147,3 @@ "use strict"; | ||
exports.getCioClient = getCioClient; | ||
const getActiveSectionsWithData = (activeSections, sectionsResults, sectionsRefs) => { | ||
const getActiveSectionsWithData = (activeSections, sectionsResults, sectionsRefs, podsData) => { | ||
const activeSectionsWithData = []; | ||
@@ -174,2 +174,6 @@ const getSectionData = (sectionConfig) => { | ||
const section = Object.assign(Object.assign({}, sectionConfig), { data: sectionData }); | ||
if (sectionConfig.type === 'recommendations') { | ||
section.displayName = | ||
sectionConfig.displayName || podsData[sectionConfig.podId].displayName; | ||
} | ||
// If ref passed as part of `SectionConfiguration`, use it. | ||
@@ -176,0 +180,0 @@ // Otherwise, use the ref from our library generated refs array |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = '1.23.22'; | ||
exports.default = '1.23.23'; |
@@ -68,2 +68,3 @@ // Autocomplete key index | ||
- each recommendation section object must have a \`podId\` | ||
- passing displayName in the sectionConfiguration will override the displayName set by Merchandisers on the Customer Dashboard for the recommendation section | ||
- each custom section object must have a \`displayName\` | ||
@@ -107,2 +108,3 @@ - each section object can specify a \`type\` | ||
- each recommendation section object must have a \`podId\` | ||
- passing displayName in the sectionConfiguration will override the displayName set by Merchandisers on the Customer Dashboard for the recommendation section | ||
- each custom section object must have a \`displayName\` | ||
@@ -109,0 +111,0 @@ - each section object can specify a \`type\` |
@@ -25,3 +25,3 @@ /* eslint-disable max-params */ | ||
// Return current active sections populated with data from the API response sectionsResults | ||
const activeSectionsWithData = useActiveSectionsWithData(sectionsResults, activeSections, sectionsRefs, query); | ||
const activeSectionsWithData = useActiveSectionsWithData(sectionsResults, activeSections, sectionsRefs, query, recommendations.podsData); | ||
return { | ||
@@ -28,0 +28,0 @@ fetchRecommendationResults: recommendations.fetchRecommendationResults, |
@@ -0,13 +1,14 @@ | ||
/* eslint-disable max-params */ | ||
import { useEffect, useState } from 'react'; | ||
import { getActiveSectionsWithData } from '../../utils'; | ||
export default function useActiveSectionsWithData(sectionsResults, activeSections, sectionsRefs, query) { | ||
export default function useActiveSectionsWithData(sectionsResults, activeSections, sectionsRefs, query, podsData) { | ||
const [activeSectionsWithData, setActiveSectionsWithData] = useState([]); | ||
// Add to active sections the results data and refs when autocomplete results or recommendation results fetched | ||
useEffect(() => { | ||
const activeSectionsWithDataValue = getActiveSectionsWithData(activeSections, sectionsResults, sectionsRefs); | ||
const activeSectionsWithDataValue = getActiveSectionsWithData(activeSections, sectionsResults, sectionsRefs, podsData); | ||
if (activeSectionsWithDataValue.length || !query) { | ||
setActiveSectionsWithData(activeSectionsWithDataValue); | ||
} | ||
}, [activeSections, sectionsResults, sectionsRefs, query]); | ||
}, [activeSections, sectionsResults, sectionsRefs, query, podsData]); | ||
return activeSectionsWithData; | ||
} |
@@ -133,3 +133,3 @@ import ConstructorIOClient from '@constructor-io/constructorio-client-javascript'; | ||
}; | ||
export const getActiveSectionsWithData = (activeSections, sectionsResults, sectionsRefs) => { | ||
export const getActiveSectionsWithData = (activeSections, sectionsResults, sectionsRefs, podsData) => { | ||
const activeSectionsWithData = []; | ||
@@ -163,2 +163,6 @@ const getSectionData = (sectionConfig) => { | ||
}; | ||
if (sectionConfig.type === 'recommendations') { | ||
section.displayName = | ||
sectionConfig.displayName || podsData[sectionConfig.podId].displayName; | ||
} | ||
// If ref passed as part of `SectionConfiguration`, use it. | ||
@@ -165,0 +169,0 @@ // Otherwise, use the ref from our library generated refs array |
@@ -1,1 +0,1 @@ | ||
export default '1.23.22'; | ||
export default '1.23.23'; |
@@ -5,5 +5,5 @@ import { AutocompleteSubmitEvent } from './types'; | ||
export declare const hookDescription = "- import `useCioAutocomplete` and call this custom hook in a functional component.\n- This hook leaves rendering logic up to you, while handling:\n - state management\n - data fetching\n - keyboard navigation\n - mouse interactions\n - focus and submit event handling\n - accessibility\n- To use this hook, an `apiKey` or `cioJsClient` are required, and an `onSubmit` callback must be passed to the `useCioAutocomplete` hook to configure behavior. All other values are optional.\n- use the <a href=\"https://kentcdodds.com/blog/how-to-give-rendering-control-to-users-with-prop-getters\" target=\"__blank\">prop getters</a> and other variables returned by this hook (below) to leverage the functionality described above with jsx elements in your react component definitions\n\n> **Important: Please note that all of the select or submit events should go through the `onSubmit` callback. The `getItemProps` hook returns click and keyboard handlers which should be applied to the elements using the spread operator (see code examples below). Adding an `onClick` event manually to the elements would override the default behavior of the library preventing it from sending tracking events and would cause different behavior between click and keyboard events. Selecting an item or submitting the search would both cause `onSubmit` to be called. **\n\nCalling the `useCioAutocomplete` hook returns an object with the following keys:\n\n```jsx\nconst {\n // must be used for a hooks integrations\n query: string, // current input field value\n sections: [{...}], // array of sections data to render in menu list\n totalNumResultsPerSection: {\n \"Products\": number,\n \"Search Suggestions\": number,\n ...\n }, // total number of product and search suggestion results (and other sections)\n getFormProps: () => ({...})), // prop getter for jsx form element\n getInputProps: () => ({...})), // prop getter for jsx input element\n getMenuProps: () => ({...})), // prop getter for jsx element rendering the results container\n getItemProps: (item) => ({...})), // prop getter for jsx element rendering each result\n getSectionProps: (section: Section) => ({...})), // prop getter for jsx element rendering each section.\n\n // available for use, but not required for all use cases\n selectedItem: item, // undefined or current selected item (via hover or arrow keys)\n isOpen: boolean, // current state of the menu list\n openMenu: () => void, // open menu\n closeMenu: () => void, // close menu\n setQuery: () => void, // update the current input field value\n getLabelProps: () => ({...})), // prop getter for a jsx label element\n cioJsClient, // instance of constructorio-client-javascript\n } = useCioAutocomplete(args);\n```\n\n> Note: when we say `cioJsClient`, we are referring to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n\nThe following stories show how different options affect the hook's behavior!\n"; | ||
export declare const sectionsDescription = "- by default, typing a query will fetch data for Search Suggestions and Products\n- to override this, pass an array of sections objects\n- the order of the objects in the `sections` array determines the order of the results\n- each autocomplete section object must have a `indexSectionName`\n- each recommendation section object must have a `podId`\n- each custom section object must have a `displayName`\n- each section object can specify a `type`\n- each section object can override the default `numResults` of 8\n\n`indexSectionName` refers to a section under an index. The default sections are \"Products\" and \"Search Suggestions\". You can find all the sections that exist in your index under the \"Indexes\" tab of Constructor dashboard.\n\nWhen no values are passed for the `sections` argument, the following defaults are used:\n\n```jsx\n[\n {\n indexSectionName: 'Search Suggestions',\n type: 'autocomplete',\n numResults: 8\n },\n {\n indexSectionName: 'Products',\n type: 'autocomplete',\n numResults: 8\n }\n]\n```\n"; | ||
export declare const sectionsDescription = "- by default, typing a query will fetch data for Search Suggestions and Products\n- to override this, pass an array of sections objects\n- the order of the objects in the `sections` array determines the order of the results\n- each autocomplete section object must have a `indexSectionName`\n- each recommendation section object must have a `podId`\n- passing displayName in the sectionConfiguration will override the displayName set by Merchandisers on the Customer Dashboard for the recommendation section\n- each custom section object must have a `displayName`\n- each section object can specify a `type`\n- each section object can override the default `numResults` of 8\n\n`indexSectionName` refers to a section under an index. The default sections are \"Products\" and \"Search Suggestions\". You can find all the sections that exist in your index under the \"Indexes\" tab of Constructor dashboard.\n\nWhen no values are passed for the `sections` argument, the following defaults are used:\n\n```jsx\n[\n {\n indexSectionName: 'Search Suggestions',\n type: 'autocomplete',\n numResults: 8\n },\n {\n indexSectionName: 'Products',\n type: 'autocomplete',\n numResults: 8\n }\n]\n```\n"; | ||
export declare const userEventsDescription = "- pass callback functions to respond to user events\n- if provided, the onFocus callback function will be called each time the user focuses on the text input field\n- if provided, the onChange callback function will be called each time the user changes the value in the text input field\n- the onSubmit callback function will be called each time the user submits the form\n- the user can submit the form by pressing the enter key in the text input field, clicking a submit button within the form, clicking on a result, or pressing enter while a result is selected\n\n> \u26A0\uFE0F NOTE \u26A0\uFE0F Use the Storybook Canvas Actions tab to explore the behavior of all of these `OnEvent` callback functions as you interact with our Default User Events example rendered in the Canvas. In the stories below, Storybook Canvas Actions have been disabled to focus on each of these callback functions in isolation. Each of the example callback functions in the stories below log output to the console tab of the browser's developer tools."; | ||
export declare const zeroStateDescription = "- when the text input field has no text, we call this zero state\n- by default, the autocomplete shows nothing in the menu it's for zero state\n- to show zero state results, pass an array of section objects for `zeroStateSections`\n- when `zeroStateSections` has sections, the menu will open on user focus by default\n- set `openOnFocus` to false, to only show `zeroStateSections` after user has typed and then cleared the text input, instead of as soon as the user focuses on the text input\n- the order of the objects in the `zeroStateSections` array determines the order of the results\n- each autocomplete section object must have a `indexSectionName`\n- each recommendation section object must have a `podId`\n- each custom section object must have a `displayName`\n- each section object can specify a `type`\n- each section object can override the default `numResults` of 8"; | ||
export declare const zeroStateDescription = "- when the text input field has no text, we call this zero state\n- by default, the autocomplete shows nothing in the menu it's for zero state\n- to show zero state results, pass an array of section objects for `zeroStateSections`\n- when `zeroStateSections` has sections, the menu will open on user focus by default\n- set `openOnFocus` to false, to only show `zeroStateSections` after user has typed and then cleared the text input, instead of as soon as the user focuses on the text input\n- the order of the objects in the `zeroStateSections` array determines the order of the results\n- each autocomplete section object must have a `indexSectionName`\n- each recommendation section object must have a `podId`\n- passing displayName in the sectionConfiguration will override the displayName set by Merchandisers on the Customer Dashboard for the recommendation section\n- each custom section object must have a `displayName`\n- each section object can specify a `type`\n- each section object can override the default `numResults` of 8"; | ||
export declare const fullFeaturedAndStyledExampleDescription = "Using the default options, the library displays clean and minimal visual elements, with the intent of making it easy for consumers to easily extend and customize the styles to suit unique needs. The example below shows a full featured and styled example to demonstrate what is possible using Constructor.io's advanced Autocomplete UI library."; | ||
@@ -10,0 +10,0 @@ export declare const apiKeyDescription = "Pass an `apiKey` to request results from constructor's servers"; |
import { RefObject } from 'react'; | ||
import { UserDefinedSection, Section, SectionsData } from '../../types'; | ||
export default function useActiveSectionsWithData(sectionsResults: SectionsData, activeSections: UserDefinedSection[], sectionsRefs: React.MutableRefObject<RefObject<HTMLLIElement>[]>, query: string): Section[]; | ||
import { UserDefinedSection, Section, SectionsData, PodData } from '../../types'; | ||
export default function useActiveSectionsWithData(sectionsResults: SectionsData, activeSections: UserDefinedSection[], sectionsRefs: React.MutableRefObject<RefObject<HTMLLIElement>[]>, query: string, podsData: Record<string, PodData>): Section[]; |
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript'; | ||
import { AutocompleteRequestType, Nullable, ConstructorClientOptions } from '@constructor-io/constructorio-client-javascript/lib/types'; | ||
import { Item, Section, UserDefinedSection, SectionsData, Translations } from './types'; | ||
import { Item, Section, UserDefinedSection, SectionsData, Translations, PodData } from './types'; | ||
export type GetItemPosition = (args: { | ||
@@ -40,3 +40,3 @@ item: Item; | ||
export declare const getCioClient: (apiKey?: string, cioJsClientOptions?: ConstructorClientOptions) => ConstructorIOClient | null; | ||
export declare const getActiveSectionsWithData: (activeSections: UserDefinedSection[], sectionsResults: SectionsData, sectionsRefs: React.MutableRefObject<React.RefObject<HTMLLIElement>[]>) => Section[]; | ||
export declare const getActiveSectionsWithData: (activeSections: UserDefinedSection[], sectionsResults: SectionsData, sectionsRefs: React.MutableRefObject<React.RefObject<HTMLLIElement>[]>, podsData: Record<string, PodData>) => Section[]; | ||
export declare const escapeRegExp: (string: string) => string; | ||
@@ -43,0 +43,0 @@ export declare const trackRecommendationView: (target: HTMLElement, activeSectionsWithData: Section[], cioClient: Nullable<ConstructorIOClient>) => void; |
@@ -1,2 +0,2 @@ | ||
declare const _default: "1.23.22"; | ||
declare const _default: "1.23.23"; | ||
export default _default; |
{ | ||
"name": "@constructor-io/constructorio-ui-autocomplete", | ||
"version": "1.23.22", | ||
"version": "1.23.23", | ||
"description": "Constructor.io Autocomplete UI library for web applications", | ||
@@ -5,0 +5,0 @@ "main": "lib/cjs/index.js", |
Sorry, the diff of this file is too big to display
524027
5314