From 52d17b5abec975e9f39efd462fe2f89347f1f955 Mon Sep 17 00:00:00 2001 From: ManeVaishnu Date: Thu, 2 Oct 2025 21:54:35 +0530 Subject: [PATCH 1/2] feat(navbar): add smooth fade-slide dropdowns for Docs, Tools, Community --- components/navigation/NavBar.tsx | 171 +++++++++++++++++++++++-------- 1 file changed, 131 insertions(+), 40 deletions(-) diff --git a/components/navigation/NavBar.tsx b/components/navigation/NavBar.tsx index 28b6917001bb..9881affbbcff 100644 --- a/components/navigation/NavBar.tsx +++ b/components/navigation/NavBar.tsx @@ -33,11 +33,18 @@ const isMobile = isMobileDevice(); * @param {string} [props.className=''] - Additional CSS classes for styling. * @param {boolean} [props.hideLogo=false] - Indicates whether to hide the logo. */ -export default function NavBar({ className = '', hideLogo = false }: NavBarProps) { +export default function NavBar({ + className = '', + hideLogo = false, +}: NavBarProps) { const router: NextRouter = useRouter(); const { pathname, query, asPath } = router; - const [open, setOpen] = useState<'learning' | 'tooling' | 'community' | null>(null); + const [open, setOpen] = useState<'learning' | 'tooling' | 'community' | null>( + null, + ); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); + const [closeTimeout, setCloseTimeout] = useState(null); + const { i18n } = useTranslation(); /** @@ -54,7 +61,9 @@ export default function NavBar({ className = '', hideLogo = false }: NavBarProps } // Filter unique languages based on i18nPaths that include the modified pathnameWithoutLocale - const uniqueLangs = Object.keys(i18nPaths).filter((lang) => i18nPaths[lang].includes(pathnameWithoutLocale)); + const uniqueLangs = Object.keys(i18nPaths).filter((lang) => + i18nPaths[lang].includes(pathnameWithoutLocale), + ); // If no unique languages are found, default to ['en'] return uniqueLangs.length === 0 ? ['en'] : uniqueLangs; @@ -63,7 +72,7 @@ export default function NavBar({ className = '', hideLogo = false }: NavBarProps const uniqueLangs = getUniqueLangs().map((lang) => ({ key: lang, text: lang, - value: lang + value: lang, })); /** @@ -72,7 +81,10 @@ export default function NavBar({ className = '', hideLogo = false }: NavBarProps * @param {boolean} langPicker - Indicates whether the change is from the language picker. * If true, stores the language in local storage. */ - const changeLanguage = async (locale: string, langPicker: boolean): Promise => { + const changeLanguage = async ( + locale: string, + langPicker: boolean, + ): Promise => { // Verifies if the language change is from langPicker or the browser-api if (langPicker) { localStorage.setItem('i18nLang', locale); @@ -121,7 +133,10 @@ export default function NavBar({ className = '', hideLogo = false }: NavBarProps * @param {('learning' | 'tooling' | 'community' | null)} menu - The menu to show or hide. */ function showMenu(menu: 'learning' | 'tooling' | 'community' | null) { - if (open === menu) return; + if (closeTimeout) { + clearTimeout(closeTimeout); + setCloseTimeout(null); + } setOpen(menu); } @@ -145,81 +160,157 @@ export default function NavBar({ className = '', hideLogo = false }: NavBarProps return (
-
+
{!hideLogo && ( -
-
- - +
+
+ +
)} -
+