-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnavlink.tsx
More file actions
40 lines (37 loc) · 1.08 KB
/
navlink.tsx
File metadata and controls
40 lines (37 loc) · 1.08 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
"use client";
import { cn } from "@/lib/utils";
import Link from "next/link";
import { useSelectedLayoutSegment } from "next/navigation";
type Props = {
href: string;
className?: string;
external?: boolean;
children: React.ReactNode;
};
export const NavLink = ({ href, children, external, className }: Props) => {
const segment = useSelectedLayoutSegment();
const isActive =
segment === href.slice(1) || (segment === null && href === "/");
return (
<li className="relative group">
<Link
target={external ? "_blank" : "_self"}
href={href}
className={cn(
"w-full h-full block py-4 px-5 transition-colors",
"group-hover:text-foreground",
isActive ? "text-foreground" : "text-muted-foreground",
)}
>
{children}
</Link>
<div
className={cn(
"absolute bottom-0 h-0.5 bg-muted-foreground opacity-0 transition-all duration-500",
"group-hover:opacity-100 group-hover:w-full",
isActive ? "opacity-100 w-full" : "w-0",
)}
/>
</li>
);
};