Heritage, Bold, Community and Clean drawing all 26 section variants with their headers, homepage order and style settings; colours made safe (WCAG AA) by the backend; fonts and corners from the shared brand style. Publishing into numbered versions, the content API with live messages and events and the church profile from Accounts, uploads, every page kind, simple event pages, Coming soon, 404, sitemap, SEO basics and the church's JSON-LD. The demo church (npm run demo) and Playwright e2e: every template's pages pass axe and the SEO checks. website.sh builds packages/seo. Decision 17 (first Owner) recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
133 lines
6.0 KiB
TypeScript
133 lines
6.0 KiB
TypeScript
/**
|
|
* Each template's header (WEBSITE-1.0-PLAN §3, "Headers"), with its options from the Header style
|
|
* setting. Every header collapses to a Menu button on phones (a <details>, so it works without
|
|
* JavaScript). Links to the church's other sites (Events, App) sit next to the pages (§9).
|
|
*/
|
|
import Link from "next/link";
|
|
import { productLinks } from "@crosscode/ui";
|
|
import { ScrollSolid } from "./ScrollSolid";
|
|
import { cx } from "./parts";
|
|
import type { Published } from "./types";
|
|
|
|
type Item = { label: string; href: string; current: boolean };
|
|
|
|
function items(site: Published, path: string): { nav: Item[]; visit: Item | null } {
|
|
const pages = site.snapshot.pages;
|
|
const nav: Item[] = pages.filter((p) => p.inNav).map((p) => ({ label: p.navLabel, href: p.path, current: p.path === path }));
|
|
for (const l of site.church ? productLinks(site.church.links, "website") : []) nav.push({ label: l.label, href: l.href, current: false });
|
|
const v = pages.find((p) => p.kind === "visit");
|
|
return { nav, visit: v ? { label: v.navLabel, href: v.path, current: v.path === path } : null };
|
|
}
|
|
|
|
function Brand({ site, className, light }: { site: Published; className?: string; light?: boolean }) {
|
|
const church = site.church;
|
|
const name = church?.name ?? "Home";
|
|
return (
|
|
<Link href="/" className={cx("inline-flex items-center gap-3 no-underline", className)} aria-label={`${name}, home`}>
|
|
{church?.branding.logoUrl
|
|
? <img src={church.branding.logoUrl} alt="" className={cx("h-10 w-auto max-w-[12rem] object-contain", light && "brightness-0 invert")} />
|
|
: <span className="font-heading text-xl font-semibold">{name}</span>}
|
|
</Link>
|
|
);
|
|
}
|
|
|
|
function Links({ nav, className, linkClass }: { nav: Item[]; className?: string; linkClass?: string }) {
|
|
return (
|
|
<ul className={className}>
|
|
{nav.map((n) => (
|
|
<li key={n.href}>
|
|
<a href={n.href} aria-current={n.current ? "page" : undefined} className={cx("no-underline hover:underline underline-offset-8", n.current && "underline", linkClass)}>{n.label}</a>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
);
|
|
}
|
|
|
|
function MobileMenu({ nav, visit, className, always = false }: { nav: Item[]; visit: Item | null; className?: string; always?: boolean }) {
|
|
return (
|
|
<details className={cx("group relative", !always && "md:hidden", className)}>
|
|
<summary className="cursor-pointer list-none rounded-cc-sm border border-current px-3 py-1.5 text-sm font-semibold [&::-webkit-details-marker]:hidden">Menu</summary>
|
|
<nav aria-label="Main" className="absolute right-0 z-50 mt-2 w-64 rounded-cc bg-white p-4 text-gray-900 shadow-xl">
|
|
<Links nav={nav} className="space-y-3 text-base" />
|
|
{visit && <a href={visit.href} className="cc-btn mt-4 w-full">{visit.label}</a>}
|
|
</nav>
|
|
</details>
|
|
);
|
|
}
|
|
|
|
export function Header({ site, path }: { site: Published; path: string }) {
|
|
const { template, style } = site.snapshot.design;
|
|
const { nav, visit } = items(site, path);
|
|
const option = style.header;
|
|
|
|
if (template === "heritage") {
|
|
const nextService = site.church?.serviceTimes[0];
|
|
return (
|
|
<header className="bg-white">
|
|
{option === "centred-top-bar" && (nextService || visit) && (
|
|
<div className="bg-brand text-sm text-brand-on">
|
|
<div className="cc-wrap flex items-center justify-center gap-4 py-2">
|
|
{nextService && <span>Sundays {site.church!.serviceTimes.filter((s) => s.day === "sunday").map((s) => s.time).join(" & ") || nextService.time}</span>}
|
|
{visit && <a href={visit.href} className="font-semibold underline underline-offset-4">{visit.label}</a>}
|
|
</div>
|
|
</div>
|
|
)}
|
|
<div className="cc-wrap flex flex-col items-center gap-5 py-8">
|
|
<Brand site={site} className="text-center text-2xl" />
|
|
<nav aria-label="Main" className="hidden w-full border-y border-brand-text/20 py-3 md:block">
|
|
<Links nav={nav} className="flex flex-wrap justify-center gap-x-8 gap-y-2 text-sm uppercase tracking-[0.18em]" />
|
|
</nav>
|
|
<MobileMenu nav={nav} visit={visit} />
|
|
</div>
|
|
</header>
|
|
);
|
|
}
|
|
|
|
if (template === "bold") {
|
|
const transparent = !!site.transparentHeader[path];
|
|
return (
|
|
<ScrollSolid transparent={transparent} className="sticky top-0 z-40">
|
|
<div className="cc-wrap flex items-center justify-between gap-6 py-4">
|
|
<Brand site={site} className="text-white" light={transparent} />
|
|
<nav aria-label="Main" className="hidden items-center gap-8 md:flex">
|
|
<Links nav={nav} className="flex gap-6 text-sm font-semibold uppercase tracking-wider" />
|
|
{visit && <a href={visit.href} className="cc-btn px-5 py-2 text-sm">{visit.label}</a>}
|
|
</nav>
|
|
<MobileMenu nav={nav} visit={visit} />
|
|
</div>
|
|
</ScrollSolid>
|
|
);
|
|
}
|
|
|
|
if (template === "community") {
|
|
return (
|
|
<header className={cx(option === "logo-left-tinted" ? "bg-brand-tint" : "bg-white", "border-b border-brand/10")}>
|
|
<div className="cc-wrap flex items-center justify-between gap-6 py-4">
|
|
<Brand site={site} />
|
|
<nav aria-label="Main" className="hidden items-center gap-6 md:flex">
|
|
<Links nav={nav} className="flex gap-5 font-semibold" linkClass="text-gray-800" />
|
|
{visit && <a href={visit.href} className="cc-btn px-5 py-2">{visit.label}</a>}
|
|
</nav>
|
|
<MobileMenu nav={nav} visit={visit} />
|
|
</div>
|
|
</header>
|
|
);
|
|
}
|
|
|
|
// Clean: small, logo left, text navigation (or a menu on every width).
|
|
const menuOnly = option === "small-menu";
|
|
return (
|
|
<header className="bg-white">
|
|
<div className="mx-auto flex w-full max-w-5xl items-center justify-between gap-6 px-4 py-5 sm:px-6">
|
|
<Brand site={site} className="text-lg" />
|
|
{!menuOnly && (
|
|
<nav aria-label="Main" className="hidden md:block">
|
|
<Links nav={nav} className="flex gap-6 text-sm text-gray-700" />
|
|
</nav>
|
|
)}
|
|
<MobileMenu nav={nav} visit={visit} always={menuOnly} />
|
|
</div>
|
|
</header>
|
|
);
|
|
}
|