Skip to content

Commit 0e22525

Browse files
authored
Merge pull request #9406 from marmelab/doc-search-with-result-component
[Doc] introduce SearchWithResult component ducumentation
2 parents 4b0d058 + c913389 commit 0e22525

File tree

3 files changed

+508
-10
lines changed

3 files changed

+508
-10
lines changed

docs/Search.md

+75-10
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,84 @@ export const App = () => (
159159

160160
## Props
161161

162+
The `<Search>` component accepts the following props:
162163

163-
| Prop | Required | Type | Default | Description |
164-
| ----------- | -------- | ------------------ | -------- | ------------------------------------------------------------------ |
165-
| `children` | Optional | `ReactNode` | `<SearchResultsPanel>` | The search result renderer |
166-
| `options` | Optional | `object` | - | The search options (see details below) |
167-
| `wait` | Optional | `number` | 500 | The delay of debounce for the search to launch after typing in ms. |
168-
| `color` | Optional | `'light' | 'dark'` | 'light' | The color mode for the input, applying light or dark background. |
164+
| Prop | Required | Type | Default | Description |
165+
| ------------- | -------- | --------- | ---------------------- | -------------------------------------------------------------------------------------------------- |
166+
| `children` | Optional | `Element` | `<SearchResultsPanel>` | A component that will display the results. |
167+
| `color` | Optional | `string` | `light` | The color mode for the input, applying light or dark backgrounds. Accept either `light` or `dark`. |
168+
| `historySize` | Optional | `number` | 5 | The number of past queries to keep in history. |
169+
| `options` | Optional | `Object` | - | An object containing options to apply to the search. |
170+
| `wait` | Optional | `number` | 500 | The delay of debounce for the search to launch after typing in ms. |
169171

170-
The `options` object can contain the following keys:
172+
## `children`
171173

172-
- `targets`: `string[]` An array of the indices on which to perform the search. Defaults to an empty array.
173-
- `historySize`: `number` The max number of search texts kept in the history. Default is 5.
174-
- `{any}`: `{any}` Any custom option to pass to the search engine.
174+
The `<Search>` children allow you to customize the way results are displayed. The child component can grab the search result using the `useSearchResult` hook.
175+
176+
```tsx
177+
import { Admin, AppBar, TitlePortal, Layout } from 'react-admin';
178+
import { Search, useSearchResult } from '@react-admin/ra-search';
179+
180+
const CustomSearchResultsPanel = () => {
181+
const { data, onClose } = useSearchResult();
182+
183+
return (
184+
<ul>
185+
{data.map(searchResult => (
186+
<li key={searchResult.id}>{searchResult.content.label}</li>
187+
))}
188+
</ul>
189+
);
190+
};
191+
192+
const MyAppBar = () => (
193+
<AppBar>
194+
<TitlePortal />
195+
<Search>
196+
<CustomSearchResultsPanel />
197+
</Search>
198+
</AppBar>
199+
);
200+
201+
const MyLayout = props => <Layout {...props} appBar={MyAppBar} />;
202+
203+
export const App = () => (
204+
<Admin dataProvider={searchDataProvider} layout={MyLayout}>
205+
// ...
206+
</Admin>
207+
);
208+
```
209+
210+
## `color`
211+
212+
If you need it, you can choose to render the `light` or the `dark` version of search input.
213+
214+
```tsx
215+
<Search color="dark" />
216+
```
217+
218+
## `historySize`
219+
220+
The number of previous user searches to keep in the popover. For example, if a user performs 10 searches and `historySize` is set to 5, the popover will display the user's last 5 queries.
221+
222+
```tsx
223+
<Search historySize={5} />
224+
```
225+
226+
## `options`
227+
228+
An object containing options to apply to the search:
229+
230+
- `targets`:`string[]`: an array of the indices on which to perform the search. Defaults to an empty array.
231+
- `{any}`:`{any}`: any custom option to pass to the search engine.
232+
233+
## `wait`
234+
235+
The number of milliseconds to wait before processing the search request, immediately after the user enters their last character.
236+
237+
```tsx
238+
<Search wait={200} />
239+
```
175240

176241
## Customizing The Result Items
177242

0 commit comments

Comments
 (0)