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.

Add dark mode to `NavMobile`

Tim Wilson9a0ca8a903ef
diff --git a/packages/ui/src/nav-mobile.tsx b/packages/ui/src/nav-mobile.tsx
index 0b39b7bfea..f58b70be88 100644
--- a/packages/ui/src/nav-mobile.tsx
+++ b/packages/ui/src/nav-mobile.tsx
@@ -7,9 +7,9 @@ import { useParams } from "next/navigation";
import { useEffect, useState } from "react";
import useSWR from "swr";
import { FEATURES_LIST } from "./content";
-import { navItems } from "./nav";
+import { navItems, type NavTheme } from "./nav";
-export function NavMobile() {
+export function NavMobile({ theme = "light" }: { theme?: NavTheme }) {
const { domain = "dub.co" } = useParams() as { domain: string };
const [open, setOpen] = useState(false);
const [openFeatures, setOpenFeatures] = useState(false);
@@ -31,27 +31,27 @@ export function NavMobile() {
);
return (
- <>
+ <div className={cn(theme === "dark" && "dark")}>
<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 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 dark:hover:bg-white/20 dark:active:bg-white/30 lg:hidden",
open && "hover:bg-gray-100 active:bg-gray-200",
)}
>
{open ? (
- <X className="h-5 w-5 text-gray-600" />
+ <X className="h-5 w-5 text-gray-600 dark:text-white/70" />
) : (
- <Menu className="h-5 w-5 text-gray-600" />
+ <Menu className="h-5 w-5 text-gray-600 dark:text-white/70" />
)}
</button>
<nav
className={cn(
- "fixed inset-0 z-20 hidden w-full bg-white px-5 py-16 lg:hidden",
+ "fixed inset-0 z-20 hidden w-full bg-white px-5 py-16 dark:bg-black dark:text-white/70 lg:hidden",
open && "block",
)}
>
- <ul className="grid divide-y divide-gray-200">
+ <ul className="grid divide-y divide-gray-200 dark:divide-white/[0.15]">
<li className="py-3">
<button
className="flex w-full justify-between"
@@ -60,7 +60,7 @@ export function NavMobile() {
<p className="font-semibold">Features</p>
<ChevronDown
className={cn(
- "h-5 w-5 text-gray-500 transition-all",
+ "h-5 w-5 text-gray-500 transition-all dark:text-white/50",
openFeatures && "rotate-180",
)}
/>
@@ -78,7 +78,7 @@ export function NavMobile() {
onClick={() => setOpen(false)}
className="flex w-full space-x-2"
>
- <Icon className="h-5 w-5 text-gray-500" />
+ <Icon className="h-5 w-5 text-gray-500 dark:text-white/80" />
<span className="text-sm">{shortTitle}</span>
</Link>
))}
@@ -131,6 +131,6 @@ export function NavMobile() {
)}
</ul>
</nav>
- </>
+ </div>
);
}
diff --git a/packages/ui/src/nav.tsx b/packages/ui/src/nav.tsx
index bb7adaecbb..3c6bb4602f 100644
--- a/packages/ui/src/nav.tsx
+++ b/packages/ui/src/nav.tsx
@@ -13,9 +13,11 @@ import { useScroll } from "./hooks";
import { MaxWidthWrapper } from "./max-width-wrapper";
import { NavLogo } from "./nav-logo";
-type Theme = "light" | "dark";
+export type NavTheme = "light" | "dark";
-export const NavContext = createContext<{ theme: Theme }>({ theme: "light" });
+export const NavContext = createContext<{ theme: NavTheme }>({
+ theme: "light",
+});
export const navItems = [
{
@@ -40,7 +42,7 @@ export const navItems = [
},
];
-export function Nav({ theme = "light" }: { theme?: Theme }) {
+export function Nav({ theme = "light" }: { theme?: NavTheme }) {
const { domain = "dub.co" } = useParams() as { domain: string };
const scrolled = useScroll(80);
const selectedLayout = useSelectedLayoutSegment();