-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: François Chalifour <[email protected]> Co-authored-by: Sarah Dayan <[email protected]> Co-authored-by: Maria Elisabeth Schreiber <[email protected]>
- Loading branch information
Showing
30 changed files
with
1,780 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
--- | ||
id: api | ||
title: API | ||
title: Introduction | ||
--- | ||
|
||
import Draft from './partials/draft.md' | ||
|
||
<Draft /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
id: basic-options | ||
title: Basic configuration options | ||
--- | ||
|
||
Everything you need to create fantastic autocomplete experiences. | ||
|
||
We've built Autocomplete to give you unlimited flexibility while freeing you from having to think about things like keyboard navigation, accessibility, or UI state. **The library offers a wide variety of APIs to let you fully customize the behavior and rendering of your autocomplete.** | ||
|
||
Yet, only two parameters are required to create an autocomplete: | ||
- The **container** you want your autocomplete to go in. | ||
- The **sources** from which to get the items to display (see more in [**Sources**](sources)). | ||
|
||
```js title="JavaScript" | ||
import { autocomplete } from '@algolia/autocomplete-js'; | ||
|
||
autocomplete({ | ||
container: '#autocomplete', | ||
getSources() { | ||
return [ | ||
{ | ||
getItems({ query }) { | ||
return [ | ||
{ label: 'Twitter', url: 'https://twitter.com' }, | ||
{ label: 'GitHub', url: 'https://github.com' }, | ||
].filter(({ label }) => | ||
label.toLowerCase().includes(query.toLowerCase()) | ||
); | ||
}, | ||
getItemUrl({ item }) { | ||
return item.url; | ||
}, | ||
templates: { | ||
item({ item }) { | ||
return item.label; | ||
}, | ||
}, | ||
}, | ||
]; | ||
}, | ||
}); | ||
``` | ||
|
||
The `container` options refers to where to inject the autocomplete in your HTML. It can be a [CSS selector](https://developer.mozilla.org/docs/Web/CSS/CSS_Selectors) or an [Element](https://developer.mozilla.org/docs/Web/API/HTMLElement). Make sure to provide a container (e.g., a `div`), not an `input`. Autocomplete generates a fully accessible search box for you. | ||
|
||
```html title="HTML" | ||
<div id="autocomplete"></div> | ||
``` | ||
|
||
This is all you need to build a [fully functional, accessible, keyboard-navigable autocomplete](https://codesandbox.io/s/vigilant-dew-g2ezl). | ||
|
||
Now, this is a great start, but **you can go much further**. Here are some of the options you'll probably want to use next: | ||
- Use [`placeholder`](autocomplete-js#placeholder) to define the text that appears in the input before the user types anything. | ||
- Use [`autoFocus`](autocomplete-js#autofocus) to focus on the search box on page load, and [`openOnFocus`](autocomplete-js#openonfocus) to display items as soon as a user selects the autocomplete, even without typing. | ||
- Use the [`onStateChange`](autocomplete-js#onstatechange) lifecycle hook to execute code whenever the state changes. | ||
- Use [`debug: true`](autocomplete-js#debug) to keep the autocomplete panel open even when the blur event occurs (see [**Debugging**](debugging)). | ||
|
||
For a full list of all available parameters, check out the [API reference](autocomplete-js). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--- | ||
id: createAlgoliaInsightsPlugin | ||
--- | ||
|
||
## Example | ||
|
||
```ts | ||
import algoliasearch from 'algoliasearch/lite'; | ||
import { autocomplete } from '@algolia/autocomplete-js'; | ||
import { createAlgoliaInsightsPlugin } from '@algolia/autocomplete-plugin-algolia-insights'; | ||
import insightsClient from 'search-insights'; | ||
|
||
const appId = 'latency'; | ||
const apiKey = '6be0576ff61c053d5f9a3225e2a90f76'; | ||
const searchClient = algoliasearch(appId, apiKey); | ||
insightsClient('init', { appId, apiKey }); | ||
|
||
const algoliaInsightsPlugin = createAlgoliaInsightsPlugin({ insightsClient }); | ||
|
||
autocomplete({ | ||
container: '#autocomplete', | ||
plugins: [algoliaInsightsPlugin], | ||
}); | ||
``` | ||
|
||
## Import | ||
|
||
```ts | ||
import { createAlgoliaInsightsPlugin } from '@algolia/autocomplete-plugin-algolia-insights'; | ||
``` | ||
|
||
## Params | ||
|
||
### `insightsClient` | ||
|
||
> `InsightsClient` | required | ||
The initialized Search Insights client. | ||
|
||
### `onItemsChange` | ||
|
||
> `(params: OnItemsChangeParams) => void` | ||
Hook to send an Insights event when the items change. | ||
|
||
This hook is debounced every 400ms to better reflect when items are acknowledged by the user. | ||
|
||
```ts | ||
type OnItemsChangeParams = { | ||
insights: InsightsApi; | ||
insightsEvents: ViewedObjectIDsParams[]; | ||
state: AutocompleteState<any>; | ||
}; | ||
``` | ||
|
||
### `onSelect` | ||
|
||
> `(params: OnSelectParams) => void` | ||
Hook to send an Insights event when an item is selected. | ||
|
||
```ts | ||
type OnSelectParams = { | ||
insights: InsightsApi; | ||
insightsEvents: ClickedObjectIDsAfterSearchParams[]; | ||
item: AlgoliaInsightsHit; | ||
state: AutocompleteState<any>; | ||
event: any; | ||
}; | ||
``` | ||
|
||
### `onActive` | ||
|
||
> `(params: OnActiveParams) => void` | ||
Hook to send an Insights event when an item is active. | ||
|
||
```ts | ||
type OnActiveParams = { | ||
insights: InsightsApi; | ||
insightsEvents: ClickedObjectIDsAfterSearchParams[]; | ||
item: AlgoliaInsightsHit; | ||
state: AutocompleteState<any>; | ||
event: any; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
id: creating-multi-source-autocompletes | ||
title: Creating multi-source autocompletes | ||
--- |
Oops, something went wrong.