@constructor-io/constructorio-ui-autocomplete 1.5.3 → 1.7.0
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/README.md +47 -24
- package/dist/constructorio-ui-autocomplete-bundled.js +43 -0
- package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js +6 -1
- package/lib/cjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +1 -4
- package/lib/cjs/constants.js +8 -3
- package/lib/cjs/hooks/useCioAutocomplete.js +13 -6
- package/lib/cjs/hooks/useDebouncedFetchSections.js +33 -5
- package/lib/cjs/hooks/useFetchRecommendationPod.js +4 -1
- package/lib/cjs/typeGuards.js +11 -4
- package/lib/cjs/utils.js +5 -17
- package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js +7 -2
- package/lib/mjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +1 -1
- package/lib/mjs/constants.js +7 -2
- package/lib/mjs/hooks/useCioAutocomplete.js +13 -6
- package/lib/mjs/hooks/useDebouncedFetchSections.js +37 -8
- package/lib/mjs/hooks/useFetchRecommendationPod.js +1 -0
- package/lib/mjs/typeGuards.js +7 -3
- package/lib/mjs/utils.js +4 -15
- package/lib/styles.css +4 -0
- package/lib/types/constants.d.ts +4 -1
- package/lib/types/hooks/useCioAutocomplete.d.ts +2 -2
- package/lib/types/hooks/useDebouncedFetchSections.d.ts +2 -2
- package/lib/types/typeGuards.d.ts +3 -1
- package/lib/types/types.d.ts +21 -12
- package/lib/types/utils.d.ts +2 -2
- package/package.json +21 -14
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Constructor.io Autocomplete UI Library
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@constructor-io/constructorio-ui-autocomplete)
|
|
4
|
+
[](https://github.com/Constructor-io/constructorio-ui-autocomplete/blob/main/LICENSE)
|
|
5
|
+
|
|
3
6
|
## Introduction
|
|
4
7
|
|
|
5
8
|
This UI Library provides React components that manage fetching and rendering logic for [Constructor.io's autosuggest services](https://constructor.io/products/autosuggest/).
|
|
@@ -8,16 +11,15 @@ This UI Library provides React components that manage fetching and rendering log
|
|
|
8
11
|
|
|
9
12
|

|
|
10
13
|
|
|
11
|
-
##
|
|
12
|
-
## Install
|
|
14
|
+
## Installation
|
|
13
15
|
|
|
14
16
|
```bash
|
|
15
17
|
npm i @constructor-io/constructorio-ui-autocomplete
|
|
16
18
|
```
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
## Usage
|
|
19
21
|
|
|
20
|
-
### Component
|
|
22
|
+
### Using the React Component
|
|
21
23
|
|
|
22
24
|
The `CioAutocomplete` component handles state management, data fetching, and rendering logic.
|
|
23
25
|
|
|
@@ -32,14 +34,15 @@ function YourComponent() {
|
|
|
32
34
|
);
|
|
33
35
|
```
|
|
34
36
|
|
|
35
|
-
###
|
|
37
|
+
### Using React Hooks
|
|
36
38
|
|
|
37
39
|
The `useCioAutocomplete` hook leaves rendering logic up to you, while handling:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
|
|
41
|
+
- state management
|
|
42
|
+
- data fetching
|
|
43
|
+
- keyboard navigation
|
|
44
|
+
- mouse interactions
|
|
45
|
+
- focus and submit event handling
|
|
43
46
|
|
|
44
47
|
An `apiKey` or `cioJsClient` must be passed to the `useCioAutocomplete` hook along with an `onSubmit` callback function. All other values are optional.
|
|
45
48
|
|
|
@@ -47,8 +50,8 @@ An `apiKey` or `cioJsClient` must be passed to the `useCioAutocomplete` hook alo
|
|
|
47
50
|
import { useCioAutocomplete } from '@constructor-io/constructorio-ui-autocomplete';
|
|
48
51
|
|
|
49
52
|
const args = {
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
apiKey: 'key_Gep3oQOu5IMcNh9A',
|
|
54
|
+
onSubmit: (submitEvent) => console.dir(submitEvent),
|
|
52
55
|
};
|
|
53
56
|
|
|
54
57
|
function YourComponent() {
|
|
@@ -60,7 +63,7 @@ function YourComponent() {
|
|
|
60
63
|
getInputProps,
|
|
61
64
|
getMenuProps,
|
|
62
65
|
getItemProps,
|
|
63
|
-
autocompleteClassName
|
|
66
|
+
autocompleteClassName,
|
|
64
67
|
} = useCioAutocomplete(args);
|
|
65
68
|
|
|
66
69
|
return (
|
|
@@ -82,9 +85,9 @@ function YourComponent() {
|
|
|
82
85
|
</div>
|
|
83
86
|
<div className='cio-items'>
|
|
84
87
|
{section?.data?.map((item) => (
|
|
85
|
-
<div {...getItemProps(item)} key={item?.
|
|
88
|
+
<div {...getItemProps(item)} key={item?.id}>
|
|
86
89
|
<div>
|
|
87
|
-
{
|
|
90
|
+
{item.data?.image_url && (
|
|
88
91
|
<img
|
|
89
92
|
width='100%'
|
|
90
93
|
src={item.data?.image_url}
|
|
@@ -92,7 +95,11 @@ function YourComponent() {
|
|
|
92
95
|
data-testid='cio-img'
|
|
93
96
|
/>
|
|
94
97
|
)}
|
|
95
|
-
|
|
98
|
+
{item.groupName ? (
|
|
99
|
+
<p className='cio-term-in-group'>in {item.groupName}</p>
|
|
100
|
+
) : (
|
|
101
|
+
<p>{item.value}</p>
|
|
102
|
+
)}
|
|
96
103
|
</div>
|
|
97
104
|
</div>
|
|
98
105
|
))}
|
|
@@ -108,6 +115,23 @@ function YourComponent() {
|
|
|
108
115
|
}
|
|
109
116
|
```
|
|
110
117
|
|
|
118
|
+
### Using the Javascript Bundle
|
|
119
|
+
|
|
120
|
+
This is a framework agnostic method that can be used in any JavaScript project. The `CioAutocomplete` function provides a simple interface to inject an entire Autocomplete UI into the provided `selector`.
|
|
121
|
+
In addition to [Autocomplete component props](https://constructor-io.github.io/constructorio-ui-autocomplete/?path=/docs/autocomplete-component--docs), this function also accepts `selector` and `includeCSS`.
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
import CioAutocomplete from '@constructor-io/constructorio-ui-autocomplete/constructorio-ui-autocomplete-bundled';
|
|
125
|
+
|
|
126
|
+
CioAutocomplete({
|
|
127
|
+
selector: '#autocomplete-container',
|
|
128
|
+
includeCSS: true, // Include the default CSS styles. Defaults to true.
|
|
129
|
+
apiKey: 'key_Gep3oQOu5IMcNh9A',
|
|
130
|
+
onSubmit: (submitEvent) => console.dir(submitEvent),
|
|
131
|
+
// ... additional arguments
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
111
135
|
## Custom Styling
|
|
112
136
|
|
|
113
137
|
### Library defaults
|
|
@@ -122,14 +146,14 @@ import '@constructor-io/constructorio-ui-autocomplete/styles.css';
|
|
|
122
146
|
|
|
123
147
|
> Note: the path and syntax in this example may change slightly depending on your module bundling strategy
|
|
124
148
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
149
|
+
- These starter styles can be used as a foundation to build on top of, or just as a reference for you to replace completely.
|
|
150
|
+
- To opt out of all default styling, do not import the `styles.css` stylesheet.
|
|
151
|
+
- All starter styles in this library are scoped within the `.cio-autocomplete` css selector.
|
|
152
|
+
- These starter styles are intended to be extended by layering in your own css rules
|
|
129
153
|
- If you like, you can override the container's className like so:
|
|
130
|
-
`autocompleteClassName='custom-autocomplete-container'`
|
|
131
|
-
|
|
132
|
-
`autocompleteClassName='cio-autocomplete custom-autocomplete-container'`
|
|
154
|
+
`autocompleteClassName='custom-autocomplete-container'`
|
|
155
|
+
- If you like, you can pass additional className(s) of your choosing like so:
|
|
156
|
+
`autocompleteClassName='cio-autocomplete custom-autocomplete-container'`
|
|
133
157
|
|
|
134
158
|
## Troubleshooting
|
|
135
159
|
|
|
@@ -147,7 +171,6 @@ Relevant open issues:
|
|
|
147
171
|
|
|
148
172
|
[Issue 1810](https://github.com/import-js/eslint-plugin-import/issues/1810)
|
|
149
173
|
|
|
150
|
-
|
|
151
174
|
## Local Development
|
|
152
175
|
|
|
153
176
|
### Development scripts
|