- docs, AGENT.md, the 16 skills, PROGRAMISTA and README use the preferred names (scripted, same list of forms); past CHANGELOG entries and the proposals in docs/dev are not rewritten - AGENT.md: 'Names: IAPL and ipal-kit' — old name, new name, state in 1.x; what is not renamed; storageNames - iapl-upgrade '→ 1.17.0', PROGRAMISTA §6 item 72, CHANGELOG 1.17.0 (draft): nothing required - env.md, doctor.md (legacy-names, storage-names), stats.md, security.md, project-starter.md, iapl-reference, iapl-setup - skill scripts read ipal-audit-skip and IPAL_IP_HEADER too; audit rule ids stay what they were - reference site: iapl(), iapl-doctor.json, iapl-* skills, storageNames: 'iapl'; INDEX.md regenerated Co-Authored-By: Claude Fable 5.2 <[email protected]>
6.3 KiB
Navigation code — Header, Footer, mobile menu
Resources of the iapl-nav skill. Rules:
node_modules/@intecion/ipal-kit/docs/agent/AGENT.md§6.8. Requires the UI primitives from../iapl-block/resources/section-code.md(CMSLink, Media).
Header and Footer (navigation globals)
Navigation, footer and company data are project globals (the model depends on the client and the country), built from the same shared fields as sections. Logo and name live in Site settings — do not duplicate them in Header.
// src/globals/Header.ts
import type { GlobalConfig } from 'payload'
import { buildLinkField, buildLinksField, rowLabel } from '@intecion/ipal-kit'
export const Header: GlobalConfig = {
slug: 'header',
access: { read: () => true },
fields: [
{
name: 'navItems',
type: 'array',
labels: { singular: 'Menu item', plural: 'Menu items' },
maxRows: 8,
admin: { initCollapsed: true, components: rowLabel('link.label', 'Menu item') },
fields: [
buildLinkField({ appearances: false }),
{
name: 'subItems', // one submenu level — we do not build deeper
type: 'array',
labels: { singular: 'Submenu item', plural: 'Submenu' },
maxRows: 10,
admin: { initCollapsed: true, components: rowLabel('link.label', 'Submenu item') },
fields: [buildLinkField({ appearances: false })],
},
],
},
buildLinksField({ maxRows: 1 }), // CTA button in the header
{
name: 'menuLabel',
type: 'text',
localized: true,
admin: { description: 'Accessible label of the mobile menu button, e.g. "Menu".' },
},
],
}
// src/globals/Footer.ts
import type { GlobalConfig } from 'payload'
import { buildLinkField, rowLabel } from '@intecion/ipal-kit'
export const Footer: GlobalConfig = {
slug: 'footer',
access: { read: () => true },
fields: [
{
name: 'columns',
type: 'array',
labels: { singular: 'Column', plural: 'Columns' },
maxRows: 4,
admin: { initCollapsed: true, components: rowLabel('heading', 'Column') },
fields: [
{ name: 'heading', type: 'text', localized: true },
{
name: 'items',
type: 'array',
labels: { singular: 'Link', plural: 'Links' },
admin: { initCollapsed: true, components: rowLabel('link.label', 'Link') },
fields: [buildLinkField({ appearances: false })],
},
],
},
{ name: 'note', type: 'textarea', localized: true }, // e.g. "All rights reserved"
],
}
- Legal links in the footer (privacy policy, cookies, terms):
await getSystemLinks(locale)fromlib/content— href and label (page title) from System pages; do not add them by hand tocolumns, do not write labels in code. - Highlighted menu item / button in a different colour = a style in the admin panel:
buildLinkField({ appearances: ['default', { label: 'Highlighted', value: 'highlight' }] })→ a class in the project. - Company data (name, address, NIP/ABN, phone) — the project's
companyglobal; the footer and JSON-LD read from it. Compute the copyright year in code (new Date().getFullYear()), take the name from the global. - Refreshing: a global changes on every page →
buildGlobalRevalidateHookinafterChange(hooks.md; it callsrevalidatePath('/', 'layout'), skips seeds/migrations andcontext.disableRevalidate;buildRevalidateHookis for collections):
// src/globals/Header.ts (and Footer, Company)
import { buildGlobalRevalidateHook } from '@intecion/ipal-kit'
import { revalidatePath } from 'next/cache'
hooks: {
afterChange: [buildGlobalRevalidateHook({ revalidatePath })],
},
The plugin resolves the menu from the global: await resolveNav(header.navItems, locale) from lib/content
→ { href, label, internal, newTab, targetProps, children }[] (dead links skipped, any
depth). This is plain data — it goes straight to the client MobileNav. Do not create lib/navigation.ts.
// src/components/layout/Header.tsx — server
import Link from 'next/link'
import type { Header as HeaderData } from '@/payload-types'
import { resolveNav } from '@/lib/content'
import { CMSLink } from '@/components/ui/CMSLink'
import { MobileNav } from './MobileNav'
export async function Header({ header, locale }: { header: HeaderData; locale: string }) {
const items = await resolveNav(header.navItems, locale)
return (
<header className="border-b">
<nav className="container flex items-center justify-between py-4">
{/* logo: Site settings → <Media> */}
<ul className="hidden gap-6 md:flex">
{items.map((item) => (
<li key={item.href}>
<Link href={item.href} {...item.targetProps}>{item.label}</Link>
</li>
))}
</ul>
{header.links?.map(({ id, link }) => <CMSLink key={id} link={link} locale={locale} />)}
<MobileNav items={items} menuLabel={header.menuLabel ?? ''} />
</nav>
</header>
)
}
// src/components/layout/MobileNav.tsx — client, open state only
'use client'
import { useState } from 'react'
import Link from 'next/link'
import type { NavItem } from '@intecion/ipal-kit' // TYPE import — does not pull in server code
export function MobileNav({ items, menuLabel }: { items: NavItem[]; menuLabel: string }) {
const [open, setOpen] = useState(false)
return (
<div className="md:hidden">
<button type="button" aria-expanded={open} aria-label={menuLabel} onClick={() => setOpen(!open)}>
<span aria-hidden>☰</span>
</button>
{open && (
<ul>
{items.map((item) => (
<li key={item.href}>
<Link href={item.href} onClick={() => setOpen(false)}>{item.label}</Link>
</li>
))}
</ul>
)}
</div>
)
}
Fetch Header/Footer in [locale]/layout.tsx (through a cached getter in
lib/) and pass them as props — the layout is the only place that assembles them.
Footer component — content inside NoSnippet (otherwise Google shows the footer address as
the description of every subpage; seo.md → "Descriptions in Google"):
import { NoSnippet } from '@intecion/ipal-kit/rsc'
<footer className="…">
<NoSnippet className="…">{/* company data, links, legal links */}</NoSnippet>
</footer>