Skip to content

Commit e4e43ca

Browse files
docs: update layout docs
1 parent f1c4e5b commit e4e43ca

File tree

2 files changed

+77
-45
lines changed

2 files changed

+77
-45
lines changed

packages/website/docs/autocomplete-js.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ autocomplete({
303303

304304
> `(type: any, props: Record<string, any> | null, ...children: ComponentChildren[]) => VNode` | defaults to `preact.createElement`
305305
306-
The function that create virtual nodes.
306+
The function to create virtual nodes.
307307

308308
It uses [Preact 10](https://preactjs.com/guide/v10/whats-new/)'s `createElement` by default, but you can provide your own implementation.
309309

packages/website/docs/autocomplete-layout-classic.md

Lines changed: 76 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Then import it in your project:
2020

2121
```js
2222
import {
23-
NavigationCommandsLayout,
24-
SearchByAlgoliaLayout,
23+
NavigationCommands,
24+
SearchByAlgolia,
2525
} from '@algolia/autocomplete-layout-classic';
2626
```
2727

@@ -39,22 +39,26 @@ With default translations:
3939
/** @jsx h */
4040
import { autocomplete } from '@algolia/autocomplete-js';
4141
import {
42-
NavigationCommandsLayout,
43-
SearchByAlgoliaLayout,
42+
NavigationCommands,
43+
SearchByAlgolia,
4444
} from '@algolia/autocomplete-layout-classic';
4545
import { h, render } from 'preact';
4646

4747
import '@algolia/autocomplete-theme-classic';
4848

4949
autocomplete({
5050
// ...
51-
render({ sections, createElement, Fragment }, root) {
51+
components: {
52+
NavigationCommands,
53+
SearchByAlgolia,
54+
},
55+
render({ sections, Fragment, components }, root) {
5256
render(
5357
<Fragment>
54-
<div className="aa-PanelLayout">{sections}</div>
58+
<div className="aa-PanelLayout aa-Panel--scrollable">{sections}</div>
5559
<footer className="aa-PanelFooter">
56-
{NavigationCommandsLayout({ createElement, Fragment })}
57-
{SearchByAlgoliaLayout({ createElement, Fragment })}
60+
<components.NavigationCommands />
61+
<components.SearchByAlgolia />
5862
</footer>
5963
</Fragment>,
6064
root
@@ -69,36 +73,36 @@ With French translations:
6973
/** @jsx h */
7074
import { autocomplete } from '@algolia/autocomplete-js';
7175
import {
72-
NavigationCommandsLayout,
73-
SearchByAlgoliaLayout,
76+
NavigationCommands,
77+
SearchByAlgolia,
7478
} from '@algolia/autocomplete-layout-classic';
7579
import { h, render } from 'preact';
7680

7781
import '@algolia/autocomplete-theme-classic';
7882

7983
autocomplete({
8084
// ...
81-
render({ sections, createElement, Fragment }, root) {
85+
components: {
86+
NavigationCommands,
87+
SearchByAlgolia,
88+
},
89+
render({ sections, Fragment, components }, root) {
8290
render(
8391
<Fragment>
84-
<div className="aa-PanelLayout">{sections}</div>
92+
<div className="aa-PanelLayout aa-Panel--scrollable">{sections}</div>
8593
<footer className="aa-PanelFooter">
86-
{NavigationCommandsLayout({
87-
createElement,
88-
Fragment,
89-
translations: {
94+
<components.NavigationCommands
95+
translations={{
9096
toClose: 'pour fermer',
9197
toNavigate: 'pour naviguer',
9298
toSelect: 'pour sélectionner',
93-
},
94-
})}
95-
{SearchByAlgoliaLayout({
96-
createElement,
97-
Fragment,
98-
translations: {
99+
}}
100+
/>
101+
<components.SearchByAlgolia
102+
translations={{
99103
searchBy: 'Recherche par',
100-
},
101-
})}
104+
}}
105+
/>
102106
</footer>
103107
</Fragment>,
104108
root
@@ -107,28 +111,54 @@ autocomplete({
107111
});
108112
```
109113

110-
## Layouts
114+
With a custom renderer:
111115

112-
### `NavigationCommandsLayout`
116+
```tsx
117+
import { autocomplete } from '@algolia/autocomplete-js';
118+
import {
119+
createNavigationCommandsComponent,
120+
createSearchByAlgoliaComponent,
121+
} from '@algolia/autocomplete-layout-classic';
122+
import React, { createElement, Fragment } from 'react';
113123

114-
#### `createElement`
124+
import '@algolia/autocomplete-theme-classic';
115125

116-
> `(type: any, props: Record<string, any> | null, ...children: ComponentChildren[]) => VNode`
126+
const renderer = { createElement, Fragment };
117127

118-
The function that create virtual nodes.
128+
autocomplete({
129+
// ...
130+
renderer,
131+
components: {
132+
NavigationCommands: createNavigationCommandsComponent(renderer),
133+
SearchByAlgolia: createSearchByAlgoliaComponent(renderer),
134+
},
135+
render({ sections, Fragment, components }, root) {
136+
render(
137+
<Fragment>
138+
<div className="aa-PanelLayout aa-Panel--scrollable">{sections}</div>
139+
<footer className="aa-PanelFooter">
140+
<components.NavigationCommands />
141+
<components.SearchByAlgolia />
142+
</footer>
143+
</Fragment>,
144+
root
145+
);
146+
},
147+
});
148+
```
119149

120-
#### `Fragment`
150+
## Reference
121151

122-
The component to use to create fragments.
152+
### `NavigationCommands`
123153

124154
#### `translations`
125155

126-
> `NavigationCommandsLayoutTranslations` | defaults to English strings
156+
> `NavigationCommandsTranslations` | defaults to English strings
127157
128158
The translations to display.
129159

130160
```ts
131-
type NavigationCommandsLayoutTranslations = {
161+
type NavigationCommandsTranslations = {
132162
toSelect: string;
133163
toNavigate: string;
134164
toClose: string;
@@ -145,17 +175,7 @@ const translations = {
145175
};
146176
```
147177

148-
### `SearchByAlgoliaLayout`
149-
150-
#### `createElement`
151-
152-
> `(type: any, props: Record<string, any> | null, ...children: ComponentChildren[]) => VNode`
153-
154-
The function that create virtual nodes.
155-
156-
#### `Fragment`
157-
158-
The component to use to create fragments.
178+
### `SearchByAlgolia`
159179

160180
#### `translations`
161181

@@ -176,3 +196,15 @@ const translations = {
176196
searchBy: 'Search by',
177197
};
178198
```
199+
200+
### `createNavigationCommandsComponent`
201+
202+
> `(renderer: AutocompleteRenderer) => JSX.Element`
203+
204+
The function accepts a [renderer](/docs/autocomplete-js/#renderer) and returns the [`NavigationCommands`](#navigationcommands) component. It's useful when using a framework like [React](/docs/using-react) or [Vue](/docs/using-vue).
205+
206+
### `createSearchByAlgoliaComponent`
207+
208+
> `(renderer: AutocompleteRenderer) => JSX.Element`
209+
210+
The function accepts a [renderer](/docs/autocomplete-js/#renderer) and returns the [`SearchByAlgolia`](#searchbyalgolia) component. It's useful when using a framework like [React](/docs/using-react) or [Vue](/docs/using-vue).

0 commit comments

Comments
 (0)