Skip to content

Commit

Permalink
Extract header menu links (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
carletex authored Oct 12, 2023
1 parent a0eab66 commit 57fbb41
Showing 1 changed file with 52 additions and 39 deletions.
91 changes: 52 additions & 39 deletions packages/nextjs/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,57 @@ import { Bars3Icon, BugAntIcon, MagnifyingGlassIcon, SparklesIcon } from "@heroi
import { FaucetButton, RainbowKitCustomConnectButton } from "~~/components/scaffold-eth";
import { useOutsideClick } from "~~/hooks/scaffold-eth";

const NavLink = ({ href, children }: { href: string; children: React.ReactNode }) => {
interface HeaderMenuLink {
label: string;
href: string;
icon?: React.ReactNode;
}

export const menuLinks: HeaderMenuLink[] = [
{
label: "Home",
href: "/",
},
{
label: "Debug Contracts",
href: "/debug",
icon: <BugAntIcon className="h-4 w-4" />,
},
{
label: "Example UI",
href: "/example-ui",
icon: <SparklesIcon className="h-4 w-4" />,
},
{
label: "Block Explorer",
href: "/blockexplorer",
icon: <MagnifyingGlassIcon className="h-4 w-4" />,
},
];

export const HeaderMenuLinks = () => {
const router = useRouter();
const isActive = router.pathname === href;

return (
<Link
href={href}
passHref
className={`${
isActive ? "bg-secondary shadow-md" : ""
} hover:bg-secondary hover:shadow-md focus:!bg-secondary active:!text-neutral py-1.5 px-3 text-sm rounded-full gap-2 grid grid-flow-col`}
>
{children}
</Link>
<>
{menuLinks.map(({ label, href, icon }) => {
const isActive = router.pathname === href;
return (
<li key={href}>
<Link
href={href}
passHref
className={`${
isActive ? "bg-secondary shadow-md" : ""
} hover:bg-secondary hover:shadow-md focus:!bg-secondary active:!text-neutral py-1.5 px-3 text-sm rounded-full gap-2 grid grid-flow-col`}
>
{icon}
<span>{label}</span>
</Link>
</li>
);
})}
</>
);
};

Expand All @@ -34,32 +71,6 @@ export const Header = () => {
useCallback(() => setIsDrawerOpen(false), []),
);

const navLinks = (
<>
<li>
<NavLink href="/">Home</NavLink>
</li>
<li>
<NavLink href="/debug">
<BugAntIcon className="h-4 w-4" />
Debug Contracts
</NavLink>
</li>
<li>
<NavLink href="/example-ui">
<SparklesIcon className="h-4 w-4" />
Example UI
</NavLink>
</li>
<li>
<NavLink href="/blockexplorer">
<MagnifyingGlassIcon className="h-4 w-4" />
Block Explorer
</NavLink>
</li>
</>
);

return (
<div className="sticky lg:static top-0 navbar bg-base-100 min-h-0 flex-shrink-0 justify-between z-20 shadow-md shadow-secondary px-0 sm:px-2">
<div className="navbar-start w-auto lg:w-1/2">
Expand All @@ -81,7 +92,7 @@ export const Header = () => {
setIsDrawerOpen(false);
}}
>
{navLinks}
<HeaderMenuLinks />
</ul>
)}
</div>
Expand All @@ -94,7 +105,9 @@ export const Header = () => {
<span className="text-xs">Ethereum dev stack</span>
</div>
</Link>
<ul className="hidden lg:flex lg:flex-nowrap menu menu-horizontal px-1 gap-2">{navLinks}</ul>
<ul className="hidden lg:flex lg:flex-nowrap menu menu-horizontal px-1 gap-2">
<HeaderMenuLinks />
</ul>
</div>
<div className="navbar-end flex-grow mr-4">
<RainbowKitCustomConnectButton />
Expand Down

0 comments on commit 57fbb41

Please sign in to comment.