@backstage/plugin-search-react 1.0.2-next.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
3
- import { SearchQuery, SearchResultSet, SearchResult, SearchDocument, ResultHighlight } from '@backstage/plugin-search-common';
4
- import React, { ReactElement, ReactNode, PropsWithChildren } from 'react';
5
- import { InputBaseProps } from '@material-ui/core';
6
- import { JsonObject } from '@backstage/types';
3
+ import { SearchQuery, SearchResultSet, SearchResult as SearchResult$1, SearchDocument, ResultHighlight } from '@backstage/plugin-search-common';
4
+ import React, { ForwardRefExoticComponent, ReactNode, ReactElement, PropsWithChildren } from 'react';
5
+ import { InputBaseProps, ListItemTextProps, ListProps, TypographyProps } from '@material-ui/core';
6
+ import { AutocompleteProps } from '@material-ui/lab';
7
7
  import { AsyncState } from 'react-use/lib/useAsync';
8
+ import { JsonValue, JsonObject } from '@backstage/types';
9
+ import { LinkProps } from '@backstage/core-components';
8
10
 
9
11
  /**
10
12
  * @public
@@ -42,6 +44,82 @@ declare type HighlightedSearchResultTextProps = {
42
44
  */
43
45
  declare const HighlightedSearchResultText: ({ text, preTag, postTag, }: HighlightedSearchResultTextProps) => JSX.Element;
44
46
 
47
+ /**
48
+ * Props for {@link SearchBarBase}.
49
+ *
50
+ * @public
51
+ */
52
+ declare type SearchBarBaseProps = Omit<InputBaseProps, 'onChange'> & {
53
+ debounceTime?: number;
54
+ clearButton?: boolean;
55
+ onClear?: () => void;
56
+ onSubmit?: () => void;
57
+ onChange: (value: string) => void;
58
+ };
59
+ /**
60
+ * All search boxes exported by the search plugin are based on the <SearchBarBase />,
61
+ * and this one is based on the <InputBase /> component from Material UI.
62
+ * Recommended if you don't use Search Provider or Search Context.
63
+ *
64
+ * @public
65
+ */
66
+ declare const SearchBarBase: ForwardRefExoticComponent<SearchBarBaseProps>;
67
+ /**
68
+ * Props for {@link SearchBar}.
69
+ *
70
+ * @public
71
+ */
72
+ declare type SearchBarProps = Partial<SearchBarBaseProps>;
73
+ /**
74
+ * Recommended search bar when you use the Search Provider or Search Context.
75
+ *
76
+ * @public
77
+ */
78
+ declare const SearchBar: ForwardRefExoticComponent<SearchBarProps>;
79
+
80
+ /**
81
+ * Props for {@link SearchAutocomplete}.
82
+ *
83
+ * @public
84
+ */
85
+ declare type SearchAutocompleteProps<Option> = Omit<AutocompleteProps<Option, undefined, undefined, boolean>, 'renderInput' | 'disableClearable' | 'multiple'> & {
86
+ 'data-testid'?: string;
87
+ inputPlaceholder?: SearchBarProps['placeholder'];
88
+ inputDebounceTime?: SearchBarProps['debounceTime'];
89
+ };
90
+ /**
91
+ * Type for {@link SearchAutocomplete}.
92
+ *
93
+ * @public
94
+ */
95
+ declare type SearchAutocompleteComponent = <Option>(props: SearchAutocompleteProps<Option>) => JSX.Element;
96
+ /**
97
+ * Recommended search autocomplete when you use the Search Provider or Search Context.
98
+ *
99
+ * @public
100
+ */
101
+ declare const SearchAutocomplete: SearchAutocompleteComponent;
102
+
103
+ /**
104
+ * Props for {@link SearchAutocompleteDefaultOption}.
105
+ *
106
+ * @public
107
+ */
108
+ declare type SearchAutocompleteDefaultOptionProps = {
109
+ icon?: ReactNode;
110
+ primaryText: ListItemTextProps['primary'];
111
+ primaryTextTypographyProps?: ListItemTextProps['primaryTypographyProps'];
112
+ secondaryText?: ListItemTextProps['secondary'];
113
+ secondaryTextTypographyProps?: ListItemTextProps['secondaryTypographyProps'];
114
+ disableTextTypography?: ListItemTextProps['disableTypography'];
115
+ };
116
+ /**
117
+ * A default search autocomplete option component.
118
+ *
119
+ * @public
120
+ */
121
+ declare const SearchAutocompleteDefaultOption: ({ icon, primaryText, primaryTextTypographyProps, secondaryText, secondaryTextTypographyProps, disableTextTypography, }: SearchAutocompleteDefaultOptionProps) => JSX.Element;
122
+
45
123
  /**
46
124
  * @public
47
125
  */
