@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 CHANGED
@@ -1,5 +1,8 @@
1
1
  # Constructor.io Autocomplete UI Library
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/@constructor-io/constructorio-ui-autocomplete)](https://www.npmjs.com/package/@constructor-io/constructorio-ui-autocomplete)
4
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](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
  ![Autosuggest](assets/autosuggest-ui.gif)
10
13
 
11
- ## How to use this UI Library
12
- ## Install
14
+ ## Installation
13
15
 
14
16
  ```bash
15
17
  npm i @constructor-io/constructorio-ui-autocomplete
16
18
  ```
17
19
 
18
- There are two main methods for consuming this UI Library in a React project:
20
+ ## Usage
19
21
 
20
- ### Component based
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
- ### Hook based
37
+ ### Using React Hooks
36
38
 
37
39
  The `useCioAutocomplete` hook leaves rendering logic up to you, while handling:
38
- - state management
39
- - data fetching
40
- - keyboard navigation
41
- - mouse interactions
42
- - focus and submit event handling
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
- "apiKey": "key_Gep3oQOu5IMcNh9A",
51
- "onSubmit": (submitEvent) => console.dir(submitEvent)
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
- - These starter styles can be used as a foundation to build on top of, or just as a reference for you to replace completely.
130
- - To opt out of all default styling, do not import the `styles.css` stylesheet.
131
- - All starter styles in this library are scoped within the `.cio-autocomplete` css selector.
132
- - These starter styles are intended to be extended by layering in your own css rules
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
- - If you like, you can pass additional className(s) of your choosing like so:
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