File tree Expand file tree Collapse file tree 5 files changed +26
-42
lines changed
apps/site/components/Common/Searchbox
packages/ui-components/src/Common/Search/Results/Hit Expand file tree Collapse file tree 5 files changed +26
-42
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ import { useLocale } from 'next-intl';
66
77import type { FC } from 'react' ;
88
9+ import { getDocumentHref } from '../SearchItem/utils' ;
10+
911export 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 }
Original file line number Diff line number Diff line change 11import SearchHit from '@node-core/ui-components/Common/Search/Results/Hit' ;
2+ import Link from 'next/link' ;
23import { useLocale } from 'next-intl' ;
34
45import type { Document } from '../DocumentLink' ;
6+ import type { LinkLike } from '@node-core/ui-components/types' ;
57import type { ComponentProps , FC } from 'react' ;
68
7- import { getFormattedPath } from './utils' ;
9+ import { getDocumentHref , getFormattedPath } from './utils' ;
810
911type SearchItemProps = Omit <
1012 ComponentProps < typeof SearchHit > ,
@@ -16,20 +18,16 @@ type SearchItemProps = Omit<
1618const 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 ) ;
Original file line number Diff line number Diff line change 1+ import type { Document } from '../DocumentLink' ;
2+
13export 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 } ` ;
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ type HitProps = {
1717} ;
1818
1919const 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 }
You can’t perform that action at this time.
0 commit comments