@@ -109,25 +187,128 @@ declare const SearchFilter: {
109
187
  };
110
188
 
111
189
  /**
112
- * Props for {@link SearchResultComponent}
113
- *
190
+ * Props for {@link SearchResultContext}
114
191
  * @public
115
192
  */
116
- declare type SearchResultProps = {
117
- children: (results: {
118
- results: SearchResult[];
119
- }) => JSX.Element;
193
+ declare type SearchResultContextProps = {
194
+ /**
195
+ * A child function that receives an asynchronous result set and returns a react element.
196
+ */
197
+ children: (state: AsyncState<SearchResultSet>) => JSX.Element;
120
198
  };
121
199
  /**
122
- * A component returning the search result.
123
- *
200
+ * Provides context-based results to a child function.
201
+ * @param props - see {@link SearchResultContextProps}.
202
+ * @example
203
+ * ```
204
+ * <SearchResultContext>
205
+ * {({ loading, error, value }) => (
206
+ * <List>
207
+ * {value?.map(({ document }) => (
208
+ * <DefaultSearchResultListItem
209
+ * key={document.location}
210
+ * result={document}
211
+ * />
212
+ * ))}
213
+ * </List>
214
+ * )}
215
+ * </SearchResultContext>
216
+ * ```
217
+ * @public
218
+ */
219
+ declare const SearchResultContext: (props: SearchResultContextProps) => JSX.Element;
220
+ /**
221
+ * Props for {@link SearchResultApi}
222
+ * @public
223
+ */
224
+ declare type SearchResultApiProps = SearchResultContextProps & {
225
+ query: Partial<SearchQuery>;
226
+ };
227
+ /**
228
+ * Request results through the search api and provide them to a child function.
229
+ * @param props - see {@link SearchResultApiProps}.
230
+ * @example
231
+ * ```
232
+ * <SearchResultApi>
233
+ * {({ loading, error, value }) => (
234
+ * <List>
235
+ * {value?.map(({ document }) => (
236
+ * <DefaultSearchResultListItem
237
+ * key={document.location}
238
+ * result={document}
239
+ * />
240
+ * ))}
241
+ * </List>
242
+ * )}
243
+ * </SearchResultApi>
244
+ * ```
245
+ * @public
246
+ */
247
+ declare const SearchResultApi: (props: SearchResultApiProps) => JSX.Element;
248
+ /**
249
+ * Props for {@link SearchResultState}
250
+ * @public
251
+ */
252
+ declare type SearchResultStateProps = SearchResultContextProps & Partial<SearchResultApiProps>;
253
+ /**
254
+ * Call a child render function passing a search state as an argument.
255
+ * @remarks By default, results are taken from context, but when a "query" prop is set, results are requested from the search api.
256
+ * @param props - see {@link SearchResultStateProps}.
257
+ * @example
258
+ * Consuming results from context:
259
+ * ```
260
+ * <SearchResultState>
261
+ * {({ loading, error, value }) => (
262
+ * <List>
263
+ * {value?.map(({ document }) => (
264
+ * <DefaultSearchResultListItem
265
+ * key={document.location}
266
+ * result={document}
267
+ * />
268
+ * ))}
269
+ * </List>
270
+ * )}
271
+ * </SearchResultState>
272
+ * ```
273
+ * @example
274
+ * Requesting results using the search api:
275
+ * ```
276
+ * <SearchResultState query={{ term: 'documentation' }}>
277
+ * {({ loading, error, value }) => (
278
+ * <List>
279
+ * {value?.map(({ document }) => (
280
+ * <DefaultSearchResultListItem
281
+ * key={document.location}
282
+ * result={document}
283
+ * />
284
+ * ))}
285
+ * </List>
286
+ * )}
287
+ * </SearchResultState>
288
+ * ```
289
+ * @public
290
+ */
291
+ declare const SearchResultState: (props: SearchResultStateProps) => JSX.Element;
292
+ /**
293
+ * Props for {@link SearchResult}
294
+ * @public
295
+ */
296
+ declare type SearchResultProps = Pick<SearchResultStateProps, 'query'> & {
297
+ children: (resultSet: SearchResultSet) => JSX.Element;
298
+ };
299
+ /**
300
+ * Renders results from a parent search context or api.
301
+ * @remarks default components for loading, error and empty variants are returned.
302
+ * @param props - see {@link SearchResultProps}.
124
303
  * @public
125
304
  */
126
- declare const SearchResultComponent: ({ children }: SearchResultProps) => JSX.Element;
305
+ declare const SearchResultComponent: (props: SearchResultProps) => JSX.Element;
127
306
  /**
307
+ * A component returning the search result from a parent search context or api.
308
+ * @param props - see {@link SearchResultProps}.
128
309
  * @public
129
310
  */
130
- declare const HigherOrderSearchResult: (props: SearchResultProps) => JSX.Element;
311
+ declare const SearchResult: (props: SearchResultProps) => JSX.Element;
131
312
 
132
313
  /**
133
314
  * @public
@@ -135,37 +316,200 @@ declare const HigherOrderSearchResult: (props: SearchResultProps) => JSX.Element
135
316
  declare const SearchResultPager: () => JSX.Element;
136
317
 
137
318
  /**
138
- * Props for {@link SearchBarBase}.
139
- *
319
+ * Props for {@link SearchResultListLayout}
140
320
  * @public
141
321
  */
142
- declare type SearchBarBaseProps = Omit<InputBaseProps, 'onChange'> & {
143
- debounceTime?: number;
144
- clearButton?: boolean;
145
- onClear?: () => void;
146
- onSubmit?: () => void;
147
- onChange: (value: string) => void;
322
+ declare type SearchResultListLayoutProps = ListProps & {
323
+ /**
324
+ * Search results to be rendered as a list.
325
+ */
326
+ resultItems?: SearchResult$1[];
327
+ /**
328
+ * Function to customize how result items are rendered.
329
+ */
330
+ renderResultItem?: (resultItem: SearchResult$1) => JSX.Element;
331
+ /**
332
+ * If defined, will render a default error panel.
333
+ */
334
+ error?: Error;
335
+ /**
336
+ * If defined, will render a default loading progress.
337
+ */
338
+ loading?: boolean;
148
339
  };
149
340
  /**
150
- * All search boxes exported by the search plugin are based on the <SearchBarBase />,
151
- * and this one is based on the <InputBase /> component from Material UI.
152
- * Recommended if you don't use Search Provider or Search Context.
153
- *
341
+ * Default layout for rendering search results in a list.
342
+ * @param props - See {@link SearchResultListLayoutProps}.
154
343
  * @public
155
344
  */
156
- declare const SearchBarBase: ({ onChange, onKeyDown, onSubmit, debounceTime, clearButton, fullWidth, value: defaultValue, inputProps: defaultInputProps, endAdornment: defaultEndAdornment, ...props }: SearchBarBaseProps) => JSX.Element;
345
+ declare const SearchResultListLayout: (props: SearchResultListLayoutProps) => JSX.Element;
157
346
  /**
158
- * Props for {@link SearchBar}.
159
- *
347
+ * Props for {@link SearchResultList}.
160
348
  * @public
161
349
  */
162
- declare type SearchBarProps = Partial<SearchBarBaseProps>;
350
+ declare type SearchResultListProps = Omit<SearchResultListLayoutProps, 'loading' | 'error' | 'resultItems'> & {
351
+ /**
352
+ * A search query used for requesting the results to be listed.
353
+ */
354
+ query: Partial<SearchQuery>;
355
+ };
163
356
  /**
164
- * Recommended search bar when you use the Search Provider or Search Context.
165
- *
357
+ * Given a query, search for results and render them as a list.
358
+ * @param props - See {@link SearchResultListProps}.
359
+ * @public
360
+ */
361
+ declare const SearchResultList: (props: SearchResultListProps) => JSX.Element;
362
+
363
+ /**
364
+ * Props for {@link SearchResultGroupFilterFieldLayout}
365
+ * @public
366
+ */
367
+ declare type SearchResultGroupFilterFieldLayoutProps = PropsWithChildren<{
368
+ label: string;
369
+ value?: JsonValue;
370
+ onDelete: () => void;
371
+ }>;
372
+ /**
373
+ * Default layout for a search group filter field.
374
+ * @param props - See {@link SearchResultGroupFilterFieldLayoutProps}.
375
+ * @public
376
+ */
377
+ declare const SearchResultGroupFilterFieldLayout: (props: SearchResultGroupFilterFieldLayoutProps) => JSX.Element;
378
+ /**
379
+ * Common props for a result group filter field.
380
+ * @public
381
+ */
382
+ declare type SearchResultGroupFilterFieldPropsWith<T> = T & SearchResultGroupFilterFieldLayoutProps & {
383
+ onChange: (value: JsonValue) => void;
384
+ };
385
+ /**
386
+ * Props for {@link SearchResultGroupTextFilterField}.
387
+ * @public
388
+ */
389
+ declare type SearchResultGroupTextFilterFieldProps = SearchResultGroupFilterFieldPropsWith<{}>;
390
+ /**
391
+ * A text field that can be used as filter on search result groups.
392
+ * @param props - See {@link SearchResultGroupTextFilterFieldProps}.
393
+ * @example
394
+ * ```
395
+ * <SearchResultGroupTextFilterField
396
+ * id="lifecycle"
397
+ * label="Lifecycle"
398
+ * value={value}
399
+ * onChange={handleChangeFilter}
400
+ * onDelete={handleDeleteFilter}
401
+ * />
402
+ * ```
403
+ * @public
404
+ */
405
+ declare const SearchResultGroupTextFilterField: (props: SearchResultGroupTextFilterFieldProps) => JSX.Element;
406
+ /**
407
+ * Props for {@link SearchResultGroupTextFilterField}.
408
+ * @public
409
+ */
410
+ declare type SearchResultGroupSelectFilterFieldProps = SearchResultGroupFilterFieldPropsWith<{
411
+ children: ReactNode;
412
+ }>;
413
+ /**
414
+ * A select field that can be used as filter on search result groups.
415
+ * @param props - See {@link SearchResultGroupSelectFilterFieldProps}.
416
+ * @example
417
+ * ```
418
+ * <SearchResultGroupSelectFilterField
419
+ * id="lifecycle"
420
+ * label="Lifecycle"
421
+ * value={filters.lifecycle}
422
+ * onChange={handleChangeFilter}
423
+ * onDelete={handleDeleteFilter}
424
+ * >
425
+ * <MenuItem value="experimental">Experimental</MenuItem>
426
+ * <MenuItem value="production">Production</MenuItem>
427
+ * </SearchResultGroupSelectFilterField>
428
+ * ```
429
+ * @public
430
+ */
431
+ declare const SearchResultGroupSelectFilterField: (props: SearchResultGroupSelectFilterFieldProps) => JSX.Element;
432
+ /**
433
+ * Props for {@link SearchResultGroupLayout}
434
+ * @public
435
+ */
436
+ declare type SearchResultGroupLayoutProps<FilterOption> = ListProps & {
437
+ /**
438
+ * Icon that representing a result group.
439
+ */
440
+ icon: JSX.Element;
441
+ /**
442
+ * The results group title content, it could be a text or an element.
443
+ */
444
+ title: ReactNode;
445
+ /**
446
+ * Props for the results group title.
447
+ */
448
+ titleProps?: Partial<TypographyProps>;
449
+ /**
450
+ * The results group link content, it could be a text or an element.
451
+ */
452
+ link?: ReactNode;
453
+ /**
454
+ * Props for the results group link, the "to" prop defaults to "/search".
455
+ */
456
+ linkProps?: Partial<LinkProps>;
457
+ /**
458
+ * A generic filter options that is rendered on the "Add filter" dropdown.
459
+ */
460
+ filterOptions?: FilterOption[];
461
+ /**
462
+ * Function to customize how filter options are rendered.
463
+ * @remarks Defaults to a menu item where its value and label bounds to the option string.
464
+ */
465
+ renderFilterOption?: (filterOption: FilterOption) => JSX.Element;
466
+ /**
467
+ * A list of search filter keys, also known as filter field names.
468
+ */
469
+ filterFields?: string[];
470
+ /**
471
+ * Function to customize how filter chips are rendered.
472
+ */
473
+ renderFilterField?: (key: string) => JSX.Element | null;
474
+ /**
475
+ * Search results to be rendered as a group.
476
+ */
477
+ resultItems?: SearchResult$1[];
478
+ /**
479
+ * Function to customize how result items are rendered.
480
+ */
481
+ renderResultItem?: (resultItem: SearchResult$1) => JSX.Element;
482
+ /**
483
+ * If defined, will render a default error panel.
484
+ */
485
+ error?: Error;
486
+ /**
487
+ * If defined, will render a default loading progress.
488
+ */
489
+ loading?: boolean;
490
+ };
491
+ /**
492
+ * Default layout for rendering search results in a group.
493
+ * @param props - See {@link SearchResultGroupLayoutProps}.
494
+ * @public
495
+ */
496
+ declare function SearchResultGroupLayout<FilterOption>(props: SearchResultGroupLayoutProps<FilterOption>): JSX.Element;
497
+ /**
498
+ * Props for {@link SearchResultGroup}.
166
499
  * @public
167
500
  */
168
- declare const SearchBar: ({ onChange, ...props }: SearchBarProps) => JSX.Element;
501
+ declare type SearchResultGroupProps<FilterOption> = Omit<SearchResultGroupLayoutProps<FilterOption>, 'loading' | 'error' | 'resultItems' | 'filterFields'> & {
502
+ /**
503
+ * A search query used for requesting the results to be grouped.
504
+ */
505
+ query: Partial<SearchQuery>;
506
+ };
507
+ /**
508
+ * Given a query, search for results and render them as a group.
509
+ * @param props - See {@link SearchResultGroupProps}.
510
+ * @public
511
+ */
512
+ declare function SearchResultGroup<FilterOption>(props: SearchResultGroupProps<FilterOption>): JSX.Element;
169
513
 
170
514
  /**
171
515
  * Props for {@link DefaultResultListItem}
@@ -226,13 +570,29 @@ declare const useSearchContextCheck: () => boolean;
226
570
  * @public
227
571
  */
228
572
  declare type SearchContextProviderProps = PropsWithChildren<{
573
+ /**
574
+ * State initialized by a local context.
575
+ */
229
576
  initialState?: SearchContextState;
577
+ /**
578
+ * Do not create an inheritance from the parent, as a new initial state must be defined in a local context.
579
+ */
580
+ inheritParentContextIfAvailable?: never;
581
+ }> | PropsWithChildren<{
582
+ /**
583
+ * Does not accept initial state since it is already initialized by parent context.
584
+ */
585
+ initialState?: never;
586
+ /**
587
+ * If true, don't create a child context if there is a parent one already defined.
588
+ * @remarks Defaults to false.
589
+ */
590
+ inheritParentContextIfAvailable?: boolean;
230
591
  }>;
231
592
  /**
232
593
  * @public
233
- *
234
594
  * Search context provider which gives you access to shared state between search components
235
595
  */
236
596
  declare const SearchContextProvider: (props: SearchContextProviderProps) => JSX.Element;
237
597
 
238
- export { AutocompleteFilter, CheckboxFilter, HigherOrderDefaultResultListItem as DefaultResultListItem, DefaultResultListItemProps, HighlightedSearchResultText, HighlightedSearchResultTextProps, MockSearchApi, SearchApi, SearchAutocompleteFilterProps, SearchBar, SearchBarBase, SearchBarBaseProps, SearchBarProps, SearchContextProvider, SearchContextProviderProps, SearchContextState, SearchContextValue, SearchFilter, SearchFilterComponentProps, SearchFilterWrapperProps, HigherOrderSearchResult as SearchResult, SearchResultComponent, SearchResultPager, SearchResultProps, SelectFilter, searchApiRef, useSearch, useSearchContextCheck };
598
+ export { AutocompleteFilter, CheckboxFilter, HigherOrderDefaultResultListItem as DefaultResultListItem, DefaultResultListItemProps, HighlightedSearchResultText, HighlightedSearchResultTextProps, MockSearchApi, SearchApi, SearchAutocomplete, SearchAutocompleteComponent, SearchAutocompleteDefaultOption, SearchAutocompleteDefaultOptionProps, SearchAutocompleteFilterProps, SearchAutocompleteProps, SearchBar, SearchBarBase, SearchBarBaseProps, SearchBarProps, SearchContextProvider, SearchContextProviderProps, SearchContextState, SearchContextValue, SearchFilter, SearchFilterComponentProps, SearchFilterWrapperProps, SearchResult, SearchResultApi, SearchResultApiProps, SearchResultComponent, SearchResultContext, SearchResultContextProps, SearchResultGroup, SearchResultGroupFilterFieldLayout, SearchResultGroupFilterFieldLayoutProps, SearchResultGroupFilterFieldPropsWith, SearchResultGroupLayout, SearchResultGroupLayoutProps, SearchResultGroupProps, SearchResultGroupSelectFilterField, SearchResultGroupSelectFilterFieldProps, SearchResultGroupTextFilterField, SearchResultGroupTextFilterFieldProps, SearchResultList, SearchResultListLayout, SearchResultListLayoutProps, SearchResultListProps, SearchResultPager, SearchResultProps, SearchResultState, SearchResultStateProps, SelectFilter, searchApiRef, useSearch, useSearchContextCheck };