@@ -20,8 +20,8 @@ Then import it in your project:
20
20
21
21
``` js
22
22
import {
23
- NavigationCommandsLayout ,
24
- SearchByAlgoliaLayout ,
23
+ NavigationCommands ,
24
+ SearchByAlgolia ,
25
25
} from ' @algolia/autocomplete-layout-classic' ;
26
26
```
27
27
@@ -39,22 +39,26 @@ With default translations:
39
39
/** @jsx h */
40
40
import { autocomplete } from ' @algolia/autocomplete-js' ;
41
41
import {
42
- NavigationCommandsLayout ,
43
- SearchByAlgoliaLayout ,
42
+ NavigationCommands ,
43
+ SearchByAlgolia ,
44
44
} from ' @algolia/autocomplete-layout-classic' ;
45
45
import { h , render } from ' preact' ;
46
46
47
47
import ' @algolia/autocomplete-theme-classic' ;
48
48
49
49
autocomplete ({
50
50
// ...
51
- render({ sections , createElement , Fragment }, root ) {
51
+ components: {
52
+ NavigationCommands ,
53
+ SearchByAlgolia ,
54
+ },
55
+ render({ sections , Fragment , components }, root ) {
52
56
render (
53
57
<Fragment >
54
- <div className = " aa-PanelLayout" >{ sections } </div >
58
+ <div className = " aa-PanelLayout aa-Panel--scrollable " >{ sections } </div >
55
59
<footer className = " aa-PanelFooter" >
56
- { NavigationCommandsLayout ({ createElement , Fragment }) }
57
- { SearchByAlgoliaLayout ({ createElement , Fragment }) }
60
+ < components.NavigationCommands />
61
+ < components.SearchByAlgolia />
58
62
</footer >
59
63
</Fragment >,
60
64
root
@@ -69,36 +73,36 @@ With French translations:
69
73
/** @jsx h */
70
74
import { autocomplete } from ' @algolia/autocomplete-js' ;
71
75
import {
72
- NavigationCommandsLayout ,
73
- SearchByAlgoliaLayout ,
76
+ NavigationCommands ,
77
+ SearchByAlgolia ,
74
78
} from ' @algolia/autocomplete-layout-classic' ;
75
79
import { h , render } from ' preact' ;
76
80
77
81
import ' @algolia/autocomplete-theme-classic' ;
78
82
79
83
autocomplete ({
80
84
// ...
81
- render({ sections , createElement , Fragment }, root ) {
85
+ components: {
86
+ NavigationCommands ,
87
+ SearchByAlgolia ,
88
+ },
89
+ render({ sections , Fragment , components }, root ) {
82
90
render (
83
91
<Fragment >
84
- <div className = " aa-PanelLayout" >{ sections } </div >
92
+ <div className = " aa-PanelLayout aa-Panel--scrollable " >{ sections } </div >
85
93
<footer className = " aa-PanelFooter" >
86
- { NavigationCommandsLayout ({
87
- createElement ,
88
- Fragment ,
89
- translations: {
94
+ <components.NavigationCommands
95
+ translations = { {
90
96
toClose: ' pour fermer' ,
91
97
toNavigate: ' pour naviguer' ,
92
98
toSelect: ' pour sélectionner' ,
93
- },
94
- })}
95
- { SearchByAlgoliaLayout ({
96
- createElement ,
97
- Fragment ,
98
- translations: {
99
+ }}
100
+ />
101
+ <components.SearchByAlgolia
102
+ translations = { {
99
103
searchBy: ' Recherche par' ,
100
- },
101
- }) }
104
+ }}
105
+ />
102
106
</footer >
103
107
</Fragment >,
104
108
root
@@ -107,28 +111,54 @@ autocomplete({
107
111
});
108
112
```
109
113
110
- ## Layouts
114
+ With a custom renderer:
111
115
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' ;
113
123
114
- #### ` createElement `
124
+ import ' @algolia/autocomplete-theme-classic ' ;
115
125
116
- > ` (type: any, props: Record<string, any> | null, ...children: ComponentChildren[]) => VNode `
126
+ const renderer = { createElement , Fragment };
117
127
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
+ ```
119
149
120
- #### ` Fragment `
150
+ ## Reference
121
151
122
- The component to use to create fragments.
152
+ ### ` NavigationCommands `
123
153
124
154
#### ` translations `
125
155
126
- > ` NavigationCommandsLayoutTranslations ` | defaults to English strings
156
+ > ` NavigationCommandsTranslations ` | defaults to English strings
127
157
128
158
The translations to display.
129
159
130
160
``` ts
131
- type NavigationCommandsLayoutTranslations = {
161
+ type NavigationCommandsTranslations = {
132
162
toSelect: string ;
133
163
toNavigate: string ;
134
164
toClose: string ;
@@ -145,17 +175,7 @@ const translations = {
145
175
};
146
176
```
147
177
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 `
159
179
160
180
#### ` translations `
161
181
@@ -176,3 +196,15 @@ const translations = {
176
196
searchBy: ' Search by' ,
177
197
};
178
198
```
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