-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNavMenuSingleItem.tsx
More file actions
55 lines (51 loc) · 1.35 KB
/
NavMenuSingleItem.tsx
File metadata and controls
55 lines (51 loc) · 1.35 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
import { Tag } from '@rspress/core/theme'
import { isExternalUrl, type NavItemWithLink } from '@rspress/shared'
import { useMemo, type ReactNode } from 'react'
import styles from '../../../styles/versions-nav.module.scss'
import { withoutBase } from '../../shared/index.js'
export interface NavMenuSingleItemProps extends Omit<NavItemWithLink, 'text'> {
base?: string
compact?: boolean
download?: string | boolean
pathname?: string
rightIcon?: ReactNode
text?: ReactNode
}
export function NavMenuSingleItem({
activeMatch,
base,
compact,
download,
link,
pathname,
rightIcon,
text,
tag,
}: NavMenuSingleItemProps) {
const isActive = useMemo(
() =>
!!base &&
!!pathname &&
new RegExp(activeMatch || link).test(withoutBase(pathname, base)),
[activeMatch, base, link, pathname],
)
return (
<a
key={link}
href={link}
download={download}
target={isExternalUrl(link) ? '_blank' : undefined}
rel="noopener noreferrer"
>
<div
className={`rspress-nav-menu-item ${styles.singleItem} ${
isActive ? `${styles.activeItem} rspress-nav-menu-item-active` : ''
} rp-text-sm rp-font-medium ${compact ? 'rp-mx-0.5' : 'rp-mx-1.5'} rp-px-3 rp-py-2 rp-flex rp-items-center`}
>
<Tag tag={tag} />
{text}
{rightIcon}
</div>
</a>
)
}