ππ» λ©κ°λ©λ΄λ κΈ°λ³Έ λ©λ΄λ₯Ό λ§μ°μ€ μ ννλ©΄ μλμ λ©λ΄ν¨λμ΄ λνλ©λλ€.
A mega menu is one where a menu panel appears below the main menu item when you select it with your mouse.
ππ» λ©κ°λ©λ΄λ₯Ό μ¬μ©νλ©΄ λ λ§μ λ§ν¬ νλͺ©μ μ¬μ©ν μ μμ΅λλ€.
Using a mega menu allows for a greater number of link items.
π λλ ν 리 ꡬ쑰 / Directory structure
tailwindcss-nextjs/
βββ app/
βββ layout.tsx
βββ page.tsx (root, /)
βββ globals.css
βββ favicon.ico
β
βββ ui/ β UI Components
β βββ page.tsx β /ui
β βββ _components/
β βββ button.tsx β Button
β βββ dropdown.tsx β Select/Dropdown
β βββ navigation/
β βββ HorizontalNavMenu.tsx β Horizontal Nav Menu
β βββ MegaMenu.tsx β Mega Menu
β
βββ megamenu/
β βββ page.tsx β /megamenu -> Main route
β βββ 2b/page.tsx -> page.tsx β /megamenu/2b
β
βββ button-css/ , button-tailwind/
βββ card-css/ , card-tailwind/
βββ form-css/ , form-tailwind/
π λ©λ΄ μ»΄ν¬λνΈ / Menu Component
βοΈ MegaMenu.tsx
1)λ©λ΄ λ°μ΄ν°(λ°°μ΄) / Menu data (array)
const MEGA_DATA = [
{
title: 'μΉ΄ν
μ½λ¦¬/Category',
id: 'category',
columns: [
{
heading: 'κ²μ/Game',
links: [
{ label: '2B', desc: 'Nier:Automata', href: '/megamenu/2b' },
{ label: '9S', desc: 'Nier:Automata', href: '/megamenu/branding' },
{ label: 'μμλͺ¨κ±΄/Arthor Morgan', desc: 'Red Dead Redemption2', href: '/megamenu/branding' },
],
},
{
heading: 'μμ
/Music',
links: [
{ label: 'Spotify', desc: 'Spotify', href: '/megamenu/web' },
{ label: 'Apple Music', desc: 'Apple Music', href: '/megamenu/ui' },
],
},
{
heading: 'κ°λ°/Development',
links: [
{ label: 'μ½νλ¦°/Kotlin', desc: 'Android', href: '/megamenu/sns' },
{ label: 'μ€μννΈ/Swift', desc: 'IOS', href: '/megamenu/seo' },
],
},
],
banner: { title: 'Freelifemakers 1.2 ', desc: 'μλ‘μ΄ UI λΌμ΄λΈλ¬λ¦¬/New UI Library', href: '/megamenu/new' },
},
{ title: 'SNS', href: 'https://freelifemakers.org', id: 'sns' },
{ title: 'μΉμ¬μ΄νΈ/website', href: 'https://freelifemakers.org', id: 'website' },
]
A.νλ©΄μ μ€μ λ‘ νμλλ λ©λ΄λΆλΆμ
λλ€.
This is the part of the menu that is actually displayed on the screen.
2)PCμ© λ©λ΄ μ λλ€. / This is the menu for PC.
{/* PC - λ©κ°λ©λ΄ λ©μΈ / Mega menu main */}
<nav className="hidden md:flex items-center h-16">
{MEGA_DATA.map((item) => (
<div
key={item.id}
className="h-16 flex items-center"
onMouseEnter={() => setOpenId(item.id)}
onMouseLeave={() => setOpenId(null)}
>
{item.columns ? (
<button className={`px-4 text-sm font-medium ${openId === item.id ? 'text-black font-bold' : 'text-gray-600'}`}>
{item.title} {openId === item.id ? 'β²' : 'βΌ'}
</button>
) : (
<Link href={item.href!} className="px-4 text-sm font-medium text-gray-600">
{item.title}
</Link>
)}
</div>
))}
</nav>
A.MEGA_DATAμ λ°μ΄ν°λ₯Ό mapν¨μλ‘ κΊΌλ΄μ μΆλ ₯ν©λλ€.(MEGA_DATA.map((item) =>)
Extract the data from MEGA_DATA using the map function and output it.
B.λ²νΌμ ν΄λ¦νλ©΄ μΌκ°ν λͺ¨μμ΄ λ°λλλ€.
Clicking the button changes the shape of the triangle.
{item.title} {openId === item.id ? 'β²' : 'βΌ'}
C.item.columsμ μ무 κ°μ΄ μμΌλ©΄ λ§ν¬κ° νμλ©λλ€.
If there are no values ββin item.columns, a link is displayed.
<Link href={item.href!} className="px-4 text-sm font-medium text-gray-600">
{item.title}
</Link>
2)PCμ© λ©λ΄ν¨λ / Menu panel for PC
{MEGA_DATA.find(i => i.id === openId)!.columns!.map((col) => (
<div key={col.heading}>
<h4 className="font-bold text-sm mb-3">{col.heading}</h4>
<div className="flex flex-col gap-3">
{col.links.map((link) => (
<Link key={link.label} href={link.href} className="group">
<div className="text-sm font-medium group-hover:text-black">{link.label}</div>
<div className="text-xs text-gray-400">{link.desc}</div>
</Link>
))}
</div>
</div>
))}
A.λ©λ΄λ₯Ό ν΄λ¦νλ©΄ λνλλ λ©λ΄ ν¨λμ
λλ€.
This is the menu panel that appears when you click the menu.
B.MEGA_DATAμ μλ μ 보λ₯Ό col.links.map((link) => (… …)λ‘ κΊΌλ΄μ νλ©΄μ μΆλ ₯ν©λλ€.
Extract the information from MEGA_DATA using col.links.map((link) => (... ...)) and display it on the screen.
3)λͺ¨λ°μΌ λ©λ΄ λ²νΌ / Mobile menu button
<button onPointerUp={() => setMobileOpen(v => !v)} className="md:hidden w-11 h-11 bg-gray-100 rounded-full">
{mobileOpen ? 'β' : 'β°'}
</button>
A.md(768px)λ³΄λ€ νλ©΄μ΄ μμμ§λ©΄ λ²νΌμ΄ λνλ©λλ€.
The button appears when the screen size becomes smaller than md(768px).
4)λͺ¨λ°μΌ λ©λ΄ ν¨λ / Mobile Menu Panel
{mobileOpen && (
<div className="md:hidden absolute top-16 left-0 w-full bg-white border-t px-6 py-6 flex flex-col gap-6 shadow-xl">
{MEGA_DATA.map(item => (
<div key={item.id}>
{item.columns ? (
<>
<div className="font-bold mb-2">{item.title}</div>
<div className="ml-4 flex flex-col gap-2">
{item.columns.flatMap(c => c.links).map(l => (
<Link key={l.label} href={l.href} onClick={() => setMobileOpen(false)} className="text-sm text-gray-600 py-1">{l.label}</Link>
))}
</div>
</>
) : (
<Link href={item.href!} onClick={() => setMobileOpen(false)} className="font-bold">{item.title}</Link>
)}
</div>
))}
</div>
)}
A.νλ©΄μ΄ 768pxλ³΄λ€ μμ κ²½μ°λ§ 보μ¬μ§κ³ λͺ¨λ°μΌ λ©λ΄ λ²νΌμ ν΄λ¦νλ©΄ νλ©΄μ 보μ¬μ§λλ€.
It is displayed only when the screen width is less than 768px, and it appears on the screen when the mobile menu button is clicked.
π λΌμ°νΈ / Route
βοΈ/megamenu
— http://localhost:3000/megamenu
import { MegaMenu } from '../ui/_components/navigation/MegaMenu'
export default function MegaMenuPage() {
return (
<>
<MegaMenu />
<main className="mx-auto max-w-6xl px-6 py-20">
<h1 className="text-4xl font-bold">Mega Menu / λ©κ°λ©λ΄</h1>
<p className="text-gray-500 mt-2">λ©λ΄μ λ§μ°μ€ μ¬λ¦¬λ©΄ λ©λ΄ ν¨λμ΄ νΌμ³μ§,PCλ²μ </p>
<p className="text-gray-500 mt-2">Hover your mouse over the menu to expand the menu panel, PC version</p>
<p className="text-gray-500 mt-1">λͺ¨λ°μΌμμλ νλ²κ±° λ©λ΄ μμ μΉ΄ν
κ³ λ¦¬λ³λ‘ νΌμ³μ§.</p>
<p className="text-gray-500 mt-1">On mobile, categories are displayed in an expandable format within the hamburger menu.</p>
</main>
</>
)
}
1) μμ μ£Όμλ₯Ό μ€νμ λ©κ°λ©λ΄λ₯Ό μ€ννλ μ½λμ
λλ€.
This is the code that triggers the mega menu when the address above is accessed.
2)Layout.tsxλ λ§λ€μ§μκ³ νμ΄μ§λ§λ€ <MegaMenu />μ½λλ₯Ό μ
λ ₯ν΄μΌν©λλ€.
You should not create a Layout.tsx file; instead, you must include the code on every page.
3)/megamenu/2b λΌμ°νΈκ° μλλ° μ΄ λΆλΆμλ λμΌνκ² <MegaMenu />μ½λκ° μμ΅λλ€.
There is a route at /megamenu/2b, which also contains the code.
1./megamenu
export default function MegaMenuPage() {
return (
<>
<MegaMenu />
<main className="mx-auto max-w-6xl px-6 py-20">
<h1 className="text-4xl font-bold">Mega Menu / λ©κ°λ©λ΄</h1>
<p className="text-gray-500 mt-2">λ©λ΄μ λ§μ°μ€ μ¬λ¦¬λ©΄ λ©λ΄ ν¨λμ΄ νΌμ³μ§,PCλ²μ </p>
<p className="text-gray-500 mt-2">Hover your mouse over the menu to expand the menu panel, PC version</p>
<p className="text-gray-500 mt-1">λͺ¨λ°μΌμμλ νλ²κ±° λ©λ΄ μμ μΉ΄ν
κ³ λ¦¬λ³λ‘ νΌμ³μ§.</p>
<p className="text-gray-500 mt-1">On mobile, categories are displayed in an expandable format within the hamburger menu.</p>
</main>
</>
)
}
2./megamenu/2b
export default function Page() {
return (
<>
<MegaMenu />
<main className="mx-auto max-w-6xl px-6 py-20">
<h1 className="text-3xl font-bold">2B</h1>
<p className="text-gray-500 mt-2">μ¬κΈ°λ /megamenu/2B νμ΄μ§.</p>
<p className="text-gray-500 mt-2">This is the /megamenu/2B page.</p>
</main>
</>
)
}
π ν μ€νΈ / Test
βοΈ PC


βοΈ Mobile


λ§ν볡μ 21μ₯ 22μ / Matthew 21: 22
“λν¬κ° κΈ°λν λμ 무μμ΄λ μ§ λ―Ώκ³ κ΅¬νλ κ²μ λ€ λ°μΌλ¦¬λΌ νμλλΌ”
“And everything you ask in prayer, believing, you will receive.”