From 14148b9883f2f52f9fb9436c5ea778f866c76868 Mon Sep 17 00:00:00 2001 From: Tushar Saini Date: Mon, 25 Sep 2023 17:16:25 +0530 Subject: [PATCH 1/2] feat: Adding active page indicator in Navbar --- src/components/main-nav.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/main-nav.tsx b/src/components/main-nav.tsx index cfe10a77..c16dd0c4 100644 --- a/src/components/main-nav.tsx +++ b/src/components/main-nav.tsx @@ -6,7 +6,8 @@ import { cn } from "@/lib/utils"; import { NavItem } from "@/types/nav"; import Image from "next/image"; import Link from "next/link"; -import { useEffect, useRef, useState } from "react"; +import { usePathname } from 'next/navigation'; +import { useEffect,useRef,useState } from "react"; import { BiMenuAltRight } from "react-icons/bi"; import { MdOutlineClose } from "react-icons/md"; import { ThemeToggle } from "./theme-toggle"; @@ -19,6 +20,7 @@ interface MainNavProps { export function MainNav({ items }: MainNavProps) { const [toggle, setToggle] = useState(false); const menuRef = useRef(null); + const pathname = usePathname(); useEffect(() => { if (!toggle) return; @@ -77,7 +79,8 @@ export function MainNav({ items }: MainNavProps) { href={item.href} className={cn( "flex items-center whitespace-nowrap text-xl font-semibold sm:text-sm", - item.disabled && "cursor-not-allowed opacity-80" + item.disabled && "cursor-not-allowed opacity-80", + (item.href === pathname) && "text-purple-600" )} > {item.title} From cf27ca4b789d29d4de26664d3919a5e9d0afc879 Mon Sep 17 00:00:00 2001 From: Maxime Kubik <50140834+mkubdev@users.noreply.github.com> Date: Mon, 25 Sep 2023 16:14:34 +0200 Subject: [PATCH 2/2] fix: Update src/components/main-nav.tsx --- src/components/main-nav.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/main-nav.tsx b/src/components/main-nav.tsx index c16dd0c4..abeb09c7 100644 --- a/src/components/main-nav.tsx +++ b/src/components/main-nav.tsx @@ -7,7 +7,7 @@ import { NavItem } from "@/types/nav"; import Image from "next/image"; import Link from "next/link"; import { usePathname } from 'next/navigation'; -import { useEffect,useRef,useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { BiMenuAltRight } from "react-icons/bi"; import { MdOutlineClose } from "react-icons/md"; import { ThemeToggle } from "./theme-toggle";