The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Improve sidebar nav UI
Steven Tey1bfd98ead646
diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsxindex 0c642d8314..e8fa57de7a 100644--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx@@ -198,7 +198,6 @@ const NAV_AREAS: SidebarNavAreas<SidebarNavData> = {pendingFraudEventsCount,pendingReferralsCount,partnerNetworkEnabled,- pathname,}) => ({title: "Partner Program",showNews,@@ -614,7 +613,7 @@ export function AppSidebarNav({include: ["folderId"],}),session: session || undefined,- showNews: pathname.startsWith(`/${slug}/program`) ? false : true,+ showNews: true,defaultProgramId: defaultProgramId || undefined,pendingPayoutsCount,applicationsCount,@@ -622,7 +621,8 @@ export function AppSidebarNav({unreadMessagesCount,pendingFraudEventsCount,pendingReferralsCount,- showConversionGuides: canTrackConversions,+ showConversionGuides:+ canTrackConversions && pathname.startsWith(`/${slug}/links`),partnerNetworkEnabled:program && program.partnerNetworkEnabledAt !== null,}}diff --git a/apps/web/ui/layout/sidebar/sidebar-nav.tsx b/apps/web/ui/layout/sidebar/sidebar-nav.tsxindex 7f30ea89f1..abc1d6d4c3 100644--- a/apps/web/ui/layout/sidebar/sidebar-nav.tsx+++ b/apps/web/ui/layout/sidebar/sidebar-nav.tsx@@ -8,6 +8,7 @@ import {Lock,NavWordmark,Tooltip,+ useScrollProgress,} from "@dub/ui";import { cn } from "@dub/utils";import { ChevronDown } from "lucide-react";@@ -21,6 +22,7 @@ import {ReactNode,Suspense,useMemo,+ useRef,useState,} from "react";import { UserDropdown } from "./user-dropdown";@@ -147,100 +149,154 @@ export function SidebarNav<T extends Record<any, any>>({currentArea === null && "opacity-0",)}>- <div className="scrollbar-hide relative flex h-full w-[calc(var(--sidebar-areas-width)-0.5rem)] flex-col overflow-y-auto overflow-x-hidden rounded-xl bg-neutral-100">- <div className="relative flex grow flex-col p-3 text-neutral-500">- <div className="relative w-full grow">- {Object.entries(areas).map(([area, areaConfig]) => {- const { title, backHref, content, direction } =- areaConfig(data);+ <SidebarAreasPanel+ areas={areas}+ data={data}+ currentArea={currentArea}+ newsContent={newsContent}+ bottom={bottom}+ />+ </div>+ </nav>+ </ClientOnly>+ </div>+ );+}++function SidebarAreasPanel<T extends Record<any, any>>({+ areas,+ data,+ currentArea,+ newsContent,+ bottom,+}: {+ areas: SidebarNavAreas<T>;+ data: T;+ currentArea: string | null;+ newsContent?: ReactNode;+ bottom?: ReactNode;+}) {+ const scrollRef = useRef<HTMLDivElement>(null);+ const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);+ const showNews = currentArea && areas[currentArea]?.(data).showNews;- const TitleContainer = backHref ? Link : "div";+ const hasOverflow = useMemo(() => {+ if (!currentArea) return false;+ const { content } = areas[currentArea](data);+ const totalItems = content.flatMap((c) => c.items).length;+ return totalItems > 10;+ }, [currentArea, areas, data]);- return (- <Area- key={area}- visible={area === currentArea}- direction={direction ?? "right"}- >- {title &&- (typeof title === "string" ? (- <TitleContainer- href={backHref ?? "#"}- className="group mb-2 flex items-center gap-3 px-3 py-2"- >- {backHref && (- <div- className={cn(- "text-content-muted bg-bg-emphasis flex size-6 items-center justify-center rounded-lg",- "group-hover:bg-bg-inverted/10 group-hover:text-content-subtle transition-[transform,background-color,color] duration-150 group-hover:-translate-x-0.5",- )}- >- <ChevronLeft className="size-3 [&_*]:stroke-2" />- </div>- )}- <span className="text-content-emphasis text-lg font-semibold">- {title}- </span>- </TitleContainer>- ) : (- title- ))}- <div className="flex flex-col gap-8">- {content.map(({ name, items }, idx) => (- <div key={idx} className="flex flex-col gap-0.5">- {name && (- <div className="mb-2 pl-3 text-sm text-neutral-500">- {name}- </div>+ return (+ <div className="flex h-full w-[calc(var(--sidebar-areas-width)-0.5rem)] flex-col rounded-xl bg-neutral-100">+ {/* Scrollable content with gradient overlay */}+ <div className="relative min-h-0 flex-1 overflow-hidden">+ <div+ ref={scrollRef}+ onScroll={updateScrollProgress}+ className={cn(+ "scrollbar-hide h-full overflow-x-hidden rounded-xl",+ hasOverflow ? "overflow-y-auto" : "overflow-hidden",+ )}+ >+ <div className="relative flex flex-col p-3 text-neutral-500">+ <div className="relative w-full grow">+ {Object.entries(areas).map(([area, areaConfig]) => {+ const { title, backHref, content, direction } =+ areaConfig(data);++ const TitleContainer = backHref ? Link : "div";++ return (+ <Area+ key={area}+ visible={area === currentArea}+ direction={direction ?? "right"}+ >+ {title &&+ (typeof title === "string" ? (+ <TitleContainer+ href={backHref ?? "#"}+ className="group mb-2 flex items-center gap-3 px-3 py-2"+ >+ {backHref && (+ <div+ className={cn(+ "text-content-muted bg-bg-emphasis flex size-6 items-center justify-center rounded-lg",+ "group-hover:bg-bg-inverted/10 group-hover:text-content-subtle transition-[transform,background-color,color] duration-150 group-hover:-translate-x-0.5",)}- {items.map((item) => (- <NavItem key={item.name} item={item} />- ))}+ >+ <ChevronLeft className="size-3 [&_*]:stroke-2" />+ </div>+ )}+ <span className="text-content-emphasis text-lg font-semibold">+ {title}+ </span>+ </TitleContainer>+ ) : (+ title+ ))}+ <div className="flex flex-col gap-8">+ {content.map(({ name, items }, idx) => (+ <div key={idx} className="flex flex-col gap-0.5">+ {name && (+ <div className="mb-2 pl-3 text-sm text-neutral-500">+ {name}</div>+ )}+ {items.map((item) => (+ <NavItem key={item.name} item={item} />))}</div>- </Area>- );- })}- </div>- </div>+ ))}+ </div>+ </Area>+ );+ })}+ </div>+ </div>+ </div>+ {/* Bottom scroll fade - shows when content overflows */}+ {hasOverflow && (+ <div+ className="pointer-events-none absolute bottom-0 left-0 z-10 h-16 w-full rounded-b-lg bg-gradient-to-t from-neutral-100 to-transparent"+ style={{ opacity: 1 - Math.pow(scrollProgress, 2) }}+ />+ )}+ </div>- {/* Fixed bottom sections */}- <div className="flex flex-col gap-2">- {data.showConversionGuides && (- <div className="px-3 pb-2">- <Link- href={`/${data.slug}/settings/analytics`}- className="flex items-center gap-2 rounded-lg bg-neutral-200/75 px-2.5 py-2 text-xs text-neutral-700 transition-colors hover:bg-neutral-200"- >- <BookOpen className="size-4" />- Set up conversion tracking- </Link>- </div>- )}+ {/* Fixed bottom sections - always visible */}+ <div className="flex flex-shrink-0 flex-col gap-2 rounded-b-xl">+ {data.showConversionGuides && (+ <div className="px-3 pb-2">+ <Link+ href={`/${data.slug}/settings/analytics`}+ className="flex items-center gap-2 rounded-lg bg-neutral-200/75 px-2.5 py-2 text-xs text-neutral-700 transition-colors hover:bg-neutral-200"+ >+ <BookOpen className="size-4" />+ Set up conversion tracking+ </Link>+ </div>+ )}- <AnimatePresence>- {currentArea && areas[currentArea](data).showNews && (- <motion.div- initial={{ opacity: 0, y: 10 }}- animate={{ opacity: 1, y: 0 }}- exit={{ opacity: 0, y: 10 }}- transition={{- duration: 0.1,- ease: "easeInOut",- }}- >- {newsContent}- </motion.div>- )}- </AnimatePresence>+ <AnimatePresence>+ {showNews && (+ <motion.div+ initial={{ opacity: 0, y: 10 }}+ animate={{ opacity: 1, y: 0 }}+ exit={{ opacity: 0, y: 10 }}+ transition={{+ duration: 0.1,+ ease: "easeInOut",+ }}+ >+ {newsContent}+ </motion.div>+ )}+ </AnimatePresence>- {bottom && <div className="flex flex-col">{bottom}</div>}- </div>- </div>- </div>- </nav>- </ClientOnly>+ {bottom && <div className="flex flex-col">{bottom}</div>}+ </div></div>);}