From eefe745956f5916ece2ce98092054969e9df6c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Felipe=20Gon=C3=A7alves?= Date: Sat, 2 Mar 2024 14:04:07 +0000 Subject: [PATCH] feat(header): add unique styles for active tab --- src/app/_components/header/index.tsx | 29 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/app/_components/header/index.tsx b/src/app/_components/header/index.tsx index a166e9ff..143ced5f 100644 --- a/src/app/_components/header/index.tsx +++ b/src/app/_components/header/index.tsx @@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react' import Link from 'next/link' import Image from 'next/image' +import { usePathname } from 'next/navigation' import { ToggleTheme } from './toggle-theme' import { MobileMenu } from './mobile-menu' @@ -11,6 +12,22 @@ import { Search } from './search' import signatureDark from './signature-dark.png' import signatureLight from './signature-light.png' +const MenuItem: React.FC<{ name: string; path: string }> = ({ name, path }) => { + const pathname = usePathname() + const isHome = path === '/' + const isActive = isHome ? path === pathname : pathname.startsWith(path) + + return ( + + {name} + + ) +} + export function Header() { const [scrollPosition, setScrollPosition] = useState(0) const [maxScrollValue, setMaxScrollValue] = useState(0) @@ -43,18 +60,6 @@ export function Header() { (scrollPosition / maxScrollValue) * 100 ) - const MenuItem: React.FC<{ name: string; path: string }> = ({ - name, - path - }) => ( - - {name} - - ) - return (