Skip to content

Commit 736b7ef

Browse files
committed
feat(orama): add SearchHit UI component
1 parent 9dd8a43 commit 736b7ef

File tree

7 files changed

+96
-76
lines changed

7 files changed

+96
-76
lines changed

apps/site/components/Common/Searchbox/DocumentLink/index.module.css

Lines changed: 0 additions & 31 deletions
This file was deleted.

apps/site/components/Common/Searchbox/DocumentLink/index.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
'use client';
22

3+
import styles from '@node-core/ui-components/Common/Search/Results/Hit/index.module.css';
34
import Link from 'next/link';
45
import { useLocale } from 'next-intl';
56

67
import type { FC } from 'react';
78

8-
import styles from './index.module.css';
9-
109
export type Document = {
1110
path: string;
1211
siteSection: string;
@@ -22,7 +21,7 @@ type DocumentLinkProps = {
2221

2322
export const DocumentLink: FC<DocumentLinkProps> = ({
2423
document,
25-
className = styles.documentLink,
24+
className = styles.link,
2625
children,
2726
'data-focus-on-arrow-nav': dataFocusOnArrowNav,
2827
...props
@@ -41,11 +40,7 @@ export const DocumentLink: FC<DocumentLinkProps> = ({
4140
data-focus-on-arrow-nav={dataFocusOnArrowNav}
4241
{...props}
4342
>
44-
{children || (
45-
<span className={styles.documentTitle}>
46-
{document.pageSectionTitle}
47-
</span>
48-
)}
43+
{children}
4944
</Link>
5045
);
5146
};
Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
1-
'use client';
2-
3-
import { DocumentTextIcon } from '@heroicons/react/24/outline';
4-
import { SearchResults } from '@orama/ui/components';
1+
import SearchHit from '@node-core/ui-components/Common/Search/Results/Hit';
2+
import { useLocale } from 'next-intl';
53

64
import type { Document } from '../DocumentLink';
7-
import type { FC } from 'react';
5+
import type { ComponentProps, FC } from 'react';
86

9-
import { DocumentLink } from '../DocumentLink';
107
import { getFormattedPath } from './utils';
118

12-
import styles from './index.module.css';
13-
14-
type SearchItemProps = {
9+
type SearchItemProps = Omit<
10+
ComponentProps<typeof SearchHit>,
11+
'document' | 'as'
12+
> & {
1513
document: Document;
16-
mode?: 'search' | 'chat';
1714
};
1815

19-
export const SearchItem: FC<SearchItemProps> = ({ document, mode }) => (
20-
<SearchResults.Item className={styles.searchResultsItem}>
21-
<DocumentLink
22-
document={document as Document}
23-
tabIndex={mode === 'search' ? 0 : -1}
24-
aria-hidden={mode === 'chat'}
25-
data-focus-on-arrow-nav
26-
>
27-
<DocumentTextIcon />
28-
<div>
29-
{typeof document?.pageSectionTitle === 'string' && (
30-
<h3>{document.pageSectionTitle}</h3>
31-
)}
32-
{typeof document?.pageSectionTitle === 'string' &&
33-
typeof document?.path === 'string' && (
34-
<p className={styles.searchResultsItemDescription}>
35-
{getFormattedPath(document.path, document.pageSectionTitle)}
36-
</p>
37-
)}
38-
</div>
39-
</DocumentLink>
40-
</SearchResults.Item>
41-
);
16+
const SearchItem: FC<SearchItemProps> = ({ document, ...props }) => {
17+
const locale = useLocale();
18+
19+
const href =
20+
document.siteSection?.toLowerCase() === 'docs'
21+
? `/${document.path}`
22+
: `/${locale}/${document.path}`;
23+
24+
return (
25+
<SearchHit
26+
document={{
27+
title: document.pageSectionTitle,
28+
description:
29+
document.pageSectionTitle &&
30+
getFormattedPath(document.path, document.pageSectionTitle),
31+
href,
32+
}}
33+
{...props}
34+
/>
35+
);
36+
};
37+
38+
export default SearchItem;

apps/site/components/Common/Searchbox/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { FC } from 'react';
1414

1515
import { Footer } from './Footer';
1616
import { oramaClient } from './orama-client';
17-
import { SearchItem } from './SearchItem';
17+
import SearchItem from './SearchItem';
1818
import { SlidingChatPanel } from './SlidingChatPanel';
1919

2020
import styles from './index.module.css';

packages/ui-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@node-core/ui-components",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"type": "module",
55
"exports": {
66
"./*": [

apps/site/components/Common/Searchbox/SearchItem/index.module.css renamed to packages/ui-components/src/Common/Search/Results/Hit/index.module.css

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@reference "../../../../styles/index.css";
22

3-
.searchResultsItem {
3+
.hit {
44
> a {
55
@apply flex
66
items-center
@@ -27,7 +27,27 @@
2727
}
2828
}
2929

30-
.searchResultsItemDescription {
30+
.link {
31+
@apply rounded-xl
32+
bg-neutral-100
33+
px-4
34+
py-2
35+
text-neutral-900
36+
duration-300
37+
hover:bg-neutral-200
38+
focus:bg-neutral-200
39+
motion-safe:transition-colors
40+
dark:bg-neutral-950
41+
dark:text-neutral-200
42+
hover:dark:bg-neutral-900
43+
focus:dark:bg-neutral-900;
44+
45+
svg {
46+
@apply size-5;
47+
}
48+
}
49+
50+
.hitDescription {
3151
@apply text-sm
3252
text-neutral-600
3353
dark:text-neutral-700;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { DocumentTextIcon } from '@heroicons/react/24/outline';
2+
import { SearchResults } from '@orama/ui/components';
3+
4+
import type { LinkLike } from '#ui/types';
5+
import type { FC } from 'react';
6+
7+
import styles from './index.module.css';
8+
9+
type HitProps = {
10+
document: {
11+
title?: string;
12+
description?: string;
13+
href: string;
14+
};
15+
mode?: 'search' | 'chat';
16+
as?: LinkLike;
17+
};
18+
19+
const Hit: FC<HitProps> = ({ document, mode = 'search', as: Link = 'a' }) => (
20+
<SearchResults.Item className={styles.hit}>
21+
<Link
22+
href={document.href}
23+
tabIndex={mode === 'search' ? 0 : -1}
24+
aria-hidden={mode === 'chat'}
25+
data-focus-on-arrow-nav
26+
className={styles.link}
27+
>
28+
<DocumentTextIcon />
29+
<div>
30+
{typeof document?.title === 'string' && <h3>{document.title}</h3>}
31+
{typeof document?.description === 'string' && (
32+
<p className={styles.hitDescription}>{document.description}</p>
33+
)}
34+
</div>
35+
</Link>
36+
</SearchResults.Item>
37+
);
38+
39+
export default Hit;

0 commit comments

Comments
 (0)