The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add dark mode to nav
Tim Wilson20bd0459acaa
diff --git a/packages/tailwind-config/tailwind.config.ts b/packages/tailwind-config/tailwind.config.tsindex f1265895cd..381e6d004f 100644--- a/packages/tailwind-config/tailwind.config.ts+++ b/packages/tailwind-config/tailwind.config.ts@@ -6,6 +6,7 @@ import radix from "tailwindcss-radix";const config: Config = {content: ["./src/**/*.{js,ts,jsx,tsx,mdx}"],+ darkMode: "class",future: {hoverOnlyWhenSupported: true,},diff --git a/packages/ui/src/icons/logo.tsx b/packages/ui/src/icons/logo.tsxindex 91f85dce90..39bf4497fb 100644--- a/packages/ui/src/icons/logo.tsx+++ b/packages/ui/src/icons/logo.tsx@@ -8,7 +8,7 @@ export default function Logo({ className }: { className?: string }) {viewBox="0 0 191 191"fill="none"xmlns="http://www.w3.org/2000/svg"- className={cn("h-10 w-10 text-black", className)}+ className={cn("h-10 w-10 text-black dark:text-white", className)}><g clipPath="url(#clip0_1301_107)"><path@@ -21,7 +21,13 @@ export default function Logo({ className }: { className?: string }) {</g><defs><clipPath id="clip0_1301_107">- <rect width="191" height="191" rx="95.5" fill="white" />+ <rect+ width="191"+ height="191"+ rx="95.5"+ className="text-white dark:text-black"+ fill="currentColor"+ /></clipPath></defs></svg>diff --git a/packages/ui/src/icons/logotype.tsx b/packages/ui/src/icons/logotype.tsxindex 272f297400..4c0040e3bd 100644--- a/packages/ui/src/icons/logotype.tsx+++ b/packages/ui/src/icons/logotype.tsx@@ -8,7 +8,7 @@ export default function LogoType({ className }: { className?: string }) {viewBox="0 0 834 236"fill="none"xmlns="http://www.w3.org/2000/svg"- className={cn("h-6 w-24", className)}+ className={cn("h-6 w-24 text-black dark:text-white", className)}><pathd="M266 119.5C266 181.632 215.632 232 153.5 232C91.368 232 41 181.632 41 119.5C41 57.368 91.368 7 153.5 7C215.632 7 266 57.368 266 119.5Z"@@ -30,9 +30,9 @@ export default function LogoType({ className }: { className?: string }) {fill="currentColor"/></mask>- <g mask="url(#mask0_46_2)">- <ellipse cx="153" cy="124.5" rx="58" ry="57.5" fill="white" />- <path d="M185 -10H211V181H185V-10Z" fill="white" />+ <g mask="url(#mask0_46_2)" className="text-white dark:text-black">+ <ellipse cx="153" cy="124.5" rx="58" ry="57.5" fill="currentColor" />+ <path d="M185 -10H211V181H185V-10Z" fill="currentColor" /></g><pathd="M397.25 213.75C385.25 213.75 374.833 211.083 366 205.75C357.167 200.417 350.25 192.917 345.25 183.25C340.417 173.417 338 161.917 338 148.75C338 135.417 340.5 123.75 345.5 113.75C350.5 103.583 357.583 95.6667 366.75 90C376.083 84.3333 387.083 81.5 399.75 81.5C407.583 81.5 414.833 82.9167 421.5 85.75C428.333 88.5833 433.583 92.3333 437.25 97V22H475.75V210.5H439.5L437.5 194.5C434.167 200.167 428.833 204.833 421.5 208.5C414.333 212 406.25 213.75 397.25 213.75ZM406.5 178.5C412.5 178.5 417.75 177.25 422.25 174.75C426.917 172.083 430.5 168.417 433 163.75C435.667 158.917 437 153.417 437 147.25C437 140.917 435.667 135.417 433 130.75C430.5 126.083 426.917 122.5 422.25 120C417.75 117.333 412.5 116 406.5 116C400.5 116 395.25 117.333 390.75 120C386.25 122.667 382.75 126.333 380.25 131C377.917 135.667 376.75 141.083 376.75 147.25C376.75 153.417 377.917 158.833 380.25 163.5C382.75 168.167 386.25 171.833 390.75 174.5C395.25 177.167 400.5 178.5 406.5 178.5Z"diff --git a/packages/ui/src/nav-logo.tsx b/packages/ui/src/nav-logo.tsxindex d4e8eee7c8..7fb5b386ff 100644--- a/packages/ui/src/nav-logo.tsx+++ b/packages/ui/src/nav-logo.tsx@@ -3,10 +3,11 @@import { cn } from "@dub/utils";import * as Popover from "@radix-ui/react-popover";import { Home, LayoutGrid, Type } from "lucide-react";-import { MouseEvent, useCallback, useState } from "react";+import { MouseEvent, useCallback, useContext, useState } from "react";import { toast } from "sonner";-import { Button } from "./button";+import { Button, ButtonProps } from "./button";import { Logo, LogoType } from "./icons";+import { NavContext } from "./nav";const logoSvg = `<svg width="191" height="191" viewBox="0 0 191 191" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_36_30)">@@ -63,6 +64,8 @@ export function NavLogo({isInApp?: boolean;className?: string;}) {+ const { theme } = useContext(NavContext);+const [isPopoverOpen, setIsPopoverOpen] = useState(false);const handleContextMenu = useCallback((e: MouseEvent<HTMLDivElement>) => {@@ -90,50 +93,45 @@ export function NavLogo({<Popover.ContentsideOffset={14}align="start"- className="z-50 items-center rounded-lg border border-gray-200 bg-white drop-shadow-sm"+ className={cn("z-50", theme === "dark" && "dark")}onClick={(e) => {e.stopPropagation();setIsPopoverOpen(false);}}>- <div className="grid gap-1 p-1 sm:min-w-[240px]">- <Button+ <div className="grid gap-1 rounded-lg border border-gray-200 bg-white p-1 drop-shadow-sm dark:border-white/[0.15] dark:bg-black sm:min-w-[240px]">+ <ContextMenuButtontext="Copy Logo as SVG"variant="outline"onClick={() => copy(logoSvg)}icon={<Logo className="h-4 w-4" />}- className="h-9 justify-start px-3 font-medium hover:text-gray-700"/>- <Button+ <ContextMenuButtontext="Copy Wordmark as SVG"variant="outline"onClick={() => copy(wordmarkSvg)}icon={<Type strokeWidth={2} className="h-4 w-4" />}- className="h-9 justify-start px-3 font-medium hover:text-gray-700"/>{/* TODO: Uncomment once /brand page is live */}- {/* <Button+ {/* <ContextMenuButtontext="Brand Guidelines"variant="outline"onClick={() => window.open("https://dub.co/brand", "_blank")}icon={<BoxSelect strokeWidth={2} className="h-4 w-4" />}- className="h-9 justify-start px-3 font-medium hover:text-gray-700"/> */}{isInApp ? (- <Button+ <ContextMenuButtontext="Home Page"variant="outline"onClick={() => window.open("https://dub.co", "_blank")}icon={<Home strokeWidth={2} className="h-4 w-4" />}- className="h-9 justify-start px-3 font-medium hover:text-gray-700"/>) : (- <Button+ <ContextMenuButtontext="Dashboard"variant="outline"onClick={() => window.open("https://app.dub.co", "_blank")}icon={<LayoutGrid strokeWidth={2} className="h-4 w-4" />}- className="h-9 justify-start px-3 font-medium hover:text-gray-700"/>)}</div>@@ -142,3 +140,15 @@ export function NavLogo({</Popover.Root>);}++function ContextMenuButton({ className, ...rest }: ButtonProps) {+ return (+ <Button+ className={cn(+ "h-9 justify-start px-3 font-medium hover:text-gray-700 dark:text-white/70 dark:hover:bg-white/[0.15] dark:hover:text-white",+ className,+ )}+ {...rest}+ />+ );+}diff --git a/packages/ui/src/nav.tsx b/packages/ui/src/nav.tsxindex 6f28e23f11..a111e5a196 100644--- a/packages/ui/src/nav.tsx+++ b/packages/ui/src/nav.tsx@@ -6,12 +6,17 @@ import va from "@vercel/analytics";import { ChevronDown } from "lucide-react";import Link from "next/link";import { useParams, useSelectedLayoutSegment } from "next/navigation";+import { createContext } from "react";import useSWR from "swr";import { FEATURES_LIST } from "./content";import { useScroll } from "./hooks";import { MaxWidthWrapper } from "./max-width-wrapper";import { NavLogo } from "./nav-logo";+type Theme = "light" | "dark";++export const NavContext = createContext<{ theme: Theme }>({ theme: "light" });+export const navItems = [{name: "Customers",@@ -35,7 +40,7 @@ export const navItems = [},];-export function Nav() {+export function Nav({ theme = "light" }: { theme?: Theme }) {const { domain = "dub.co" } = useParams() as { domain: string };const scrolled = useScroll(80);const selectedLayout = useSelectedLayoutSegment();@@ -48,164 +53,176 @@ export function Nav() {);return (- <div- className={cn(`sticky inset-x-0 top-0 z-30 w-full transition-all`, {- "border-b border-gray-200 bg-white/75 backdrop-blur-lg": scrolled,- "border-b border-gray-200 bg-white":- selectedLayout && HIDE_BACKGROUND_SEGMENTS.includes(selectedLayout),- })}- >- <MaxWidthWrapper>- <div className="flex h-14 items-center justify-between">- <div className="flex items-center space-x-4">- <Link- href={domain === "dub.co" ? "/" : `https://dub.co`}- {...(domain !== "dub.co" && {- onClick: () => {- va.track("Referred from custom domain", {- domain,- medium: "logo",- });- },- })}- >- <NavLogo />- </Link>- <NavigationMenuPrimitive.Root- delayDuration={0}- className="relative hidden lg:block"- >- <NavigationMenuPrimitive.List className="flex flex-row space-x-2 p-4">- <NavigationMenuPrimitive.Item>- <NavigationMenuPrimitive.Trigger className="group flex items-center space-x-2 rounded-md px-3 py-2 text-sm font-medium hover:bg-gray-100 focus:outline-none">- <p- className={cn(- "text-sm font-medium text-gray-500 transition-colors ease-out group-hover:text-black",- {- "text-black": selectedLayout === "features",- },- )}- >- Features- </p>- <ChevronDown className="h-4 w-4 transition-all group-data-[state=open]:rotate-180" />- </NavigationMenuPrimitive.Trigger>+ <NavContext.Provider value={{ theme }}>+ <div+ className={cn(+ `sticky inset-x-0 top-0 z-30 w-full transition-all`,+ theme === "dark" && "dark",+ )}+ >+ <div+ className={cn("-z-1 absolute inset-0 transition-all dark:bg-black", {+ "border-b border-gray-200 bg-white/75 backdrop-blur-lg dark:border-gray-800 dark:bg-black/75":+ scrolled,+ "border-b border-gray-200 bg-white dark:border-gray-900 dark:bg-black":+ selectedLayout &&+ HIDE_BACKGROUND_SEGMENTS.includes(selectedLayout),+ })}+ ></div>+ <MaxWidthWrapper className="relative">+ <div className="flex h-14 items-center justify-between">+ <div className="flex items-center space-x-4">+ <Link+ href={domain === "dub.co" ? "/" : `https://dub.co`}+ {...(domain !== "dub.co" && {+ onClick: () => {+ va.track("Referred from custom domain", {+ domain,+ medium: "logo",+ });+ },+ })}+ >+ <NavLogo />+ </Link>+ <NavigationMenuPrimitive.Root+ delayDuration={0}+ className="relative hidden lg:block"+ >+ <NavigationMenuPrimitive.List className="flex flex-row space-x-2 p-4">+ <NavigationMenuPrimitive.Item>+ <NavigationMenuPrimitive.Trigger className="group flex items-center space-x-2 rounded-md px-3 py-2 text-sm font-medium hover:bg-gray-100 focus:outline-none dark:hover:bg-white/10">+ <p+ className={cn(+ "text-sm font-medium text-gray-500 transition-colors ease-out group-hover:text-black dark:text-white dark:group-hover:text-white",+ {+ "text-black dark:text-white":+ selectedLayout === "features",+ },+ )}+ >+ Features+ </p>+ <ChevronDown className="h-4 w-4 text-black transition-all group-data-[state=open]:rotate-180 dark:text-white" />+ </NavigationMenuPrimitive.Trigger>- <NavigationMenuPrimitive.Content>- <div className="grid w-[32rem] grid-cols-2 gap-1 p-3">- {FEATURES_LIST.map(- ({ slug, icon: Icon, title, shortTitle }) => (- <Link- key={slug}- href={- domain === "dub.co"- ? `/${slug}`- : `https://dub.co/${slug}`- }- {...(domain !== "dub.co" && {- onClick: () => {- va.track("Referred from custom domain", {- domain,- medium: `navbar item (/${slug})`,- });- },- })}- className="rounded-lg p-3 transition-colors hover:bg-gray-100 active:bg-gray-200"- >- <div className="flex items-center space-x-2">- <Icon className="h-4 w-4 text-gray-700" />- <p className="text-sm font-medium text-gray-700">- {shortTitle}+ <NavigationMenuPrimitive.Content>+ <div className="grid w-[32rem] grid-cols-2 gap-1 p-3">+ {FEATURES_LIST.map(+ ({ slug, icon: Icon, title, shortTitle }) => (+ <Link+ key={slug}+ href={+ domain === "dub.co"+ ? `/${slug}`+ : `https://dub.co/${slug}`+ }+ {...(domain !== "dub.co" && {+ onClick: () => {+ va.track("Referred from custom domain", {+ domain,+ medium: `navbar item (/${slug})`,+ });+ },+ })}+ className="rounded-lg p-3 transition-colors hover:bg-gray-100 active:bg-gray-200 dark:hover:bg-white/[0.15] dark:active:bg-white/20"+ >+ <div className="flex items-center space-x-2">+ <Icon className="h-4 w-4 text-gray-700 dark:text-white/80" />+ <p className="text-sm font-medium text-gray-700 dark:text-white">+ {shortTitle}+ </p>+ </div>+ <p className="mt-1 line-clamp-1 text-sm text-gray-500 dark:text-white/60">+ {title}</p>- </div>- <p className="mt-1 line-clamp-1 text-sm text-gray-500">- {title}- </p>- </Link>- ),- )}- </div>- </NavigationMenuPrimitive.Content>- </NavigationMenuPrimitive.Item>-- {navItems.map(({ name, slug }) => (- <NavigationMenuPrimitive.Item key={slug} asChild>- <Link- id={`nav-${slug}`}- key={slug}- href={- domain === "dub.co"- ? `/${slug}`- : `https://dub.co/${slug}`- }- {...(domain !== "dub.co" && {- onClick: () => {- va.track("Referred from custom domain", {- domain,- medium: `navbar item (${slug})`,- });- },- })}- className={cn(- "rounded-md px-3 py-2 text-sm font-medium text-gray-500 transition-colors ease-out hover:text-black",- {- "text-black": selectedLayout === slug,- },- )}- >- {name}- </Link>+ </Link>+ ),+ )}+ </div>+ </NavigationMenuPrimitive.Content></NavigationMenuPrimitive.Item>- ))}- </NavigationMenuPrimitive.List>- <NavigationMenuPrimitive.Viewport className="data-[state=closed]:animate-scale-out-content data-[state=open]:animate-scale-in-content absolute left-0 top-full flex w-[var(--radix-navigation-menu-viewport-width)] origin-[top_center] justify-start rounded-lg border border-gray-200 bg-white shadow-lg" />- </NavigationMenuPrimitive.Root>- </div>+ {navItems.map(({ name, slug }) => (+ <NavigationMenuPrimitive.Item key={slug} asChild>+ <Link+ id={`nav-${slug}`}+ key={slug}+ href={+ domain === "dub.co"+ ? `/${slug}`+ : `https://dub.co/${slug}`+ }+ {...(domain !== "dub.co" && {+ onClick: () => {+ va.track("Referred from custom domain", {+ domain,+ medium: `navbar item (${slug})`,+ });+ },+ })}+ className={cn(+ "rounded-md px-3 py-2 text-sm font-medium text-gray-500 transition-colors ease-out hover:text-black dark:text-white dark:hover:text-white/70",+ {+ "text-black dark:text-white":+ selectedLayout === slug,+ },+ )}+ >+ {name}+ </Link>+ </NavigationMenuPrimitive.Item>+ ))}+ </NavigationMenuPrimitive.List>- <div className="hidden lg:block">- {session && Object.keys(session).length > 0 ? (- <Link- href={APP_DOMAIN}- className="animate-fade-in rounded-full border border-black bg-black px-4 py-1.5 text-sm text-white transition-all hover:bg-white hover:text-black"- >- Dashboard- </Link>- ) : !isLoading ? (- <>- <Link- href={`${APP_DOMAIN}/login`}- {...(domain !== "dub.co" && {- onClick: () => {- va.track("Referred from custom domain", {- domain,- medium: `navbar item (login)`,- });- },- })}- className="animate-fade-in rounded-full px-4 py-1.5 text-sm font-medium text-gray-500 transition-colors ease-out hover:text-black"- >- Log in- </Link>+ <NavigationMenuPrimitive.Viewport className="data-[state=closed]:animate-scale-out-content data-[state=open]:animate-scale-in-content absolute left-0 top-full flex w-[var(--radix-navigation-menu-viewport-width)] origin-[top_center] justify-start rounded-lg border border-gray-200 bg-white shadow-lg dark:border-white/[0.15] dark:bg-black" />+ </NavigationMenuPrimitive.Root>+ </div>++ <div className="hidden lg:block">+ {session && Object.keys(session).length > 0 ? (<Link- href={`${APP_DOMAIN}/register`}- {...(domain !== "dub.co" && {- onClick: () => {- va.track("Referred from custom domain", {- domain,- medium: `navbar item (signup)`,- });- },- })}- className="animate-fade-in rounded-full border border-black bg-black px-4 py-1.5 text-sm text-white transition-all hover:bg-white hover:text-black"+ href={APP_DOMAIN}+ className="animate-fade-in rounded-full border border-black bg-black px-4 py-1.5 text-sm text-white transition-all hover:bg-white hover:text-black dark:border-white dark:bg-white dark:text-black dark:hover:bg-black dark:hover:text-white">- Sign Up+ Dashboard</Link>- </>- ) : null}+ ) : !isLoading ? (+ <>+ <Link+ href={`${APP_DOMAIN}/login`}+ {...(domain !== "dub.co" && {+ onClick: () => {+ va.track("Referred from custom domain", {+ domain,+ medium: `navbar item (login)`,+ });+ },+ })}+ className="animate-fade-in rounded-full px-4 py-1.5 text-sm font-medium text-gray-500 transition-colors ease-out hover:text-black dark:text-white dark:hover:text-white/70"+ >+ Log in+ </Link>+ <Link+ href={`${APP_DOMAIN}/register`}+ {...(domain !== "dub.co" && {+ onClick: () => {+ va.track("Referred from custom domain", {+ domain,+ medium: `navbar item (signup)`,+ });+ },+ })}+ className="animate-fade-in rounded-full border border-black bg-black px-4 py-1.5 text-sm text-white transition-all hover:bg-white hover:text-black dark:border-white dark:bg-white dark:text-black dark:hover:bg-black dark:hover:text-white"+ >+ Sign Up+ </Link>+ </>+ ) : null}+ </div></div>- </div>- </MaxWidthWrapper>- </div>+ </MaxWidthWrapper>+ </div>+ </NavContext.Provider>);}