Accounts 1.7.0 + @crosscode/ui 0.2.0: brand style, the church's fonts and footer, church.update
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* The church's brand style and footer, shared by Accounts, Cross Events' public pages, the Website
|
||||
* and later the App (WEBSITE-1.0-PLAN §3 and §9, contracts 1.17.0).
|
||||
*
|
||||
* Fonts: import `@crosscode/ui/fonts.css` once (it holds every pairing's @font-face; a browser only
|
||||
* downloads the files a page uses), then put `brandAttributes(style)` on `<html>`. The page's CSS
|
||||
* uses `var(--cc-font-body, <its own font>)`, `var(--cc-font-heading, …)` and
|
||||
* `font-variation-settings: var(--cc-heading-variation, normal)` on headings, and the components
|
||||
* here use `--cc-radius`, so a church without a pairing keeps the app's own fonts.
|
||||
*/
|
||||
import React from "react";
|
||||
|
||||
const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
|
||||
|
||||
/** `branding.style` from `crosscode.church/1` (structural, so this package needn't depend on the contracts). */
|
||||
export type BrandStyle = { fontPairing?: string | null; corners?: string | null } | null | undefined;
|
||||
|
||||
/** Attributes for `<html>`: the pairing (only when the church picked one) and the corners (`soft` by default). */
|
||||
export function brandAttributes(style: BrandStyle): Record<string, string> {
|
||||
const out: Record<string, string> = { "data-cc-corners": style?.corners || "soft" };
|
||||
if (style?.fontPairing) out["data-cc-fonts"] = style.fontPairing;
|
||||
return out;
|
||||
}
|
||||
|
||||
const DAYS: Record<string, string> = { monday: "Mondays", tuesday: "Tuesdays", wednesday: "Wednesdays", thursday: "Thursdays", friday: "Fridays", saturday: "Saturdays", sunday: "Sundays" };
|
||||
const NETWORKS: Record<string, string> = { facebook: "Facebook", instagram: "Instagram", youtube: "YouTube", tiktok: "TikTok", x: "X", spotify: "Spotify", "whatsapp-channel": "WhatsApp channel", other: "Link" };
|
||||
|
||||
/** What the footer needs from `crosscode.church/1`. */
|
||||
export type FooterChurch = {
|
||||
name: string;
|
||||
branding: { logoUrl: string | null };
|
||||
serviceTimes?: { day: string; time: string; label: string | null }[];
|
||||
contact?: {
|
||||
email: string | null;
|
||||
phone: string | null;
|
||||
whatsapp: string | null;
|
||||
address: { line1: string; line2: string | null; suburb: string | null; city: string; postalCode: string | null } | null;
|
||||
};
|
||||
social?: { network: string; url: string }[];
|
||||
links: { website: string | null; events: string | null; app: string | null; accounts: string };
|
||||
};
|
||||
|
||||
export type FooterProduct = "website" | "events" | "app" | "accounts";
|
||||
|
||||
const PRODUCT_LINKS: { key: FooterProduct; label: string }[] = [
|
||||
{ key: "website", label: "Website" },
|
||||
{ key: "events", label: "Events" },
|
||||
{ key: "app", label: "App" },
|
||||
{ key: "accounts", label: "Your account" },
|
||||
];
|
||||
|
||||
/** The church's other sites, for a product's header: each that exists except this one. */
|
||||
export function productLinks(links: FooterChurch["links"], current: FooterProduct): { label: string; href: string }[] {
|
||||
return PRODUCT_LINKS.filter((p) => p.key !== current && p.key !== "accounts" && links[p.key]).map((p) => ({ label: p.label, href: links[p.key]! }));
|
||||
}
|
||||
|
||||
/**
|
||||
* One footer for every product: the church's name and logo, service times, address and contact,
|
||||
* social links, links to its other sites, and the privacy notice. Sections without data are left
|
||||
* out. `className` lets a Website template restyle it.
|
||||
*/
|
||||
export function ChurchFooter({ church, current, privacyUrl, className }: { church: FooterChurch; current: FooterProduct; privacyUrl?: string | null; className?: string }) {
|
||||
const times = church.serviceTimes ?? [];
|
||||
const contact = church.contact;
|
||||
const address = contact?.address;
|
||||
const social = church.social ?? [];
|
||||
const sites = PRODUCT_LINKS.filter((p) => p.key !== current && church.links[p.key]);
|
||||
const tel = (n: string) => `tel:${n.replace(/\s+/g, "")}`;
|
||||
const heading = "mb-2 text-sm font-semibold text-gray-900 [font-family:var(--cc-font-heading,inherit)] [font-variation-settings:var(--cc-heading-variation,normal)]";
|
||||
return (
|
||||
<footer className={cx("border-t border-brand/15 bg-white/80 text-sm text-gray-700", className)}>
|
||||
<div className="mx-auto grid max-w-5xl gap-8 px-4 py-10 sm:grid-cols-2 lg:grid-cols-4">
|
||||
<div>
|
||||
{church.branding.logoUrl
|
||||
? <img src={church.branding.logoUrl} alt={church.name} className="mb-3 h-10 w-auto max-w-[10rem] object-contain" />
|
||||
: <p className={cx(heading, "text-base")}>{church.name}</p>}
|
||||
{address && (
|
||||
<address className="not-italic leading-relaxed">
|
||||
{address.line1}{address.line2 && <>, {address.line2}</>}<br />
|
||||
{[address.suburb, address.city, address.postalCode].filter(Boolean).join(", ")}
|
||||
</address>
|
||||
)}
|
||||
</div>
|
||||
{times.length > 0 && (
|
||||
<div>
|
||||
<h2 className={heading}>Service times</h2>
|
||||
<ul className="space-y-1">
|
||||
{times.map((t, i) => <li key={i}>{DAYS[t.day] ?? t.day} {t.time}{t.label && <span className="text-gray-500"> · {t.label}</span>}</li>)}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
{contact && (contact.email || contact.phone || contact.whatsapp || social.length > 0) && (
|
||||
<div>
|
||||
<h2 className={heading}>Contact</h2>
|
||||
<ul className="space-y-1">
|
||||
{contact.phone && <li><a className="hover:text-brand hover:underline" href={tel(contact.phone)}>{contact.phone}</a></li>}
|
||||
{contact.whatsapp && <li><a className="hover:text-brand hover:underline" href={`https://wa.me/${contact.whatsapp.replace(/\D/g, "")}`}>WhatsApp {contact.whatsapp}</a></li>}
|
||||
{contact.email && <li><a className="break-all hover:text-brand hover:underline" href={`mailto:${contact.email}`}>{contact.email}</a></li>}
|
||||
{social.map((s) => <li key={s.url}><a className="hover:text-brand hover:underline" href={s.url} rel="me noopener">{NETWORKS[s.network] ?? s.network}</a></li>)}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
{(sites.length > 0 || privacyUrl) && (
|
||||
<nav aria-label={`${church.name}'s sites`}>
|
||||
<h2 className={heading}>Our sites</h2>
|
||||
<ul className="space-y-1">
|
||||
{sites.map((s) => <li key={s.key}><a className="hover:text-brand hover:underline" href={church.links[s.key]!}>{s.label}</a></li>)}
|
||||
{privacyUrl && <li><a className="hover:text-brand hover:underline" href={privacyUrl}>Privacy notice</a></li>}
|
||||
</ul>
|
||||
</nav>
|
||||
)}
|
||||
</div>
|
||||
<p className="px-4 pb-6 text-center text-xs text-gray-500">© {new Date().getFullYear()} {church.name}</p>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user