-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathnav-link.tsx
More file actions
44 lines (38 loc) · 1.07 KB
/
nav-link.tsx
File metadata and controls
44 lines (38 loc) · 1.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
"use client"
import clsx from "clsx"
import type * as normalizePages from "nextra/normalize-pages"
import React from "react"
import { Anchor } from "@/app/conf/_design-system/anchor"
import { usePathname } from "next/navigation"
export const navLinkClasses =
"typography-menu flex items-center text-neu-900 px-3 py-1 nextra-focus [text-box:trim-both_cap_alphabetic] leading-none hover:underline underline-offset-2 md:py-5"
export interface NavLinkProps {
href: string
isActive: boolean
page: normalizePages.PageItem
}
export function NavLink({
href,
page,
}: {
href: string
page: normalizePages.PageItem
}) {
const pathname = usePathname() || "/"
const isActive =
page.route === pathname || pathname.startsWith(page.route + "/")
return (
<Anchor
href={href}
className={clsx(
navLinkClasses,
"whitespace-nowrap max-md:hidden",
isActive && !page.newWindow && "underline",
)}
target={page.newWindow ? "_blank" : undefined}
aria-current={!page.newWindow && isActive}
>
{page.title}
</Anchor>
)
}