src/components/nav/NavOffcanvas.astro
---
/**
* NavOffcanvas
* Navigatie met offcanvas zijpaneel op mobiel en desktop.
*/
interface Props {
logo: string;
links: { label: string; href: string; active?: boolean; icon?: string }[];
cta?: { label: string; href: string };
}
const { logo, links, cta } = Astro.props;
---
<header class="noc" id="noc">
<nav class="noc-inner">
<button class="noc-burger" id="noc-burger" aria-label="Menu">
<span></span><span></span><span></span>
</button>
<a href="/" class="noc-logo">{logo}</a>
{cta && <a href={cta.href} class="noc-cta">{cta.label}</a>}
</nav>
</header>
<div class="noc-backdrop" id="noc-backdrop"></div>
<aside class="noc-panel" id="noc-panel" aria-hidden="true">
<div class="noc-panel-head">
<span class="noc-panel-logo">{logo}</span>
<button class="noc-close" id="noc-close" aria-label="Sluiten">✕</button>
</div>
<ul class="noc-menu">
{links.map(l => (
<li>
<a href={l.href} class={`noc-menu-link${l.active ? ' noc-menu-link--active' : ''}`}>
{l.icon && <span class="noc-menu-icon">{l.icon}</span>}
{l.label}
</a>
</li>
))}
</ul>
</aside>
<script>
const burger = document.getElementById('noc-burger');
const close = document.getElementById('noc-close');
const panel = document.getElementById('noc-panel');
const backdrop = document.getElementById('noc-backdrop');
function open() { panel?.classList.add('noc-panel--open'); backdrop?.classList.add('noc-backdrop--show'); panel?.setAttribute('aria-hidden','false'); }
function closePanel() { panel?.classList.remove('noc-panel--open'); backdrop?.classList.remove('noc-backdrop--show'); panel?.setAttribute('aria-hidden','true'); }
burger?.addEventListener('click', open);
close?.addEventListener('click', closePanel);
backdrop?.addEventListener('click', closePanel);
</script>
<style>
.noc { background: #fff; border-bottom: 1px solid #e5e7eb; position: sticky; top: 0; z-index: 200; }
.noc-inner { max-width: 1280px; margin: 0 auto; padding: 0 1.5rem; display: flex; align-items: center; height: 60px; gap: 1rem; }
.noc-burger { background: none; border: none; cursor: pointer; display: flex; flex-direction: column; gap: 4px; padding: 4px; }
.noc-burger span { display: block; width: 20px; height: 2px; background: #0a0a0a; border-radius: 2px; }
.noc-logo { font-weight: 800; font-size: 1.0625rem; color: #0a0a0a; text-decoration: none; letter-spacing: -0.02em; flex: 1; }
.noc-cta { font-size: 0.875rem; font-weight: 600; padding: 0.5rem 1.125rem; background: var(--color-accent,#6366f1); color: #fff; border-radius: 0.5rem; text-decoration: none; }
.noc-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 299; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.noc-backdrop--show { opacity: 1; pointer-events: all; }
.noc-panel { position: fixed; top: 0; left: -320px; width: 300px; height: 100vh; background: #fff; z-index: 300; transition: left 0.35s cubic-bezier(0.4,0,0.2,1); box-shadow: 4px 0 32px rgba(0,0,0,0.1); display: flex; flex-direction: column; }
.noc-panel--open { left: 0; }
.noc-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1.5rem; border-bottom: 1px solid #f1f5f9; }
.noc-panel-logo { font-weight: 800; font-size: 1.0625rem; color: #0a0a0a; letter-spacing: -0.02em; }
.noc-close { background: none; border: none; font-size: 1.125rem; cursor: pointer; color: #6b7280; padding: 0.25rem; transition: color 0.15s; }
.noc-close:hover { color: #0a0a0a; }
.noc-menu { list-style: none; padding: 0.75rem 0.75rem; margin: 0; display: flex; flex-direction: column; gap: 0.125rem; }
.noc-menu-link { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9375rem; font-weight: 500; color: #374151; text-decoration: none; padding: 0.75rem 0.875rem; border-radius: 0.5rem; transition: all 0.15s; }
.noc-menu-link:hover, .noc-menu-link--active { background: rgba(99,102,241,0.07); color: var(--color-accent,#6366f1); }
.noc-menu-icon { font-size: 1.125rem; }
</style>
Props
| Prop | Type | Default | Beschrijving |
|---|---|---|---|
logo * | string | — | Merknaam |
links * | { label: string; href: string; active?: boolean; icon?: string }[] | — | Menu links (met optioneel emoji icon) |
cta | { label: string; href: string } | — | CTA knop |
* = verplicht