Skip to content

Commit 5ef0dd7

Browse files
authored
[CSL-2389] Adds option to consume library as a bundle (#63)
* Adds option to consume library as a bundle * Update export names * Readme edits
1 parent 0e7fdd2 commit 5ef0dd7

File tree

6 files changed

+807
-37
lines changed

6 files changed

+807
-37
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ out
9090
# Nuxt.js build / generate output
9191
.nuxt
9292
lib
93+
dist
9394

9495
# Gatsby files
9596
.cache/

README.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ This UI Library provides React components that manage fetching and rendering log
1111

1212
![Autosuggest](assets/autosuggest-ui.gif)
1313

14-
## How to use this UI Library
15-
## Install
14+
## Installation
1615

1716
```bash
1817
npm i @constructor-io/constructorio-ui-autocomplete
1918
```
2019

21-
There are two main methods for consuming this UI Library in a React project:
20+
## Usage
2221

23-
### Component based
22+
### Using the React Component
2423

2524
The `CioAutocomplete` component handles state management, data fetching, and rendering logic.
2625

@@ -35,23 +34,24 @@ function YourComponent() {
3534
);
3635
```
3736
38-
### Hook based
37+
### Using React Hooks
3938
4039
The `useCioAutocomplete` hook leaves rendering logic up to you, while handling:
41-
- state management
42-
- data fetching
43-
- keyboard navigation
44-
- mouse interactions
45-
- focus and submit event handling
40+
41+
- state management
42+
- data fetching
43+
- keyboard navigation
44+
- mouse interactions
45+
- focus and submit event handling
4646
4747
An `apiKey` or `cioJsClient` must be passed to the `useCioAutocomplete` hook along with an `onSubmit` callback function. All other values are optional.
4848
4949
```jsx
5050
import { useCioAutocomplete } from '@constructor-io/constructorio-ui-autocomplete';
5151

5252
const args = {
53-
"apiKey": "key_Gep3oQOu5IMcNh9A",
54-
"onSubmit": (submitEvent) => console.dir(submitEvent)
53+
apiKey: 'key_Gep3oQOu5IMcNh9A',
54+
onSubmit: (submitEvent) => console.dir(submitEvent),
5555
};
5656

5757
function YourComponent() {
@@ -63,7 +63,7 @@ function YourComponent() {
6363
getInputProps,
6464
getMenuProps,
6565
getItemProps,
66-
autocompleteClassName
66+
autocompleteClassName,
6767
} = useCioAutocomplete(args);
6868

6969
return (
@@ -115,6 +115,23 @@ function YourComponent() {
115115
}
116116
```
117117
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+
118135
## Custom Styling
119136
120137
### Library defaults
@@ -129,14 +146,14 @@ import '@constructor-io/constructorio-ui-autocomplete/styles.css';
129146
130147
> Note: the path and syntax in this example may change slightly depending on your module bundling strategy
131148
132-
- These starter styles can be used as a foundation to build on top of, or just as a reference for you to replace completely.
133-
- To opt out of all default styling, do not import the `styles.css` stylesheet.
134-
- All starter styles in this library are scoped within the `.cio-autocomplete` css selector.
135-
- 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
136153
- If you like, you can override the container's className like so:
137-
`autocompleteClassName='custom-autocomplete-container'`
138-
- If you like, you can pass additional className(s) of your choosing like so:
139-
`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'`
140157
141158
## Troubleshooting
142159
@@ -154,7 +171,6 @@ Relevant open issues:
154171

155172
[Issue 1810](https://github.com/import-js/eslint-plugin-import/issues/1810)
156173

157-
158174
## Local Development
159175

160176
### Development scripts

0 commit comments

Comments
 (0)