@constructor-io/constructorio-ui-autocomplete 1.1.8 → 1.1.10

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.
Files changed (98) hide show
  1. package/lib/cjs/components/Autocomplete/Autocomplete.css +110 -0
  2. package/lib/cjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js +22 -0
  3. package/lib/cjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js.map +1 -0
  4. package/lib/cjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js +18 -0
  5. package/lib/cjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js.map +1 -0
  6. package/lib/cjs/components/Autocomplete/CioAutocompleteProvider.js +15 -0
  7. package/lib/cjs/components/Autocomplete/CioAutocompleteProvider.js.map +1 -0
  8. package/lib/cjs/components/Autocomplete/SearchInput/SearchInput.js +30 -0
  9. package/lib/cjs/components/Autocomplete/SearchInput/SearchInput.js.map +1 -0
  10. package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js +22 -0
  11. package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js.map +1 -0
  12. package/lib/cjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +22 -0
  13. package/lib/cjs/components/Autocomplete/SectionItemsList/SectionItemsList.js.map +1 -0
  14. package/lib/cjs/constants.js +179 -0
  15. package/lib/cjs/constants.js.map +1 -0
  16. package/lib/cjs/hooks/useCioAutocomplete.js +107 -0
  17. package/lib/cjs/hooks/useCioAutocomplete.js.map +1 -0
  18. package/lib/cjs/hooks/useCioClient.js +22 -0
  19. package/lib/cjs/hooks/useCioClient.js.map +1 -0
  20. package/lib/cjs/hooks/useDebounce.js +24 -0
  21. package/lib/cjs/hooks/useDebounce.js.map +1 -0
  22. package/lib/cjs/hooks/useDebouncedFetchSections.js +35 -0
  23. package/lib/cjs/hooks/useDebouncedFetchSections.js.map +1 -0
  24. package/lib/cjs/hooks/useDownShift.js +37 -0
  25. package/lib/cjs/hooks/useDownShift.js.map +1 -0
  26. package/lib/cjs/hooks/useFetchRecommendationPod.js +30 -0
  27. package/lib/cjs/hooks/useFetchRecommendationPod.js.map +1 -0
  28. package/lib/cjs/hooks/usePrevious.js +12 -0
  29. package/lib/cjs/hooks/usePrevious.js.map +1 -0
  30. package/lib/cjs/index.js +16 -0
  31. package/lib/cjs/index.js.map +1 -0
  32. package/lib/cjs/stories/Autocomplete/argTypes.js +65 -0
  33. package/lib/cjs/stories/Autocomplete/argTypes.js.map +1 -0
  34. package/lib/cjs/typeGuards.js +10 -0
  35. package/lib/cjs/typeGuards.js.map +1 -0
  36. package/lib/cjs/types.js +3 -0
  37. package/lib/cjs/types.js.map +1 -0
  38. package/lib/cjs/utils.js +72 -0
  39. package/lib/cjs/utils.js.map +1 -0
  40. package/lib/mjs/components/Autocomplete/Autocomplete.css +110 -0
  41. package/lib/mjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js +21 -0
  42. package/lib/mjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js.map +1 -0
  43. package/lib/mjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js +15 -0
  44. package/lib/mjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js.map +1 -0
  45. package/lib/mjs/components/Autocomplete/CioAutocompleteProvider.js +10 -0
  46. package/lib/mjs/components/Autocomplete/CioAutocompleteProvider.js.map +1 -0
  47. package/lib/mjs/components/Autocomplete/SearchInput/SearchInput.js +27 -0
  48. package/lib/mjs/components/Autocomplete/SearchInput/SearchInput.js.map +1 -0
  49. package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js +18 -0
  50. package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js.map +1 -0
  51. package/lib/mjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +15 -0
  52. package/lib/mjs/components/Autocomplete/SectionItemsList/SectionItemsList.js.map +1 -0
  53. package/lib/mjs/constants.js +176 -0
  54. package/lib/mjs/constants.js.map +1 -0
  55. package/lib/mjs/hooks/useCioAutocomplete.js +118 -0
  56. package/lib/mjs/hooks/useCioAutocomplete.js.map +1 -0
  57. package/lib/mjs/hooks/useCioClient.js +20 -0
  58. package/lib/mjs/hooks/useCioClient.js.map +1 -0
  59. package/lib/mjs/hooks/useDebounce.js +22 -0
  60. package/lib/mjs/hooks/useDebounce.js.map +1 -0
  61. package/lib/mjs/hooks/useDebouncedFetchSections.js +41 -0
  62. package/lib/mjs/hooks/useDebouncedFetchSections.js.map +1 -0
  63. package/lib/mjs/hooks/useDownShift.js +33 -0
  64. package/lib/mjs/hooks/useDownShift.js.map +1 -0
  65. package/lib/mjs/hooks/useFetchRecommendationPod.js +27 -0
  66. package/lib/mjs/hooks/useFetchRecommendationPod.js.map +1 -0
  67. package/lib/mjs/hooks/usePrevious.js +10 -0
  68. package/lib/mjs/hooks/usePrevious.js.map +1 -0
  69. package/lib/mjs/index.js +7 -0
  70. package/lib/mjs/index.js.map +1 -0
  71. package/lib/mjs/stories/Autocomplete/argTypes.js +62 -0
  72. package/lib/mjs/stories/Autocomplete/argTypes.js.map +1 -0
  73. package/lib/mjs/typeGuards.js +6 -0
  74. package/lib/mjs/typeGuards.js.map +1 -0
  75. package/lib/mjs/types.js +2 -0
  76. package/lib/mjs/types.js.map +1 -0
  77. package/lib/mjs/utils.js +58 -0
  78. package/lib/mjs/utils.js.map +1 -0
  79. package/lib/types/components/Autocomplete/AutocompleteResults/AutocompleteResults.d.ts +11 -0
  80. package/lib/types/components/Autocomplete/CioAutocomplete/CioAutocomplete.d.ts +3 -0
  81. package/lib/types/components/Autocomplete/CioAutocompleteProvider.d.ts +28 -0
  82. package/lib/types/components/Autocomplete/SearchInput/SearchInput.d.ts +7 -0
  83. package/lib/types/components/Autocomplete/SectionItem/SectionItem.d.ts +10 -0
  84. package/lib/types/components/Autocomplete/SectionItemsList/SectionItemsList.d.ts +12 -0
  85. package/lib/types/constants.d.ts +23 -0
  86. package/lib/types/hooks/useCioAutocomplete.d.ts +29 -0
  87. package/lib/types/hooks/useCioClient.d.ts +15 -0
  88. package/lib/types/hooks/useDebounce.d.ts +2 -0
  89. package/lib/types/hooks/useDebouncedFetchSections.d.ts +4 -0
  90. package/lib/types/hooks/useDownShift.d.ts +16 -0
  91. package/lib/types/hooks/useFetchRecommendationPod.d.ts +4 -0
  92. package/lib/types/hooks/usePrevious.d.ts +2 -0
  93. package/lib/types/index.d.ts +6 -0
  94. package/lib/types/stories/Autocomplete/argTypes.d.ts +62 -0
  95. package/lib/types/typeGuards.d.ts +2 -0
  96. package/lib/types/types.d.ts +131 -0
  97. package/lib/types/utils.d.ts +24 -0
  98. package/package.json +1 -3
