@constructor-io/constructorio-ui-autocomplete 1.6.0 → 1.7.1
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 +40 -21
- package/dist/constructorio-ui-autocomplete-bundled.js +43 -0
- package/lib/cjs/hooks/useCioAutocomplete.js +20 -45
- package/lib/cjs/hooks/useConsoleErrors.js +16 -0
- package/lib/cjs/hooks/useDebouncedFetchSections.js +18 -12
- package/lib/cjs/hooks/useDownShift.js +1 -8
- package/lib/cjs/hooks/useFetchRecommendationPod.js +6 -1
- package/lib/cjs/hooks/useItems.js +12 -0
- package/lib/cjs/hooks/useSections.js +36 -0
- package/lib/cjs/utils.js +36 -17
- package/lib/mjs/hooks/useCioAutocomplete.js +20 -45
- package/lib/mjs/hooks/useConsoleErrors.js +14 -0
- package/lib/mjs/hooks/useDebouncedFetchSections.js +18 -14
- package/lib/mjs/hooks/useDownShift.js +1 -7
- package/lib/mjs/hooks/useFetchRecommendationPod.js +6 -1
- package/lib/mjs/hooks/useItems.js +10 -0
- package/lib/mjs/hooks/useSections.js +32 -0
- package/lib/mjs/utils.js +34 -15
- package/lib/types/hooks/useCioAutocomplete.d.ts +3 -3
- package/lib/types/hooks/useConsoleErrors.d.ts +2 -0
- package/lib/types/hooks/useDownShift.d.ts +0 -1
- package/lib/types/hooks/useItems.d.ts +3 -0
- package/lib/types/hooks/useSections.d.ts +8 -0
- package/lib/types/types.d.ts +1 -1
- package/lib/types/utils.d.ts +6 -4
- 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 (
|
|
@@ -112,6 +115,23 @@ function YourComponent() {
|
|
|
112
115
|
}
|
|
113
116
|
```
|
|
114
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
|
+
|
|
115
135
|
## Custom Styling
|
|
116
136
|
|
|
117
137
|
### Library defaults
|
|
@@ -126,14 +146,14 @@ import '@constructor-io/constructorio-ui-autocomplete/styles.css';
|
|
|
126
146
|
|
|
127
147
|
> Note: the path and syntax in this example may change slightly depending on your module bundling strategy
|
|
128
148
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
|
133
153
|
- If you like, you can override the container's className like so:
|
|
134
|
-
`autocompleteClassName='custom-autocomplete-container'`
|
|
135
|
-
|
|
136
|
-
`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'`
|
|
137
157
|
|
|
138
158
|
## Troubleshooting
|
|
139
159
|
|
|
@@ -151,7 +171,6 @@ Relevant open issues:
|
|
|
151
171
|
|
|
152
172
|
[Issue 1810](https://github.com/import-js/eslint-plugin-import/issues/1810)
|
|
153
173
|
|
|
154
|
-
|
|
155
174
|
## Local Development
|
|
156
175
|
|
|
157
176
|
### Development scripts
|