From eee78a79d9baee783f28fb4712eb7005564b36aa Mon Sep 17 00:00:00 2001 From: Shubham Palriwala Date: Mon, 20 May 2024 20:27:18 +0530 Subject: [PATCH] fix: navbar on mobile docs for grouped features (#2658) Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com> --- apps/docs/components/Layout.tsx | 2 +- apps/docs/components/MobileNavigation.tsx | 2 +- apps/docs/components/Navigation.tsx | 61 ++++++++++++++++------- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/apps/docs/components/Layout.tsx b/apps/docs/components/Layout.tsx index ac97dcfbc4..f4cc294be2 100644 --- a/apps/docs/components/Layout.tsx +++ b/apps/docs/components/Layout.tsx @@ -32,7 +32,7 @@ export const Layout = ({
- +
diff --git a/apps/docs/components/MobileNavigation.tsx b/apps/docs/components/MobileNavigation.tsx index b63771cef7..aa51c5363a 100644 --- a/apps/docs/components/MobileNavigation.tsx +++ b/apps/docs/components/MobileNavigation.tsx @@ -90,7 +90,7 @@ const MobileNavigationDialog = ({ isOpen, close }: { isOpen: boolean; close: () - + diff --git a/apps/docs/components/Navigation.tsx b/apps/docs/components/Navigation.tsx index e2ee9f5c64..2738794b94 100644 --- a/apps/docs/components/Navigation.tsx +++ b/apps/docs/components/Navigation.tsx @@ -46,25 +46,41 @@ const NavLink = ({ active = false, isAnchorLink = false, }: { - href: string; + href?: string; children: React.ReactNode; active: boolean; isAnchorLink?: boolean; }) => { - return ( - - {children} - + const commonClasses = clsx( + "flex justify-between gap-2 py-1 pr-3 text-sm transition", + isAnchorLink ? "pl-7" : "pl-4", + active + ? "rounded-r-md bg-slate-100 text-slate-900 dark:bg-slate-800 dark:text-white" + : "text-slate-600 hover:bg-slate-100 hover:text-slate-900 dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-white" ); + + if (href) { + return ( + + {children} + + ); + } else { + return ( +
+ {children} +
+ ); + } }; const VisibleSectionHighlight = ({ group, pathname }: { group: NavGroup; pathname: string }) => { @@ -131,6 +147,7 @@ const NavigationGroup = ({ setActiveGroup, openGroups, setOpenGroups, + isMobile, }: { group: NavGroup; className?: string; @@ -138,6 +155,7 @@ const NavigationGroup = ({ setActiveGroup: (group: NavGroup | null) => void; openGroups: string[]; setOpenGroups: (groups: string[]) => void; + isMobile: boolean; }) => { const isInsideMobileNavigation = useIsInsideMobileNavigation(); const pathname = usePathname(); @@ -171,13 +189,15 @@ const NavigationGroup = ({ {group.links.map((link) => ( {link.href ? ( - + {link.title} ) : (
toggleParentTitle(link.title)}> )} - {link.children && isParentOpen(link.title) && ( + {isActiveGroup && link.children && isParentOpen(link.title) && ( ) => { +interface NavigationProps extends React.ComponentPropsWithoutRef<"nav"> { + isMobile: boolean; +} + +export const Navigation = ({ isMobile, ...props }: NavigationProps) => { const [activeGroup, setActiveGroup] = useState(navigation[0]); const [openGroups, setOpenGroups] = useState([]); @@ -237,6 +261,7 @@ export const Navigation = (props: React.ComponentPropsWithoutRef<"nav">) => { setActiveGroup={setActiveGroup} openGroups={openGroups} setOpenGroups={setOpenGroups} + isMobile={isMobile} /> ))}