/**
* @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 (
;
}
/** 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 (
);
}
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 (