Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

steal from https://github.com/dubinc/dub/pull/2578 🥷

Steven Tey10e4a7c4dc98
diff --git a/apps/web/ui/layout/main-nav.tsx b/apps/web/ui/layout/main-nav.tsx
index ea2ff69fc3..ccfd314954 100644
--- a/apps/web/ui/layout/main-nav.tsx
+++ b/apps/web/ui/layout/main-nav.tsx
@@ -29,7 +29,6 @@ export function MainNav({
sidebar: Sidebar,
toolContent,
newsContent,
- sidebarWidth,
}: PropsWithChildren<{
sidebar: ComponentType<{
toolContent?: ReactNode;
@@ -37,7 +36,6 @@ export function MainNav({
}>;
toolContent?: ReactNode;
newsContent?: ReactNode;
- sidebarWidth?: number;
}>) {
const pathname = usePathname();
@@ -55,14 +53,7 @@ export function MainNav({
}, [pathname]);
return (
- <div
- className="min-h-screen md:grid md:grid-cols-[var(--sidebar-width,240px)_minmax(0,1fr)]"
- style={
- {
- "--sidebar-width": sidebarWidth ? `${sidebarWidth}px` : "240px",
- } as React.CSSProperties
- }
- >
+ <div className="min-h-screen md:grid md:grid-cols-[min-content_minmax(0,1fr)]">
{/* Side nav backdrop */}
<div
className={cn(
@@ -81,7 +72,7 @@ export function MainNav({
{/* Side nav */}
<div
className={cn(
- "relative h-full w-[var(--sidebar-width,240px)] max-w-full bg-neutral-200 transition-transform md:translate-x-0",
+ "relative h-full w-min max-w-full bg-neutral-200 transition-transform md:translate-x-0",
!isOpen && "-translate-x-full",
)}
>
diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
index b2b51d26ce..b92c4da8b9 100644
--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
@@ -404,9 +404,11 @@ export function AppSidebarNav({
? "userSettings"
: pathname.startsWith(`/${slug}/settings`)
? "workspaceSettings"
- : pathname.startsWith(`/${slug}/program`)
- ? "program"
- : "default";
+ : pathname.startsWith(`/${slug}/guides`)
+ ? null
+ : pathname.startsWith(`/${slug}/program`)
+ ? "program"
+ : "default";
}, [slug, pathname]);
const applicationsCount = useProgramApplicationsCount({
diff --git a/apps/web/ui/layout/sidebar/sidebar-nav.tsx b/apps/web/ui/layout/sidebar/sidebar-nav.tsx
index 32df4ebb56..d678591628 100644
--- a/apps/web/ui/layout/sidebar/sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/sidebar-nav.tsx
@@ -14,6 +14,7 @@ import Link from "next/link";
import { usePathname } from "next/navigation";
import {
ComponentType,
+ CSSProperties,
PropsWithChildren,
ReactNode,
Suspense,
@@ -58,7 +59,7 @@ export type SidebarNavGroups<T extends Record<any, any>> = (
export type SidebarNavAreas<T extends Record<any, any>> = Record<
string,
(args: T) => {
- title?: string;
+ title?: string | ReactNode;
backHref?: string;
showNews?: boolean; // show news segment – TODO: enable this for Partner Program too
hideSwitcherIcons?: boolean; // hide workspace switcher + product icons for this area
@@ -70,6 +71,10 @@ export type SidebarNavAreas<T extends Record<any, any>> = Record<
}
>;
+const SIDEBAR_WIDTH = 304;
+const SIDEBAR_GROUPS_WIDTH = 64;
+const SIDEBAR_AREAS_WIDTH = SIDEBAR_WIDTH - SIDEBAR_GROUPS_WIDTH;
+
export function SidebarNav<T extends Record<any, any>>({
groups,
areas,
@@ -82,7 +87,7 @@ export function SidebarNav<T extends Record<any, any>>({
}: {
groups: SidebarNavGroups<T>;
areas: SidebarNavAreas<T>;
- currentArea: string;
+ currentArea: string | null;
data: T;
toolContent?: ReactNode;
newsContent?: ReactNode;
@@ -90,125 +95,149 @@ export function SidebarNav<T extends Record<any, any>>({
bottom?: ReactNode;
}) {
return (
- <ClientOnly className="size-full">
- <nav className="grid size-full grid-cols-[64px_1fr]">
- <div className="flex flex-col items-center justify-between">
- <div className="flex flex-col items-center p-2">
- <div className="pb-1 pt-2">
- <Link
- href="/"
- className="block rounded-lg px-1 py-4 outline-none transition-opacity focus-visible:ring-2 focus-visible:ring-black/50"
- >
- <NavWordmark className="h-5" isInApp />
- </Link>
+ <div
+ className={cn(
+ "h-full w-[var(--sidebar-width)] transition-[width] duration-300",
+ )}
+ style={
+ {
+ "--sidebar-width": `${currentArea === null ? SIDEBAR_GROUPS_WIDTH : SIDEBAR_WIDTH}px`,
+ "--sidebar-groups-width": `${SIDEBAR_GROUPS_WIDTH}px`,
+ "--sidebar-areas-width": `${SIDEBAR_AREAS_WIDTH}px`,
+ } as CSSProperties
+ }
+ >
+ <ClientOnly className="size-full">
+ <nav className="grid size-full grid-cols-[var(--sidebar-groups-width)_1fr]">
+ <div className="flex flex-col items-center justify-between">
+ <div className="flex flex-col items-center p-2">
+ <div className="pb-1 pt-2">
+ <Link
+ href="/"
+ className="block rounded-lg px-1 py-4 outline-none transition-opacity focus-visible:ring-2 focus-visible:ring-black/50"
+ >
+ <NavWordmark className="h-5" isInApp />
+ </Link>
+ </div>
+ {(!currentArea ||
+ !areas[currentArea](data).hideSwitcherIcons) && (
+ <div className="flex flex-col gap-3">
+ {switcher}
+ {groups(data).map((group) => (
+ <NavGroupItem key={group.name} group={group} />
+ ))}
+ </div>
+ )}
</div>
- {!areas[currentArea](data).hideSwitcherIcons && (
- <div className="flex flex-col gap-3">
- {switcher}
- {groups(data).map((group) => (
- <NavGroupItem key={group.name} group={group} />
- ))}
+ <div className="flex flex-col items-center gap-3 py-3">
+ <Suspense fallback={null}>{toolContent}</Suspense>
+ <div className="flex size-12 items-center justify-center">
+ <UserDropdown />
</div>
- )}
- </div>
- <div className="flex flex-col items-center gap-3 py-3">
- <Suspense fallback={null}>{toolContent}</Suspense>
- <div className="flex size-12 items-center justify-center">
- <UserDropdown />
</div>
</div>
- </div>
- <div className="size-full overflow-hidden py-2 pr-2">
- <div className="scrollbar-hide relative flex size-full 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, showNews, direction } =
- areaConfig(data);
+ <div
+ className={cn(
+ "size-full overflow-hidden py-2 pr-2 transition-opacity duration-300",
+ 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, showNews, direction } =
+ areaConfig(data);
- const TitleContainer = backHref ? Link : "div";
+ const TitleContainer = backHref ? Link : "div";
- return (
- <Area
- key={area}
- visible={area === currentArea}
- direction={direction ?? "right"}
- >
- {title && (
- // @ts-ignore - TS can't handle the conditional Link+href
- <TitleContainer
- {...(backHref ? { 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",
- )}
+ return (
+ <Area
+ key={area}
+ visible={area === currentArea}
+ direction={direction ?? "right"}
+ >
+ {title &&
+ (typeof title === "string" ? (
+ // @ts-ignore - TS can't handle the conditional Link+href
+ <TitleContainer
+ {...(backHref ? { href: backHref } : {})}
+ className="group mb-2 flex items-center gap-3 px-3 py-2"
>
- <ChevronLeft className="size-3 [&_*]:stroke-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>
+ )}
+ {items.map((item) => (
+ <NavItem key={item.name} item={item} />
+ ))}
</div>
- )}
- <span className="text-content-emphasis text-lg font-semibold">
- {title}
- </span>
- </TitleContainer>
- )}
- <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>
- ))}
- </div>
-
- <div className="-mx-3 flex grow flex-col justify-end">
- {data.showConversionGuides && (
- <Link
- href={`/${data.slug}/guides`}
- className="m-3 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>
- {showNews && (
- <motion.div
- initial={{ opacity: 0, y: 10 }}
- animate={{ opacity: 1, y: 0 }}
- exit={{ opacity: 0, y: 10 }}
- transition={{
- duration: 0.1,
- ease: "easeInOut",
- }}
+ <div className="-mx-3 flex grow flex-col justify-end">
+ {data.showConversionGuides && (
+ <Link
+ href={`/${data.slug}/guides`}
+ className="m-3 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"
>
- {newsContent}
- </motion.div>
+ <BookOpen className="size-4" />
+ Set up conversion tracking
+ </Link>
)}
- </AnimatePresence>
- </div>
- </Area>
- );
- })}
+
+ <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>
+ </div>
+ </Area>
+ );
+ })}
+ </div>
</div>
+ {bottom && (
+ <div className="relative flex flex-col justify-end">
+ {bottom}
+ </div>
+ )}
</div>
- {bottom && (
- <div className="relative flex flex-col justify-end">{bottom}</div>
- )}
</div>
- </div>
- </nav>
- </ClientOnly>
+ </nav>
+ </ClientOnly>
+ </div>
);
}