Archived
The cookie consent banner was fixed at bottom-0 under the z-50 BottomNav, so on mobile it was hidden. It now sits above the nav (h-16 + safe-area) and publishes its height as --cookie-banner-h, which HelpFab adds to its offset so the banner no longer covers the help button either. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
2.3 KiB
TypeScript
46 lines
2.3 KiB
TypeScript
"use client";
|
|
|
|
import React, { useEffect, useRef, useState } from "react";
|
|
import Link from "next/link";
|
|
import { Cookie } from "lucide-react";
|
|
import { getConsent, setConsent } from "@/lib/analytics";
|
|
|
|
/**
|
|
* Asks once whether we may use a cookie-like identifier to count visits (our own
|
|
* registration-funnel stats). Declining changes nothing else about the site.
|
|
*/
|
|
export function CookieConsent() {
|
|
const [show, setShow] = useState(false);
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
useEffect(() => { setShow(getConsent() === null); }, []);
|
|
// Publishes the banner's height as --cookie-banner-h so HelpFab can sit above it.
|
|
useEffect(() => {
|
|
const el = ref.current;
|
|
if (!show || !el) return;
|
|
const root = document.documentElement;
|
|
const update = () => root.style.setProperty("--cookie-banner-h", `${el.offsetHeight}px`);
|
|
update();
|
|
const ro = new ResizeObserver(update);
|
|
ro.observe(el);
|
|
return () => { ro.disconnect(); root.style.removeProperty("--cookie-banner-h"); };
|
|
}, [show]);
|
|
if (!show) return null;
|
|
const choose = (v: "accepted" | "declined") => { setConsent(v); setShow(false); };
|
|
return (
|
|
// On mobile, sit above BottomNav (fixed, h-16 + safe-area, z-50).
|
|
<div ref={ref} className="fixed bottom-[calc(4rem+env(safe-area-inset-bottom))] md:bottom-0 inset-x-0 z-40 p-3 sm:p-4 pointer-events-none" role="region" aria-label="Cookie consent">
|
|
<div className="pointer-events-auto max-w-3xl mx-auto bg-white border shadow-lg rounded-xl p-4 flex flex-col sm:flex-row sm:items-center gap-3">
|
|
<Cookie className="w-6 h-6 text-brand-600 shrink-0 hidden sm:block" />
|
|
<p className="text-sm text-gray-700 flex-1">
|
|
May we count your visit? We use our own anonymous statistics (no third-party analytics) to see how people find and register for events.{" "}
|
|
<Link href="/legal/privacy#cookies" className="text-brand-700 underline">Privacy policy</Link>
|
|
</p>
|
|
<div className="flex gap-2 shrink-0">
|
|
<button onClick={() => choose("declined")} className="px-3 py-1.5 text-sm rounded-lg border hover:bg-gray-50">No thanks</button>
|
|
<button onClick={() => choose("accepted")} className="px-3 py-1.5 text-sm rounded-lg bg-brand-600 text-white hover:bg-brand-700">Allow</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|