@constructor-io/constructorio-ui-autocomplete 1.1.6
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.
- package/LICENSE +21 -0
- package/README.md +129 -0
- package/lib/.DS_Store +0 -0
- package/lib/cjs/components/Autocomplete/Autocomplete.css +110 -0
- package/lib/cjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js +22 -0
- package/lib/cjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js.map +1 -0
- package/lib/cjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js +18 -0
- package/lib/cjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js.map +1 -0
- package/lib/cjs/components/Autocomplete/CioAutocompleteProvider.js +15 -0
- package/lib/cjs/components/Autocomplete/CioAutocompleteProvider.js.map +1 -0
- package/lib/cjs/components/Autocomplete/SearchInput/SearchInput.js +30 -0
- package/lib/cjs/components/Autocomplete/SearchInput/SearchInput.js.map +1 -0
- package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js +22 -0
- package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js.map +1 -0
- package/lib/cjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +22 -0
- package/lib/cjs/components/Autocomplete/SectionItemsList/SectionItemsList.js.map +1 -0
- package/lib/cjs/constants.js +163 -0
- package/lib/cjs/constants.js.map +1 -0
- package/lib/cjs/hooks/useCioAutocomplete.js +107 -0
- package/lib/cjs/hooks/useCioAutocomplete.js.map +1 -0
- package/lib/cjs/hooks/useCioClient.js +22 -0
- package/lib/cjs/hooks/useCioClient.js.map +1 -0
- package/lib/cjs/hooks/useDebounce.js +24 -0
- package/lib/cjs/hooks/useDebounce.js.map +1 -0
- package/lib/cjs/hooks/useDebouncedFetchSections.js +35 -0
- package/lib/cjs/hooks/useDebouncedFetchSections.js.map +1 -0
- package/lib/cjs/hooks/useDownShift.js +37 -0
- package/lib/cjs/hooks/useDownShift.js.map +1 -0
- package/lib/cjs/hooks/useFetchRecommendationPod.js +30 -0
- package/lib/cjs/hooks/useFetchRecommendationPod.js.map +1 -0
- package/lib/cjs/hooks/usePrevious.js +12 -0
- package/lib/cjs/hooks/usePrevious.js.map +1 -0
- package/lib/cjs/index.js +16 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/stories/Autocomplete/argTypes.js +65 -0
- package/lib/cjs/stories/Autocomplete/argTypes.js.map +1 -0
- package/lib/cjs/typeGuards.js +10 -0
- package/lib/cjs/typeGuards.js.map +1 -0
- package/lib/cjs/types.js +3 -0
- package/lib/cjs/types.js.map +1 -0
- package/lib/cjs/utils.js +72 -0
- package/lib/cjs/utils.js.map +1 -0
- package/lib/mjs/components/Autocomplete/Autocomplete.css +110 -0
- package/lib/mjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js +21 -0
- package/lib/mjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js.map +1 -0
- package/lib/mjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js +15 -0
- package/lib/mjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js.map +1 -0
- package/lib/mjs/components/Autocomplete/CioAutocompleteProvider.js +10 -0
- package/lib/mjs/components/Autocomplete/CioAutocompleteProvider.js.map +1 -0
- package/lib/mjs/components/Autocomplete/SearchInput/SearchInput.js +27 -0
- package/lib/mjs/components/Autocomplete/SearchInput/SearchInput.js.map +1 -0
- package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js +18 -0
- package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js.map +1 -0
- package/lib/mjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +15 -0
- package/lib/mjs/components/Autocomplete/SectionItemsList/SectionItemsList.js.map +1 -0
- package/lib/mjs/constants.js +160 -0
- package/lib/mjs/constants.js.map +1 -0
- package/lib/mjs/hooks/useCioAutocomplete.js +118 -0
- package/lib/mjs/hooks/useCioAutocomplete.js.map +1 -0
- package/lib/mjs/hooks/useCioClient.js +20 -0
- package/lib/mjs/hooks/useCioClient.js.map +1 -0
- package/lib/mjs/hooks/useDebounce.js +22 -0
- package/lib/mjs/hooks/useDebounce.js.map +1 -0
- package/lib/mjs/hooks/useDebouncedFetchSections.js +41 -0
- package/lib/mjs/hooks/useDebouncedFetchSections.js.map +1 -0
- package/lib/mjs/hooks/useDownShift.js +33 -0
- package/lib/mjs/hooks/useDownShift.js.map +1 -0
- package/lib/mjs/hooks/useFetchRecommendationPod.js +27 -0
- package/lib/mjs/hooks/useFetchRecommendationPod.js.map +1 -0
- package/lib/mjs/hooks/usePrevious.js +10 -0
- package/lib/mjs/hooks/usePrevious.js.map +1 -0
- package/lib/mjs/index.js +7 -0
- package/lib/mjs/index.js.map +1 -0
- package/lib/mjs/stories/Autocomplete/argTypes.js +62 -0
- package/lib/mjs/stories/Autocomplete/argTypes.js.map +1 -0
- package/lib/mjs/typeGuards.js +6 -0
- package/lib/mjs/typeGuards.js.map +1 -0
- package/lib/mjs/types.js +2 -0
- package/lib/mjs/types.js.map +1 -0
- package/lib/mjs/utils.js +58 -0
- package/lib/mjs/utils.js.map +1 -0
- package/lib/types/components/Autocomplete/AutocompleteResults/AutocompleteResults.d.ts +11 -0
- package/lib/types/components/Autocomplete/CioAutocomplete/CioAutocomplete.d.ts +3 -0
- package/lib/types/components/Autocomplete/CioAutocompleteProvider.d.ts +28 -0
- package/lib/types/components/Autocomplete/SearchInput/SearchInput.d.ts +7 -0
- package/lib/types/components/Autocomplete/SectionItem/SectionItem.d.ts +10 -0
- package/lib/types/components/Autocomplete/SectionItemsList/SectionItemsList.d.ts +12 -0
- package/lib/types/constants.d.ts +23 -0
- package/lib/types/hooks/useCioAutocomplete.d.ts +29 -0
- package/lib/types/hooks/useCioClient.d.ts +15 -0
- package/lib/types/hooks/useDebounce.d.ts +2 -0
- package/lib/types/hooks/useDebouncedFetchSections.d.ts +4 -0
- package/lib/types/hooks/useDownShift.d.ts +16 -0
- package/lib/types/hooks/useFetchRecommendationPod.d.ts +4 -0
- package/lib/types/hooks/usePrevious.d.ts +2 -0
- package/lib/types/index.d.ts +6 -0
- package/lib/types/stories/Autocomplete/argTypes.d.ts +62 -0
- package/lib/types/typeGuards.d.ts +2 -0
- package/lib/types/types.d.ts +131 -0
- package/lib/types/utils.d.ts +24 -0
- package/package.json +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Constructor.io
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Constructor.io Autocomplete UI Library
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
This UI Library provides React components that manage fetching and rendering logic for [Constructor.io's autosuggest services](https://constructor.io/products/autosuggest/).
|
|
6
|
+
|
|
7
|
+
[Our storybook docs](https://constructor-io.github.io/constructorio-ui-autocomplete) are the best place to explore the behavior and configuration options for this UI Library.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
## How to use this UI Library
|
|
12
|
+
|
|
13
|
+
There are two main methods for consuming this UI Library in a React project:
|
|
14
|
+
|
|
15
|
+
### Component based
|
|
16
|
+
|
|
17
|
+
The `CioAutocomplete` component handles state management, data fetching, and rendering logic.
|
|
18
|
+
|
|
19
|
+
```jsx
|
|
20
|
+
import { CioAutocomplete } from 'constructorio-ui-autocomplete';
|
|
21
|
+
|
|
22
|
+
function YourComponent() {
|
|
23
|
+
return (
|
|
24
|
+
<div>
|
|
25
|
+
<CioAutocomplete apiKey="key_Gep3oQOu5IMcNh9A" />
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Hook based
|
|
31
|
+
|
|
32
|
+
The `useCioAutocomplete` hook handles state management and data fetching, but leaves rendering logic up to you.
|
|
33
|
+
|
|
34
|
+
```jsx
|
|
35
|
+
import { useCioAutocomplete } from 'constructorio-ui-autocomplete';
|
|
36
|
+
|
|
37
|
+
function YourComponent() {
|
|
38
|
+
const {
|
|
39
|
+
isOpen,
|
|
40
|
+
sections,
|
|
41
|
+
getFormProps,
|
|
42
|
+
getLabelProps,
|
|
43
|
+
getInputProps,
|
|
44
|
+
getMenuProps,
|
|
45
|
+
getItemProps,
|
|
46
|
+
autocompleteClassName
|
|
47
|
+
} = useCioAutocomplete(args);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div className={autocompleteClassName}>
|
|
51
|
+
<form {...getFormProps()}>
|
|
52
|
+
<label {...getLabelProps()} hidden>
|
|
53
|
+
Search
|
|
54
|
+
</label>
|
|
55
|
+
<input {...getInputProps()} />
|
|
56
|
+
</form>
|
|
57
|
+
<div {...getMenuProps()}>
|
|
58
|
+
{isOpen && (
|
|
59
|
+
<>
|
|
60
|
+
{sections?.map((section) => (
|
|
61
|
+
<div key={section.identifier} className={section.identifier}>
|
|
62
|
+
<div className='cio-section'>
|
|
63
|
+
<div className='cio-sectionName'>
|
|
64
|
+
{section?.displayName || section.identifier}
|
|
65
|
+
</div>
|
|
66
|
+
<div className='cio-items'>
|
|
67
|
+
{section?.data?.map((item, index) => (
|
|
68
|
+
<div
|
|
69
|
+
{...getItemProps({
|
|
70
|
+
item,
|
|
71
|
+
index,
|
|
72
|
+
sectionIdentifier: section.identifier
|
|
73
|
+
})}
|
|
74
|
+
key={item?.data?.id}>
|
|
75
|
+
<div>
|
|
76
|
+
{isProduct(item) && (
|
|
77
|
+
<img
|
|
78
|
+
width='100%'
|
|
79
|
+
src={item.data?.image_url}
|
|
80
|
+
alt=''
|
|
81
|
+
data-testid='cio-img'
|
|
82
|
+
/>
|
|
83
|
+
)}
|
|
84
|
+
<p>{item.value}</p>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
))}
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
))}
|
|
92
|
+
</>
|
|
93
|
+
)}
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Custom Styling
|
|
101
|
+
|
|
102
|
+
### Library defaults
|
|
103
|
+
|
|
104
|
+
This library provides some default styles. These default styles can be used as a foundation to build on top of or just as a reference for you to replace completely. All default styles in this library are scoped within the `.cio-autocomplete` css selector.
|
|
105
|
+
|
|
106
|
+
- If you would like to remove all default styling, simply pass an empty string or your own custom autocomplete container className as the value for the `autocompleteClassName` option
|
|
107
|
+
- If you would like to layer your own custom styles on top of the library default styles, you can do so by passing additional className(s) of your choosing `autocompleteClassName='cio-autocomplete custom-autocomplete-container'`
|
|
108
|
+
|
|
109
|
+
## Local Development
|
|
110
|
+
|
|
111
|
+
### Development scripts
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npm ci # install dependencies for local dev
|
|
115
|
+
npm run dev # start a local dev server for Storybook
|
|
116
|
+
npm run lint # run linter
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Maintain Library
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npm run compile # generate lib folder for publishing to npm
|
|
123
|
+
npm run build-storybook # generate storybook static bundle for deploy with GH Pages
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Supporting Docs
|
|
127
|
+
|
|
128
|
+
- [Storybook 7 Introduction](https://storybook.js.org/docs/7.0/react/get-started/introduction)
|
|
129
|
+
- [Typescript Docs](https://www.typescriptlang.org/docs/)
|
package/lib/.DS_Store
ADDED
|
Binary file
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/* Autosuggest Container */
|
|
2
|
+
.cio-autocomplete {
|
|
3
|
+
position: relative;
|
|
4
|
+
height: 2rem;
|
|
5
|
+
padding: 20px;
|
|
6
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/* Autosuggest Form */
|
|
10
|
+
.cio-autocomplete .cio-form {
|
|
11
|
+
position: relative;
|
|
12
|
+
height: 100%;
|
|
13
|
+
width: 24rem;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.cio-autocomplete .cio-input {
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: 100%;
|
|
19
|
+
border: 1px solid gray;
|
|
20
|
+
padding: 0 10px;
|
|
21
|
+
border-radius: 3px;
|
|
22
|
+
font-size: 1rem;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.cio-autocomplete .cio-submit-btn,
|
|
26
|
+
.cio-autocomplete .cio-clear-btn {
|
|
27
|
+
position: absolute;
|
|
28
|
+
top: 1px;
|
|
29
|
+
bottom: -1px;
|
|
30
|
+
right: -21px;
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.cio-autocomplete button:disabled {
|
|
35
|
+
cursor: not-allowed;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.cio-autocomplete .cio-submit-btn {
|
|
39
|
+
right: -21px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.cio-autocomplete .cio-clear-btn {
|
|
43
|
+
right: 10px;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.cio-autocomplete .cio-icon {
|
|
47
|
+
display: flex;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Autosuggest Results */
|
|
52
|
+
.cio-autocomplete .cio-results {
|
|
53
|
+
position: absolute;
|
|
54
|
+
background-color: white;
|
|
55
|
+
gap: 20px;
|
|
56
|
+
padding-left: 0px;
|
|
57
|
+
list-style: none;
|
|
58
|
+
display: flex;
|
|
59
|
+
flex-direction: row;
|
|
60
|
+
z-index: 1000;
|
|
61
|
+
margin-top: 5px;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.cio-autocomplete .cio-sectionName {
|
|
65
|
+
margin: 15px 0;
|
|
66
|
+
font-size: 1rem;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.cio-autocomplete .cio-section-items {
|
|
70
|
+
padding: 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.cio-autocomplete .cio-item-SearchSuggestions {
|
|
74
|
+
flex-direction: column;
|
|
75
|
+
min-width: 160px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.cio-autocomplete .cio-item {
|
|
79
|
+
flex: 1;
|
|
80
|
+
display: flex;
|
|
81
|
+
flex-direction: column;
|
|
82
|
+
cursor: pointer;
|
|
83
|
+
list-style: none;
|
|
84
|
+
padding: 5px;
|
|
85
|
+
border-bottom: 3px solid transparent;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.cio-autocomplete .cio-item[aria-selected='true'] {
|
|
89
|
+
background-color: hsl(0, 0%, 90%);
|
|
90
|
+
border-radius: 4px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.cio-autocomplete .Products .cio-item {
|
|
94
|
+
display: inline-flex;
|
|
95
|
+
align-items: center;
|
|
96
|
+
width: 25%;
|
|
97
|
+
height: 140px;
|
|
98
|
+
padding: 5px 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.cio-autocomplete .cio-item p {
|
|
102
|
+
margin: 0;
|
|
103
|
+
overflow: hidden;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.cio-autocomplete .cio-item img {
|
|
107
|
+
width: 100%;
|
|
108
|
+
max-width: 100px;
|
|
109
|
+
max-height: 100px;
|
|
110
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
|
|
5
|
+
const SectionItemsList_1 = require("../SectionItemsList/SectionItemsList");
|
|
6
|
+
const DefaultRenderResults = ({ sections }) => sections === null || sections === void 0 ? void 0 : sections.map((section) => (react_1.default.createElement(SectionItemsList_1.default, { section: section, key: section.identifier })));
|
|
7
|
+
function AutocompleteResults(props) {
|
|
8
|
+
const { children = DefaultRenderResults } = props;
|
|
9
|
+
const { sections, isOpen, getMenuProps, getItemProps } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
10
|
+
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; });
|
|
11
|
+
let content;
|
|
12
|
+
if (isOpen && hasResults) {
|
|
13
|
+
content = typeof children === 'function' ? children({ sections, getItemProps }) : children;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
content = null;
|
|
17
|
+
}
|
|
18
|
+
const menuProps = Object.assign({}, getMenuProps());
|
|
19
|
+
return react_1.default.createElement("ul", Object.assign({}, menuProps), content);
|
|
20
|
+
}
|
|
21
|
+
exports.default = AutocompleteResults;
|
|
22
|
+
//# sourceMappingURL=AutocompleteResults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutocompleteResults.js","sourceRoot":"","sources":["../../../../../src/components/Autocomplete/AutocompleteResults/AutocompleteResults.tsx"],"names":[],"mappings":";;AAAA,iCAAqD;AAErD,wEAAoE;AACpE,2EAAoE;AAWpE,MAAM,oBAAoB,GAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAC3D,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,GAAG,CAAC,CAAC,OAA6B,EAAE,EAAE,CAAC,CAC/C,8BAAC,0BAAgB,IAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,UAAU,GAAI,CAChE,CAAC,CAAC;AAEL,SAAwB,mBAAmB,CAAC,KAA+B;IACzE,MAAM,EAAE,QAAQ,GAAG,oBAAoB,EAAE,GAAG,KAAK,CAAC;IAClD,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,IAAA,kBAAU,EAAC,gDAAsB,CAAC,CAAC;IAE5F,MAAM,UAAU,GAAG,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,WAAC,OAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,MAAM,CAAA,EAAA,CAAC,CAAC;IAEjF,IAAI,OAAO,CAAC;IACZ,IAAI,MAAM,IAAI,UAAU,EAAE;QACxB,OAAO,GAAG,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;KAC5F;SAAM;QACL,OAAO,GAAG,IAAI,CAAC;KAChB;IAED,MAAM,SAAS,qBACV,YAAY,EAAE,CAClB,CAAC;IAEF,OAAO,sDAAQ,SAAS,GAAG,OAAO,CAAM,CAAC;AAC3C,CAAC;AAlBD,sCAkBC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
|
|
5
|
+
const AutocompleteResults_1 = require("../AutocompleteResults/AutocompleteResults");
|
|
6
|
+
const SearchInput_1 = require("../SearchInput/SearchInput");
|
|
7
|
+
function CioAutocomplete(props) {
|
|
8
|
+
const { children } = props;
|
|
9
|
+
if (children) {
|
|
10
|
+
return react_1.default.createElement(CioAutocompleteProvider_1.default, Object.assign({}, props), children);
|
|
11
|
+
}
|
|
12
|
+
return (react_1.default.createElement("div", null,
|
|
13
|
+
react_1.default.createElement(CioAutocompleteProvider_1.default, Object.assign({}, props),
|
|
14
|
+
react_1.default.createElement(SearchInput_1.default, null),
|
|
15
|
+
react_1.default.createElement(AutocompleteResults_1.default, null))));
|
|
16
|
+
}
|
|
17
|
+
exports.default = CioAutocomplete;
|
|
18
|
+
//# sourceMappingURL=CioAutocomplete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CioAutocomplete.js","sourceRoot":"","sources":["../../../../../src/components/Autocomplete/CioAutocomplete/CioAutocomplete.tsx"],"names":[],"mappings":";;AAAA,iCAA0B;AAC1B,wEAAiE;AACjE,oFAA6E;AAC7E,4DAAqD;AAGrD,SAAwB,eAAe,CAAC,KAA2B;IACjE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAE3B,IAAI,QAAQ,EAAE;QACZ,OAAO,8BAAC,iCAAuB,oBAAK,KAAK,GAAG,QAAQ,CAA2B,CAAC;KACjF;IAED,OAAO,CACL;QACE,8BAAC,iCAAuB,oBAAK,KAAK;YAChC,8BAAC,qBAAW,OAAG;YACf,8BAAC,6BAAmB,OAAG,CACC,CACtB,CACP,CAAC;AACJ,CAAC;AAfD,kCAeC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CioAutocompleteContext = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const useCioAutocomplete_1 = require("../../hooks/useCioAutocomplete");
|
|
7
|
+
exports.CioAutocompleteContext = (0, react_1.createContext)({});
|
|
8
|
+
function CioAutocompleteProvider(props) {
|
|
9
|
+
const { children } = props, restProps = tslib_1.__rest(props, ["children"]);
|
|
10
|
+
const cioAutocomplete = (0, useCioAutocomplete_1.default)(restProps);
|
|
11
|
+
return (react_1.default.createElement(exports.CioAutocompleteContext.Provider, { value: cioAutocomplete },
|
|
12
|
+
react_1.default.createElement("div", { className: cioAutocomplete.autocompleteClassName }, children)));
|
|
13
|
+
}
|
|
14
|
+
exports.default = CioAutocompleteProvider;
|
|
15
|
+
//# sourceMappingURL=CioAutocompleteProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CioAutocompleteProvider.js","sourceRoot":"","sources":["../../../../src/components/Autocomplete/CioAutocompleteProvider.tsx"],"names":[],"mappings":";;;;AAAA,iCAA6C;AAC7C,uEAAgE;AAGnD,QAAA,sBAAsB,GAAG,IAAA,qBAAa,EACjD,EAA2C,CAC5C,CAAC;AAEF,SAAwB,uBAAuB,CAAC,KAA2B;IACzE,MAAM,EAAE,QAAQ,KAAmB,KAAK,EAAnB,SAAS,kBAAK,KAAK,EAAlC,YAA0B,CAAQ,CAAC;IACzC,MAAM,eAAe,GAAG,IAAA,4BAAkB,EAAC,SAAS,CAAC,CAAC;IAEtD,OAAO,CACL,8BAAC,8BAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,eAAe;QACrD,uCAAK,SAAS,EAAE,eAAe,CAAC,qBAAqB,IAAG,QAAQ,CAAO,CACvC,CACnC,CAAC;AACJ,CAAC;AATD,0CASC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
|
|
5
|
+
function DefaultRenderInput({ getFormProps, getInputProps, getLabelProps, setQuery }) {
|
|
6
|
+
const inputProps = getInputProps();
|
|
7
|
+
return (react_1.default.createElement("form", Object.assign({}, getFormProps()),
|
|
8
|
+
react_1.default.createElement("label", Object.assign({}, getLabelProps(), { htmlFor: 'cio-input' }),
|
|
9
|
+
react_1.default.createElement("input", Object.assign({ id: 'cio-input' }, inputProps))),
|
|
10
|
+
react_1.default.createElement("button", { className: 'cio-clear-btn', "data-testid": 'cio-clear-btn', hidden: !inputProps.value, onClick: () => {
|
|
11
|
+
setQuery('');
|
|
12
|
+
if (inputProps.id) {
|
|
13
|
+
setTimeout(() => { var _a; return (_a = document.getElementById(inputProps.id)) === null || _a === void 0 ? void 0 : _a.focus(); }, 100);
|
|
14
|
+
}
|
|
15
|
+
}, type: 'button', "aria-label": 'Clear search field text' },
|
|
16
|
+
react_1.default.createElement("div", { className: 'cio-icon' },
|
|
17
|
+
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' },
|
|
18
|
+
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' })))),
|
|
19
|
+
react_1.default.createElement("button", { className: 'cio-submit-btn', "data-testid": 'cio-submit-btn', disabled: !inputProps.value, type: 'submit', "aria-label": 'Submit Search' },
|
|
20
|
+
react_1.default.createElement("div", { className: 'cio-icon' },
|
|
21
|
+
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' },
|
|
22
|
+
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' }))))));
|
|
23
|
+
}
|
|
24
|
+
function SearchInput(props) {
|
|
25
|
+
const { children = DefaultRenderInput } = props;
|
|
26
|
+
const { getFormProps, getInputProps, getLabelProps, setQuery } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
27
|
+
return children({ getFormProps, getInputProps, getLabelProps, setQuery });
|
|
28
|
+
}
|
|
29
|
+
exports.default = SearchInput;
|
|
30
|
+
//# sourceMappingURL=SearchInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchInput.js","sourceRoot":"","sources":["../../../../../src/components/Autocomplete/SearchInput/SearchInput.tsx"],"names":[],"mappings":";;AAAA,iCAAwD;AAExD,wEAAoE;AAMpE,SAAS,kBAAkB,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE;IAClF,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IAEnC,OAAO,CACL,wDAAU,YAAY,EAAE;QACtB,yDAAW,aAAa,EAAE,IAAE,OAAO,EAAC,WAAW;YAC7C,uDAAO,EAAE,EAAC,WAAW,IAAK,UAAU,EAAI,CAClC;QACR,0CACE,SAAS,EAAC,eAAe,iBACb,eAAe,EAC3B,MAAM,EAAE,CAAC,UAAU,CAAC,KAAK,EACzB,OAAO,EAAE,GAAG,EAAE;gBACZ,QAAQ,CAAC,EAAE,CAAC,CAAC;gBACb,IAAI,UAAU,CAAC,EAAE,EAAE;oBACjB,UAAU,CAAC,GAAG,EAAE,WAAC,OAAA,MAAA,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC,0CAAE,KAAK,EAAE,CAAA,EAAA,EAAE,GAAG,CAAC,CAAC;iBACxE;YACH,CAAC,EACD,IAAI,EAAC,QAAQ,gBACF,yBAAyB;YACpC,uCAAK,SAAS,EAAC,UAAU;gBACvB,uCACE,MAAM,EAAC,cAAc,EACrB,IAAI,EAAC,cAAc,EACnB,WAAW,EAAC,GAAG,EACf,OAAO,EAAC,aAAa,EACrB,MAAM,EAAC,KAAK,EACZ,KAAK,EAAC,KAAK,EACX,KAAK,EAAC,4BAA4B;oBAClC,wCAAM,CAAC,EAAC,4HAA4H,GAAG,CACnI,CACF,CACC;QACT,0CACE,SAAS,EAAC,gBAAgB,iBACd,gBAAgB,EAC5B,QAAQ,EAAE,CAAC,UAAU,CAAC,KAAK,EAC3B,IAAI,EAAC,QAAQ,gBACF,eAAe;YAC1B,uCAAK,SAAS,EAAC,UAAU;gBACvB,uCACE,MAAM,EAAC,cAAc,EACrB,IAAI,EAAC,cAAc,EACnB,WAAW,EAAC,GAAG,EACf,OAAO,EAAC,aAAa,EACrB,MAAM,EAAC,KAAK,EACZ,KAAK,EAAC,KAAK,EACX,KAAK,EAAC,4BAA4B;oBAClC,wCAAM,CAAC,EAAC,2VAA2V,GAAG,CAClW,CACF,CACC,CACJ,CACR,CAAC;AACJ,CAAC;AAED,SAAwB,WAAW,CAAC,KAAuB;IACzD,MAAM,EAAE,QAAQ,GAAG,kBAAkB,EAAE,GAAG,KAAK,CAAC;IAChD,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,GAC5D,IAAA,kBAAU,EAAC,gDAAsB,CAAC,CAAC;IAErC,OAAO,QAAQ,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC5E,CAAC;AAND,8BAMC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
|
|
5
|
+
const typeGuards_1 = require("../../../typeGuards");
|
|
6
|
+
function SectionItem(props) {
|
|
7
|
+
var _a;
|
|
8
|
+
const { item, index, sectionIdentifier, children } = props;
|
|
9
|
+
const { getItemProps } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
10
|
+
let defaultChildren;
|
|
11
|
+
if ((0, typeGuards_1.isProduct)(item)) {
|
|
12
|
+
defaultChildren = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
13
|
+
react_1.default.createElement("img", { "data-testid": 'cio-img', src: (_a = item.data) === null || _a === void 0 ? void 0 : _a.image_url, alt: item.value }),
|
|
14
|
+
react_1.default.createElement("p", { "data-testid": 'cio-text' }, item.value)));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
defaultChildren = item.value;
|
|
18
|
+
}
|
|
19
|
+
return (react_1.default.createElement("li", Object.assign({}, getItemProps({ item, index, sectionIdentifier })), children || defaultChildren));
|
|
20
|
+
}
|
|
21
|
+
exports.default = SectionItem;
|
|
22
|
+
//# sourceMappingURL=SectionItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SectionItem.js","sourceRoot":"","sources":["../../../../../src/components/Autocomplete/SectionItem/SectionItem.tsx"],"names":[],"mappings":";;AAAA,iCAAqD;AACrD,wEAAoE;AAEpE,oDAAgD;AAUhD,SAAwB,WAAW,CAAC,KAAuB;;IACzD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3D,MAAM,EAAE,YAAY,EAAE,GAAG,IAAA,kBAAU,EAAC,gDAAsB,CAAC,CAAC;IAE5D,IAAI,eAAe,CAAC;IACpB,IAAI,IAAA,sBAAS,EAAC,IAAI,CAAC,EAAE;QACnB,eAAe,GAAG,CAChB;YACE,sDAAiB,SAAS,EAAC,GAAG,EAAE,MAAA,IAAI,CAAC,IAAI,0CAAE,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,GAAI;YACzE,oDAAe,UAAU,IAAE,IAAI,CAAC,KAAK,CAAK,CACzC,CACJ,CAAC;KACH;SAAM;QACL,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC;KAC9B;IAED,OAAO,CACL,sDAAQ,YAAY,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC,GAAG,QAAQ,IAAI,eAAe,CAAM,CAC7F,CAAC;AACJ,CAAC;AAnBD,8BAmBC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const SectionItem_1 = require("../SectionItem/SectionItem");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
// eslint-disable-next-line func-names
|
|
7
|
+
const DefaultRenderSectionItemsList = function ({ section }) {
|
|
8
|
+
var _a;
|
|
9
|
+
const sectionName = (section === null || section === void 0 ? void 0 : section.displayName) || (section === null || section === void 0 ? void 0 : section.identifier);
|
|
10
|
+
return (react_1.default.createElement("li", { className: `${sectionName} cio-section`, role: 'none' },
|
|
11
|
+
react_1.default.createElement("h5", { className: 'cio-sectionName', "aria-hidden": true }, (0, utils_1.camelToStartCase)(sectionName)),
|
|
12
|
+
react_1.default.createElement("ul", { className: 'cio-section-items', role: 'none' }, (_a = section === null || section === void 0 ? void 0 : section.data) === null || _a === void 0 ? void 0 : _a.map((item, index) => {
|
|
13
|
+
var _a;
|
|
14
|
+
return (react_1.default.createElement(SectionItem_1.default, { item: item, index: index, sectionIdentifier: section === null || section === void 0 ? void 0 : section.identifier, key: `${section === null || section === void 0 ? void 0 : section.identifier}_${(_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.id}` }));
|
|
15
|
+
}))));
|
|
16
|
+
};
|
|
17
|
+
function SectionItemsList(props) {
|
|
18
|
+
const { section, children = DefaultRenderSectionItemsList } = props;
|
|
19
|
+
return children({ section });
|
|
20
|
+
}
|
|
21
|
+
exports.default = SectionItemsList;
|
|
22
|
+
//# sourceMappingURL=SectionItemsList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SectionItemsList.js","sourceRoot":"","sources":["../../../../../src/components/Autocomplete/SectionItemsList/SectionItemsList.tsx"],"names":[],"mappings":";;AAAA,iCAA4C;AAE5C,4DAAqD;AACrD,0CAAkD;AAYlD,sCAAsC;AACtC,MAAM,6BAA6B,GAA2B,UAAU,EAAE,OAAO,EAAE;;IACjF,MAAM,WAAW,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAA,CAAC;IAEhE,OAAO,CACL,sCAAI,SAAS,EAAE,GAAG,WAAW,cAAc,EAAE,IAAI,EAAC,MAAM;QACtD,sCAAI,SAAS,EAAC,iBAAiB,yBAC5B,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAC3B;QACL,sCAAI,SAAS,EAAC,mBAAmB,EAAC,IAAI,EAAC,MAAM,IAC1C,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;;YAAC,OAAA,CACnC,8BAAC,qBAAW,IACV,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,EACZ,iBAAiB,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,EACtC,GAAG,EAAE,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,IAAI,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,0CAAE,EAAE,EAAE,GAC/C,CACH,CAAA;SAAA,CAAC,CACC,CACF,CACN,CAAC;AACJ,CAAC,CAAC;AAEF,SAAwB,gBAAgB,CAAC,KAA4B;IACnE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,6BAA6B,EAAE,GAAG,KAAK,CAAC;IAEpE,OAAO,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/B,CAAC;AAJD,mCAIC"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.customStylesDescription = exports.multipleSectionsDescription = exports.openOnFocusDescription = exports.zeroStateSectionsDescription = exports.onSubmitDescription = exports.onChangeDescription = exports.onFocusDescription = exports.customSectionDescription = exports.recommendationsDescription = exports.sectionOrderDescription = exports.numResultsDescription = exports.contentDescription = exports.productsDescription = exports.searchSuggestionsDescription = exports.placeholderDescription = exports.cioJsClientDescription = exports.apiKeyDescription = exports.zeroStateDescription = exports.userEventsDescription = exports.sectionsDescription = exports.hookDescription = exports.componentDescription = exports.apiKey = void 0;
|
|
4
|
+
// Autocomplete key index
|
|
5
|
+
exports.apiKey = 'key_Gep3oQOu5IMcNh9A';
|
|
6
|
+
/// //////////////////////////////
|
|
7
|
+
// Storybook Folder Descriptions
|
|
8
|
+
/// //////////////////////////////
|
|
9
|
+
exports.componentDescription = `- import \`CioAutocomplete\` to render in your JSX.
|
|
10
|
+
- This component handles state management, data fetching, and rendering logic.
|
|
11
|
+
- To use this component, an \`apiKey\` or \`cioJsClient\` are required, all other values are optional.
|
|
12
|
+
- Use different props to configure the behavior of this component.
|
|
13
|
+
- The following stories shows how different props affect the component's behavior
|
|
14
|
+
|
|
15
|
+
> 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)
|
|
16
|
+
`;
|
|
17
|
+
exports.hookDescription = `- import \`useCioAutocomplete\` and call this custom hook in a functional component.
|
|
18
|
+
- This hook handles state management & data fetching, but leaves rendering logic up to you
|
|
19
|
+
- To use this hook, an \`apiKey\` or \`cioJsClient\` are required, all other values are optional.
|
|
20
|
+
- Pass different options to the \`useCioAutocomplete\` hook to configure behavior.
|
|
21
|
+
- The following stories shows how different options affect the hook's behavior
|
|
22
|
+
|
|
23
|
+
Calling the \`useCioAutocomplete\` hook returns an object with the following keys:
|
|
24
|
+
|
|
25
|
+
\`\`\`jsx
|
|
26
|
+
const {
|
|
27
|
+
// must be used for a hooks integrations
|
|
28
|
+
query: string, // current input field value
|
|
29
|
+
sections: [{...}], // array of sections data to render in menu list,
|
|
30
|
+
getFormProps: () => ({...})), // prop getter for jsx form element
|
|
31
|
+
getLabelProps: () => ({...})), // optional: prop getter for jsx label element
|
|
32
|
+
getInputProps: () => ({...})), // prop getter for jsx input element
|
|
33
|
+
getMenuProps: () => ({...})), // prop getter for jsx element serving as menu container
|
|
34
|
+
getItemProps: () => ({...})), // prop getter for jsx element serving as each result
|
|
35
|
+
isOpen: boolean,
|
|
36
|
+
|
|
37
|
+
// available for advanced hooks integration use cases
|
|
38
|
+
openMenu: () => void, // open menu
|
|
39
|
+
closeMenu: () => void, // close menu
|
|
40
|
+
setQuery: () => void, // update the current input field value
|
|
41
|
+
cioJsClient, // instance of constructorio-client-javascript
|
|
42
|
+
} = useCioAutocomplete(args);
|
|
43
|
+
\`\`\`
|
|
44
|
+
|
|
45
|
+
> 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)
|
|
46
|
+
`;
|
|
47
|
+
/// //////////////////////////////
|
|
48
|
+
// Storybook Pages
|
|
49
|
+
/// //////////////////////////////
|
|
50
|
+
exports.sectionsDescription = `- by default, typing a query will fetch data for search suggestions and Products
|
|
51
|
+
- to override this, pass a an array of sections objects
|
|
52
|
+
- the order of the objects in the \`sections\` array determines the order of the results
|
|
53
|
+
- each section object must have an \`identifier\`
|
|
54
|
+
- each section object can specify a \`type\`
|
|
55
|
+
- each section object can override the default \`numResults\` of 8
|
|
56
|
+
|
|
57
|
+
When no values are passed for the \`sections\` argument, the following defaults are used:
|
|
58
|
+
|
|
59
|
+
\`\`\`jsx
|
|
60
|
+
[
|
|
61
|
+
{
|
|
62
|
+
identifier: 'Search Suggestions',
|
|
63
|
+
type: 'autocomplete',
|
|
64
|
+
numResults: 8
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
identifier: 'Products',
|
|
68
|
+
type: 'autocomplete',
|
|
69
|
+
numResults: 8
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
\`\`\`
|
|
73
|
+
`;
|
|
74
|
+
exports.userEventsDescription = `- pass callback functions to respond to user events
|
|
75
|
+
- if provided, the onFocus callback function will be called each time the user focuses on the text input field
|
|
76
|
+
- if provided, the onChange callback function will be called each time the user changes the value in the text input field
|
|
77
|
+
- if provided, the onSubmit callback function will be called each time the user submits the form
|
|
78
|
+
- 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
|
|
79
|
+
|
|
80
|
+
> ⚠️ NOTE ⚠️ 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.`;
|
|
81
|
+
exports.zeroStateDescription = `- when the text input field has no text, we call this zero state
|
|
82
|
+
- by default, the autocomplete shows nothing in the menu it's for zero state
|
|
83
|
+
- to show zero state results, pass an array of section objects for \`zeroStateSections\`
|
|
84
|
+
- when \`zeroStateSections\` has sections, the menu will open on user focus by default
|
|
85
|
+
- 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
|
|
86
|
+
- the order of the objects in the \`zeroStateSections\` array determines the order of the results
|
|
87
|
+
- each section object must have an \`identifier\`
|
|
88
|
+
- each section object can specify a \`type\`
|
|
89
|
+
- each section object can override the default \`numResults\` of 8`;
|
|
90
|
+
/// //////////////////////////////
|
|
91
|
+
// Storybook Stories
|
|
92
|
+
/// //////////////////////////////
|
|
93
|
+
exports.apiKeyDescription = `Pass an \`apiKey\` to request results from constructor's servers`;
|
|
94
|
+
exports.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
|
|
95
|
+
|
|
96
|
+
> 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)`;
|
|
97
|
+
exports.placeholderDescription = `Pass a \`placeholder\` to override the default input field placeholder text shown to users before they start typing their query`;
|
|
98
|
+
exports.searchSuggestionsDescription = `Override default \`sections\` to only suggest search terms`;
|
|
99
|
+
exports.productsDescription = `Override default \`sections\` to only suggested products`;
|
|
100
|
+
exports.contentDescription = `Override default \`sections\` to only suggest content`;
|
|
101
|
+
exports.numResultsDescription = `Override default \`numResults\` to only suggest 2 products per query`;
|
|
102
|
+
exports.sectionOrderDescription = `Override default \`numResults\` to suggest products, then terms`;
|
|
103
|
+
exports.recommendationsDescription = `Use constructor's recommendations service, with \`"type": "recommendations"\``;
|
|
104
|
+
exports.customSectionDescription = `Use a custom section, by managing and passing your own data, with \`"type": "custom"\` and \`"data":[{...}]\``;
|
|
105
|
+
exports.onFocusDescription = `Pass an \`onFocus\` callback function to execute some code each time the user applies focus to the text input field`;
|
|
106
|
+
exports.onChangeDescription = `Pass an \`onChange\` callback function to execute some code each time the user changes the value of the text input field`;
|
|
107
|
+
exports.onSubmitDescription = `Pass an \`onSubmit\` callback function to execute some code after a user submits the search form.
|
|
108
|
+
|
|
109
|
+
Your callback function will be invoked with a submit event containing useful metadata about the submit event:
|
|
110
|
+
- if the user submits the text input:
|
|
111
|
+
- the \`query\` field will provide the value of that input field
|
|
112
|
+
- if the user selects a suggested item from the dropdown list:
|
|
113
|
+
- the \`originalQuery\` field will provide the value of the input field that generated the selected item
|
|
114
|
+
- an \`item\` object with information about the suggestion that the user selected`;
|
|
115
|
+
exports.zeroStateSectionsDescription = `Use \`zeroStateSections\` to show suggestions after a user applies focus to the search input field and before they start typing a query`;
|
|
116
|
+
exports.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`;
|
|
117
|
+
exports.multipleSectionsDescription = `Use as many different \`recommendations\` and \`custom\` sections as you'd like and in whatever order you would like!`;
|
|
118
|
+
// from .storybook/custom-styles-story.css
|
|
119
|
+
exports.customStylesDescription = `
|
|
120
|
+
This library provides some default styles. These default styles can be used as a foundation to build on top of or just as a reference for you to replace completely. All default styles in this library are scoped within the \`.cio-autocomplete\` css selector.
|
|
121
|
+
|
|
122
|
+
- If you would like to remove all default styling, simply pass an empty string or your own custom autocomplete container className as the value for the \`autocompleteClassName\` prop
|
|
123
|
+
- If you would like to layer your own custom styles on top of the library default styles, you can do so by passing additional className(s) of your choosing \`autocompleteClassName='cio-autocomplete custom-autocomplete-container'\`
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
\`\`\`css
|
|
127
|
+
.cio-autocomplete.custom-autocomplete-styles form {
|
|
128
|
+
height: 44px;
|
|
129
|
+
width: 600px;
|
|
130
|
+
border-radius: 8px;
|
|
131
|
+
background-color: rgb(247, 247, 247);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.cio-autocomplete.custom-autocomplete-styles .cio-input {
|
|
135
|
+
font-weight: bold;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.cio-autocomplete.custom-autocomplete-styles .cio-form button {
|
|
139
|
+
width: 44px;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.cio-autocomplete.custom-autocomplete-styles .cio-clear-btn {
|
|
143
|
+
right: 24px;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.cio-autocomplete.custom-autocomplete-styles .cio-sectionName {
|
|
147
|
+
margin: 5px 3px;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.cio-autocomplete.custom-autocomplete-styles .cio-results {
|
|
151
|
+
width: 620px;
|
|
152
|
+
max-height: 334px;
|
|
153
|
+
overflow: hidden;
|
|
154
|
+
border-radius: 0px 0px 8px 8px;
|
|
155
|
+
color: rgb(51, 51, 51);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.cio-autocomplete.custom-autocomplete-styles .Products p {
|
|
159
|
+
padding: 5px 5px 0;
|
|
160
|
+
}
|
|
161
|
+
\`\`\`
|
|
162
|
+
`;
|
|
163
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACZ,QAAA,MAAM,GAAG,sBAAsB,CAAC;AAE7C,kCAAkC;AAClC,gCAAgC;AAChC,kCAAkC;AAErB,QAAA,oBAAoB,GAAG;;;;;;;CAOnC,CAAC;AAEW,QAAA,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6B9B,CAAC;AAEF,kCAAkC;AAClC,kBAAkB;AAClB,kCAAkC;AAErB,QAAA,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;CAuBlC,CAAC;AAEW,QAAA,qBAAqB,GAAG;;;;;;+bAM0Z,CAAC;AAEnb,QAAA,oBAAoB,GAAG;;;;;;;;mEAQ+B,CAAC;AAEpE,kCAAkC;AAClC,oBAAoB;AACpB,kCAAkC;AAErB,QAAA,iBAAiB,GAAG,kEAAkE,CAAC;AACvF,QAAA,sBAAsB,GAAG;;6LAEuJ,CAAC;AACjL,QAAA,sBAAsB,GAAG,iIAAiI,CAAC;AAC3J,QAAA,4BAA4B,GAAG,4DAA4D,CAAC;AAC5F,QAAA,mBAAmB,GAAG,0DAA0D,CAAC;AACjF,QAAA,kBAAkB,GAAG,uDAAuD,CAAC;AAC7E,QAAA,qBAAqB,GAAG,sEAAsE,CAAC;AAC/F,QAAA,uBAAuB,GAAG,iEAAiE,CAAC;AAC5F,QAAA,0BAA0B,GAAG,+EAA+E,CAAC;AAC7G,QAAA,wBAAwB,GAAG,+GAA+G,CAAC;AAC3I,QAAA,kBAAkB,GAAG,qHAAqH,CAAC;AAC3I,QAAA,mBAAmB,GAAG,0HAA0H,CAAC;AACjJ,QAAA,mBAAmB,GAAG;;;;;;;sFAOmD,CAAC;AAC1E,QAAA,4BAA4B,GAAG,yIAAyI,CAAC;AACzK,QAAA,sBAAsB,GAAG,mJAAmJ,CAAC;AAC7K,QAAA,2BAA2B,GAAG,uHAAuH,CAAC;AAEnK,0CAA0C;AAC7B,QAAA,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CtC,CAAC"}
|