Skip to content

Commit 57c0878

Browse files
mocca102MudaafiZSnake
authored
Ci 4255 os UI autocomplete add GitHub readme overview (#201)
* Add Library overview and installation and quick guide * update title * update styles * update styles * updates * updates * Edit gif height * remove yarn * remove yarn * update * Update README Co-authored-by: Ahmad Mudaafi' <[email protected]> Co-authored-by: Viktor Zavala <[email protected]> * Address comments --------- Co-authored-by: Ahmad Mudaafi' <[email protected]> Co-authored-by: Viktor Zavala <[email protected]>
1 parent 3591fbd commit 57c0878

File tree

1 file changed

+34
-214
lines changed

1 file changed

+34
-214
lines changed

README.md

+34-214
Original file line numberDiff line numberDiff line change
@@ -1,231 +1,51 @@
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>
25

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>
57

6-
## Introduction
8+
[**Read The Docs**](https://constructor-io.github.io/constructorio-ui-autocomplete/?path=/docs/autocomplete-component--docs)
9+
</div>
710

8-
This UI Library provides React components that manage fetching and rendering logic for [Constructor.io's autosuggest services](https://constructor.com/solutions/search).
11+
<hr />
12+
<div align="center">
913

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.
14+
![minzipped size](https://img.shields.io/bundlephobia/minzip/@constructor-io/constructorio-ui-autocomplete?color=green&style=flat-square)
15+
[![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)
16+
[![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)
1117

12-
![Autocomplete UI demonstration](assets/autocomplete-ui-demonstration.gif)
18+
<img src="assets/autocomplete-ui-demonstration.gif" alt="Autocomplete UI demonstration" height="500">
1319

14-
## Installation
20+
</div>
1521

16-
```bash
17-
npm i @constructor-io/constructorio-ui-autocomplete
18-
```
22+
## Features
1923

20-
## Usage
24+
- 🔌 Easy Integration – Quickly integrate with your app as a plug-and-play React component
25+
- ⚡ Lightweight & Fast – Tiny bundle size, optimized for speed
26+
- 🎨 Customizable UI – With minmal styles, and supports for custom markup
27+
- ⌨️ Keyboard Navigation – Fully supports accessible keyboard naviagation
28+
- ♿ Accessible (a11y) – Built-in ARIA support for screen readers
29+
- 🛡 Written in TypeScript with type safety
2130

22-
### Using the React Component
23-
24-
The `CioAutocomplete` component handles state management, data fetching, and rendering logic.
31+
## Installation & Quick Start
32+
Install the library
33+
```sh
34+
npm i @constructor-io/constructorio-ui-autocomplete
35+
```
2536

26-
```jsx
37+
Import and use the `CioAutocomplete` component
38+
```ts
2739
import { CioAutocomplete } from '@constructor-io/constructorio-ui-autocomplete';
40+
import '@constructor-io/constructorio-ui-autocomplete/styles.css';
2841

2942
function YourComponent() {
3043
return (
3144
<div>
32-
<CioAutocomplete apiKey="key_M57QS8SMPdLdLx4x" onSubmit={(e) => {console.log(e)}} />
33-
</div>
34-
);
35-
```
36-
37-
### Using React Hooks
38-
39-
The `useCioAutocomplete` hook leaves rendering logic up to you, while handling:
40-
41-
- state management
42-
- data fetching
43-
- keyboard navigation
44-
- mouse interactions
45-
- focus and submit event handling
46-
47-
An `apiKey` or `cioJsClient` must be passed to the `useCioAutocomplete` hook along with an `onSubmit` callback function. All other values are optional.
48-
49-
```jsx
50-
import { useCioAutocomplete } from '@constructor-io/constructorio-ui-autocomplete';
51-
52-
const args = {
53-
"apiKey": "key_M57QS8SMPdLdLx4x",
54-
"onSubmit": (submitEvent) => console.dir(submitEvent)
55-
};
56-
57-
function YourComponent() {
58-
const {
59-
isOpen,
60-
sections,
61-
getFormProps,
62-
getLabelProps,
63-
getInputProps,
64-
getMenuProps,
65-
getItemProps,
66-
autocompleteClassName,
67-
} = useCioAutocomplete(args);
68-
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>
45+
<CioAutocomplete
46+
apiKey="key_M57QS8SMPdLdLx4x"
47+
onSubmit={(e) => {console.log(e)}}
48+
/>
11349
</div>
11450
);
115-
}
116-
```
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-
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'`
157-
158-
## Troubleshooting
159-
160-
### Known Issues
161-
162-
**Older Javascript environments**
163-
164-
The library provides two different builds. CommonJS (cjs) and ECMAScript Modules (mjs)
165-
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.
168-
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
196-
```
197-
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).
213-
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
218-
219-
Dispatch the [Deploy Storybook](https://github.com/Constructor-io/constructorio-ui-autocomplete/actions/workflows/deploy-storybook.yml) workflow in GitHub Actions.
220-
221-
#### ℹ️ Note: This is already done automatically when publishing a new version.
222-
223-
224-
## Supporting Docs
225-
226-
- [Storybook 7 Introduction](https://storybook.js.org/docs/7/get-started/setup)
227-
- [Typescript Docs](https://www.typescriptlang.org/docs/)
228-
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)
51+
```

0 commit comments

Comments
 (0)