/** * @crosscode/ui — the branded shell, cards, buttons, fields and notices shared by Accounts, the * Church Website and the Church App. Colours come from `--brand` (see README). */ import React from "react"; export * from "./brand"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export type Branding = { name: string; shortName?: string | null; logoUrl?: string | null }; /** The page frame: the church's logo and name, then the content in a centred column. */ /** The church's logo, or its first letter on its colour while it has none. */ export function ChurchMark({ branding, size = "md" }: { branding: Branding; size?: "md" | "lg" }) { const box = size === "lg" ? "h-14 w-14 text-2xl" : "h-10 w-10 text-lg"; if (branding.logoUrl) return ; return {(branding.shortName || branding.name || "?").trim().charAt(0).toUpperCase()}; } /** * The page frame (as the church's other sites): a soft wash of the church's colour, its logo and * name across the top, the content in a centred column, and a quiet footer. `wide` for the account * and admin pages; otherwise a sign-in column. */ /** `footer` replaces the quiet line at the bottom (Accounts 1.7.0 passes the `ChurchFooter`). */ export function Shell({ branding, children, wide = false, aside, footer }: { branding: Branding; children: React.ReactNode; wide?: boolean; aside?: React.ReactNode; footer?: React.ReactNode }) { return (
{branding.name} {aside &&
{aside}
}
{children}
{footer ?? ( )}
); } export function Card({ children, className }: { children: React.ReactNode; className?: string }) { return
{children}
; } /** A page's title, with an optional icon in a tile of the church's colour (as on the church's other sites). */ export function Heading({ children, sub, icon }: { children: React.ReactNode; sub?: React.ReactNode; icon?: React.ReactNode }) { return (
{icon && {icon}}

{children}

{sub &&

{sub}

}
); } type ButtonProps = React.ButtonHTMLAttributes & { variant?: "primary" | "secondary" | "danger" | "link"; busy?: boolean }; export function Button({ variant = "primary", busy, className, children, disabled, ...rest }: ButtonProps) { const styles = { primary: "bg-brand text-white hover:bg-brand-dark", secondary: "border bg-white text-gray-800 hover:bg-gray-50", danger: "bg-red-600 text-white hover:bg-red-700", link: "text-brand underline px-0 py-0", }[variant]; return ( ); } type FieldProps = React.InputHTMLAttributes & { label: string; error?: string | null; hint?: React.ReactNode }; export function Field({ label, error, hint, id, className, ...rest }: FieldProps) { const fieldId = id ?? `f-${label.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`; return (
{hint && !error &&

{hint}

} {error &&

{error}

}
); } export const isHexColour = (v: string) => /^#[0-9a-fA-F]{6}$/.test(v.trim()); type ColourFieldProps = { label: string; value: string; onChange: (hex: string) => void; hint?: React.ReactNode; error?: string | null; /** For a form read with FormData: the hex is sent under this name. */ name?: string; id?: string; disabled?: boolean; }; /** * A colour: the swatch to pick it, the hex code to type or paste it, and a bar showing it, as Cross * Events' Branding settings. Controlled: `value` is what's typed, so it can be half-typed; it's a * colour once it reads `#rrggbb` (`isHexColour`), and says so when it doesn't. */ export function ColourField({ label, value, onChange, hint, error, name, id, disabled }: ColourFieldProps) { const fieldId = id ?? `f-${label.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`; const valid = isHexColour(value); const problem = error || (valid ? null : "Enter a colour code like #1f4e79."); return (
onChange(e.target.value)} /> onChange(e.target.value)} />
{hint && !problem &&

{hint}

} {problem &&

{problem}

}
); } export function Checkbox({ label, hint, ...rest }: React.InputHTMLAttributes & { label: React.ReactNode; hint?: React.ReactNode }) { return ( ); } export function Notice({ tone = "info", children }: { tone?: "info" | "error" | "success" | "warning"; children: React.ReactNode }) { const styles = { info: "bg-blue-50 text-blue-900 border-blue-200", error: "bg-red-50 text-red-800 border-red-200", success: "bg-green-50 text-green-800 border-green-200", warning: "bg-amber-50 text-amber-900 border-amber-200" }[tone]; return
{children}
; }