|
| 1 | +import { |
| 2 | + AutocompleteOptions as AutocompleteCoreOptions, |
| 3 | + BaseItem, |
| 4 | + GetSourcesParams, |
| 5 | +} from '@algolia/autocomplete-core'; |
| 6 | +import { MaybePromise } from '@algolia/autocomplete-shared'; |
| 7 | + |
| 8 | +import { AutocompleteClassNames } from './AutocompleteClassNames'; |
| 9 | +import { AutocompleteSource } from './AutocompleteSource'; |
| 10 | +import { AutocompleteState } from './AutocompleteState'; |
| 11 | + |
| 12 | +export type AutocompleteRenderer<TItem extends BaseItem> = (params: { |
| 13 | + root: HTMLElement; |
| 14 | + sections: HTMLElement[]; |
| 15 | + state: AutocompleteState<TItem>; |
| 16 | +}) => void; |
| 17 | + |
| 18 | +export interface AutocompleteOptions<TItem extends BaseItem> |
| 19 | + extends AutocompleteCoreOptions<TItem> { |
| 20 | + /** |
| 21 | + * The container for the Autocomplete search box. |
| 22 | + * |
| 23 | + * You can either pass a [CSS selector](https://developer.mozilla.org/docs/Web/CSS/CSS_Selectors) or an [Element](https://developer.mozilla.org/docs/Web/API/HTMLElement). The first element matching the provided selector will be used as container. |
| 24 | + */ |
| 25 | + container: string | HTMLElement; |
| 26 | + /** |
| 27 | + * The container for the Autocomplete panel. |
| 28 | + * |
| 29 | + * You can either pass a [CSS selector](https://developer.mozilla.org/docs/Web/CSS/CSS_Selectors) or an [Element](https://developer.mozilla.org/docs/Web/API/HTMLElement). The first element matching the provided selector will be used as container. |
| 30 | + * |
| 31 | + * @default document.body |
| 32 | + */ |
| 33 | + panelContainer?: string | HTMLElement; |
| 34 | + getSources?: ( |
| 35 | + params: GetSourcesParams<TItem> |
| 36 | + ) => MaybePromise<Array<AutocompleteSource<TItem>>>; |
| 37 | + /** |
| 38 | + * The panel horizontal position. |
| 39 | + * |
| 40 | + * @default "input-wrapper-width" |
| 41 | + */ |
| 42 | + panelPlacement?: 'start' | 'end' | 'full-width' | 'input-wrapper-width'; |
| 43 | + /** |
| 44 | + * The class names to inject in each created DOM element. |
| 45 | + * |
| 46 | + * It it useful to design with external CSS frameworks. |
| 47 | + */ |
| 48 | + classNames?: Partial<AutocompleteClassNames>; |
| 49 | + /** |
| 50 | + * Function called to render the autocomplete results. It is useful for rendering sections in different row or column layouts. |
| 51 | + * The default implementation appends all the sections to the root: |
| 52 | + * |
| 53 | + * ```js |
| 54 | + * autocomplete({ |
| 55 | + * // ... |
| 56 | + * render({ root, sections }) { |
| 57 | + * for (const section of sections) { |
| 58 | + * root.appendChild(section); |
| 59 | + * } |
| 60 | + * }, |
| 61 | + * }); |
| 62 | + * ``` |
| 63 | + */ |
| 64 | + render?: AutocompleteRenderer<TItem>; |
| 65 | + initialState?: Partial<AutocompleteState<TItem>>; |
| 66 | +} |
0 commit comments