Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

💄 Expand mobile nav into a full screen menu (#3021)

Luke Vellaf960452ada6e
diff --git a/apps/landing/public/locales/en/common.json b/apps/landing/public/locales/en/common.json
index fad446196..7607afbfc 100644
--- a/apps/landing/public/locales/en/common.json
+++ b/apps/landing/public/locales/en/common.json
@@ -1,5 +1,6 @@
{
"blog": "Blog",
+ "close": "Close",
"compare": "Compare",
"cookiePolicy": "Cookie policy",
"discussions": "Discussions",
diff --git a/apps/landing/src/app/[locale]/(main)/layout.tsx b/apps/landing/src/app/[locale]/(main)/layout.tsx
index 5cc2c0121..e67074abe 100644
--- a/apps/landing/src/app/[locale]/(main)/layout.tsx
+++ b/apps/landing/src/app/[locale]/(main)/layout.tsx
@@ -1,15 +1,4 @@
import languages from "@rallly/languages";
-import { buttonVariants } from "@rallly/ui";
-import { Button } from "@rallly/ui/button";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuLabel,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
-} from "@rallly/ui/dropdown-menu";
-import { MenuIcon } from "lucide-react";
import type { Viewport } from "next";
import { cacheLife } from "next/cache";
import Image from "next/image";
@@ -20,8 +9,8 @@ import { CtaButton } from "@/components/home/cta-button";
import { LoginButton } from "@/components/login-button";
import { LinkBase } from "@/i18n/client/link";
import { getTranslation } from "@/i18n/server";
-import { linkToApp } from "@/lib/linkToApp";
import { Footer } from "./footer";
+import { MobileMenu } from "./mobile-menu";
import { NavLink } from "./nav-link";
export async function generateStaticParams() {
@@ -86,48 +75,20 @@ export default async function Root(props: {
</CtaButton>
</div>
<div className="flex items-center justify-center lg:hidden">
- <DropdownMenu>
- <DropdownMenuTrigger
- render={
- <Button
- size="sm"
- variant="ghost"
- aria-label={t("menu", { defaultValue: "Menu" })}
- />
- }
- >
- <MenuIcon className="size-4 text-muted-foreground" />
- </DropdownMenuTrigger>
- <DropdownMenuContent
- className="w-48"
- align="end"
- sideOffset={16}
- >
- <DropdownMenuItem render={<LinkBase href="/pricing" />}>
- <Trans t={t} i18nKey="pricing" defaults="Pricing" />
- </DropdownMenuItem>
- <DropdownMenuItem render={<LinkBase href="/blog" />}>
- <Trans t={t} i18nKey="blog" />
- </DropdownMenuItem>
- <DropdownMenuItem
- render={<LinkBase href="https://support.rallly.co" />}
- >
- <Trans t={t} i18nKey="support" />
- </DropdownMenuItem>
- <DropdownMenuSeparator />
- <DropdownMenuLabel className="space-y-2">
- <LinkBase
- href={linkToApp("/login")}
- className={buttonVariants({
- variant: "default",
- className: "w-full",
- })}
- >
- <Trans t={t} i18nKey="login" defaults="Login" />
- </LinkBase>
- </DropdownMenuLabel>
- </DropdownMenuContent>
- </DropdownMenu>
+ <MobileMenu
+ links={[
+ { href: "/pricing", label: t("pricing") },
+ { href: "/blog", label: t("blog") },
+ { href: "https://support.rallly.co", label: t("support") },
+ ]}
+ menuLabel={t("menu", { defaultValue: "Menu" })}
+ closeLabel={t("close", { defaultValue: "Close" })}
+ loginLabel={t("login", { defaultValue: "Login" })}
+ ctaLabel={t("createAPoll", {
+ ns: "home",
+ defaultValue: "Create a poll",
+ })}
+ />
</div>
</div>
</div>
diff --git a/apps/landing/src/app/[locale]/(main)/mobile-menu.tsx b/apps/landing/src/app/[locale]/(main)/mobile-menu.tsx
new file mode 100644
index 000000000..b57f1e194
--- /dev/null
+++ b/apps/landing/src/app/[locale]/(main)/mobile-menu.tsx
@@ -0,0 +1,136 @@
+"use client";
+
+import { buttonVariants, cn } from "@rallly/ui";
+import { Button } from "@rallly/ui/button";
+import { MenuIcon, XIcon } from "lucide-react";
+import { usePathname } from "next/navigation";
+import React from "react";
+import { CtaButton } from "@/components/home/cta-button";
+import { LinkBase } from "@/i18n/client/link";
+import { linkToApp } from "@/lib/linkToApp";
+
+const PANEL_ID = "mobile-menu-panel";
+// Matches the `lg:hidden` on the panel below. Tailwind's default `lg`.
+const DESKTOP_MEDIA_QUERY = "(min-width: 1024px)";
+
+export const MobileMenu = ({
+ links,
+ menuLabel,
+ closeLabel,
+ loginLabel,
+ ctaLabel,
+}: {
+ links: { href: string; label: string }[];
+ menuLabel: string;
+ closeLabel: string;
+ loginLabel: string;
+ ctaLabel: string;
+}) => {
+ const pathname = usePathname();
+ const [open, setOpen] = React.useState(false);
+
+ // biome-ignore lint/correctness/useExhaustiveDependencies: dismiss the menu whenever navigation happens
+ React.useEffect(() => {
+ setOpen(false);
+ }, [pathname]);
+
+ React.useEffect(() => {
+ if (!open) return;
+ const mediaQuery = window.matchMedia(DESKTOP_MEDIA_QUERY);
+ if (mediaQuery.matches) {
+ setOpen(false);
+ return;
+ }
+ const onDesktop = (event: MediaQueryListEvent) => {
+ if (event.matches) setOpen(false);
+ };
+ mediaQuery.addEventListener("change", onDesktop);
+
+ const { body } = document;
+ const previous = body.style.overflow;
+ body.style.overflow = "hidden";
+
+ const onKeyDown = (event: KeyboardEvent) => {
+ if (event.key === "Escape") setOpen(false);
+ };
+ document.addEventListener("keydown", onKeyDown);
+
+ return () => {
+ body.style.overflow = previous;
+ document.removeEventListener("keydown", onKeyDown);
+ mediaQuery.removeEventListener("change", onDesktop);
+ };
+ }, [open]);
+
+ return (
+ <>
+ <Button
+ size="icon"
+ variant="ghost"
+ aria-label={open ? closeLabel : menuLabel}
+ aria-expanded={open}
+ aria-controls={PANEL_ID}
+ onClick={() => setOpen((value) => !value)}
+ >
+ <span className="relative block size-4">
+ <span
+ className={cn(
+ "absolute inset-0 flex items-center justify-center transition-all duration-200 ease-out",
+ open
+ ? "rotate-90 scale-50 opacity-0"
+ : "rotate-0 scale-100 opacity-100",
+ )}
+ >
+ <MenuIcon className="size-4 text-muted-foreground" />
+ </span>
+ <span
+ className={cn(
+ "absolute inset-0 flex items-center justify-center transition-all duration-200 ease-out",
+ open
+ ? "rotate-0 scale-100 opacity-100"
+ : "-rotate-90 scale-50 opacity-0",
+ )}
+ >
+ <XIcon className="size-4 text-muted-foreground" />
+ </span>
+ </span>
+ </Button>
+ <div
+ id={PANEL_ID}
+ hidden={!open}
+ className="absolute inset-x-0 top-full z-10 flex h-[calc(100dvh-100%)] flex-col bg-gray-100 lg:hidden"
+ >
+ <nav className="flex grow flex-col gap-1 overflow-y-auto px-4 py-8 sm:px-6">
+ {links.map((link) => (
+ <LinkBase
+ key={link.href}
+ href={link.href}
+ className="-mx-2 block rounded-lg px-2 py-3 font-normal text-3xl text-foreground tracking-tight hover:bg-gray-200 hover:no-underline"
+ >
+ {link.label}
+ </LinkBase>
+ ))}
+ </nav>
+ <div className="flex flex-col gap-3 border-t px-4 py-6 sm:px-6">
+ <LinkBase
+ href={linkToApp("/login")}
+ className={buttonVariants({
+ variant: "default",
+ size: "lg",
+ className: "w-full",
+ })}
+ >
+ {loginLabel}
+ </LinkBase>
+ <CtaButton
+ size="lg"
+ className="w-full"
+ captureEvent="landing:mobile_menu_cta_click"
+ >
+ {ctaLabel}
+ </CtaButton>
+ </div>
+ </div>
+ </>
+ );
+};