first commit
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
---
|
||||
import { sections, COMPANY_NAME, type Section } from "../lib/sections";
|
||||
|
||||
interface Props {
|
||||
section: Section;
|
||||
}
|
||||
|
||||
const { section } = Astro.props;
|
||||
const config = sections[section];
|
||||
const currentPath = Astro.url.pathname;
|
||||
---
|
||||
|
||||
<header class="border-b border-brand-ink/10 bg-white/80 backdrop-blur sticky top-0 z-50">
|
||||
<div class="mx-auto max-w-6xl px-4 sm:px-6 lg:px-8">
|
||||
<div class="flex h-16 items-center justify-between gap-4">
|
||||
<a href={config.homeHref} class="flex items-center gap-2 shrink-0">
|
||||
<img src="/images/place4bees-logo.png" alt="" class="h-10 w-10" />
|
||||
<span class="font-display text-xl text-brand-ink">{COMPANY_NAME}</span>
|
||||
</a>
|
||||
|
||||
<div class="hidden md:flex items-center gap-1 rounded-full bg-brand-surface p-1">
|
||||
{Object.entries(sections).map(([key, s]) => (
|
||||
<a
|
||||
href={s.homeHref}
|
||||
class:list={[
|
||||
"rounded-full px-4 py-1.5 text-sm font-semibold transition-colors",
|
||||
key === section ? "bg-brand-primary text-brand-ink" : "text-brand-text hover:text-brand-primary",
|
||||
]}
|
||||
>
|
||||
{s.label}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<nav class="hidden md:flex gap-6 items-center">
|
||||
{config.nav.map((item) => (
|
||||
<a
|
||||
href={item.href}
|
||||
class:list={[
|
||||
"text-sm font-medium hover:text-brand-primary transition-colors",
|
||||
currentPath === item.href ? "text-brand-primary" : "text-brand-text",
|
||||
]}
|
||||
>
|
||||
{item.label}
|
||||
</a>
|
||||
))}
|
||||
{section === "private" && (
|
||||
<a href="/warenkorb" class="relative inline-flex items-center hover:opacity-80 transition-opacity" aria-label="Warenkorb">
|
||||
<span class="sr-only">Warenkorb</span>
|
||||
<svg viewBox="0 0 24 24" class="h-7 w-7" aria-hidden="true">
|
||||
<ellipse cx="12" cy="5.4" rx="6.4" ry="2.1" fill="#8a5a2b" />
|
||||
<circle cx="12" cy="3.2" r="1.05" fill="#8a5a2b" />
|
||||
<path d="M5.6 7 C5.6 7 5.1 15 6.6 19 C7.4 21 16.6 21 17.4 19 C18.9 15 18.4 7 18.4 7 Z" fill="#e0a94a" stroke="#a9722a" stroke-width="0.5" />
|
||||
<rect x="5.8" y="7" width="12.4" height="2.1" rx="1" fill="#c6922f" />
|
||||
<path d="M12 21 C12 21 13 22.4 12 23.2 C11 22.4 12 21 12 21 Z" fill="#c6922f" />
|
||||
</svg>
|
||||
<span
|
||||
id="cart-badge"
|
||||
style="display:none"
|
||||
class="absolute -top-2 -right-2 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-brand-ink px-1 text-xs text-white ring-2 ring-white"
|
||||
></span>
|
||||
</a>
|
||||
)}
|
||||
</nav>
|
||||
|
||||
<button
|
||||
id="menu-toggle"
|
||||
class="md:hidden inline-flex items-center justify-center rounded-md p-2 text-brand-text"
|
||||
aria-label="Menü öffnen"
|
||||
aria-expanded="false"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<nav id="mobile-menu" class="md:hidden hidden pb-4 flex flex-col gap-3">
|
||||
<div class="flex gap-1 rounded-full bg-brand-surface p-1 mb-2">
|
||||
{Object.entries(sections).map(([key, s]) => (
|
||||
<a
|
||||
href={s.homeHref}
|
||||
class:list={[
|
||||
"flex-1 text-center rounded-full px-4 py-1.5 text-sm font-semibold transition-colors",
|
||||
key === section ? "bg-brand-primary text-brand-ink" : "text-brand-text",
|
||||
]}
|
||||
>
|
||||
{s.label}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
{config.nav.map((item) => (
|
||||
<a href={item.href} class="text-sm font-medium text-brand-text hover:text-brand-primary">
|
||||
{item.label}
|
||||
</a>
|
||||
))}
|
||||
{section === "private" && (
|
||||
<a href="/warenkorb" class="relative inline-flex items-center gap-2 text-sm font-medium text-brand-text hover:text-brand-primary">
|
||||
<svg viewBox="0 0 24 24" class="h-6 w-6 shrink-0" aria-hidden="true">
|
||||
<ellipse cx="12" cy="5.4" rx="6.4" ry="2.1" fill="#8a5a2b" />
|
||||
<circle cx="12" cy="3.2" r="1.05" fill="#8a5a2b" />
|
||||
<path d="M5.6 7 C5.6 7 5.1 15 6.6 19 C7.4 21 16.6 21 17.4 19 C18.9 15 18.4 7 18.4 7 Z" fill="#e0a94a" stroke="#a9722a" stroke-width="0.5" />
|
||||
<rect x="5.8" y="7" width="12.4" height="2.1" rx="1" fill="#c6922f" />
|
||||
<path d="M12 21 C12 21 13 22.4 12 23.2 C11 22.4 12 21 12 21 Z" fill="#c6922f" />
|
||||
</svg>
|
||||
Warenkorb
|
||||
<span
|
||||
id="cart-badge-mobile"
|
||||
style="display:none"
|
||||
class="inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-brand-ink px-1 text-xs text-white"
|
||||
></span>
|
||||
</a>
|
||||
)}
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<script>
|
||||
const toggle = document.getElementById("menu-toggle");
|
||||
const menu = document.getElementById("mobile-menu");
|
||||
toggle?.addEventListener("click", () => {
|
||||
const isHidden = menu?.classList.contains("hidden");
|
||||
menu?.classList.toggle("hidden");
|
||||
toggle.setAttribute("aria-expanded", String(isHidden));
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import { getCart } from "../lib/cart";
|
||||
import { getCartIdClient } from "../lib/cartCookie";
|
||||
|
||||
async function refreshCartBadge() {
|
||||
const badges = [
|
||||
document.getElementById("cart-badge"),
|
||||
document.getElementById("cart-badge-mobile"),
|
||||
].filter((el): el is HTMLElement => el != null);
|
||||
if (badges.length === 0) return;
|
||||
|
||||
const cartId = getCartIdClient();
|
||||
if (!cartId) {
|
||||
badges.forEach((badge) => (badge.style.display = "none"));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const cart = await getCart(cartId);
|
||||
const count = (cart.items ?? []).reduce((sum, item) => sum + item.quantity, 0);
|
||||
badges.forEach((badge) => {
|
||||
if (count > 0) {
|
||||
badge.textContent = String(count);
|
||||
badge.style.display = "inline-flex";
|
||||
} else {
|
||||
badge.style.display = "none";
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
badges.forEach((badge) => (badge.style.display = "none"));
|
||||
}
|
||||
}
|
||||
|
||||
refreshCartBadge();
|
||||
window.addEventListener("cart:updated", refreshCartBadge);
|
||||
</script>
|
||||
Reference in New Issue
Block a user