/** Small building blocks every template uses. */ import type { Image } from "./types"; export const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); /** * An uploaded image at the size the screen needs (ยง3: responsive sizes in WebP and JPEG): the * browser picks from the `srcset`s by `sizes`. `alt` overrides the image's own (e.g. "" when it's * only decoration behind text). */ export function Picture({ image, className, sizes = "100vw", priority = false, alt }: { image: Image; className?: string; sizes?: string; priority?: boolean; alt?: string }) { const img = ( {alt ); return image.srcset ? {img} : img; } /** An image in a frame (Heritage frames, duotone tints), or a soft placeholder when there's none. */ export function Img({ image, className, sizes = "(min-width: 768px) 50vw, 100vw", priority = false, ratio = "aspect-[4/3]" }: { image: Image | null; className?: string; sizes?: string; priority?: boolean; ratio?: string }) { return (
{image ? ( ) : ( ); } export type ButtonData = { label: string; href: string } | null | undefined; export function Button({ button, className }: { button: ButtonData; className?: string }) { if (!button?.label || !button.href) return null; const external = button.href.startsWith("https://"); return ( {button.label} ); } /** Text the admins wrote, as paragraphs (blank lines). Never HTML. */ export function Paragraphs({ text, className }: { text: string | null | undefined; className?: string }) { if (!text) return null; const paras = text.split(/\n\s*\n/).map((p) => p.trim()).filter(Boolean); return (
{paras.map((p, i) =>

{p.split("\n").map((line, j) => {j > 0 &&
}{line}
)}

)}
); } const DAYS: Record = { monday: "Monday", tuesday: "Tuesday", wednesday: "Wednesday", thursday: "Thursday", friday: "Friday", saturday: "Saturday", sunday: "Sunday" }; export const dayName = (d: string) => DAYS[d] ?? d; export function fmtDate(iso: string, timeZone: string, opts: Intl.DateTimeFormatOptions = { weekday: "short", day: "numeric", month: "long" }) { return new Intl.DateTimeFormat("en-ZA", { timeZone, ...opts }).format(new Date(iso)); } export function fmtTime(iso: string, timeZone: string) { return new Intl.DateTimeFormat("en-ZA", { timeZone, hour: "2-digit", minute: "2-digit", hour12: false }).format(new Date(iso)); } /** Day and month in a box (event cards and lists). */ export function DateBadge({ iso, timeZone, className }: { iso: string; timeZone: string; className?: string }) { return ( ); } export function SectionHeading({ eyebrow, heading, intro, centred = false, as: H = "h2" }: { eyebrow?: string | null; heading?: string | null; intro?: string | null; centred?: boolean; as?: "h1" | "h2" }) { if (!heading && !eyebrow && !intro) return null; return (
{eyebrow &&

{eyebrow}

} {heading && {heading}} {intro &&

{intro}

}
); }