Site footer with newsletter
A multi-column site footer: logo and one line about the product, a newsletter form with client-side validation and a confirmation, icon links with accessible names, four link groups in a labelled navigation, and a bottom bar with copyright, legal links and a status indicator. The brand name returns across the full width at the bottom. Link groups fold from four columns to two on phones; everything is passed as props.
Source
"use client";
import { useId, useState, type FormEvent, type ReactNode } from "react";
import { AtSign, CircleCheck, CirclePlay, MessagesSquare, Rss, type LucideIcon } from "lucide-react";
import { cn } from "@/lib/utils";
export type FooterLinkGroup = { title: string; links: { label: string; href: string }[] };
export type FooterSocial = { label: string; href: string; icon: LucideIcon };
export type SiteFooterProps = {
brand?: string;
logo?: ReactNode;
tagline?: string;
groups?: FooterLinkGroup[];
socials?: FooterSocial[];
legal?: { label: string; href: string }[];
/** Shown in the bottom bar with a status dot. Pass null to hide. */
status?: { label: string; href: string } | null;
newsletterLabel?: string;
/** Called with a valid email. Defaults to a short simulated request. */
onSubscribe?: (email: string) => Promise<void> | void;
/** Draw the brand name across the full width at the very bottom. */
showWordmark?: boolean;
year?: number;
className?: string;
};
const DEFAULT_GROUPS: FooterLinkGroup[] = [
{ title: "Product", links: [{ label: "Docs", href: "#" }, { label: "Whiteboards", href: "#" }, { label: "Forms", href: "#" }, { label: "Automations", href: "#" }, { label: "Pricing", href: "#" }] },
{ title: "Company", links: [{ label: "About", href: "#" }, { label: "Customers", href: "#" }, { label: "Careers", href: "#" }, { label: "Press kit", href: "#" }] },
{ title: "Resources", links: [{ label: "Help centre", href: "#" }, { label: "Templates", href: "#" }, { label: "Changelog", href: "#" }, { label: "API reference", href: "#" }] },
{ title: "Trust", links: [{ label: "Security", href: "#" }, { label: "Data processing", href: "#" }, { label: "Sub-processors", href: "#" }, { label: "Accessibility", href: "#" }] },
];
const DEFAULT_SOCIALS: FooterSocial[] = [
{ label: "Paperlark on social media", href: "#", icon: AtSign },
{ label: "Community forum", href: "#", icon: MessagesSquare },
{ label: "Video tutorials", href: "#", icon: CirclePlay },
{ label: "Changelog RSS feed", href: "#", icon: Rss },
];
const DEFAULT_LEGAL = [{ label: "Privacy", href: "#" }, { label: "Terms", href: "#" }, { label: "Cookies", href: "#" }];
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
const focusRing = "outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background";
function DefaultLogo() {
return (
<svg viewBox="0 0 24 24" className="size-7" aria-hidden="true">
<path d="M5 3h9l5 5v13H5V3Z" fill="currentColor" />
<path d="M14 3v5h5" fill="none" stroke="var(--background)" strokeWidth="1.6" />
<path d="M8.5 13.5h7M8.5 17h4.5" stroke="var(--background)" strokeWidth="1.6" strokeLinecap="round" />
</svg>
);
}
export function SiteFooter({
brand = "Paperlark",
logo = <DefaultLogo />,
tagline = "Docs, specs and runbooks for teams that write things down.",
groups = DEFAULT_GROUPS,
socials = DEFAULT_SOCIALS,
legal = DEFAULT_LEGAL,
status = { label: "All systems normal", href: "#status" },
newsletterLabel = "Product updates, once a month",
onSubscribe = () => new Promise((resolve) => setTimeout(resolve, 700)),
showWordmark = true,
year = new Date().getFullYear(),
className,
}: SiteFooterProps) {
const id = useId();
const [email, setEmail] = useState("");
const [error, setError] = useState("");
const [state, setState] = useState<"idle" | "sending" | "done">("idle");
const subscribe = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
if (!EMAIL.test(email.trim())) {
setError(email.trim() ? "Check the email address." : "Enter your email address.");
return;
}
setError("");
setState("sending");
try {
await onSubscribe(email.trim());
setState("done");
} catch {
setState("idle");
setError("That did not go through. Try again.");
}
};
return (
<footer aria-labelledby={`${id}-title`} className={cn("overflow-hidden bg-muted/50 text-foreground dark:bg-card/60", className)}>
<h2 id={`${id}-title`} className="sr-only">Site footer</h2>
<div className="mx-auto max-w-6xl px-4 pt-16 sm:px-6 lg:px-8 lg:pt-20">
<div className="grid gap-12 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.6fr)] lg:gap-16">
<div className="max-w-sm">
<a href="/" className={cn("inline-flex items-center gap-2.5 rounded-md text-lg font-semibold tracking-tight", focusRing)}>
{logo}
{brand}
</a>
<p className="mt-4 text-sm leading-relaxed text-muted-foreground">{tagline}</p>
<div aria-live="polite" className="mt-8">
{state === "done" ? (
<p className="flex items-center gap-2 text-sm font-medium">
<CircleCheck className="size-4 text-emerald-600 dark:text-emerald-400" aria-hidden="true" />
Subscribed. The next issue goes out on the first Tuesday.
</p>
) : (
<form noValidate onSubmit={subscribe}>
<label htmlFor={`${id}-email`} className="text-sm font-medium">{newsletterLabel}</label>
<div className="mt-2 flex gap-2">
<input
id={`${id}-email`}
type="email"
autoComplete="email"
placeholder="you@company.com"
value={email}
onChange={(event) => setEmail(event.target.value)}
aria-invalid={error ? true : undefined}
aria-describedby={error ? `${id}-error` : undefined}
className={cn(
"h-10 min-w-0 flex-1 rounded-md border bg-background px-3 text-sm placeholder:text-muted-foreground",
error ? "border-destructive" : "border-input",
focusRing,
)}
/>
<button
type="submit"
disabled={state === "sending"}
className={cn("h-10 shrink-0 rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-opacity hover:opacity-90 disabled:opacity-60", focusRing)}
>
{state === "sending" ? "Joining…" : "Subscribe"}
</button>
</div>
{error && <p id={`${id}-error`} className="mt-2 text-sm text-destructive">{error}</p>}
</form>
)}
</div>
<ul className="mt-8 flex gap-1" aria-label="Elsewhere">
{socials.map(({ label, href, icon: Icon }) => (
<li key={label}>
<a
href={href}
aria-label={label}
title={label}
className={cn("grid size-10 place-items-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground", focusRing)}
>
<Icon className="size-[1.125rem]" aria-hidden="true" />
</a>
</li>
))}
</ul>
</div>
<nav aria-label="Footer" className="grid grid-cols-2 gap-x-6 gap-y-10 sm:grid-cols-4">
{groups.map((group) => (
<div key={group.title}>
<h3 className="text-sm font-semibold">{group.title}</h3>
<ul className="mt-4 space-y-3">
{group.links.map((link) => (
<li key={link.label}>
<a href={link.href} className={cn("rounded-sm text-sm text-muted-foreground transition-colors hover:text-foreground", focusRing)}>
{link.label}
</a>
</li>
))}
</ul>
</div>
))}
</nav>
</div>
<div className="mt-16 flex flex-col gap-4 border-t border-border py-6 text-sm text-muted-foreground sm:flex-row sm:items-center sm:justify-between">
<p>© {year} {brand} Ltd.</p>
<div className="flex flex-wrap items-center gap-x-6 gap-y-2">
{legal.map((link) => (
<a key={link.label} href={link.href} className={cn("rounded-sm transition-colors hover:text-foreground", focusRing)}>
{link.label}
</a>
))}
{status && (
<a href={status.href} className={cn("inline-flex items-center gap-2 rounded-sm transition-colors hover:text-foreground", focusRing)}>
<span className="size-2 rounded-full bg-emerald-500" aria-hidden="true" />
{status.label}
</a>
)}
</div>
</div>
</div>
{showWordmark && (
<div aria-hidden="true" className="mx-auto max-w-6xl select-none px-4 sm:px-6 lg:px-8">
<svg viewBox="0 0 1000 150" className="block h-auto w-full text-foreground/[0.07] dark:text-foreground/[0.06]">
<text x="0" y="178" textLength="1000" lengthAdjust="spacingAndGlyphs" fill="currentColor" fontSize="232" fontWeight="700" letterSpacing="-6">
{brand}
</text>
</svg>
</div>
)}
</footer>
);
}
