Skip to content

Commit 29b7454

Browse files
docs(createAutocomplete): rewrite docs (#472)
* docs(createAutocomplete): rewrite docs * fix(createAutocomplete): fix links * fix: apply suggestions from code review Co-authored-by: François Chalifour <[email protected]> Co-authored-by: François Chalifour <[email protected]>
1 parent c59b144 commit 29b7454

File tree

3 files changed

+57
-33
lines changed

3 files changed

+57
-33
lines changed

packages/website/docs/createAutocomplete.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,42 @@
22
id: createAutocomplete
33
---
44

5-
This function returns the methods to create an autocomplete experience.
5+
Autocomplete Core exposes primitives to build an autocomplete experience.
66

7-
You're in charge of [creating your own autocomplete renderer](creating-a-renderer) with the returned API.
7+
The `createAutocomplete` function returns methods to help you create an autocomplete experience from scratch. This is fully headless: you're in charge of [creating your own autocomplete renderer](creating-a-renderer).
8+
9+
:::info
10+
11+
Building a custom renderer is an advanced pattern. You likely don't need it unless you've reached limitations with [`autocomplete-js`](autocomplete-js) and its templating capabilities.
12+
13+
:::
14+
15+
## Installation
16+
17+
First, you need to install the package.
18+
19+
```bash
20+
yarn add @algolia/autocomplete-core@alpha
21+
# or
22+
npm install @algolia/autocomplete-core@alpha
23+
```
24+
25+
Then import it in your project:
26+
27+
```js
28+
import { createAutocomplete } from '@algolia/autocomplete-core';
29+
```
30+
31+
If you don't use a package manager, you can use a standalone endpoint:
32+
33+
```html
34+
<script src="https://cdn.jsdelivr.net/npm/@algolia/autocomplete-core@alpha"></script>
35+
```
836

937
## Example
1038

39+
This example uses the package along with the [`algoliasearch`](https://www.npmjs.com/package/algoliasearch) API client and [`getAlgoliaHits`](getAlgoliaHits) function from the Autocomplete Algolia preset. It returns [a set of functions](#returns) to build an autocomplete experience.
40+
1141
```js
1242
import algoliasearch from 'algoliasearch/lite';
1343
import { createAutocomplete } from '@algolia/autocomplete-core';
@@ -44,20 +74,16 @@ const autocomplete = createAutocomplete({
4474
});
4575
```
4676

47-
## Import
48-
49-
```ts
50-
import { createAutocomplete } from '@algolia/autocomplete-core';
51-
```
52-
53-
## Options
77+
## Parameters
5478

5579
import CreateAutocompleteProps from './partials/createAutocomplete-props.md'
5680

5781
<CreateAutocompleteProps />
5882

5983
## Returns
6084

85+
The `createAutocomplete` function returns [prop getters](prop-getters), [state setters](state#setters), and a `refresh` method that updates the UI state.
86+
6187
```js
6288
const {
6389
getEnvironmentProps,
@@ -76,5 +102,3 @@ const {
76102
refresh,
77103
} = createAutocomplete(options);
78104
```
79-
80-
This function returns the [prop getters](prop-getters), the [state setters](state#setters) and the `refresh` method that updates the UI state.

packages/website/docs/partials/createAutocomplete-props.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ The [sources](/docs/sources) to get the collections from.
88

99
> `string` | defaults to `"autocomplete-0"` (incremented for each instance)
1010
11-
The autocomplete ID to create accessible attributes.
11+
An ID for the autocomplete to create accessible attributes.
1212

1313
### `onStateChange`
1414

1515
> `(params: { state: AutocompleteState<TItem> }) => void`
1616
17-
Function called when the internal state changes.
17+
The function called when the internal state changes.
1818

1919
### `placeholder`
2020

2121
> `string`
2222
23-
The text that appears in the search box input when there is no query.
23+
The placeholder text to show in the search input when there's no query.
2424

2525
### `autoFocus`
2626

2727
> `boolean` | defaults to `false`
2828
29-
Whether to focus the search box when the page is loaded.
29+
Whether to focus the search input or not when the page is loaded.
3030

3131
### `defaultActiveItemId`
3232

@@ -40,13 +40,13 @@ We recommend using `0` when the query typed aims at opening item links, without
4040

4141
> `boolean` | defaults to `false`
4242
43-
Whether to open the panel on focus when there's no query.
43+
Whether to open the panel on focus or not when there's no query.
4444

4545
### `stallThreshold`
4646

4747
> `number` | defaults to `300`
4848
49-
The number of milliseconds that must elapse before the autocomplete experience is stalled.
49+
How many milliseconds must elapse before considering the autocomplete experience [stalled](/docs/state#status).
5050

5151
### `initialState`
5252

@@ -58,44 +58,44 @@ The initial state to apply when autocomplete is created.
5858

5959
> `typeof window` | defaults to `window`
6060
61-
The environment from where your JavaScript is running.
61+
The environment in which your application is running.
6262

63-
Useful if you're using autocomplete in a different context than `window`.
63+
This is useful if you're using autocomplete in a different context than `window`.
6464

6565
### `navigator`
6666

6767
> `Navigator`
6868
69-
Navigator API to redirect the user when a link should be opened.
69+
An implementation of Autocomplete's Navigator API to redirect the user when opening a link.
7070

71-
Learn more on the [Navigator API](/docs/keyboard-navigation) documentation.
71+
Learn more on the [**Navigator API**](/docs/keyboard-navigation) documentation.
7272

7373
### `shouldPanelOpen`
7474

7575
> `(params: { state: AutocompleteState }) => boolean`
7676
77-
The function called to determine whether the panel should open.
77+
The function called to determine whether the panel should open or not.
7878

79-
By default, it opens when there are items in the state.
79+
By default, the panel opens when there are items in the state.
8080

8181
### `onSubmit`
8282

8383
> `(params: { state: AutocompleteState, event: Event, ...setters }) => void`
8484
85-
The function called when the Autocomplete form is submitted.
85+
The function called when submitting the Autocomplete form.
8686

8787
### `onReset`
8888

8989
> `(params: { state: AutocompleteState, event: Event, ...setters }) => void`
9090
91-
The function called when the Autocomplete form is reset.
91+
The function called when resetting the Autocomplete form.
9292

9393
### `debug`
9494

9595
> `boolean` | defaults to `false`
9696
97-
Whether to consider the experience in debug mode.
97+
A flag to activate the debug mode.
9898

99-
It is useful when developing because it doesn't close the panel when the blur event occurs. This option should only be used during development.
99+
This is useful while developing because it keeps the panel open even when the blur event occurs. **Make sure to disable it in production.**
100100

101-
See "[Debugging](/docs/debugging)" for more information.
101+
See [**Debugging**](/docs/debugging) for more information.

packages/website/sidebars.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ module.exports = {
2828
],
2929
'API Reference': [
3030
'api',
31-
{
32-
type: 'category',
33-
label: 'autocomplete-core',
34-
items: ['createAutocomplete'],
35-
},
3631
{
3732
type: 'category',
3833
label: 'autocomplete-js',
@@ -47,6 +42,11 @@ module.exports = {
4742
'reverseSnippetHit',
4843
],
4944
},
45+
{
46+
type: 'category',
47+
label: 'autocomplete-core',
48+
items: ['createAutocomplete'],
49+
},
5050
{
5151
type: 'category',
5252
label: 'autocomplete-plugin-recent-searches',

0 commit comments

Comments
 (0)