-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docsearch): add search suggestions
- Loading branch information
1 parent
fa42ab2
commit a448e9e
Showing
4 changed files
with
87 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,58 @@ | ||
import React from 'react'; | ||
import { AutocompleteState } from '@francoischalifour/autocomplete-core'; | ||
|
||
interface NoResultsProps { | ||
query: string; | ||
state: AutocompleteState<any>; | ||
setQuery(value: string): void; | ||
refresh(): Promise<void>; | ||
inputRef: React.MutableRefObject<HTMLInputElement>; | ||
} | ||
|
||
export function NoResults(props: NoResultsProps) { | ||
return <div className="DocSearch-NoResults"> | ||
<div className="Docsearch-Hit-title">No results for “{props.query}“.</div> | ||
<div className="DocSearch-Label">Try another search or if you believe this query should lead to actual results, please let us know with a <a href="">GitHub issue</a>.</div> | ||
</div>; | ||
return ( | ||
<div className="DocSearch-NoResults"> | ||
<p className="Docsearch-Hit-title"> | ||
No results for “{props.state.query}“. | ||
</p> | ||
|
||
<p> | ||
Try searching for{' '} | ||
{(props.state.context.searchSuggestions as string[]) | ||
.slice(0, 3) | ||
.reduce<React.ReactNode[]>( | ||
(acc, search) => [ | ||
...acc, | ||
acc.length > 0 ? ', ' : '', | ||
'“', | ||
<button | ||
className="DocSearch-Link" | ||
key={search} | ||
onClick={() => { | ||
props.setQuery(search.toLowerCase() + ' '); | ||
props.refresh(); | ||
props.inputRef.current.focus(); | ||
}} | ||
> | ||
{search} | ||
</button>, | ||
'“', | ||
], | ||
[] | ||
)} | ||
. | ||
</p> | ||
|
||
<p className="DocSearch-Label"> | ||
If you believe this query should return results, please{' '} | ||
<a | ||
href="https://github.com/algolia/docsearch-configs/issues/new?template=Missing_results.md" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
let us know on GitHub | ||
</a> | ||
. | ||
</p> | ||
</div> | ||
); | ||
} |
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