-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ab12c5
commit 3e4829a
Showing
4 changed files
with
102 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { | ||
AutocompleteSetters as AutocompleteCoreSetters, | ||
PublicAutocompleteOptions as PublicAutocompleteCoreOptions, | ||
AutocompleteState as AutocompleteCoreState, | ||
AutocompleteSource as AutocompleteCoreSource, | ||
GetSourcesParams, | ||
} from '@algolia/autocomplete-core'; | ||
|
||
type Template<TParams> = (params: TParams) => string | void; | ||
|
||
export type AutocompleteSource<TItem> = AutocompleteCoreSource<TItem> & { | ||
/** | ||
* Templates to display in the autocomplete dropdown. | ||
* | ||
* A template can either return a string, or perform DOM mutations (manipulating DOM elements with JavaScript and attaching events) without returning a string. | ||
*/ | ||
templates: { | ||
/** | ||
* The template for the suggestion item. | ||
*/ | ||
item: Template<{ | ||
root: HTMLElement; | ||
item: TItem; | ||
state: AutocompleteCoreState<TItem>; | ||
}>; | ||
/** | ||
* The template for the section header. | ||
*/ | ||
header?: Template<{ | ||
root: HTMLElement; | ||
state: AutocompleteCoreState<TItem>; | ||
}>; | ||
/** | ||
* The template for the section footer. | ||
*/ | ||
footer?: Template<{ | ||
root: HTMLElement; | ||
state: AutocompleteCoreState<TItem>; | ||
}>; | ||
}; | ||
}; | ||
|
||
type GetSources<TItem> = ( | ||
params: GetSourcesParams<TItem> | ||
) => Promise<Array<AutocompleteSource<TItem>>>; | ||
|
||
export interface AutocompleteOptions<TItem> | ||
extends PublicAutocompleteCoreOptions<TItem> { | ||
/** | ||
* The container for the autocomplete search box. | ||
* | ||
* 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. | ||
*/ | ||
container: string | HTMLElement; | ||
getSources: GetSources<TItem>; | ||
/** | ||
* The dropdown horizontal position. | ||
* | ||
* @default "input-wrapper-width" | ||
*/ | ||
dropdownPlacement?: 'start' | 'end' | 'full-width' | 'input-wrapper-width'; | ||
/** | ||
* Function called to render the autocomplete results. It is useful for rendering sections in different row or column layouts. | ||
* The default implementation appends all the sections to the root: | ||
* | ||
* ```js | ||
* autocomplete({ | ||
* // ... | ||
* render({ root, sections }) { | ||
* for (const section of sections) { | ||
* root.appendChild(section); | ||
* } | ||
* }, | ||
* }); | ||
* ``` | ||
*/ | ||
render?(params: { | ||
root: HTMLElement; | ||
sections: HTMLElement[]; | ||
state: AutocompleteCoreState<TItem>; | ||
}): void; | ||
} | ||
|
||
export interface AutocompleteApi<TItem> extends AutocompleteCoreSetters<TItem> { | ||
/** | ||
* Triggers a search to refresh the state. | ||
*/ | ||
refresh(): Promise<void>; | ||
/** | ||
* Cleans up the DOM mutations and event listeners. | ||
*/ | ||
destroy(): void; | ||
} |