Files

101 lines
2.9 KiB
TypeScript

import type { CSSProperties, ReactNode } from "react";
import { BaseLayout } from "../_layout/BaseLayout.js";
import { Button } from "../_layout/Button.js";
import { Eyebrow } from "../_layout/Eyebrow.js";
import type { MailBrand } from "../_layout/theme.js";
import type { MailFooterCopy, MailLanguage } from "../_layout/Footer.js";
export interface TransactionalChromeProps {
readonly language?: MailLanguage;
readonly footerCopy?: MailFooterCopy;
}
/**
* Shared visual scaffold for all transactional templates.
*
* Every transactional email follows the same shape: eyebrow → headline →
* intro paragraph → CTA → optional outro paragraph → support sign-off.
* Concentrating that into one component keeps per-template files small
* and ensures brand-theme application is uniform.
*/
export interface TransactionalScaffoldProps extends TransactionalChromeProps {
readonly brand: MailBrand;
readonly subject: string;
readonly previewText?: string;
readonly eyebrow: string;
readonly title: string;
readonly intro: ReactNode;
readonly actionUrl?: string;
readonly actionLabel?: string;
readonly outro?: ReactNode;
readonly children?: ReactNode;
readonly unsubscribeUrl?: string;
readonly signoffThanks?: string;
}
const titleStyle = (brand: MailBrand): CSSProperties => ({
margin: "8px 0 18px",
fontSize: "30px",
lineHeight: 1.16,
color: brand.textColor,
fontWeight: 700,
});
const paragraphStyle = (brand: MailBrand): CSSProperties => ({
margin: "0 0 24px",
fontSize: "16px",
lineHeight: 1.6,
color: brand.textColor,
});
const outroStyle = (brand: MailBrand): CSSProperties => ({
margin: "30px 0 0",
fontSize: "15px",
lineHeight: 1.6,
color: brand.mutedTextColor,
});
const signoffStyle = (brand: MailBrand): CSSProperties => ({
margin: "24px 0 0",
fontSize: "14px",
lineHeight: 1.6,
color: brand.textColor,
});
export function TransactionalScaffold({
brand,
subject,
previewText,
eyebrow,
title,
intro,
actionUrl,
actionLabel,
outro,
children,
unsubscribeUrl,
signoffThanks,
language,
footerCopy,
}: TransactionalScaffoldProps) {
return (
<BaseLayout brand={brand} title={subject} previewText={previewText ?? subject} unsubscribeUrl={unsubscribeUrl} language={language} footerCopy={footerCopy}>
<Eyebrow brand={brand}>{eyebrow}</Eyebrow>
<h1 style={titleStyle(brand)}>{title}</h1>
<p style={paragraphStyle(brand)}>{intro}</p>
{actionUrl && actionLabel ? (
<Button brand={brand} href={actionUrl}>
{actionLabel}
</Button>
) : null}
{outro ? <p style={outroStyle(brand)}>{outro}</p> : null}
{children}
<p style={signoffStyle(brand)}>
{footerCopy?.signoffClosing ?? signoffThanks ?? "Kind regards,"}
<br />
<strong>{footerCopy?.signoffTeam ?? brand.supportFromName}</strong>
</p>
</BaseLayout>
);
}