The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update settings nav layout
Tim Wilson531860aa3106
diff --git a/apps/web/ui/layout/settings-layout.tsx b/apps/web/ui/layout/settings-layout.tsxindex 396e833b93..bd189f1fbc 100644--- a/apps/web/ui/layout/settings-layout.tsx+++ b/apps/web/ui/layout/settings-layout.tsx@@ -2,6 +2,7 @@ import { Icon, MaxWidthWrapper } from "@dub/ui";import { cn } from "@dub/utils";import { ReactNode } from "react";import NavLink from "./settings-nav-link";+import { SettingsNavMobile } from "./settings-nav-mobile";interface Tab {name: string;@@ -9,7 +10,7 @@ interface Tab {segment: string | null;}-interface SettingsLayoutProps {+export interface SettingsLayoutProps {tabs: {group: string;tabs: Tab[];@@ -26,28 +27,41 @@ export default function SettingsLayout({return (<div className="relative min-h-[calc(100vh-16px)] bg-white"><MaxWidthWrapper className="grid items-start gap-8 py-10 lg:grid-cols-5">+ <div className="lg:hidden">+ <SettingsNavMobile tabs={tabs}>+ <Tabs tabs={tabs} />+ </SettingsNavMobile>+ </div><divclassName={cn(- "flex flex-wrap gap-4 lg:sticky lg:grid",+ "hidden flex-wrap gap-4 lg:sticky lg:flex lg:grid",tabContainerClassName,)}>- {tabs.map(({ group, tabs }) => (- <div className="flex flex-col">- {group && (- <span className="pb-2 text-sm text-gray-500">{group}</span>- )}-- {tabs.map(({ name, icon, segment }) => (- <NavLink segment={segment} icon={icon}>- {name}- </NavLink>- ))}- </div>- ))}+ <Tabs tabs={tabs} /></div><div className="grid gap-5 lg:col-span-4">{children}</div></MaxWidthWrapper></div>);}++function Tabs({ tabs }: Pick<SettingsLayoutProps, "tabs">) {+ return (+ <>+ {tabs.map(({ group, tabs }) => (+ <div className="flex flex-col gap-y-0.5">+ {group && (+ <span className="pb-1.5 text-sm text-gray-500">{group}</span>+ )}++ {tabs.map(({ name, icon, segment }) => (+ <NavLink segment={segment} icon={icon}>+ {name}+ </NavLink>+ ))}+ </div>+ ))}+ </>+ );+}diff --git a/apps/web/ui/layout/settings-nav-mobile.tsx b/apps/web/ui/layout/settings-nav-mobile.tsxnew file mode 100644index 0000000000..c880e218a2--- /dev/null+++ b/apps/web/ui/layout/settings-nav-mobile.tsx@@ -0,0 +1,62 @@+"use client";++import { Button, Popover } from "@dub/ui";+import { Menu3 } from "@dub/ui/src/icons";+import { cn } from "@dub/utils";+import { ChevronDown } from "lucide-react";+import { useSelectedLayoutSegment } from "next/navigation";+import { PropsWithChildren, useState } from "react";+import { SettingsLayoutProps } from "./settings-layout";++export function SettingsNavMobile({+ tabs,+ children,+}: PropsWithChildren<Pick<SettingsLayoutProps, "tabs">>) {+ const [openPopover, setOpenPopover] = useState(false);++ const selectedLayoutSegment = useSelectedLayoutSegment();+ // Find selected tab nested in the tabs array+ const selectedTab = tabs+ .flatMap((group) => group.tabs)+ .find((tab) => tab.segment === selectedLayoutSegment);++ const Icon = selectedTab?.icon ?? Menu3;+ const label = selectedTab?.name ?? "Menu";++ return (+ <Popover+ openPopover={openPopover}+ setOpenPopover={setOpenPopover}+ align="start"+ content={+ <div+ className="flex w-full flex-col gap-4 px-5 sm:min-w-[200px] sm:px-4 sm:py-3"+ onClick={(e) => {+ if (e.target instanceof HTMLElement && e.target.tagName === "A")+ setOpenPopover(false);+ }}+ >+ {children}+ </div>+ }+ >+ <Button+ variant="secondary"+ className="w-full hover:bg-white sm:w-auto sm:min-w-[200px] [&>div]:w-full"+ text={+ <div className="flex w-full items-center gap-2">+ <div className="relative shrink-0">+ <Icon className="h-4 w-4" />+ </div>+ <span className="grow text-left">{label}</span>+ <ChevronDown+ className={cn("h-4 w-4 text-gray-400 transition-transform", {+ "rotate-180": openPopover,+ })}+ />+ </div>+ }+ />+ </Popover>+ );+}