diff --git a/apps/marketing/src/components/(marketing)/header.tsx b/apps/marketing/src/components/(marketing)/header.tsx index 60d36a614..4e57387dd 100644 --- a/apps/marketing/src/components/(marketing)/header.tsx +++ b/apps/marketing/src/components/(marketing)/header.tsx @@ -13,15 +13,15 @@ import { MobileNavigation } from './mobile-navigation'; export type HeaderProps = HTMLAttributes; export const Header = ({ className, ...props }: HeaderProps) => { - const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); + const [isMobileOpen, setIsMobileOpen] = useState(false); const handleMenuToggle = () => { - setIsMobileMenuOpen(!isMobileMenuOpen); + setIsMobileOpen(!isMobileOpen); }; return (
- + isMobileOpen && handleMenuToggle()}> Documenso Logo @@ -43,8 +43,8 @@ export const Header = ({ className, ...props }: HeaderProps) => { - - + +
); }; diff --git a/apps/marketing/src/components/(marketing)/mobile-hamburger.tsx b/apps/marketing/src/components/(marketing)/mobile-hamburger.tsx index 0c23f6f1f..9b4bc93a2 100644 --- a/apps/marketing/src/components/(marketing)/mobile-hamburger.tsx +++ b/apps/marketing/src/components/(marketing)/mobile-hamburger.tsx @@ -6,19 +6,25 @@ import { Menu, X } from 'lucide-react'; import { Button } from '@documenso/ui/primitives/button'; +import { useWindowSize } from '~/hooks/use-window-size'; + export interface HamburgerMenuProps { isMenuOpen: boolean; menuToggle: () => void; } export const HamburgerMenu = ({ isMenuOpen, menuToggle }: HamburgerMenuProps) => { + const { width } = useWindowSize(); + useEffect(() => { // Update document.body.style.overflow based on the menu state - // and check that the window width is less than 768px - // if (window.innerWidth < 768) { - // document.body.style.overflow = isMenuOpen ? 'hidden' : 'auto'; - // } - }, [isMenuOpen]); + // If the window width is less than 768px, we want to prevent scrolling when the menu is open + if (width < 768 && isMenuOpen) { + document.body.style.overflow = 'hidden'; + } else { + document.body.style.overflow = 'auto'; + } + }, [isMenuOpen, width]); return (
diff --git a/apps/marketing/src/components/(marketing)/mobile-navigation.tsx b/apps/marketing/src/components/(marketing)/mobile-navigation.tsx index 88b1cdc8d..a4ea79de6 100644 --- a/apps/marketing/src/components/(marketing)/mobile-navigation.tsx +++ b/apps/marketing/src/components/(marketing)/mobile-navigation.tsx @@ -12,12 +12,48 @@ import backgroundPattern from '~/assets/background-pattern.png'; export type MobileNavigationProps = { isMenuOpen: boolean; - className?: string; + menuToggle: () => void; }; -export const MobileNavigation = ({ isMenuOpen }: MobileNavigationProps) => { +export interface MenuNavigationLinksProps { + href: string; + text: string; +} + +export const MenuNavigationLinks = [ + { + href: '/blog', + text: 'Blog', + }, + { + href: '/pricing', + text: 'Pricing', + }, + { + href: 'https://status.documenso.com', + text: 'Status', + }, + { + href: 'mailto:support@documenso.com', + text: 'Support', + }, + { + href: '/privacy', + text: 'Privacy', + }, + { + href: 'https://app.documenso.com/login', + text: 'Sign in', + }, +]; + +export const MobileNavigation = ({ isMenuOpen, menuToggle }: MobileNavigationProps) => { const shouldReduceMotion = useReducedMotion(); + const handleMenuItemClick = () => { + menuToggle(); + }; + const itemVariants: Variants = { open: { opacity: 1, @@ -71,51 +107,18 @@ export const MobileNavigation = ({ isMenuOpen }: MobileNavigationProps) => { }, }} > - - - Blog - - - - Pricing - - - - Status - - - - Support - - - - Privacy - - - - Sign in - + + {MenuNavigationLinks.map((link: MenuNavigationLinksProps) => ( + handleMenuItemClick()} + href={link.href} + className="text-4xl font-semibold text-[#8D8D8D] hover:text-[#6D6D6D]" + > + {link.text} + + ))}
@@ -147,7 +150,7 @@ export const MobileNavigation = ({ isMenuOpen }: MobileNavigationProps) => { background pattern
diff --git a/apps/marketing/src/hooks/use-window-size.ts b/apps/marketing/src/hooks/use-window-size.ts new file mode 100644 index 000000000..816703b66 --- /dev/null +++ b/apps/marketing/src/hooks/use-window-size.ts @@ -0,0 +1,35 @@ +import { useEffect, useState } from 'react'; + +// This hook is used to get the window size +// It returns an object with the width and height of the window +// Works with window resizing as well, not to be confused with isMobile from is-mobile package + +interface WindowSize { + width: number; + height: number; +} + +export function useWindowSize(): WindowSize { + const [windowSize, setWindowSize] = useState({ + width: 0, + height: 0, + }); + + const handleSize = () => { + setWindowSize({ + width: window.innerWidth, + height: window.innerHeight, + }); + }; + + useEffect(() => { + handleSize(); + window.addEventListener('resize', handleSize); + + return () => { + window.removeEventListener('resize', handleSize); + }; + }, []); + + return windowSize; +}