From 2f270c7363c07ffcae4be7b0c1f9c91e78310f32 Mon Sep 17 00:00:00 2001 From: Si Taggart Date: Wed, 20 Sep 2023 11:24:16 -0700 Subject: [PATCH] fix: highlight component in nav even on new sub pages --- .../site-wrapper/sidebar/SidebarAnchor.tsx | 12 +++- .../sidebar/SidebarNavigation.tsx | 55 +++++++++++++++---- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/packages/paste-website/src/components/site-wrapper/sidebar/SidebarAnchor.tsx b/packages/paste-website/src/components/site-wrapper/sidebar/SidebarAnchor.tsx index d30cead45e..f64859e117 100644 --- a/packages/paste-website/src/components/site-wrapper/sidebar/SidebarAnchor.tsx +++ b/packages/paste-website/src/components/site-wrapper/sidebar/SidebarAnchor.tsx @@ -6,18 +6,26 @@ import {useLocationPathname} from '../../../utils/RouteUtils'; interface SidebarAnchorProps { children: NonNullable; + selected?: boolean; href: string; onClick?: () => void; } -const SidebarAnchor: React.FC> = ({children, href, onClick, ...props}) => { +const SidebarAnchor: React.FC> = ({ + children, + href, + onClick, + selected, + ...props +}) => { const pathname = useLocationPathname(); const pathnameWithoutTrailingSlash = pathname.endsWith('/') ? pathname.slice(0, -1) : pathname; + const itemSelected = selected || pathnameWithoutTrailingSlash === href; return ( {/* @ts-expect-error using nextjs passHref means that we can't satisfy the nav item href required prop */} - + {children} diff --git a/packages/paste-website/src/components/site-wrapper/sidebar/SidebarNavigation.tsx b/packages/paste-website/src/components/site-wrapper/sidebar/SidebarNavigation.tsx index 8ce6264b6b..a0aa6c9366 100644 --- a/packages/paste-website/src/components/site-wrapper/sidebar/SidebarNavigation.tsx +++ b/packages/paste-website/src/components/site-wrapper/sidebar/SidebarNavigation.tsx @@ -57,6 +57,7 @@ const NavigationDisclosure: React.FC< const SiteSidebarNavigation = (): JSX.Element => { // TODO: move to a server component in the App directory const navigationData = useNavigationContext(); + const pathname = useLocationPathname(); // take airtable feature data and mutate it into navigation data const {allPasteComponent, allPasteLayout, allPastePrimitive, allPastePattern, allPastePageTemplate} = @@ -214,6 +215,7 @@ const SiteSidebarNavigation = (): JSX.Element => { > Overview {filteredComponentSidebarItems.map(({name, slug}: {[key: string]: string}) => { + const selected = pathname.includes(`${SidebarCategoryRoutes.COMPONENTS}/${slug}`); if (name === 'Icon') { return ( { }) } > - Singleselect - + + Singleselect + + Multiselect @@ -270,8 +280,18 @@ const SiteSidebarNavigation = (): JSX.Element => { }) } > - Status Badge - Status Menu + + Status Badge + + + Status Menu + ); } @@ -289,15 +309,23 @@ const SiteSidebarNavigation = (): JSX.Element => { }) } > - Sidebar Container - + + Sidebar Container + + Sidebar Navigation ); } return ( - + {name} ); @@ -315,11 +343,14 @@ const SiteSidebarNavigation = (): JSX.Element => { } > Overview - {filteredPrimitives.map(({name, slug}: {[key: string]: string}) => ( - - {name} - - ))} + {filteredPrimitives.map(({name, slug}: {[key: string]: string}) => { + const selected = pathname.includes(`${SidebarCategoryRoutes.PRIMITIVES}/${slug}`); + return ( + + {name} + + ); + })}