From b7d14be5906a8e698ab5f95963675337b0d80505 Mon Sep 17 00:00:00 2001 From: Kyle Yohler Date: Sun, 31 Aug 2025 10:02:17 -0500 Subject: [PATCH] add exclude option to navlink active indicator --- .../core/components/nav-link/nav-link.tsx | 54 +++++++++++++++---- src/features/core/hooks/use-links.ts | 3 +- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/features/core/components/nav-link/nav-link.tsx b/src/features/core/components/nav-link/nav-link.tsx index 48a6185..81918b5 100644 --- a/src/features/core/components/nav-link/nav-link.tsx +++ b/src/features/core/components/nav-link/nav-link.tsx @@ -1,6 +1,6 @@ import { Flex, Box, Text } from "@mantine/core"; import { Link, useRouterState } from "@tanstack/react-router"; -import styles from './styles.module.css'; +import styles from "./styles.module.css"; import { Icon } from "@phosphor-icons/react"; import { useMemo } from "react"; @@ -9,21 +9,55 @@ interface NavLinkProps { label: string; Icon: Icon; include?: string[]; + exclude?: string[]; } -export const NavLink = ({ href, label, Icon, include }: NavLinkProps) => { +export const NavLink = ({ + href, + label, + Icon, + include, + exclude, +}: NavLinkProps) => { const router = useRouterState(); - const isActive = useMemo(() => (router.location.pathname === href || (router.location.pathname.includes(href) && href !== '/')) || include?.includes(router.location.pathname), [router.location.pathname, href]); - + const isActive = useMemo( + () => + (!exclude?.some((e) => router.location.pathname.includes(e)) && + (router.location.pathname === href || + (router.location.pathname.includes(href) && href !== "/"))) || + include?.includes(router.location.pathname), + [router.location.pathname, href] + ); + return ( - - - - {label} + + + + {label} + - ) -} + ); +}; diff --git a/src/features/core/hooks/use-links.ts b/src/features/core/hooks/use-links.ts index d361f6e..9992fcd 100644 --- a/src/features/core/hooks/use-links.ts +++ b/src/features/core/hooks/use-links.ts @@ -17,7 +17,8 @@ export const useLinks = (userId: string | undefined, roles: string[]) => { label: 'Tournaments', href: '/tournaments', - Icon: TrophyIcon + Icon: TrophyIcon, + exclude: ['/admin/tournaments'] }, { label: 'Profile',