Skip to content

Commit bab86e7

Browse files
committed
fixup!
1 parent 736b7ef commit bab86e7

File tree

5 files changed

+26
-42
lines changed

5 files changed

+26
-42
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { useLocale } from 'next-intl';
66

77
import type { FC } from 'react';
88

9+
import { getDocumentHref } from '../SearchItem/utils';
10+
911
export type Document = {
1012
path: string;
1113
siteSection: string;
@@ -28,14 +30,9 @@ export const DocumentLink: FC<DocumentLinkProps> = ({
2830
}) => {
2931
const locale = useLocale();
3032

31-
const href =
32-
document.siteSection?.toLowerCase() === 'docs'
33-
? `/${document.path}`
34-
: `/${locale}/${document.path}`;
35-
3633
return (
3734
<Link
38-
href={href}
35+
href={getDocumentHref(document, locale)}
3936
className={className}
4037
data-focus-on-arrow-nav={dataFocusOnArrowNav}
4138
{...props}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import SearchHit from '@node-core/ui-components/Common/Search/Results/Hit';
2+
import Link from 'next/link';
23
import { useLocale } from 'next-intl';
34

45
import type { Document } from '../DocumentLink';
6+
import type { LinkLike } from '@node-core/ui-components/types';
57
import type { ComponentProps, FC } from 'react';
68

7-
import { getFormattedPath } from './utils';
9+
import { getDocumentHref, getFormattedPath } from './utils';
810

911
type SearchItemProps = Omit<
1012
ComponentProps<typeof SearchHit>,
@@ -16,20 +18,16 @@ type SearchItemProps = Omit<
1618
const SearchItem: FC<SearchItemProps> = ({ document, ...props }) => {
1719
const locale = useLocale();
1820

19-
const href =
20-
document.siteSection?.toLowerCase() === 'docs'
21-
? `/${document.path}`
22-
: `/${locale}/${document.path}`;
23-
2421
return (
2522
<SearchHit
2623
document={{
2724
title: document.pageSectionTitle,
2825
description:
2926
document.pageSectionTitle &&
3027
getFormattedPath(document.path, document.pageSectionTitle),
31-
href,
28+
href: getDocumentHref(document, locale),
3229
}}
30+
as={Link as LinkLike}
3331
{...props}
3432
/>
3533
);

apps/site/components/Common/Searchbox/SearchItem/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Document } from '../DocumentLink';
2+
13
export const uppercaseFirst = (word: string) =>
24
word.charAt(0).toUpperCase() + word.slice(1);
35

@@ -9,3 +11,8 @@ export const getFormattedPath = (path: string, title: string) =>
911
.map(element => uppercaseFirst(element))
1012
.filter(Boolean)
1113
.join(' > ')}${title}`;
14+
15+
export const getDocumentHref = (document: Document, locale: string) =>
16+
document.siteSection?.toLowerCase() === 'docs'
17+
? `/${document.path}`
18+
: `/${locale}/${document.path}`;

packages/ui-components/src/Common/Search/Results/Hit/index.module.css

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

3-
.hit {
4-
> a {
5-
@apply flex
6-
items-center
7-
gap-4
8-
rounded-lg
9-
border
10-
border-transparent
11-
px-2
12-
py-3
13-
text-sm
14-
duration-300
15-
outline-none
16-
hover:bg-neutral-300
17-
focus-visible:border-green-600
18-
focus-visible:bg-transparent
19-
motion-safe:transition-colors
20-
dark:bg-neutral-950
21-
dark:hover:bg-neutral-900;
22-
}
23-
24-
svg {
25-
@apply size-5
26-
shrink-0;
27-
}
28-
}
29-
303
.link {
31-
@apply rounded-xl
4+
@apply flex
5+
items-center
6+
gap-4
7+
rounded-xl
8+
border
9+
border-transparent
3210
bg-neutral-100
3311
px-4
3412
py-2
13+
text-sm
3514
text-neutral-900
3615
duration-300
16+
outline-none
3717
hover:bg-neutral-200
3818
focus:bg-neutral-200
19+
focus-visible:border-green-600
20+
focus-visible:bg-transparent
3921
motion-safe:transition-colors
4022
dark:bg-neutral-950
4123
dark:text-neutral-200

packages/ui-components/src/Common/Search/Results/Hit/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type HitProps = {
1717
};
1818

1919
const Hit: FC<HitProps> = ({ document, mode = 'search', as: Link = 'a' }) => (
20-
<SearchResults.Item className={styles.hit}>
20+
<SearchResults.Item>
2121
<Link
2222
href={document.href}
2323
tabIndex={mode === 'search' ? 0 : -1}

0 commit comments

Comments
 (0)