mirror of
https://github.com/vercel/commerce.git
synced 2025-10-08 15:12:40 +00:00
.github
.vscode
app
components
breadcrumb
cart
grid
icons
layout
navbar
search
footer-menu.tsx
footer.tsx
product-grid-items.tsx
product
profile
banner.tsx
carousel.tsx
checkbox.tsx
label.tsx
loading-dots.tsx
logo-square.tsx
opengraph-image.tsx
price.tsx
prose.tsx
tooltip.tsx
fonts
lib
public
.env.example
.eslintrc.js
.gitignore
.nvmrc
.prettierignore
README.md
license.md
next.config.js
package.json
pnpm-lock.yaml
postcss.config.js
prettier.config.js
tailwind.config.js
tsconfig.json
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
'use client';
|
|
|
|
import clsx from 'clsx';
|
|
import { Menu } from 'lib/shopify/types';
|
|
import Link from 'next/link';
|
|
import { usePathname } from 'next/navigation';
|
|
import { useEffect, useState } from 'react';
|
|
|
|
const FooterMenuItem = ({ item }: { item: Menu }) => {
|
|
const pathname = usePathname();
|
|
const [active, setActive] = useState(pathname === item.path);
|
|
|
|
useEffect(() => {
|
|
setActive(pathname === item.path);
|
|
}, [pathname, item.path]);
|
|
|
|
return (
|
|
<li>
|
|
<Link
|
|
href={item.path}
|
|
className={clsx(
|
|
'block py-2 text-lg underline-offset-4 hover:underline md:inline-block md:text-sm',
|
|
{
|
|
'text-black dark:text-neutral-300': active
|
|
}
|
|
)}
|
|
>
|
|
{item.title}
|
|
</Link>
|
|
</li>
|
|
);
|
|
};
|
|
|
|
function FooterMenu({ menu }: { menu: Menu[] }) {
|
|
if (!menu.length) return null;
|
|
|
|
return (
|
|
<ul>
|
|
{menu.map((item: Menu) => {
|
|
return <FooterMenuItem key={item.title} item={item} />;
|
|
})}
|
|
</ul>
|
|
);
|
|
}
|
|
|
|
export default function FooterMenuGrid({ menu }: { menu: Menu[] }) {
|
|
if (!menu.length) return null;
|
|
|
|
return (
|
|
<nav className="ml-2 flex lg:ml-auto">
|
|
<div className="grid w-full grid-cols-2 gap-0 md:grid-cols-3 lg:gap-4">
|
|
{menu.map((item) => (
|
|
<div key={item.title}>
|
|
<span className="text-primary">{item.title}</span>
|
|
<FooterMenu menu={item.items} />
|
|
</div>
|
|
))}
|
|
</div>
|
|
</nav>
|
|
);
|
|
}
|