@constructor-io/constructorio-ui-autocomplete 1.25.2 → 1.25.4

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,231 +1,275 @@
1
- # Constructor.io Autocomplete UI Library
1
+ <div align="center">
2
+ <img src="https://constructor.com/hubfs/constructor-favicon-2024-1.svg" alt="constructor logo" title="constructor logo" width="220px" height="220px">
3
+
4
+ <h1>Autocomplete UI</h1>
2
5
 
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)
6
+ <p align="center" style="font-size: 1.2rem;">Lightweight, minimalistic, and fully customizable autocomplete component for fast, accessible, and flexible search experiences with <a href='https://constructor.com/solutions/search'>Constructor.io's autosuggest services</a>. 🚀</p>
5
7
 
6
- ## Introduction
8
+ [**Read The Docs**](https://constructor-io.github.io/constructorio-ui-autocomplete/?path=/docs/autocomplete-component--docs)
7
9
 
8
- This UI Library provides React components that manage fetching and rendering logic for [Constructor.io's autosuggest services](https://constructor.com/solutions/search).
10
+ </div>
9
11
 
10
- [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.
12
+ <hr />
13
+ <div align="center">
11
14
 
12
- ![Autocomplete UI demonstration](assets/autocomplete-ui-demonstration.gif)
15
+ ![minzipped size](https://img.shields.io/bundlephobia/minzip/@constructor-io/constructorio-ui-autocomplete?color=green&style=flat-square)
16
+ [![NPM Version](https://img.shields.io/npm/v/@constructor-io/constructorio-ui-autocomplete?style=flat-square)](https://www.npmjs.com/package/@constructor-io/constructorio-ui-autocomplete)
17
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/Constructor-io/constructorio-ui-autocomplete/blob/main/LICENSE)
13
18
 
14
- ## Installation
19
+ <img src="assets/autocomplete-ui-demonstration.gif" alt="Autocomplete UI demonstration" height="500">
15
20
 
16
- ```bash
17
- npm i @constructor-io/constructorio-ui-autocomplete
18
- ```
21
+ </div>
22
+
23
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
24
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
25
+ ## 📌 Table of Contents
26
+
27
+ - [Features](#features)
28
+ - [React](#react)
29
+ - [⚡ Installation & Quick Start](#-installation--quick-start)
30
+ - [Shopify](#shopify)
31
+ - [⚡ Installation & Quick Start](#-installation--quick-start-1)
32
+ - [Bundle (Vanilla JS)](#bundle-vanilla-js)
33
+ - [⚡ Installation & Quick Start](#-installation--quick-start-2)
34
+ - [💡 Code Examples](#-code-examples)
35
+ - [🎨 Customization](#-customization)
36
+ - [🚀 Advanced Features](#-advanced-features)
37
+ - [🛠 Troubleshooting](#-troubleshooting)
38
+ - [📖 API Reference](#-api-reference)
39
+ - [🔗 Complementary Resources](#-complementary-resources)
40
+ - [🤝 Contributing](#-contributing)
41
+ - [📜 License](#-license)
42
+
43
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
44
+
45
+ ## Features
46
+
47
+ - 🔌 Easy Integration – Quickly integrate with your app as a plug-and-play React component
48
+ - ⚡ Lightweight & Fast – Tiny bundle size, optimized for speed
49
+ - 🎨 Customizable UI – With minmal styles, and supports for custom markup
50
+ - âŒ¨ī¸ Keyboard Navigation – Fully supports accessible keyboard naviagation
51
+ - â™ŋ Accessible (a11y) – Built-in ARIA support for screen readers
52
+ - 🛡 Written in TypeScript with type safety
19
53
 
20
- ## Usage
21
54
 
22
- ### Using the React Component
55
+ ## React
23
56
 
24
- The `CioAutocomplete` component handles state management, data fetching, and rendering logic.
57
+ ### ⚡ Installation & Quick Start
58
+ Install the library
25
59
 
26
- ```jsx
60
+ ```sh
61
+ npm i @constructor-io/constructorio-ui-autocomplete
62
+ ```
63
+
64
+ Import and use the `CioAutocomplete` component
65
+
66
+ ```tsx
27
67
  import { CioAutocomplete } from '@constructor-io/constructorio-ui-autocomplete';
68
+ import '@constructor-io/constructorio-ui-autocomplete/styles.css';
28
69
 
29
70
  function YourComponent() {
30
71
  return (
31
72
  <div>
32
- <CioAutocomplete apiKey="key_M57QS8SMPdLdLx4x" onSubmit={(e) => {console.log(e)}} />
73
+ <CioAutocomplete
74
+ apiKey="key_M57QS8SMPdLdLx4x"
75
+ onSubmit={(e) => {console.log(e)}}
33
76
  </div>
34
77
  );
35
78
  ```
36
79
 
37
- ### Using React Hooks
80
+ ## Shopify
38
81
 
39
- The `useCioAutocomplete` hook leaves rendering logic up to you, while handling:
82
+ ### ⚡ Installation & Quick Start
40
83
 
41
- - state management
42
- - data fetching
43
- - keyboard navigation
44
- - mouse interactions
45
- - focus and submit event handling
84
+ The Constructor autocomplete component is available as part of the [Constructor.io Shopify App](https://apps.shopify.com/constructor-connect)
46
85
 
47
- An `apiKey` or `cioJsClient` must be passed to the `useCioAutocomplete` hook along with an `onSubmit` callback function. All other values are optional.
86
+ After installing the app, you can use the Constructor autocomplete component by clicking 'Add Section' in your theme editor and adding the Constructor autocomplete liquid component
48
87
 
49
- ```jsx
50
- import { useCioAutocomplete } from '@constructor-io/constructorio-ui-autocomplete';
88
+ ![installation gif](./assets/autocomplete-ui-liquid-shopify-demo.gif)
51
89
 
52
- const args = {
53
- "apiKey": "key_M57QS8SMPdLdLx4x",
54
- "onSubmit": (submitEvent) => console.dir(submitEvent)
55
- };
90
+ For more in depth instructions, check out the [Shopify documentation](https://docs.constructor.com/docs/integrating-with-constructor-platform-connectors-frontend-connectors-shopify-ui).
56
91
 
57
- function YourComponent() {
58
- const {
59
- isOpen,
60
- sections,
61
- getFormProps,
62
- getLabelProps,
63
- getInputProps,
64
- getMenuProps,
65
- getItemProps,
66
- autocompleteClassName,
67
- } = useCioAutocomplete(args);
92
+ ## Bundle (Vanilla JS)
93
+ 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. In addition to Autocomplete component props, this function also accepts a selector and includeCSS.
68
94
 
69
- return (
70
- <div className={autocompleteClassName}>
71
- <form {...getFormProps()}>
72
- <label {...getLabelProps()} hidden>
73
- Search
74
- </label>
75
- <input {...getInputProps()} />
76
- </form>
77
- <div {...getMenuProps()}>
78
- {isOpen && (
79
- <>
80
- {sections?.map((section) => (
81
- <div key={section.indexSectionName} className={section.indexSectionName}>
82
- <div className='cio-section'>
83
- <div className='cio-section-name'>
84
- {section?.displayName || section.indexSectionName}
85
- </div>
86
- <div className='cio-items'>
87
- {section?.data?.map((item) => (
88
- <div {...getItemProps(item)} key={item?.id}>
89
- <div>
90
- {item.data?.image_url && (
91
- <img
92
- width='100%'
93
- src={item.data?.image_url}
94
- alt=''
95
- data-testid='cio-img'
96
- />
97
- )}
98
- {item.groupName ? (
99
- <p className='cio-term-in-group'>in {item.groupName}</p>
100
- ) : (
101
- <p>{item.value}</p>
102
- )}
103
- </div>
104
- </div>
105
- ))}
106
- </div>
107
- </div>
108
- </div>
109
- ))}
110
- </>
111
- )}
112
- </div>
113
- </div>
114
- );
115
- }
116
- ```
95
+ ### ⚡ Installation & Quick Start
117
96
 
118
- ### Using the Javascript Bundle
97
+ Install the library
119
98
 
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`.
99
+ ```sh
100
+ npm i @constructor-io/constructorio-ui-autocomplete
101
+ ```
122
102
 
123
- ```js
103
+ Import and use the `CioAutocomplete` component
104
+ ```javascript
124
105
  import CioAutocomplete from '@constructor-io/constructorio-ui-autocomplete/constructorio-ui-autocomplete-bundled';
125
106
 
126
107
  CioAutocomplete({
127
108
  selector: '#autocomplete-container',
128
109
  includeCSS: true, // Include the default CSS styles. Defaults to true.
129
- apiKey: 'key_Gep3oQOu5IMcNh9A',
110
+ apiKey: 'key_M57QS8SMPdLdLx4x',
130
111
  onSubmit: (submitEvent) => console.dir(submitEvent),
131
112
  // ... additional arguments
132
113
  });
114
+ </script>
133
115
  ```
134
116
 
135
- ## Custom Styling
136
-
137
- ### Library defaults
138
-
139
- By default, importing react components or hooks from this library does not pull any css into your project.
140
-
141
- If you wish to use some starter styles from this library, add an import statement similar to the example import statement below:
142
-
143
- ```js
144
- import '@constructor-io/constructorio-ui-autocomplete/styles.css';
145
- ```
146
-
147
- > Note: the path and syntax in this example may change slightly depending on your module bundling strategy
148
-
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
153
- - If you like, you can override the container's className like so:
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'`
117
+ ## 💡 Code Examples
157
118
 
158
- ## Troubleshooting
119
+ Ready-to-use, copy-paste examples with explanations.
159
120
 
160
- ### Known Issues
121
+ - [Full Featured example](https://constructor-io.github.io/constructorio-ui-autocomplete/?path=/docs/autocomplete-component--docs#full-featured-and-styled-example)
122
+ - [Render Search Suggestions](https://constructor-io.github.io/constructorio-ui-autocomplete/?path=/docs/autocomplete-component-sections--docs#render-search-suggestions)
123
+ - [Render Product Suggestions](https://constructor-io.github.io/constructorio-ui-autocomplete/?path=/docs/autocomplete-component-sections--docs#render-suggested-products)
161
124
 
162
- **Older Javascript environments**
125
+ 🔹 For more examples check the [full examples](https://constructor-io.github.io/constructorio-ui-autocomplete/?path=/docs/autocomplete-component--docs)
163
126
 
164
- The library provides two different builds. CommonJS (cjs) and ECMAScript Modules (mjs)
127
+ ## 🎨 Customization
165
128
 
166
- For ECMAScript Modules (mjs) build. The Javascript version is ESNext which might not be supported by your environment.
167
- If that's the case and your environment is using an older Javascript version like ES6 (ES2015), you might get this error.
129
+ CSS styles are not imported by default. Add this to your code to import basic styles
168
130
 
169
- `Module parse failed: Unexpected token (15:32)
170
- You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file`
171
-
172
- To solve this you can import the CommonJS (cjs) build which supports ES6 (ES2015) syntax:
173
-
174
- `import CioAutocomplete from '@constructor-io/constructorio-ui-autocomplete/cjs'`
175
-
176
- **ESLint**
177
-
178
- There is a known issue with ESLint where it fails to resolve the paths exposed in the `exports` statement of NPM packages. If you are receiving the following error, you can safely disable ESLint using `// eslint-disable-line` for that line.
179
-
180
- `Unable to resolve path to module '@constructor-io/constructorio-ui-autocomplete/styles.css'`
181
-
182
- Relevant open issues:
183
-
184
- [Issue 1868](https://github.com/import-js/eslint-plugin-import/issues/1868)
185
-
186
- [Issue 1810](https://github.com/import-js/eslint-plugin-import/issues/1810)
187
-
188
- ## Local Development
189
-
190
- ### Development scripts
191
-
192
- ```bash
193
- npm ci # install dependencies for local dev
194
- npm run dev # start a local dev server for Storybook
195
- npm run lint # run linter
131
+ ```tsx
132
+ import '@constructor-io/constructorio-ui-autocomplete/styles.css';
196
133
  ```
197
134
 
198
- ## Publishing new versions
199
-
200
- Dispatch the [Publish](https://github.com/Constructor-io/constructorio-ui-autocomplete/actions/workflows/publish.yml) workflow in GitHub Actions. You're required to provide two arguments:
201
- - **Version Strategy**: `major`, `minor`, or `patch`.
202
- - **Title**: A title for the release.
203
-
204
- This workflow will automatically:
205
- 1. Bump the library version using the provided strategy.
206
- 2. Create a new git tag.
207
- 3. Create a new GitHub release.
208
- 4. Compile the library.
209
- 5. Publish the new version to NPM.
210
- 6. Publish the new version to our public CDN.
211
- 7. Deploy the Storybook docs to GitHub Pages.
212
- 8. Report the progress on the [relevant Slack channel](https://constructor.slack.com/archives/C061D3CFVR9).
135
+ All styles are scoped under .cio-autocomplete. You can extend them by targeting that selector.
213
136
 
214
- #### â„šī¸ Note: Please don't manually increase the package.json version or create new git tags.
215
- The library version is tracked by releases and git tags. We intentionally keep the package.json version at `0.0.0` to avoid pushing changes to the `main` branch. This solves many security concerns by avoiding the need for branch-protection rule exceptions.
216
-
217
- ## New Storybook Version
137
+ ```css
138
+ /* Custom Style Sheet */
139
+ .cio-autocomplete .cio-submit-btn {
140
+ border-radius: 10px;
141
+ border: 1px solid red;
142
+ }
143
+ ```
218
144
 
219
- Dispatch the [Deploy Storybook](https://github.com/Constructor-io/constructorio-ui-autocomplete/actions/workflows/deploy-storybook.yml) workflow in GitHub Actions.
145
+ If you'd like to override or extend the base `className`, you can do so with the `autocompleteClassName` argument
220
146
 
221
- #### â„šī¸ Note: This is already done automatically when publishing a new version.
147
+ ```tsx
148
+ import { CioAutocomplete } from '@constructor-io/constructorio-ui-autocomplete';
149
+ import '@constructor-io/constructorio-ui-autocomplete/styles.css';
222
150
 
151
+ function YourComponent() {
152
+ return (
153
+ <div>
154
+ <CioAutocomplete
155
+ apiKey="key_M57QS8SMPdLdLx4x"
156
+ onSubmit={(e) => { console.log(e)}}
157
+ autocompleteClassName="cio-autocomplete custom-autocomplete-container"
158
+ />
159
+ </div>
160
+ );
161
+ ```
223
162
 
224
- ## Supporting Docs
163
+ Then you can modify styles like so
225
164
 
226
- - [Storybook 7 Introduction](https://storybook.js.org/docs/7/get-started/setup)
227
- - [Typescript Docs](https://www.typescriptlang.org/docs/)
165
+ ```css
166
+ /* Custom Style Sheet */
167
+ .cio-autocomplete.custom-autocomplete-styles .cio-input {
168
+ font-weight: bold;
169
+ }
170
+ ```
228
171
 
229
- ## Usage examples
230
- - [Javascript](https://codesandbox.io/s/autocomplete-ui-integration-plain-y9zjl7)
231
- - [Remix App](https://codesandbox.io/p/sandbox/remix-example-for-constructorio-ui-autocomplete-kk5vh5?file=%2Fapp%2Froutes%2Findex.tsx)
172
+ ## 🚀 Advanced Features
173
+
174
+ - [Terms With Group Suggestions](https://constructor-io.github.io/constructorio-ui-autocomplete/?path=/docs/autocomplete-component-advanced-parameters--docs#terms-with-group-suggestions)
175
+ - [Filtered Suggestions](https://constructor-io.github.io/constructorio-ui-autocomplete/?path=/docs/autocomplete-component-advanced-parameters--docs#filtered-suggestions)
176
+ - [Terms With Images And Counts](https://constructor-io.github.io/constructorio-ui-autocomplete/?path=/docs/autocomplete-component-advanced-parameters--docs#terms-with-images-and-counts)
177
+
178
+ 🔹 For more advanced use cases check the [full documentation](https://constructor-io.github.io/constructorio-ui-autocomplete/?path=/docs/autocomplete-component-advanced-parameters--docs)
179
+
180
+ ## 🛠 Troubleshooting
181
+
182
+ Common issues and solutions.
183
+
184
+ <table>
185
+ <thead>
186
+ <tr>
187
+ <th>Problem</th>
188
+ <th>Description</th>
189
+ <th>Solution</th>
190
+ </tr>
191
+ </thead>
192
+ <tbody>
193
+ <tr>
194
+ <td>Older JavaScript environments</td>
195
+ <td>
196
+ The library provides two different builds. CommonJS (cjs) and ECMAScript Modules (mjs)
197
+ <br>
198
+ <br>
199
+ For ECMAScript Modules (mjs) build, the JavaScript version is ESNext which might not be supported by your environment. If that's the case and your environment is using an older Javascript version like ES6 (ES2015), you might get this error.
200
+ <br>
201
+ <br>
202
+ <code>Module parse failed: Unexpected token (15:32) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file</code>
203
+ </td>
204
+ <td>
205
+ To solve this you can import the CommonJS (cjs) build which supports ES6 (ES2015) syntax:
206
+ <br>
207
+ <br>
208
+ <code>import CioAutocomplete from '@constructor-io/constructorio-ui-autocomplete/cjs'</code>
209
+ </td>
210
+ </tr>
211
+ <tr>
212
+ <td>ESLint</td>
213
+ <td>
214
+ There is a known issue with ESLint where it fails to resolve the paths exposed in the exports statement of NPM packages.
215
+ <br>
216
+ <br>
217
+ For ECMAScript Modules (mjs) build. The Javascript version is ESNext which might not be supported by your environment. If that's the case and your environment is using an older Javascript version like ES6 (ES2015), you might get this error.
218
+ <br>
219
+ <br>
220
+ <code>Unable to resolve path to module '@constructor-io/constructorio-ui-autocomplete/styles.css'</code>
221
+ <br>
222
+ <br>
223
+ Relevant open issues:
224
+ <ul>
225
+ <li><a href='https://github.com/import-js/eslint-plugin-import/issues/1868'>Issue 1868</a>
226
+ <li><a href='https://github.com/import-js/eslint-plugin-import/issues/1810'>Issue 1810</a>
227
+ </td>
228
+ <td>
229
+ If you are receiving the following error, you can safely disable ESLint using <code>// eslint-disable-line</code> for that line.
230
+ </td>
231
+ </tr>
232
+ <tr>
233
+ <td>Peer Dependencies</td>
234
+ <td>
235
+ The library requires a couple of peer dependencies to be installed, so ensure they're installed if not already.
236
+ <br />
237
+ <br />
238
+ <ol>
239
+ <li><a href="https://github.com/Constructor-io/constructorio-client-javascript">constructorio-client-javascript</a></li>
240
+ <li><a href="https://github.com/downshift-js/downshift">downshift</a></li>
241
+ </ol>
242
+ </td>
243
+ <td>
244
+ Run <code>npm i downshift @constructor-io/constructorio-client-javascript</code>
245
+ </td>
246
+ </tr>
247
+ </tbody>
248
+ </table>
249
+
250
+ đŸ’Ŧ Need help? Join our [GitHub Discussions](https://github.com/Constructor-io/constructorio-ui-autocomplete/discussions)
251
+
252
+ ## 📖 API Reference
253
+
254
+ <!-- TODO: reference the API docs from storybook -->
255
+ - Full API docs: Click here
256
+
257
+ ## 🔗 Complementary Resources
258
+
259
+ - 📖 Full Documentation: [Storybook](https://constructor-io.github.io/constructorio-ui-autocomplete/)
260
+ - đŸ“Ļ JS Client: [SDK Documentation](https://constructor-io.github.io/constructorio-client-javascript/module-autocomplete.html#~getAutocompleteResults)
261
+ - 🛒 Shopify App: [App Store Link](https://apps.shopify.com/constructor-connect)
262
+ - 🌐 Constructor's REST API: [Autocomplete](https://docs.constructor.com/reference/v1-autocomplete-get-autocomplete-results)
263
+
264
+ ## 🤝 Contributing
265
+
266
+ 1. Fork the repo & create a new branch.
267
+ 2. Run `npm install` to install dependencies.
268
+ 3. After making the desired changes, run `npm run tests && npm run lint` locally.
269
+ 4. Submit a PR for review.
270
+
271
+ ## 📜 License
272
+
273
+ [MIT License](./LICENSE)
274
+
275
+ Copyright (c) 2022-present Constructor.io Corporation