30 lines
798 B
TypeScript
30 lines
798 B
TypeScript
import Link, { LinkProps } from "next/link";
|
|
import { forwardRef } from "react";
|
|
import { cn } from "@/lib/utils";
|
|
import { usePathname } from "next/navigation";
|
|
|
|
interface NavLinkCompatProps extends Omit<LinkProps, "className"> {
|
|
className?: string;
|
|
activeClassName?: string;
|
|
pendingClassName?: string;
|
|
}
|
|
|
|
const NavLink = forwardRef<HTMLAnchorElement, NavLinkCompatProps>(
|
|
({ className, activeClassName, pendingClassName, href, ...props }, ref) => {
|
|
const pathname = usePathname();
|
|
const isActive = pathname === href;
|
|
const isPending = false;
|
|
|
|
return (
|
|
<Link
|
|
ref={ref}
|
|
href={href}
|
|
className={cn(className, isActive && activeClassName, isPending && pendingClassName)}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
);
|
|
|
|
NavLink.displayName = "NavLink";
|