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.

WIP new nav

Tim Wilsonc0587e17a37a
diff --git a/apps/web/app/app.dub.co/(dashboard)/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/layout.tsx
index 49d9d10504..167a50d573 100644
--- a/apps/web/app/app.dub.co/(dashboard)/layout.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/layout.tsx
@@ -23,6 +23,7 @@ export default async function Layout({ children }: { children: ReactNode }) {
</>
}
newsContent={<NewsRSC />}
+ sidebarWidth={320} // TODO: Move into MainNav once app. and partners. are unified
>
{children}
</MainNav>
diff --git a/apps/web/ui/layout/main-nav.tsx b/apps/web/ui/layout/main-nav.tsx
index a9e4e98fd4..fb1f0b9c67 100644
--- a/apps/web/ui/layout/main-nav.tsx
+++ b/apps/web/ui/layout/main-nav.tsx
@@ -29,6 +29,7 @@ export function MainNav({
sidebar: Sidebar,
toolContent,
newsContent,
+ sidebarWidth,
}: PropsWithChildren<{
sidebar: ComponentType<{
toolContent?: ReactNode;
@@ -36,6 +37,7 @@ export function MainNav({
}>;
toolContent?: ReactNode;
newsContent?: ReactNode;
+ sidebarWidth?: number;
}>) {
const pathname = usePathname();
@@ -53,7 +55,14 @@ export function MainNav({
}, [pathname]);
return (
- <div className="min-h-screen md:grid md:grid-cols-[240px_minmax(0,1fr)]">
+ <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
+ }
+ >
{/* Side nav backdrop */}
<div
className={cn(
@@ -72,23 +81,15 @@ export function MainNav({
{/* Side nav */}
<div
className={cn(
- "relative h-full w-[240px] max-w-full bg-neutral-100 transition-transform md:translate-x-0",
+ "relative h-full w-[var(--sidebar-width,240px)] max-w-full bg-neutral-200 transition-transform md:translate-x-0",
!isOpen && "-translate-x-full",
)}
>
- <div className="absolute inset-0 overflow-hidden">
- <div
- className={cn(
- "pointer-events-none absolute -left-2/3 bottom-0 aspect-square w-[140%] translate-y-1/4 rounded-full opacity-15 blur-[75px]",
- "bg-[conic-gradient(from_32deg_at_center,#855AFC_0deg,#3A8BFD_72deg,#00FFF9_144deg,#5CFF80_198deg,#EAB308_261deg,#f00_360deg)]",
- )}
- />
- </div>
<Sidebar toolContent={toolContent} newsContent={newsContent} />
</div>
</div>
- <div className="bg-neutral-100 md:pt-1.5">
- <div className="relative min-h-full bg-neutral-100 pt-px md:rounded-tl-2xl md:border md:border-b-0 md:border-r-0 md:border-neutral-200/80 md:bg-white">
+ <div className="bg-neutral-200 md:pt-1.5">
+ <div className="relative min-h-full bg-neutral-100 pt-px md:rounded-tl-2xl md:bg-white">
<SideNavContext.Provider value={{ isOpen, setIsOpen }}>
{children}
</SideNavContext.Provider>
diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
index 26befb00bd..bf14996699 100644
--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
@@ -7,10 +7,14 @@ import {
CircleInfo,
ConnectedDots,
CubeSettings,
+ Gauge6,
Gear2,
Gift,
Globe,
+ InvoiceDollar,
Key,
+ MoneyBills2,
+ Paintbrush,
Receipt2,
ShieldCheck,
Users6,
@@ -21,25 +25,55 @@ import { useSession } from "next-auth/react";
import { useParams, usePathname } from "next/navigation";
import { ReactNode, useMemo } from "react";
import UserSurveyButton from "../user-survey";
+import { Compass } from "./icons/compass";
import { ConnectedDots4 } from "./icons/connected-dots4";
import { CursorRays } from "./icons/cursor-rays";
import { Hyperlink } from "./icons/hyperlink";
import { LinesY } from "./icons/lines-y";
import { User } from "./icons/user";
-import { SidebarNav, SidebarNavAreas } from "./sidebar-nav";
+import { SidebarNav, SidebarNavAreas, SidebarNavGroups } from "./sidebar-nav";
import { Usage } from "./usage";
import { WorkspaceDropdown } from "./workspace-dropdown";
-const NAV_AREAS: SidebarNavAreas<{
+type SidebarNavData = {
slug: string;
pathname: string;
queryString: string;
defaultProgramId?: string;
session?: Session | null;
showNews?: boolean;
-}> = {
+};
+
+const NAV_GROUPS: SidebarNavGroups<SidebarNavData> = ({
+ slug,
+ pathname,
+ queryString,
+ defaultProgramId,
+}) => [
+ {
+ name: "Short Links",
+ icon: Compass,
+ href: `/${slug}/links${pathname === `/${slug}/links` ? "" : queryString}`,
+ active:
+ pathname.startsWith(`/${slug}`) &&
+ !pathname.startsWith(`/${slug}/program`),
+ },
+ ...(defaultProgramId
+ ? [
+ {
+ name: "Programs",
+ icon: ConnectedDots4,
+ href: `/${slug}/program`,
+ active: pathname.startsWith(`/${slug}/program`),
+ },
+ ]
+ : []),
+];
+
+const NAV_AREAS: SidebarNavAreas<SidebarNavData> = {
// Top-level
default: ({ slug, pathname, queryString, defaultProgramId, showNews }) => ({
+ title: "Short Links",
showSwitcher: true,
showNews,
direction: "left",
@@ -66,42 +100,51 @@ const NAV_AREAS: SidebarNavAreas<{
icon: User,
href: `/${slug}/customers`,
},
- ...(defaultProgramId
- ? [
- {
- name: "Program",
- icon: ConnectedDots4,
- href: `/${slug}/program`,
- items: [
- {
- name: "Overview",
- href: `/${slug}/program`,
- exact: true,
- },
- {
- name: "Partners",
- href: `/${slug}/program/partners`,
- },
- {
- name: "Commissions",
- href: `/${slug}/program/commissions`,
- },
- {
- name: "Payouts",
- href: `/${slug}/program/payouts?status=pending&sortBy=amount`,
- },
- {
- name: "Branding",
- href: `/${slug}/program/branding`,
- },
- {
- name: "Configuration",
- href: `/${slug}/program/settings`,
- },
- ],
- },
- ]
- : []),
+ ],
+ },
+ ],
+ }),
+
+ // Program
+ program: ({ slug, showNews }) => ({
+ title: "Program",
+ showSwitcher: true,
+ showNews,
+ direction: "left",
+ content: [
+ {
+ items: [
+ {
+ name: "Overview",
+ icon: Gauge6,
+ href: `/${slug}/program`,
+ exact: true,
+ },
+ {
+ name: "Partners",
+ icon: Users6,
+ href: `/${slug}/program/partners`,
+ },
+ {
+ name: "Commissions",
+ icon: InvoiceDollar,
+ href: `/${slug}/program/commissions`,
+ },
+ {
+ name: "Payouts",
+ icon: MoneyBills2,
+ href: `/${slug}/program/payouts?status=pending&sortBy=amount`,
+ },
+ {
+ name: "Branding",
+ icon: Paintbrush,
+ href: `/${slug}/program/branding`,
+ },
+ {
+ name: "Configuration",
+ icon: Gear2,
+ href: `/${slug}/program/settings`,
+ },
],
},
],
@@ -239,11 +282,14 @@ export function AppSidebarNav({
? "userSettings"
: pathname.startsWith(`/${slug}/settings`)
? "workspaceSettings"
- : "default";
+ : pathname.startsWith(`/${slug}/program`)
+ ? "program"
+ : "default";
}, [slug, pathname]);
return (
<SidebarNav
+ groups={NAV_GROUPS}
areas={NAV_AREAS}
currentArea={currentArea}
data={{
diff --git a/apps/web/ui/layout/sidebar/icons/compass.tsx b/apps/web/ui/layout/sidebar/icons/compass.tsx
new file mode 100644
index 0000000000..4561136d4b
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/icons/compass.tsx
@@ -0,0 +1,59 @@
+import { SVGProps, useEffect, useRef } from "react";
+
+export function Compass({
+ "data-hovered": hovered,
+ ...rest
+}: { "data-hovered"?: boolean } & SVGProps<SVGSVGElement>) {
+ const ref = useRef<SVGPathElement>(null);
+
+ useEffect(() => {
+ if (!ref.current) return;
+
+ if (hovered) {
+ ref.current.animate(
+ [
+ { transform: "rotate(0)" },
+ { transform: "rotate(20deg)" },
+ { transform: "rotate(-20deg)" },
+ { transform: "rotate(0)" },
+ ],
+ {
+ duration: 300,
+ },
+ );
+ }
+ }, [hovered]);
+
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...rest}
+ >
+ <g fill="currentColor">
+ <path
+ ref={ref}
+ d="M12.536,5.464l-1.806,4.214c-.202,.472-.578,.848-1.05,1.05l-4.214,1.806,1.806-4.214c.202-.472,.578-.848,1.05-1.05l4.214-1.806Z"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ className="[transform-box:fill-box] [transform-origin:center]"
+ />
+ <circle
+ cx="9"
+ cy="9"
+ fill="none"
+ r="7.25"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/sidebar-nav.tsx b/apps/web/ui/layout/sidebar/sidebar-nav.tsx
index ed1371e8f9..0cdd67975b 100644
--- a/apps/web/ui/layout/sidebar/sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/sidebar-nav.tsx
@@ -1,7 +1,7 @@
import { AnimatedSizeContainer, ClientOnly, Icon, NavWordmark } from "@dub/ui";
import { cn } from "@dub/utils";
import { AnimatePresence, motion } from "framer-motion";
-import { ChevronDown, ChevronLeft } from "lucide-react";
+import { ChevronDown } from "lucide-react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import {
@@ -27,6 +27,17 @@ export type NavItemType = NavItemCommon & {
items?: NavSubItemType[];
};
+export type NavGroupType = {
+ name: string;
+ icon: Icon;
+ href: string;
+ active: boolean;
+};
+
+export type SidebarNavGroups<T extends Record<any, any>> = (
+ args: T,
+) => NavGroupType[];
+
export type SidebarNavAreas<T extends Record<any, any>> = Record<
string,
(args: T) => {
@@ -43,6 +54,7 @@ export type SidebarNavAreas<T extends Record<any, any>> = Record<
>;
export function SidebarNav<T extends Record<any, any>>({
+ groups,
areas,
currentArea,
data,
@@ -51,6 +63,7 @@ export function SidebarNav<T extends Record<any, any>>({
switcher,
bottom,
}: {
+ groups: SidebarNavGroups<T>;
areas: SidebarNavAreas<T>;
currentArea: string;
data: T;
@@ -60,101 +73,114 @@ export function SidebarNav<T extends Record<any, any>>({
bottom?: ReactNode;
}) {
return (
- <ClientOnly className="scrollbar-hide relative flex h-full w-full flex-col overflow-y-auto overflow-x-hidden">
- <nav className="relative flex grow flex-col p-3 text-neutral-500">
- <div className="relative flex items-start justify-between gap-1 pb-3">
- {Object.entries(areas).map(([area, areaConfig]) => {
- const { title, backHref } = areaConfig(data);
-
- return (
- <Link
- key={area}
- href={backHref ?? "/"}
- className={cn(
- "rounded-md px-1 outline-none transition-opacity focus-visible:ring-2 focus-visible:ring-black/50",
- area === currentArea
- ? "relative opacity-100"
- : "pointer-events-none absolute opacity-0",
- (!title || !backHref) && "mb-1",
- )}
- aria-hidden={area !== currentArea ? true : undefined}
- {...{ inert: area !== currentArea ? "" : undefined }}
- >
- {title && backHref ? (
- <div className="py group -my-1 -ml-1 flex items-center gap-2 py-2 pr-1 text-sm font-medium text-neutral-900">
- <ChevronLeft className="size-4 text-neutral-500 transition-transform duration-100 group-hover:-translate-x-0.5" />
- {title}
- </div>
- ) : (
- <NavWordmark className="h-6" isInApp />
- )}
- </Link>
- );
- })}
- <div className="hidden items-center gap-3 md:flex">
- <Suspense fallback={null}>{toolContent}</Suspense>
- <UserDropdown />
+ <ClientOnly className="size-full">
+ <nav className="grid size-full grid-cols-[80px_1fr]">
+ <div className="flex flex-col items-center p-2">
+ <Link
+ href=""
+ className="rounded-md px-1 py-5 outline-none transition-opacity focus-visible:ring-2 focus-visible:ring-black/50"
+ >
+ <NavWordmark className="h-6" isInApp />
+ </Link>
+ <div className="flex flex-col gap-4">
+ {groups(data).map((group) => (
+ <NavGroupItem key={group.name} group={group} />
+ ))}
</div>
</div>
- <div className="relative w-full grow">
- {Object.entries(areas).map(([area, areaConfig]) => {
- const { content, showSwitcher, showNews, direction } =
- areaConfig(data);
- return (
- <Area
- key={area}
- visible={area === currentArea}
- direction={direction ?? "right"}
- >
- {showSwitcher && switcher && (
- <div className="pt-2">{switcher}</div>
- )}
-
- <div className="flex flex-col gap-4 pt-4">
- {content.map(({ name, items }, idx) => (
- <div key={idx} className="flex flex-col gap-0.5">
- {name && (
- <div className="mb-2 pl-1 text-sm text-neutral-500">
- {name}
- </div>
- )}
- {items.map((item) => (
- <NavItem key={item.name} item={item} />
- ))}
- </div>
- ))}
+ <div className="size-full overflow-hidden py-1.5 pr-1.5">
+ <div className="scrollbar-hide relative flex size-full flex-col overflow-y-auto overflow-x-hidden rounded-2xl bg-neutral-100">
+ <div className="relative flex grow flex-col p-3 text-neutral-500">
+ <div className="relative flex items-start justify-between gap-1 pb-3">
+ <div className="hidden items-center gap-3 md:flex">
+ <Suspense fallback={null}>{toolContent}</Suspense>
+ <UserDropdown />
</div>
+ </div>
+ <div className="relative w-full grow">
+ {Object.entries(areas).map(([area, areaConfig]) => {
+ const { content, showSwitcher, showNews, direction } =
+ areaConfig(data);
+ return (
+ <Area
+ key={area}
+ visible={area === currentArea}
+ direction={direction ?? "right"}
+ >
+ {showSwitcher && switcher && (
+ <div className="pt-2">{switcher}</div>
+ )}
- {currentArea === "default" && <CreateProgramCard />}
+ <div className="flex flex-col gap-4 pt-4">
+ {content.map(({ name, items }, idx) => (
+ <div key={idx} className="flex flex-col gap-0.5">
+ {name && (
+ <div className="mb-2 pl-1 text-sm text-neutral-500">
+ {name}
+ </div>
+ )}
+ {items.map((item) => (
+ <NavItem key={item.name} item={item} />
+ ))}
+ </div>
+ ))}
+ </div>
- <AnimatePresence>
- {showNews && (
- <motion.div
- className="-mx-3 flex grow flex-col justify-end"
- 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>
- </Area>
- );
- })}
+ {currentArea === "default" && <CreateProgramCard />}
+
+ <AnimatePresence>
+ {showNews && (
+ <motion.div
+ className="-mx-3 flex grow flex-col justify-end"
+ 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>
+ </Area>
+ );
+ })}
+ </div>
+ </div>
+ {bottom && (
+ <div className="relative flex flex-col justify-end">{bottom}</div>
+ )}
+ </div>
</div>
</nav>
- {bottom && (
- <div className="relative flex flex-col justify-end">{bottom}</div>
- )}
</ClientOnly>
);
}
+function NavGroupItem({
+ group: { name, icon: Icon, href, active },
+}: {
+ group: NavGroupType;
+}) {
+ const [hovered, setHovered] = useState(false);
+
+ return (
+ <Link
+ href={href}
+ onPointerEnter={() => setHovered(true)}
+ onPointerLeave={() => setHovered(false)}
+ className={cn(
+ "flex size-12 items-center justify-center rounded-lg transition-colors duration-150",
+ active ? "bg-white" : "hover:bg-bg-inverted/5 active:bg-bg-inverted/10",
+ )}
+ >
+ <Icon className="text-content-default size-5" data-hovered={hovered} />
+ </Link>
+ );
+}
+
function NavItem({ item }: { item: NavItemType | NavSubItemType }) {
const { name, href, exact } = item;