@tonycodes-ui/mortar 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -22
- package/README.md +1 -1
- package/catalog.json +119 -119
- package/dist/agent-data.json +1 -1
- package/dist/email-components.d.ts +115 -0
- package/dist/email-components.js +221 -0
- package/dist/email-templates.d.ts +108 -0
- package/dist/email-templates.js +57 -0
- package/dist/email-theme.d.ts +38 -0
- package/dist/email-theme.js +200 -0
- package/dist/email.d.ts +6 -0
- package/dist/email.js +5 -0
- package/docs/auth-flows.md +2 -0
- package/docs/email.md +116 -0
- package/package.json +14 -3
- package/src/email-components.tsx +528 -0
- package/src/email-templates.tsx +355 -0
- package/src/email-theme.ts +254 -0
- package/src/email.ts +47 -0
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
/* Email components for @tonycodes-ui/mortar/email. Built on React Email,
|
|
2
|
+
which renders the table layout and inline styles email clients need; these
|
|
3
|
+
components give it Mortar's tokens, brand and copy. Nothing here uses
|
|
4
|
+
Mortar's stylesheet or app components, which email clients cannot run.
|
|
5
|
+
Requires the optional peer dependency @react-email/components. */
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
createContext,
|
|
9
|
+
useContext,
|
|
10
|
+
type CSSProperties,
|
|
11
|
+
type ReactNode,
|
|
12
|
+
} from "react";
|
|
13
|
+
import {
|
|
14
|
+
Body,
|
|
15
|
+
Button,
|
|
16
|
+
Container,
|
|
17
|
+
Head,
|
|
18
|
+
Heading,
|
|
19
|
+
Hr,
|
|
20
|
+
Html,
|
|
21
|
+
Img,
|
|
22
|
+
Link,
|
|
23
|
+
Preview,
|
|
24
|
+
Text,
|
|
25
|
+
render,
|
|
26
|
+
} from "@react-email/components";
|
|
27
|
+
import type { Tone } from "./primitives.js";
|
|
28
|
+
import { emailTheme, type EmailTheme } from "./email-theme.js";
|
|
29
|
+
|
|
30
|
+
const ShellContext = createContext<
|
|
31
|
+
{ theme: EmailTheme; dir: "ltr" | "rtl" } | undefined
|
|
32
|
+
>(undefined);
|
|
33
|
+
let neutral: EmailTheme | undefined;
|
|
34
|
+
/** The theme from the enclosing EmailShell, or Mortar's neutral theme. */
|
|
35
|
+
function useTheme(): EmailTheme {
|
|
36
|
+
return useContext(ShellContext)?.theme ?? (neutral ??= emailTheme());
|
|
37
|
+
}
|
|
38
|
+
/* Email clients don't support logical properties, so the inline start and
|
|
39
|
+
end are worked out from the shell's direction. */
|
|
40
|
+
function useSides() {
|
|
41
|
+
const rtl = useContext(ShellContext)?.dir === "rtl";
|
|
42
|
+
return {
|
|
43
|
+
start: rtl ? "right" : "left",
|
|
44
|
+
end: rtl ? "left" : "right",
|
|
45
|
+
} as const;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* Links leave the mail client, so only web and mail addresses are allowed. */
|
|
49
|
+
export function assertHref(href: string, component: string, mail = false) {
|
|
50
|
+
if (!(mail ? /^(?:https?:|mailto:)/i : /^https?:\/\//i).test(href.trim()))
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Mortar ${component} needs an absolute ${mail ? "http(s) or mailto" : "http(s)"} URL: "${href}"`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* A one-cell layout table. Outlook for Windows ignores padding, margins and
|
|
57
|
+
backgrounds on tables, so spacing and fills go on the cell. */
|
|
58
|
+
function Cell({
|
|
59
|
+
style,
|
|
60
|
+
children,
|
|
61
|
+
}: {
|
|
62
|
+
style: CSSProperties;
|
|
63
|
+
children: ReactNode;
|
|
64
|
+
}) {
|
|
65
|
+
return (
|
|
66
|
+
<table
|
|
67
|
+
role="presentation"
|
|
68
|
+
width="100%"
|
|
69
|
+
border={0}
|
|
70
|
+
cellPadding={0}
|
|
71
|
+
cellSpacing={0}
|
|
72
|
+
>
|
|
73
|
+
<tbody>
|
|
74
|
+
<tr>
|
|
75
|
+
<td style={style}>{children}</td>
|
|
76
|
+
</tr>
|
|
77
|
+
</tbody>
|
|
78
|
+
</table>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface EmailLogo {
|
|
83
|
+
/** An absolute URL: the email is read away from your site. */
|
|
84
|
+
src: string;
|
|
85
|
+
alt: string;
|
|
86
|
+
width: number;
|
|
87
|
+
height: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface EmailShellProps {
|
|
91
|
+
/** The inbox preview line shown after the subject. */
|
|
92
|
+
preview: string;
|
|
93
|
+
/** From `emailTheme(brand)`; Mortar's neutral theme by default. */
|
|
94
|
+
theme?: EmailTheme;
|
|
95
|
+
logo?: EmailLogo;
|
|
96
|
+
/** Why the person received the email, and what to do if it wasn't for them. */
|
|
97
|
+
footer?: ReactNode;
|
|
98
|
+
lang?: string;
|
|
99
|
+
dir?: "ltr" | "rtl";
|
|
100
|
+
children: ReactNode;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The whole email: a card up to 600px wide on the sunken backdrop, with an
|
|
104
|
+
* optional logo above it and footer below. It sets the theme for the email
|
|
105
|
+
* components inside, and marks the email light-only so mail apps don't
|
|
106
|
+
* recolour the brand.
|
|
107
|
+
*/
|
|
108
|
+
export function EmailShell({
|
|
109
|
+
preview,
|
|
110
|
+
theme: given,
|
|
111
|
+
logo,
|
|
112
|
+
footer,
|
|
113
|
+
lang = "en",
|
|
114
|
+
dir = "ltr",
|
|
115
|
+
children,
|
|
116
|
+
}: EmailShellProps) {
|
|
117
|
+
const theme = given ?? emailTheme();
|
|
118
|
+
if (logo) assertHref(logo.src, "EmailShell logo");
|
|
119
|
+
return (
|
|
120
|
+
<ShellContext.Provider value={{ theme, dir }}>
|
|
121
|
+
<Html lang={lang} dir={dir}>
|
|
122
|
+
<Head>
|
|
123
|
+
<meta name="color-scheme" content="light" />
|
|
124
|
+
<meta name="supported-color-schemes" content="light" />
|
|
125
|
+
</Head>
|
|
126
|
+
<Preview>{preview}</Preview>
|
|
127
|
+
<Body
|
|
128
|
+
style={{
|
|
129
|
+
margin: 0,
|
|
130
|
+
padding: "32px 12px",
|
|
131
|
+
backgroundColor: theme.sunken,
|
|
132
|
+
color: theme.ink,
|
|
133
|
+
fontFamily: theme.font,
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
<Container style={{ width: "100%", maxWidth: "600px" }}>
|
|
137
|
+
{logo && (
|
|
138
|
+
<Cell style={{ padding: "0 0 24px" }}>
|
|
139
|
+
<Img
|
|
140
|
+
src={logo.src}
|
|
141
|
+
alt={logo.alt}
|
|
142
|
+
width={logo.width}
|
|
143
|
+
height={logo.height}
|
|
144
|
+
/>
|
|
145
|
+
</Cell>
|
|
146
|
+
)}
|
|
147
|
+
<Cell
|
|
148
|
+
style={{
|
|
149
|
+
backgroundColor: theme.surface,
|
|
150
|
+
border: `1px solid ${theme.line}`,
|
|
151
|
+
borderRadius: "12px",
|
|
152
|
+
padding: "32px",
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
{children}
|
|
156
|
+
</Cell>
|
|
157
|
+
{footer && (
|
|
158
|
+
<Cell style={{ padding: "24px 32px 0" }}>
|
|
159
|
+
<Text
|
|
160
|
+
style={{
|
|
161
|
+
margin: 0,
|
|
162
|
+
fontFamily: theme.font,
|
|
163
|
+
fontSize: "12px",
|
|
164
|
+
lineHeight: "18px",
|
|
165
|
+
color: theme.muted,
|
|
166
|
+
}}
|
|
167
|
+
>
|
|
168
|
+
{footer}
|
|
169
|
+
</Text>
|
|
170
|
+
</Cell>
|
|
171
|
+
)}
|
|
172
|
+
</Container>
|
|
173
|
+
</Body>
|
|
174
|
+
</Html>
|
|
175
|
+
</ShellContext.Provider>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface EmailHeadingProps {
|
|
180
|
+
/** 1 for the email's title (once per email), 2 for a section. */
|
|
181
|
+
level?: 1 | 2;
|
|
182
|
+
children: ReactNode;
|
|
183
|
+
}
|
|
184
|
+
export function EmailHeading({ level = 1, children }: EmailHeadingProps) {
|
|
185
|
+
const theme = useTheme();
|
|
186
|
+
return (
|
|
187
|
+
<Heading
|
|
188
|
+
as={level === 1 ? "h1" : "h2"}
|
|
189
|
+
style={{
|
|
190
|
+
margin: "0 0 16px",
|
|
191
|
+
fontFamily: theme.fontHeading,
|
|
192
|
+
fontSize: level === 1 ? "24px" : "18px",
|
|
193
|
+
lineHeight: level === 1 ? "32px" : "26px",
|
|
194
|
+
fontWeight: 600,
|
|
195
|
+
letterSpacing: "-0.02em",
|
|
196
|
+
color: theme.ink,
|
|
197
|
+
}}
|
|
198
|
+
>
|
|
199
|
+
{children}
|
|
200
|
+
</Heading>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface EmailTextProps {
|
|
205
|
+
/** `muted` for secondary details such as an expiry time. */
|
|
206
|
+
tone?: "default" | "muted";
|
|
207
|
+
size?: "md" | "sm";
|
|
208
|
+
children: ReactNode;
|
|
209
|
+
}
|
|
210
|
+
/** A paragraph. 16px by default: email is read on phones, at arm's length. */
|
|
211
|
+
export function EmailText({
|
|
212
|
+
tone = "default",
|
|
213
|
+
size = "md",
|
|
214
|
+
children,
|
|
215
|
+
}: EmailTextProps) {
|
|
216
|
+
const theme = useTheme();
|
|
217
|
+
return (
|
|
218
|
+
<Text
|
|
219
|
+
style={{
|
|
220
|
+
margin: "0 0 16px",
|
|
221
|
+
fontFamily: theme.font,
|
|
222
|
+
fontSize: size === "md" ? "16px" : "14px",
|
|
223
|
+
lineHeight: size === "md" ? "24px" : "20px",
|
|
224
|
+
color: tone === "muted" ? theme.muted : theme.ink,
|
|
225
|
+
}}
|
|
226
|
+
>
|
|
227
|
+
{children}
|
|
228
|
+
</Text>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export interface EmailButtonProps {
|
|
233
|
+
/** An absolute http(s) URL. */
|
|
234
|
+
href: string;
|
|
235
|
+
children: ReactNode;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* The email's main action, on its own line. Padding is applied in a way
|
|
239
|
+
* Outlook for Windows keeps, so the whole button is clickable there too.
|
|
240
|
+
* Follow it with the URL as an EmailLink for clients that block buttons.
|
|
241
|
+
*/
|
|
242
|
+
export function EmailButton({ href, children }: EmailButtonProps) {
|
|
243
|
+
const theme = useTheme();
|
|
244
|
+
assertHref(href, "EmailButton");
|
|
245
|
+
return (
|
|
246
|
+
<Cell style={{ padding: "8px 0 24px" }}>
|
|
247
|
+
<Button
|
|
248
|
+
href={href}
|
|
249
|
+
style={{
|
|
250
|
+
display: "inline-block",
|
|
251
|
+
backgroundColor: theme.primary,
|
|
252
|
+
color: theme.onPrimary,
|
|
253
|
+
fontFamily: theme.font,
|
|
254
|
+
fontSize: "16px",
|
|
255
|
+
lineHeight: "24px",
|
|
256
|
+
fontWeight: 600,
|
|
257
|
+
textDecoration: "none",
|
|
258
|
+
padding: "12px 24px",
|
|
259
|
+
borderRadius: "8px",
|
|
260
|
+
}}
|
|
261
|
+
>
|
|
262
|
+
{children}
|
|
263
|
+
</Button>
|
|
264
|
+
</Cell>
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export interface EmailLinkProps {
|
|
269
|
+
/** An absolute http(s) or mailto URL. */
|
|
270
|
+
href: string;
|
|
271
|
+
/** The URL itself when omitted, for "paste this link" fallbacks. */
|
|
272
|
+
children?: ReactNode;
|
|
273
|
+
}
|
|
274
|
+
export function EmailLink({ href, children }: EmailLinkProps) {
|
|
275
|
+
const theme = useTheme();
|
|
276
|
+
assertHref(href, "EmailLink", true);
|
|
277
|
+
return (
|
|
278
|
+
<Link
|
|
279
|
+
href={href}
|
|
280
|
+
style={{
|
|
281
|
+
color: theme.link,
|
|
282
|
+
textDecoration: "underline",
|
|
283
|
+
// A bare URL may break anywhere so it can't widen the email.
|
|
284
|
+
wordBreak: children === undefined ? "break-all" : undefined,
|
|
285
|
+
}}
|
|
286
|
+
>
|
|
287
|
+
{children ?? href}
|
|
288
|
+
</Link>
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export interface EmailCodeProps {
|
|
293
|
+
/** A one-time code, shown large and spaced for reading and copying. */
|
|
294
|
+
code: string;
|
|
295
|
+
}
|
|
296
|
+
export function EmailCode({ code }: EmailCodeProps) {
|
|
297
|
+
const theme = useTheme();
|
|
298
|
+
return (
|
|
299
|
+
<Cell style={{ padding: "8px 0 24px" }}>
|
|
300
|
+
<Cell
|
|
301
|
+
style={{
|
|
302
|
+
backgroundColor: theme.sunken,
|
|
303
|
+
borderRadius: "8px",
|
|
304
|
+
padding: "16px",
|
|
305
|
+
textAlign: "center",
|
|
306
|
+
}}
|
|
307
|
+
>
|
|
308
|
+
<Text
|
|
309
|
+
style={{
|
|
310
|
+
margin: 0,
|
|
311
|
+
fontFamily: theme.mono,
|
|
312
|
+
fontSize: "28px",
|
|
313
|
+
lineHeight: "36px",
|
|
314
|
+
fontWeight: 600,
|
|
315
|
+
letterSpacing: "0.2em",
|
|
316
|
+
color: theme.ink,
|
|
317
|
+
}}
|
|
318
|
+
>
|
|
319
|
+
{code}
|
|
320
|
+
</Text>
|
|
321
|
+
</Cell>
|
|
322
|
+
</Cell>
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export interface EmailCalloutProps {
|
|
327
|
+
/** Colours the edge: a status, or `neutral` for an aside such as a quoted message. */
|
|
328
|
+
tone?: Tone;
|
|
329
|
+
title?: string;
|
|
330
|
+
children: ReactNode;
|
|
331
|
+
}
|
|
332
|
+
/** A highlighted block: a warning, a status or a quoted personal message. */
|
|
333
|
+
export function EmailCallout({
|
|
334
|
+
tone = "neutral",
|
|
335
|
+
title,
|
|
336
|
+
children,
|
|
337
|
+
}: EmailCalloutProps) {
|
|
338
|
+
const theme = useTheme();
|
|
339
|
+
const { start } = useSides();
|
|
340
|
+
const edge = tone === "neutral" ? theme.line : theme[tone];
|
|
341
|
+
return (
|
|
342
|
+
<Cell style={{ padding: "8px 0 24px" }}>
|
|
343
|
+
<Cell
|
|
344
|
+
style={{
|
|
345
|
+
backgroundColor: theme.sunken,
|
|
346
|
+
[start === "left" ? "borderLeft" : "borderRight"]:
|
|
347
|
+
`4px solid ${edge}`,
|
|
348
|
+
padding: "16px 20px",
|
|
349
|
+
fontFamily: theme.font,
|
|
350
|
+
fontSize: "15px",
|
|
351
|
+
lineHeight: "22px",
|
|
352
|
+
color: theme.ink,
|
|
353
|
+
}}
|
|
354
|
+
>
|
|
355
|
+
{title && (
|
|
356
|
+
<Text
|
|
357
|
+
style={{
|
|
358
|
+
margin: "0 0 4px",
|
|
359
|
+
fontFamily: theme.font,
|
|
360
|
+
fontSize: "15px",
|
|
361
|
+
lineHeight: "22px",
|
|
362
|
+
fontWeight: 600,
|
|
363
|
+
color: theme.ink,
|
|
364
|
+
}}
|
|
365
|
+
>
|
|
366
|
+
{title}
|
|
367
|
+
</Text>
|
|
368
|
+
)}
|
|
369
|
+
{children}
|
|
370
|
+
</Cell>
|
|
371
|
+
</Cell>
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** A rule between sections of an email. */
|
|
376
|
+
export function EmailDivider() {
|
|
377
|
+
const theme = useTheme();
|
|
378
|
+
return (
|
|
379
|
+
<Hr
|
|
380
|
+
style={{
|
|
381
|
+
margin: "8px 0 24px",
|
|
382
|
+
border: "none",
|
|
383
|
+
borderTop: `1px solid ${theme.line}`,
|
|
384
|
+
}}
|
|
385
|
+
/>
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export interface EmailSummaryItem {
|
|
390
|
+
name: string;
|
|
391
|
+
/** Preformatted, e.g. "£42.00". */
|
|
392
|
+
price: string;
|
|
393
|
+
quantity?: number;
|
|
394
|
+
/** Chosen options, e.g. "Natural · Small". */
|
|
395
|
+
meta?: string;
|
|
396
|
+
}
|
|
397
|
+
export interface EmailSummaryProps {
|
|
398
|
+
/** Line items, each with its preformatted price. */
|
|
399
|
+
items?: EmailSummaryItem[];
|
|
400
|
+
/** Cost lines under the items, as OrderSummary takes them: subtotal, shipping, tax. */
|
|
401
|
+
lines?: { label: string; value: string }[];
|
|
402
|
+
total: { label: string; value: string };
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* A receipt's items, cost lines and total, as a two-column table: labels at
|
|
406
|
+
* the start, amounts at the end. Amounts are preformatted strings, as in
|
|
407
|
+
* Mortar's commerce components.
|
|
408
|
+
*/
|
|
409
|
+
export function EmailSummary({
|
|
410
|
+
items = [],
|
|
411
|
+
lines = [],
|
|
412
|
+
total,
|
|
413
|
+
}: EmailSummaryProps) {
|
|
414
|
+
const theme = useTheme();
|
|
415
|
+
const { start, end } = useSides();
|
|
416
|
+
const cell = (side: "start" | "end", extra: CSSProperties = {}) => ({
|
|
417
|
+
padding: "8px 0",
|
|
418
|
+
textAlign: side === "start" ? start : end,
|
|
419
|
+
verticalAlign: "top",
|
|
420
|
+
fontFamily: theme.font,
|
|
421
|
+
fontSize: "15px",
|
|
422
|
+
lineHeight: "22px",
|
|
423
|
+
color: theme.ink,
|
|
424
|
+
...extra,
|
|
425
|
+
});
|
|
426
|
+
const rule = `1px solid ${theme.line}`;
|
|
427
|
+
return (
|
|
428
|
+
<Cell style={{ padding: "8px 0 24px" }}>
|
|
429
|
+
<table
|
|
430
|
+
data-summary=""
|
|
431
|
+
role="presentation"
|
|
432
|
+
width="100%"
|
|
433
|
+
border={0}
|
|
434
|
+
cellPadding={0}
|
|
435
|
+
cellSpacing={0}
|
|
436
|
+
>
|
|
437
|
+
<tbody>
|
|
438
|
+
{items.map((item, i) => (
|
|
439
|
+
<tr key={i}>
|
|
440
|
+
<td style={cell("start", { borderBottom: rule })}>
|
|
441
|
+
{item.name}
|
|
442
|
+
{item.quantity !== undefined && item.quantity !== 1 && (
|
|
443
|
+
<span style={{ color: theme.muted }}> × {item.quantity}</span>
|
|
444
|
+
)}
|
|
445
|
+
{item.meta && (
|
|
446
|
+
<>
|
|
447
|
+
<br />
|
|
448
|
+
<span style={{ fontSize: "13px", color: theme.muted }}>
|
|
449
|
+
{item.meta}
|
|
450
|
+
</span>
|
|
451
|
+
</>
|
|
452
|
+
)}
|
|
453
|
+
</td>
|
|
454
|
+
<td
|
|
455
|
+
style={cell("end", {
|
|
456
|
+
borderBottom: rule,
|
|
457
|
+
whiteSpace: "nowrap",
|
|
458
|
+
[start === "left" ? "paddingLeft" : "paddingRight"]: "16px",
|
|
459
|
+
})}
|
|
460
|
+
>
|
|
461
|
+
{item.price}
|
|
462
|
+
</td>
|
|
463
|
+
</tr>
|
|
464
|
+
))}
|
|
465
|
+
{lines.map((line, i) => (
|
|
466
|
+
<tr key={`line-${i}`}>
|
|
467
|
+
<td style={cell("start", { color: theme.secondary })}>
|
|
468
|
+
{line.label}
|
|
469
|
+
</td>
|
|
470
|
+
<td
|
|
471
|
+
style={cell("end", {
|
|
472
|
+
color: theme.secondary,
|
|
473
|
+
whiteSpace: "nowrap",
|
|
474
|
+
})}
|
|
475
|
+
>
|
|
476
|
+
{line.value}
|
|
477
|
+
</td>
|
|
478
|
+
</tr>
|
|
479
|
+
))}
|
|
480
|
+
<tr>
|
|
481
|
+
<td style={cell("start", { borderTop: rule, fontWeight: 600 })}>
|
|
482
|
+
{total.label}
|
|
483
|
+
</td>
|
|
484
|
+
<td
|
|
485
|
+
style={cell("end", {
|
|
486
|
+
borderTop: rule,
|
|
487
|
+
fontWeight: 600,
|
|
488
|
+
whiteSpace: "nowrap",
|
|
489
|
+
})}
|
|
490
|
+
>
|
|
491
|
+
{total.value}
|
|
492
|
+
</td>
|
|
493
|
+
</tr>
|
|
494
|
+
</tbody>
|
|
495
|
+
</table>
|
|
496
|
+
</Cell>
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
export interface RenderedEmail {
|
|
501
|
+
html: string;
|
|
502
|
+
/** The plain-text alternative: send it with the HTML. */
|
|
503
|
+
text: string;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* An email element as HTML and plain text, ready for a sending service
|
|
507
|
+
* (Resend, SES, Postmark…). Keep the HTML under about 100 KB: Gmail clips
|
|
508
|
+
* longer messages.
|
|
509
|
+
*/
|
|
510
|
+
export async function renderEmail(element: ReactNode): Promise<RenderedEmail> {
|
|
511
|
+
const [html, text] = await Promise.all([
|
|
512
|
+
render(element),
|
|
513
|
+
render(element, {
|
|
514
|
+
plainText: true,
|
|
515
|
+
htmlToTextOptions: {
|
|
516
|
+
// A summary reads as rows of label and amount, not run together.
|
|
517
|
+
selectors: [
|
|
518
|
+
{
|
|
519
|
+
selector: "table[data-summary]",
|
|
520
|
+
format: "dataTable",
|
|
521
|
+
options: { maxColumnWidth: 48 },
|
|
522
|
+
},
|
|
523
|
+
],
|
|
524
|
+
},
|
|
525
|
+
}),
|
|
526
|
+
]);
|
|
527
|
+
return { html, text };
|
|
528
|
+
}
|