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.

improve mobile nav

Steven Tey8918d838a1d7
diff --git a/packages/ui/src/content.ts b/packages/ui/src/content.ts
index 985d3894ce..5281d6185e 100644
--- a/packages/ui/src/content.ts
+++ b/packages/ui/src/content.ts
@@ -24,40 +24,40 @@ import {
export const FEATURES_LIST = [
{
- title: "Powerful Analytics For The Modern Marketer",
- shortTitle: "Advanced Analytics",
+ title: "Advanced Analytics",
+ description: "Powerful Analytics For The Modern Marketer",
icon: ChartLine,
- slug: "features/analytics",
+ href: "/features/analytics",
},
{
- title: "Branded Links That Stand Out",
- shortTitle: "Branded Links",
+ title: "Branded Links",
+ description: "Branded Links That Stand Out",
icon: Hyperlink,
- slug: "features/branded-links",
+ href: "/features/branded-links",
},
{
- title: "Gorgeous QR codes for your links",
- shortTitle: "QR Codes",
+ title: "QR Codes",
+ description: "Gorgeous QR codes for your links",
icon: QRCode,
- slug: "features/qr-codes",
+ href: "/features/qr-codes",
},
{
- title: "Personalize Your Short Links",
- shortTitle: "Personalization",
+ title: "Personalization",
+ description: "Personalize Your Short Links",
icon: Paintbrush,
- slug: "features/personalization",
+ href: "/features/personalization",
},
{
- title: "Collaborate With Your Team",
- shortTitle: "Team Collaboration",
+ title: "Collaboration",
+ description: "Collaborate With Your Team",
icon: Users,
- slug: "features/collaboration",
+ href: "/features/collaboration",
},
{
- title: "Programmatic Link Creation",
- shortTitle: "API",
+ title: "API",
+ description: "Programmatic Link Creation",
icon: WindowSettings,
- slug: "docs/api-reference/introduction",
+ href: "/docs/api-reference/introduction",
},
];
@@ -106,27 +106,27 @@ export const SDKS = [
{
icon: Typescript,
iconClassName: "py-0.5 group-hover:text-[#3178C6]",
- name: "Typescript",
+ title: "Typescript",
href: "/solutions/typescript",
},
{
icon: Python,
iconClassName:
"py-0.5 [&_.snake]:transition-colors group-hover:[&_.snake1]:text-[#3776ab] group-hover:[&_.snake2]:text-[#ffd343]",
- name: "Python",
+ title: "Python",
href: "/solutions/python",
},
{
icon: Go,
iconClassName: "group-hover:text-[#00ACD7]",
- name: "Go",
+ title: "Go",
href: "/solutions/go",
},
{
icon: Ruby,
iconClassName:
"py-[3px] grayscale brightness-150 transition-[filter] group-hover:grayscale-0 group-hover:brightness-100",
- name: "Ruby",
+ title: "Ruby",
href: "/solutions/ruby",
},
];
@@ -134,32 +134,32 @@ export const SDKS = [
export const RESOURCES = [
{
icon: Headset,
- name: "Help Center",
+ title: "Help Center",
href: "/help",
},
{
icon: Book2,
- name: "Docs",
+ title: "Docs",
href: "/docs",
},
{
icon: Blog,
- name: "Blog",
+ title: "Blog",
href: "/blog",
},
{
icon: BulletList,
- name: "Changelog",
+ title: "Changelog",
href: "/changelog",
},
{
icon: Stars2,
- name: "Customers",
+ title: "Customers",
href: "/customers",
},
{
icon: HexadecagonStar,
- name: "Brand",
+ title: "Brand",
href: "/brand",
},
];
diff --git a/packages/ui/src/footer.tsx b/packages/ui/src/footer.tsx
index d48f033aa3..38fca5a5e5 100644
--- a/packages/ui/src/footer.tsx
+++ b/packages/ui/src/footer.tsx
@@ -13,9 +13,9 @@ import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavLogo } from "./nav-logo";
const navigation = {
- features: FEATURES_LIST.map(({ shortTitle, slug }) => ({
- name: shortTitle,
- href: `/${slug}`,
+ features: FEATURES_LIST.map(({ title, href }) => ({
+ name: title,
+ href,
})),
product: [
{ name: "Blog", href: "/blog" },
diff --git a/packages/ui/src/nav/content/product-content.tsx b/packages/ui/src/nav/content/product-content.tsx
index be5d5eb9d7..2275d3b7e5 100644
--- a/packages/ui/src/nav/content/product-content.tsx
+++ b/packages/ui/src/nav/content/product-content.tsx
@@ -16,21 +16,21 @@ export function ProductContent({ domain }: ContentProps) {
<div className="p-5">
<p className={cn(contentHeadingClassName, "mb-2")}>Features</p>
<div className="-mx-2 -mb-2 grid grid-cols-1 gap-0.5">
- {FEATURES_LIST.map(({ slug, icon, title, shortTitle }) => (
+ {FEATURES_LIST.map(({ icon, title, description, href }) => (
<ContentLinkCard
- key={slug}
- href={createHref(`/${slug}`, domain)}
+ key={href}
+ href={createHref(href, domain)}
{...(domain !== "dub.co" && {
onClick: () => {
va.track("Referred from custom domain", {
domain,
- medium: `navbar item (/${slug})`,
+ medium: `navbar item (${href})`,
});
},
})}
icon={<ContentIcon icon={icon} />}
- title={shortTitle}
- description={title}
+ title={title}
+ description={description}
/>
))}
</div>
diff --git a/packages/ui/src/nav/content/resources-content.tsx b/packages/ui/src/nav/content/resources-content.tsx
index ff36022d66..cb050c9ba3 100644
--- a/packages/ui/src/nav/content/resources-content.tsx
+++ b/packages/ui/src/nav/content/resources-content.tsx
@@ -151,7 +151,7 @@ export function ResourcesContent({ domain }: ContentProps) {
<div className="col-span-5 border-l border-gray-200 p-5 dark:border-white/20">
<p className={cn(contentHeadingClassName, "mb-2")}>Resources</p>
<div className="-mx-2 flex flex-col gap-0.5">
- {RESOURCES.map(({ icon: Icon, name, href }) => (
+ {RESOURCES.map(({ icon: Icon, title, href }) => (
<ContentLinkCard
href={createHref(href, domain)}
icon={
@@ -161,7 +161,7 @@ export function ResourcesContent({ domain }: ContentProps) {
)}
/>
}
- title={name}
+ title={title}
/>
))}
</div>
diff --git a/packages/ui/src/nav/content/solutions-content.tsx b/packages/ui/src/nav/content/solutions-content.tsx
index c635ed89bf..cdedded4d7 100644
--- a/packages/ui/src/nav/content/solutions-content.tsx
+++ b/packages/ui/src/nav/content/solutions-content.tsx
@@ -26,7 +26,7 @@ export function SolutionsContent({ domain }: ContentProps) {
<div className="border-l border-gray-200 p-5 dark:border-white/20">
<p className={cn(contentHeadingClassName, "mb-2")}>SDKs</p>
<div className="-mx-2 flex flex-col gap-0.5">
- {SDKS.map(({ icon: Icon, iconClassName, name, href }) => (
+ {SDKS.map(({ icon: Icon, iconClassName, title, href }) => (
<ContentLinkCard
key={href}
href={createHref(href, domain)}
@@ -38,7 +38,7 @@ export function SolutionsContent({ domain }: ContentProps) {
)}
/>
}
- title={name}
+ title={title}
/>
))}
</div>
diff --git a/packages/ui/src/nav/nav-mobile.tsx b/packages/ui/src/nav/nav-mobile.tsx
index 450c061d3d..5d2d238921 100644
--- a/packages/ui/src/nav/nav-mobile.tsx
+++ b/packages/ui/src/nav/nav-mobile.tsx
@@ -1,52 +1,17 @@
"use client";
import { APP_DOMAIN, cn, fetcher } from "@dub/utils";
-import { Menu, X } from "lucide-react";
+import { ChevronDown, Menu, X } from "lucide-react";
import Link from "next/link";
import { useParams } from "next/navigation";
-import { useEffect, useState } from "react";
+import { ElementType, useEffect, useState } from "react";
import useSWR from "swr";
-import { type NavTheme } from "./nav";
-
-const navItems = [
- {
- name: "Product",
- href: "/",
- },
- {
- name: "Pricing",
- href: "/pricing",
- },
- {
- name: "Help Center",
- href: "/help",
- },
- {
- name: "Docs",
- href: "/docs",
- },
- {
- name: "Blog",
- href: "/blog",
- },
- {
- name: "Changelog",
- href: "/changelog",
- },
- {
- name: "Customers",
- href: "/customers",
- },
- {
- name: "Brand",
- href: "/brand",
- },
-];
+import { AnimatedSizeContainer } from "../animated-size-container";
+import { navItems, type NavTheme } from "./nav";
export function NavMobile({ theme = "light" }: { theme?: NavTheme }) {
const { domain = "dub.co" } = useParams() as { domain: string };
const [open, setOpen] = useState(false);
-
// prevent body scroll when modal is open
useEffect(() => {
if (open) {
@@ -69,7 +34,7 @@ export function NavMobile({ theme = "light" }: { theme?: NavTheme }) {
<button
onClick={() => setOpen(!open)}
className={cn(
- "fixed right-3 top-3 z-40 rounded-full p-2 transition-colors duration-200 hover:bg-gray-200 focus:outline-none active:bg-gray-300 dark:hover:bg-white/20 dark:active:bg-white/30 lg:hidden",
+ "fixed right-3 top-3 z-40 rounded-full p-2 transition-colors duration-200 hover:bg-gray-200 focus:outline-none active:bg-gray-300 lg:hidden dark:hover:bg-white/20 dark:active:bg-white/30",
open && "hover:bg-gray-100 active:bg-gray-200",
)}
>
@@ -81,21 +46,19 @@ export function NavMobile({ theme = "light" }: { theme?: NavTheme }) {
</button>
<nav
className={cn(
- "fixed inset-0 z-20 hidden w-full bg-white px-5 py-16 dark:bg-black dark:text-white/70 lg:hidden",
- open && "animate-fade-in block",
+ "fixed inset-0 z-20 hidden w-full bg-white px-5 py-16 lg:hidden dark:bg-black dark:text-white/70",
+ open && "block",
)}
>
- <ul className="grid grid-cols-2">
- {navItems.map(({ name, href }, idx) => (
- <li key={href} className="py-3">
- <Link
- href={domain === "dub.co" ? href : `https://dub.co${href}`}
- onClick={() => setOpen(false)}
- className="flex w-full text-lg font-medium capitalize"
- >
- {name}
- </Link>
- </li>
+ <ul className="grid divide-y divide-gray-200 dark:divide-white/[0.15]">
+ {navItems.map(({ name, href, childItems }, idx) => (
+ <MobileNavItem
+ key={idx}
+ name={name}
+ href={href}
+ childItems={childItems}
+ setOpen={setOpen}
+ />
))}
{session && Object.keys(session).length > 0 ? (
@@ -133,3 +96,78 @@ export function NavMobile({ theme = "light" }: { theme?: NavTheme }) {
</div>
);
}
+
+const MobileNavItem = ({
+ name,
+ href,
+ childItems,
+ setOpen,
+}: {
+ name: string;
+ href?: string;
+ childItems?: {
+ title: string;
+ href: string;
+ icon: ElementType;
+ iconClassName?: string;
+ }[];
+ setOpen: (open: boolean) => void;
+}) => {
+ const { domain = "dub.co" } = useParams() as { domain: string };
+ const [expanded, setExpanded] = useState(false);
+
+ if (childItems) {
+ return (
+ <li className="py-3">
+ <AnimatedSizeContainer height>
+ <button
+ className="flex w-full justify-between"
+ onClick={() => setExpanded(!expanded)}
+ >
+ <p className="font-semibold">{name}</p>
+ <ChevronDown
+ className={cn(
+ "h-5 w-5 text-gray-500 transition-all dark:text-white/50",
+ expanded && "rotate-180",
+ )}
+ />
+ </button>
+ {expanded && (
+ <div className="grid gap-4 overflow-hidden py-4">
+ {childItems.map(({ title, href, icon: Icon, iconClassName }) => (
+ <Link
+ key={href}
+ href={
+ domain === "dub.co" ? `/${href}` : `https://dub.co/${href}`
+ }
+ onClick={() => setOpen(false)}
+ className="flex w-full space-x-2"
+ >
+ <Icon
+ className={cn(
+ "h-5 w-5 text-gray-500 dark:text-white/80",
+ iconClassName,
+ )}
+ />
+ <span className="text-sm">{title}</span>
+ </Link>
+ ))}
+ </div>
+ )}
+ </AnimatedSizeContainer>
+ </li>
+ );
+ }
+
+ return (
+ <li className="py-3">
+ <Link
+ href={domain === "dub.co" ? `/${href}` : `https://dub.co/${href}`}
+ onClick={() => setOpen(false)}
+ className="flex w-full font-semibold capitalize"
+ >
+ {name}
+ </Link>
+ </li>
+ );
+};
diff --git a/packages/ui/src/nav/nav.tsx b/packages/ui/src/nav/nav.tsx
index 0e1ea80eb9..9ce6ba4aa6 100644
--- a/packages/ui/src/nav/nav.tsx
+++ b/packages/ui/src/nav/nav.tsx
@@ -8,6 +8,7 @@ import Link from "next/link";
import { useParams, useSelectedLayoutSegment } from "next/navigation";
import { PropsWithChildren, createContext } from "react";
import useSWR from "swr";
+import { FEATURES_LIST, RESOURCES, SDKS } from "../content";
import { useScroll } from "../hooks";
import { MaxWidthWrapper } from "../max-width-wrapper";
import { NavLogo } from "../nav-logo";
@@ -22,15 +23,17 @@ export const NavContext = createContext<{ theme: NavTheme }>({
theme: "light",
});
-const navItems = [
+export const navItems = [
{
name: "Product",
href: "/",
content: ProductContent,
+ childItems: FEATURES_LIST,
},
{
name: "Solutions",
content: SolutionsContent,
+ childItems: SDKS,
},
{
name: "Pricing",
@@ -39,6 +42,7 @@ const navItems = [
{
name: "Resources",
content: ResourcesContent,
+ childItems: RESOURCES,
},
];