@@ -0,0 +1,58 @@
1
+ export const getIndexOffset = ({ activeSections, sectionIdentifier }) => {
2
+ let indexOffset = 0;
3
+ if (sectionIdentifier) {
4
+ activeSections.find((config) => {
5
+ if (config?.identifier === sectionIdentifier)
6
+ return true; // break out of loop
7
+ indexOffset += config?.data?.length || 0;
8
+ return false; // continue
9
+ });
10
+ }
11
+ return indexOffset;
12
+ };
13
+ export const camelToStartCase = (camelCaseString) => camelCaseString
14
+ // insert a space before all caps
15
+ .replace(/([A-Z])/g, ' $1')
16
+ // uppercase the first character
17
+ .replace(/^./, (str) => str.toUpperCase());
18
+ export function isTrackingRequestSent(trackingRequestUrl) {
19
+ // eslint-disable-next-line
20
+ const trackingRequestsQueue = window.localStorage?._constructorio_requests;
21
+ return (trackingRequestsQueue &&
22
+ JSON.parse(trackingRequestsQueue)?.some((request) => request?.url?.includes(trackingRequestUrl)));
23
+ }
24
+ export function clearConstructorRequests() {
25
+ // eslint-disable-next-line
26
+ if (window.localStorage?._constructorio_requests) {
27
+ window.localStorage.removeItem('_constructorio_requests');
28
+ }
29
+ }
30
+ // Function to emulate pausing between interactions
31
+ export function sleep(ms) {
32
+ // eslint-disable-next-line
33
+ return new Promise((resolve) => setTimeout(resolve, ms));
34
+ }
35
+ // More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
36
+ export const getStoryParams = (storyCode, templateCode, importCode) => {
37
+ const code = `
38
+ ${importCode}
39
+ ${storyCode}
40
+ ${templateCode}
41
+ `;
42
+ return {
43
+ docs: {
44
+ source: {
45
+ code,
46
+ language: 'jsx',
47
+ format: true,
48
+ type: 'code',
49
+ },
50
+ },
51
+ };
52
+ };
53
+ export const stringify = (obj) => JSON.stringify(obj, null, ' ');
54
+ export const disableStoryActions = (story) => {
55
+ // eslint-disable-next-line
56
+ story.parameters.actions = { argTypesRegex: null };
57
+ };
58
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,cAAc,GAAmB,CAAC,EAAE,cAAc,EAAE,iBAAiB,EAAE,EAAE,EAAE;IACtF,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,IAAI,iBAAiB,EAAE;QACrB,cAAc,CAAC,IAAI,CAAC,CAAC,MAA4B,EAAE,EAAE;YACnD,IAAI,MAAM,EAAE,UAAU,KAAK,iBAAiB;gBAAE,OAAO,IAAI,CAAC,CAAC,oBAAoB;YAC/E,WAAW,IAAI,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC;YACzC,OAAO,KAAK,CAAC,CAAC,WAAW;QAC3B,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAIF,MAAM,CAAC,MAAM,gBAAgB,GAAqB,CAAC,eAAe,EAAE,EAAE,CACpE,eAAe;IACb,iCAAiC;KAChC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;IAC3B,gCAAgC;KAC/B,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;AAE/C,MAAM,UAAU,qBAAqB,CAAC,kBAAkB;IACtD,2BAA2B;IAC3B,MAAM,qBAAqB,GAAG,MAAM,CAAC,YAAY,EAAE,uBAAuB,CAAC;IAE3E,OAAO,CACL,qBAAqB;QACrB,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CACjG,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,2BAA2B;IAC3B,IAAI,MAAM,CAAC,YAAY,EAAE,uBAAuB,EAAE;QAChD,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAC;KAC3D;AACH,CAAC;AAED,mDAAmD;AACnD,MAAM,UAAU,KAAK,CAAC,EAAE;IACtB,2BAA2B;IAC3B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AACD,mFAAmF;AACnF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE;IACpE,MAAM,IAAI,GAAG;EACb,UAAU;EACV,SAAS;EACT,YAAY;CACb,CAAC;IAEA,OAAO;QACL,IAAI,EAAE;YACJ,MAAM,EAAE;gBACN,IAAI;gBACJ,QAAQ,EAAE,KAAK;gBACf,MAAM,EAAE,IAAI;gBACZ,IAAI,EAAE,MAAM;aACb;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAElE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,EAAE;IAC3C,2BAA2B;IAC3B,KAAK,CAAC,UAAU,CAAC,OAAO,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;AACrD,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { ReactNode } from 'react';
2
+ import { GetItemProps, SectionConfiguration } from '../../../types';
3
+ export type RenderResults = (renderResultsArguments: {
4
+ sections: SectionConfiguration[];
5
+ getItemProps: GetItemProps;
6
+ }) => ReactNode;
7
+ type AutocompleteResultsProps = {
8
+ children?: RenderResults | ReactNode;
9
+ };
10
+ export default function AutocompleteResults(props: AutocompleteResultsProps): JSX.Element;
11
+ export {};
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { CioAutocompleteProps } from '../../../types';
3
+ export default function CioAutocomplete(props: CioAutocompleteProps): JSX.Element;
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { CioAutocompleteProps } from '../../types';
3
+ export declare const CioAutocompleteContext: React.Context<{
4
+ query: string;
5
+ sections: import("../../types").SectionConfiguration[];
6
+ isOpen: boolean;
7
+ getMenuProps: () => any;
8
+ getLabelProps: (options?: import("downshift").UseComboboxGetLabelPropsOptions | undefined) => any;
9
+ openMenu: () => void;
10
+ closeMenu: () => void;
11
+ getItemProps: ({ item, index, sectionIdentifier }: {
12
+ item: any;
13
+ index?: number | undefined;
14
+ sectionIdentifier?: string | undefined;
15
+ }) => any;
16
+ getInputProps: () => any;
17
+ getFormProps: () => {
18
+ onSubmit: (event: any) => {
19
+ query: string;
20
+ };
21
+ className: string;
22
+ 'data-testid': string;
23
+ };
24
+ setQuery: React.Dispatch<React.SetStateAction<string>>;
25
+ cioClient: import("@constructor-io/constructorio-client-javascript") | undefined;
26
+ autocompleteClassName: string;
27
+ }>;
28
+ export default function CioAutocompleteProvider(props: CioAutocompleteProps): JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { ReactElement } from 'react';
2
+ import { CioAutocompleteProps } from '../../../types';
3
+ type SearchInputProps = {
4
+ children?: (args: Partial<Omit<CioAutocompleteProps, 'children'>>) => ReactElement;
5
+ };
6
+ export default function SearchInput(props: SearchInputProps): JSX.Element;
7
+ export {};
@@ -0,0 +1,10 @@
1
+ import { ReactNode } from 'react';
2
+ import { Item } from '../../../types';
3
+ export interface SectionItemProps {
4
+ item: Item;
5
+ index: number;
6
+ sectionIdentifier: string;
7
+ children?: ReactNode;
8
+ key?: string;
9
+ }
10
+ export default function SectionItem(props: SectionItemProps): JSX.Element;
@@ -0,0 +1,12 @@
1
+ import React, { ReactElement } from 'react';
2
+ import { SectionConfiguration } from '../../../types';
3
+ export type RenderSectionItemsList = (renderResultsArguments: {
4
+ section: SectionConfiguration;
5
+ }) => ReactElement;
6
+ type SectionItemsListProps = {
7
+ section: SectionConfiguration;
8
+ children?: RenderSectionItemsList;
9
+ key?: string;
10
+ };
11
+ export default function SectionItemsList(props: SectionItemsListProps): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
12
+ export {};
@@ -0,0 +1,23 @@
1
+ export declare const apiKey = "key_Gep3oQOu5IMcNh9A";
2
+ export declare const componentDescription = "- import `CioAutocomplete` to render in your JSX.\n- This component handles state management, data fetching, and rendering logic.\n- To use this component, an `apiKey` or `cioJsClient` are required, all other values are optional.\n- Use different props to configure the behavior of this component.\n- The following stories shows how different props affect the component's behavior\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";
3
+ export declare const hookDescription = "- import `useCioAutocomplete` and call this custom hook in a functional component.\n- This hook handles state management & data fetching, but leaves rendering logic up to you\n- To use this hook, an `apiKey` or `cioJsClient` are required, all other values are optional.\n- Pass different options to the `useCioAutocomplete` hook to configure behavior.\n- The following stories shows how different options affect the hook's behavior\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 getFormProps: () => ({...})), // prop getter for jsx form element\n getLabelProps: () => ({...})), // optional: prop getter for jsx label element\n getInputProps: () => ({...})), // prop getter for jsx input element\n getMenuProps: () => ({...})), // prop getter for jsx element serving as menu container\n getItemProps: () => ({...})), // prop getter for jsx element serving as each result\n isOpen: boolean,\n\n // available for advanced hooks integration use cases\n openMenu: () => void, // open menu\n closeMenu: () => void, // close menu\n setQuery: () => void, // update the current input field value\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";
4
+ export declare const sectionsDescription = "- by default, typing a query will fetch data for search suggestions and Products\n- to override this, pass a an array of sections objects\n- the order of the objects in the `sections` array determines the order of the results\n- each section object must have an `identifier`\n- each section object can specify a `type`\n- each section object can override the default `numResults` of 8\n\nWhen no values are passed for the `sections` argument, the following defaults are used:\n\n```jsx\n[\n {\n identifier: 'Search Suggestions',\n type: 'autocomplete',\n numResults: 8\n },\n {\n identifier: 'Products',\n type: 'autocomplete',\n numResults: 8\n }\n]\n```\n";
5
+ 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- if provided, 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.";
6
+ 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 section object must have an `identifier`\n- each section object can specify a `type`\n- each section object can override the default `numResults` of 8";
7
+ export declare const apiKeyDescription = "Pass an `apiKey` to request results from constructor's servers";
8
+ export declare const cioJsClientDescription = "If you are already using an instance of the `ConstructorIOClient`, you can pass a `cioJsClient` instead of an `apiKey` to request results from constructor's servers\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)";
9
+ export declare const placeholderDescription = "Pass a `placeholder` to override the default input field placeholder text shown to users before they start typing their query";
10
+ export declare const searchSuggestionsDescription = "Override default `sections` to only suggest search terms";
11
+ export declare const productsDescription = "Override default `sections` to only suggested products";
12
+ export declare const contentDescription = "Override default `sections` to only suggest content";
13
+ export declare const numResultsDescription = "Override default `numResults` to only suggest 2 products per query";
14
+ export declare const sectionOrderDescription = "Override default `numResults` to suggest products, then terms";
15
+ export declare const recommendationsDescription = "Use constructor's recommendations service, with `\"type\": \"recommendations\"`";
16
+ export declare const customSectionDescription = "Use a custom section, by managing and passing your own data, with `\"type\": \"custom\"` and `\"data\":[{...}]`";
17
+ export declare const onFocusDescription = "Pass an `onFocus` callback function to execute some code each time the user applies focus to the text input field";
18
+ 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";
19
+ export declare const onSubmitDescription = "Pass an `onSubmit` callback function to execute some code after a user submits the search form.\n\n Your callback function will be invoked with a submit event containing useful metadata about the submit event:\n - if the user submits the text input:\n - the `query` field will provide the value of that input field\n - if the user selects a suggested item from the dropdown list:\n - the `originalQuery` field will provide the value of the input field that generated the selected item\n - an `item` object with information about the suggestion that the user selected";
20
+ 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";
21
+ 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";
22
+ export declare const multipleSectionsDescription = "Use as many different `recommendations` and `custom` sections as you'd like and in whatever order you would like!";
23
+ 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 'node_modules/@constructor-io/constructorio-ui-autocomplete/lib/mjs/components/Autocomplete/Autocomplete.css';\n`\n\n<i></i>\n\n- To opt out of all default styling, do not import the `Autocomplete.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";
@@ -0,0 +1,29 @@
1
+ import { CioAutocompleteProps, SectionConfiguration } from '../types';
2
+ export declare const defaultSections: SectionConfiguration[];
3
+ export type UseCioAutocompleteOptions = Omit<CioAutocompleteProps, 'children'>;
4
+ declare const useCioAutocomplete: (options: UseCioAutocompleteOptions) => {
5
+ query: string;
6
+ sections: SectionConfiguration[];
7
+ isOpen: boolean;
8
+ getMenuProps: () => any;
9
+ getLabelProps: (options?: import("downshift").UseComboboxGetLabelPropsOptions | undefined) => any;
10
+ openMenu: () => void;
11
+ closeMenu: () => void;
12
+ getItemProps: ({ item, index, sectionIdentifier }: {
13
+ item: any;
14
+ index?: number | undefined;
15
+ sectionIdentifier?: string | undefined;
16
+ }) => any;
17
+ getInputProps: () => any;
18
+ getFormProps: () => {
19
+ onSubmit: (event: any) => {
20
+ query: string;
21
+ };
22
+ className: string;
23
+ 'data-testid': string;
24
+ };
25
+ setQuery: import("react").Dispatch<import("react").SetStateAction<string>>;
26
+ cioClient: import("@constructor-io/constructorio-client-javascript") | undefined;
27
+ autocompleteClassName: string;
28
+ };
29
+ export default useCioAutocomplete;
@@ -0,0 +1,15 @@
1
+ import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
2
+ export type CioClientConfig = {
3
+ apiKey?: string;
4
+ cioJsClient?: ConstructorIOClient;
5
+ };
6
+ export type TrackSearchSubmit = (term: string, parameters: {
7
+ original_query: string;
8
+ }) => true | Error;
9
+ export type TrackAutocompleteSelect = (term: string, parameters: {
10
+ original_query: string;
11
+ section: string;
12
+ }) => true | Error;
13
+ type UseCioClient = (cioClientConfig: CioClientConfig) => ConstructorIOClient | undefined;
14
+ declare const useCioClient: UseCioClient;
15
+ export default useCioClient;
@@ -0,0 +1,2 @@
1
+ declare const useDebounce: (value: string, delay?: number) => string;
2
+ export default useDebounce;
@@ -0,0 +1,4 @@
1
+ import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
2
+ import { AutocompleteResultSections, SectionConfiguration } from '../types';
3
+ declare const useDebouncedFetchSection: (query: string, cioClient?: ConstructorIOClient, autocompleteSections?: SectionConfiguration[]) => AutocompleteResultSections;
4
+ export default useDebouncedFetchSection;
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ import { UseComboboxReturnValue } from 'downshift';
3
+ import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
4
+ import { Item, OnSubmit } from '../types';
5
+ type UseDownShiftOptions = {
6
+ setQuery: React.Dispatch<React.SetStateAction<string>>;
7
+ items: Item[];
8
+ onSubmit?: OnSubmit;
9
+ previousQuery?: string;
10
+ cioClient?: ConstructorIOClient;
11
+ onChange?: (string: any) => void;
12
+ };
13
+ export type DownShift = UseComboboxReturnValue<Item>;
14
+ type UseDownShift = (options: UseDownShiftOptions) => DownShift;
15
+ declare const useDownShift: UseDownShift;
16
+ export default useDownShift;
@@ -0,0 +1,4 @@
1
+ import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
2
+ import { AutocompleteResultSections, RecommendationsSectionConfiguration } from '../types';
3
+ declare const useFetchRecommendationPod: (cioClient: ConstructorIOClient | undefined, recommendationPods: RecommendationsSectionConfiguration[]) => AutocompleteResultSections;
4
+ export default useFetchRecommendationPod;
@@ -0,0 +1,2 @@
1
+ declare const usePrevious: (value: string) => string | undefined;
2
+ export default usePrevious;
@@ -0,0 +1,6 @@
1
+ export { default as AutocompleteResults } from './components/Autocomplete/AutocompleteResults/AutocompleteResults';
2
+ export { default as CioAutocomplete } from './components/Autocomplete/CioAutocomplete/CioAutocomplete';
3
+ export { default as SearchInput } from './components/Autocomplete/SearchInput/SearchInput';
4
+ export { default as SectionItem } from './components/Autocomplete/SectionItem/SectionItem';
5
+ export { default as SectionItemsList } from './components/Autocomplete/SectionItemsList/SectionItemsList';
6
+ export { default as useCioAutocomplete } from './hooks/useCioAutocomplete';
@@ -0,0 +1,62 @@
1
+ export declare const argTypes: {
2
+ placeholder: {
3
+ description: string;
4
+ table: {
5
+ type: {
6
+ summary: string;
7
+ };
8
+ };
9
+ control: {
10
+ type: string;
11
+ };
12
+ };
13
+ apiKey: {
14
+ type: {
15
+ name: string;
16
+ };
17
+ description: string;
18
+ table: {
19
+ type: {
20
+ summary: string;
21
+ };
22
+ };
23
+ control: {
24
+ type: string;
25
+ };
26
+ };
27
+ onSubmit: {
28
+ type: {
29
+ name: string;
30
+ };
31
+ description: string;
32
+ table: {
33
+ type: {
34
+ summary: string;
35
+ };
36
+ };
37
+ control: null;
38
+ };
39
+ onFocus: {
40
+ type: {
41
+ name: string;
42
+ };
43
+ description: string;
44
+ table: {
45
+ type: {
46
+ summary: string;
47
+ };
48
+ };
49
+ control: null;
50
+ };
51
+ openOnFocus: {
52
+ description: string;
53
+ table: {
54
+ type: {
55
+ summary: string;
56
+ };
57
+ };
58
+ control: {
59
+ type: string;
60
+ };
61
+ };
62
+ };
@@ -0,0 +1,2 @@
1
+ import { Item, Product } from './types';
2
+ export declare function isProduct(item: Item): item is Product;
@@ -0,0 +1,131 @@
1
+ import { GetItemPropsOptions } from 'downshift';
2
+ import { FormEvent, ReactNode } from 'react';
3
+ import { CioClientConfig } from './hooks/useCioClient';
4
+ export type CioAutocompleteProps = CioClientConfig & {
5
+ openOnFocus?: boolean;
6
+ onSubmit?: OnSubmit;
7
+ onFocus?: () => void;
8
+ onChange?: () => void;
9
+ placeholder?: string;
10
+ children?: ReactNode;
11
+ sections?: SectionConfiguration[];
12
+ zeroStateSections?: SectionConfiguration[];
13
+ autocompleteClassName?: string;
14
+ };
15
+ export type FormSubmitEvent = FormEvent<HTMLFormElement>;
16
+ type AutocompleteSubmitEvent = {
17
+ item: Item;
18
+ originalQuery: string;
19
+ } | {
20
+ query: string;
21
+ };
22
+ export type OnSubmit = (event: AutocompleteSubmitEvent) => unknown;
23
+ export type DownshiftGetItemPropsOptions = GetItemPropsOptions<Item>;
24
+ export type DownshiftGetItemProps = (options: GetItemPropsOptions<Item>) => object;
25
+ export type ItemPropsOptions = DownshiftGetItemPropsOptions & {
26
+ sectionName: string;
27
+ indexOffset?: number;
28
+ };
29
+ export type GetItemProps = (options: ItemPropsOptions) => object;
30
+ export interface ItemBase extends Record<string, any> {
31
+ id?: string;
32
+ url?: string;
33
+ value?: string;
34
+ section: string;
35
+ data?: Record<string, any>;
36
+ }
37
+ export type Item = Product | SearchSuggestion | ItemBase;
38
+ export type SectionOrder = string[];
39
+ export type GetAutocompleteResultsOptions = {
40
+ [sectionIdentifier: string]: {
41
+ numResults: number;
42
+ };
43
+ };
44
+ /** CIO API Response Data */
45
+ export type AutocompleteResultSections = {
46
+ [key: string]: Item[] | undefined;
47
+ };
48
+ type BaseSectionConfiguration = {
49
+ identifier: string;
50
+ displayName?: string;
51
+ numResults?: number;
52
+ };
53
+ interface AutocompleteSectionConfiguration extends BaseSectionConfiguration {
54
+ type?: 'autocomplete';
55
+ data?: Item[];
56
+ }
57
+ export interface RecommendationsSectionConfiguration extends BaseSectionConfiguration {
58
+ type: 'recommendations';
59
+ data?: Item[];
60
+ itemIds?: string[];
61
+ section?: string;
62
+ term?: string;
63
+ }
64
+ interface CustomSectionConfiguration extends BaseSectionConfiguration {
65
+ type: 'custom';
66
+ data: Item[];
67
+ }
68
+ export type SectionConfiguration = AutocompleteSectionConfiguration | RecommendationsSectionConfiguration | CustomSectionConfiguration;
69
+ export type Product = {
70
+ data: {
71
+ facets: {
72
+ name: string;
73
+ values: string[];
74
+ }[];
75
+ group_ids: string[];
76
+ id: string;
77
+ image_url: string;
78
+ price: number;
79
+ swatchColor: string;
80
+ url: string;
81
+ variation_id: string;
82
+ };
83
+ is_slotted: boolean;
84
+ labels: Record<string, unknown>;
85
+ matched_terms: string[];
86
+ value: string;
87
+ section: 'Products';
88
+ };
89
+ export type SearchSuggestion = {
90
+ data: {
91
+ id: string;
92
+ url?: string;
93
+ };
94
+ id: string;
95
+ is_slotted: boolean;
96
+ labels: Record<string, unknown>;
97
+ matched_terms: string[];
98
+ value: string;
99
+ section: 'Search Suggestions';
100
+ };
101
+ export type RecommendationPodResponse = {
102
+ pod: {
103
+ id: string;
104
+ display_name: string;
105
+ };
106
+ results: Product[];
107
+ total_num_results: number;
108
+ };
109
+ export interface RecommendationsApiResponse {
110
+ request: {
111
+ feature_variants?: {
112
+ auto_generated_refined_query_rules: string;
113
+ filter_items: string;
114
+ manual_searchandizing: string;
115
+ personalization: string;
116
+ query_items: string;
117
+ };
118
+ features?: {
119
+ auto_generated_refined_query_rules: boolean;
120
+ filter_items: boolean;
121
+ manual_searchandizing: boolean;
122
+ personalization: boolean;
123
+ query_items: boolean;
124
+ };
125
+ num_results: number;
126
+ pod_id: string;
127
+ };
128
+ result_id: string;
129
+ response: RecommendationPodResponse;
130
+ }
131
+ export {};
@@ -0,0 +1,24 @@
1
+ import { SectionConfiguration } from './types';
2
+ export type GetIndexOffset = (args: {
3
+ activeSections: SectionConfiguration[];
4
+ sectionIdentifier: string;
5
+ }) => number;
6
+ export declare const getIndexOffset: GetIndexOffset;
7
+ type CamelToStartCase = (camelCaseString: string) => string;
8
+ export declare const camelToStartCase: CamelToStartCase;
9
+ export declare function isTrackingRequestSent(trackingRequestUrl: any): any;
10
+ export declare function clearConstructorRequests(): void;
11
+ export declare function sleep(ms: any): Promise<unknown>;
12
+ export declare const getStoryParams: (storyCode: any, templateCode: any, importCode: any) => {
13
+ docs: {
14
+ source: {
15
+ code: string;
16
+ language: string;
17
+ format: boolean;
18
+ type: string;
19
+ };
20
+ };
21
+ };
22
+ export declare const stringify: (obj: any) => string;
23
+ export declare const disableStoryActions: (story: any) => void;
24
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-autocomplete",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
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",
@@ -50,12 +50,10 @@
50
50
  "@storybook/addon-essentials": "^7.0.0-beta.15",
51
51
  "@storybook/addon-interactions": "^7.0.0-beta.15",
52
52
  "@storybook/addon-links": "^7.0.0-beta.15",
53
- "@storybook/addons": "^7.0.0-beta.15",
54
53
  "@storybook/jest": "^0.0.11-next.0",
55
54
  "@storybook/react-webpack5": "7.0.0-beta.15",
56
55
  "@storybook/test-runner": "^0.10.0-next.4",
57
56
  "@storybook/testing-library": "^0.0.14-next.1",
58
- "@storybook/theming": "^7.0.0-beta.15",
59
57
  "@types/react": "^18.0.20",
60
58
  "@types/react-dom": "^18.0.6",
61
59
  "@typescript-eslint/eslint-plugin": "^5.38.0",