-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.tsx
More file actions
67 lines (58 loc) · 2.07 KB
/
index.tsx
File metadata and controls
67 lines (58 loc) · 2.07 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
'use client';
import ChatTrigger from '@node-core/ui-components/Common/Search/Chat/Trigger';
import SearchModal from '@node-core/ui-components/Common/Search/Modal';
import SearchResults from '@node-core/ui-components/Common/Search/Results';
import SearchSuggestions from '@node-core/ui-components/Common/Search/Suggestions';
import { useTranslations } from 'next-intl';
import { useState } from 'react';
import { DEFAULT_ORAMA_QUERY_PARAMS } from '#site/next.constants.mjs';
import type { Document } from './DocumentLink';
import type { FC } from 'react';
import { Footer } from './Footer';
import { oramaClient } from './orama-client';
import SearchItem from './SearchItem';
import { SlidingChatPanel } from './SlidingChatPanel';
import styles from './index.module.css';
const Searchbox: FC = () => {
const t = useTranslations();
const [mode, setMode] = useState<'chat' | 'search'>('search');
const sharedProps = {
searchParams: DEFAULT_ORAMA_QUERY_PARAMS,
tabIndex: mode === 'search' ? 0 : -1,
'aria-hidden': mode === 'chat',
};
return (
<SearchModal
client={oramaClient}
placeholder={t('components.search.searchPlaceholder')}
>
<div className={styles.searchResultsContainer}>
<ChatTrigger onClick={() => setMode('chat')}>
{t('components.search.chatButtonLabel')}
</ChatTrigger>
<SearchResults
noResultsTitle={t('components.search.noResultsFoundFor')}
onHit={hit => (
<SearchItem document={hit.document as Document} mode={mode} />
)}
{...sharedProps}
>
<SearchSuggestions
suggestions={[
t('components.search.suggestionOne'),
t('components.search.suggestionTwo'),
t('components.search.suggestionThree'),
]}
label={t('components.search.suggestions')}
/>
</SearchResults>
</div>
<Footer />
<SlidingChatPanel
open={mode === 'chat'}
onClose={() => setMode('search')}
/>
</SearchModal>
);
};
export default Searchbox;