forked from algolia/docsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoResultsScreen.tsx
More file actions
74 lines (67 loc) · 2.42 KB
/
NoResultsScreen.tsx
File metadata and controls
74 lines (67 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, { type JSX } from 'react';
import { NoResultsIcon } from './icons';
import type { ScreenStateProps } from './ScreenState';
import type { InternalDocSearchHit } from './types';
export type NoResultsScreenTranslations = Partial<{
noResultsText: string;
suggestedQueryText: string;
reportMissingResultsText: string;
reportMissingResultsLinkText: string;
}>;
type NoResultsScreenProps = Omit<ScreenStateProps<InternalDocSearchHit>, 'translations'> & {
translations?: NoResultsScreenTranslations;
};
export function NoResultsScreen({ translations = {}, ...props }: NoResultsScreenProps): JSX.Element {
const {
noResultsText = 'No results for',
suggestedQueryText = 'Try searching for',
reportMissingResultsText = 'Believe this query should return results?',
reportMissingResultsLinkText = 'Let us know.',
} = translations;
const searchSuggestions: string[] | undefined = props.state.context.searchSuggestions as string[];
return (
<div className="DocSearch-NoResults">
<div className="DocSearch-Screen-Icon">
<NoResultsIcon />
</div>
<p className="DocSearch-Title">
{noResultsText} "<strong>{props.state.query}</strong>"
</p>
{searchSuggestions && searchSuggestions.length > 0 && (
<div className="DocSearch-NoResults-Prefill-List">
<p className="DocSearch-Help">{suggestedQueryText}:</p>
<ul>
{searchSuggestions.slice(0, 3).reduce<React.ReactNode[]>(
(acc, search) => [
...acc,
<li key={search}>
<button
className="DocSearch-Prefill"
key={search}
type="button"
onClick={() => {
props.setQuery(search.toLowerCase() + ' ');
props.refresh();
props.inputRef.current!.focus();
}}
>
{search}
</button>
</li>,
],
[],
)}
</ul>
</div>
)}
{props.getMissingResultsUrl && (
<p className="DocSearch-Help">
{`${reportMissingResultsText} `}
<a href={props.getMissingResultsUrl({ query: props.state.query })} target="_blank" rel="noopener noreferrer">
{reportMissingResultsLinkText}
</a>
</p>
)}
</div>
);
}