-
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.
feat(plugin): add
transformSource
API
This updates the plugins' API to allow complete source override, as opposed to only templates override. ## Why Users might want to override the behavior of the original source (e.g., keep the panel open on select). This wasn't possible with the previous API, which only allow to modify the template. ## API ```tsx const recentSearchesPlugin = createLocalStorageRecentSearchesPlugin({ key: 'search', limit: 3, transformSource({ source, onRemove }) { return { ...source, getItemUrl({ item }) { return `https://google.com?q=${item.query}`; }, }; }, }); const querySuggestionsPlugin = createQuerySuggestionsPlugin({ searchClient, indexName: 'instant_search_demo_query_suggestions', transformSource({ source, onTapAhead }) { return { ...source, onSelect({ setIsOpen }) { setIsOpen(true); }, getItemUrl({ item }) { return `https://google.com?q=${item.query}`; }, templates: { ...source.templates, item(params) { const { item } = params; return ( <a href={`https://google.com?q=${item.query}`} className="aa-ItemLink" > {source.templates.item(params)} </a> ); }, }, }; }, }); ```
- Loading branch information
1 parent
9bc826e
commit fbd9e72
Showing
6 changed files
with
227 additions
and
63 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
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
Oops, something went wrong.