Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cool animation on NavLink.tsx #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions components/NavLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import Link from "next/link";
import { ReactNode } from "react";
import cn from "clsx";
import { useRouter } from "next/router";
import { motion } from "framer-motion";

type NavLinkProps = {
href: string;
href: string
children: ReactNode;
};

Expand All @@ -16,12 +17,19 @@ export default function NavLink({ href, children }: NavLinkProps) {
return (
<Link
className={cn(
"px-4 py-2 rounded-full text-sm hover:text-primary transition-colors",
active ? "bg-secondaryA text-primary" : "text-secondary"
"relative px-4 py-2 rounded-full text-sm hover:text-primary transition-colors",
active ? "text-primary" : "text-secondary"
)}
href={href}
>
{children}
{active && (
<motion.div
layoutId="underline"
className="absolute left-0 top-0 bottom-0 right-0 -z-20 bg-secondaryA rounded-full"
transition={{ duration: 0.35 }}
/>
)}
</Link>
);
}