@tonycodes-ui/mortar 0.13.0 → 0.14.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.
@@ -0,0 +1,254 @@
1
+ /* Email theme. Email clients cannot read Mortar's stylesheet: Gmail drops CSS
2
+ variables and Outlook for Windows renders with Word. So an email takes its
3
+ colours and fonts as literal values, resolved here from a brand the way
4
+ tokens.css resolves it for the light appearance: omitted values keep
5
+ Mortar's defaults or derive from primary, and derived colours
6
+ (color-mix(in oklab, …)) are computed in JS. tests/email.test.mjs checks
7
+ the defaults against tokens.css. */
8
+
9
+ import { isBrandFont, type BrandDefinition } from "./brand.js";
10
+
11
+ /** Literal colours (#rrggbb) and font stacks for an email. */
12
+ export interface EmailTheme {
13
+ /** The page behind the message. */
14
+ paper: string;
15
+ /** The message card. */
16
+ surface: string;
17
+ /** Recessed areas such as a one-time code. */
18
+ sunken: string;
19
+ line: string;
20
+ ink: string;
21
+ secondary: string;
22
+ muted: string;
23
+ primary: string;
24
+ onPrimary: string;
25
+ accent: string;
26
+ onAccent: string;
27
+ link: string;
28
+ /** A tint of primary on the paper, for highlighted rows and callouts. */
29
+ selected: string;
30
+ success: string;
31
+ warning: string;
32
+ danger: string;
33
+ info: string;
34
+ /** Body font stack, ending in fonts every email client has. */
35
+ font: string;
36
+ /** Heading font stack; the body stack unless the brand sets one. */
37
+ fontHeading: string;
38
+ mono: string;
39
+ }
40
+
41
+ /* The light defaults in tokens.css. */
42
+ const DEFAULTS = {
43
+ paper: "#ffffff",
44
+ surface: "#ffffff",
45
+ sunken: "#f5f5f7",
46
+ line: "#e5e5ea",
47
+ ink: "#000000",
48
+ secondary: "#3a3a3c",
49
+ muted: "#6e6e73",
50
+ primary: "#000000",
51
+ onPrimary: "#ffffff",
52
+ success: "#1f7a36",
53
+ warning: "#945700",
54
+ danger: "#c70014",
55
+ info: "#0060c7",
56
+ };
57
+ /* The neutral brand's tuned selected tint (no brand at all). */
58
+ const NEUTRAL_SELECTED = "#f2f2f4";
59
+
60
+ /* Mortar's system stack, plus the fonts Windows and Android mail apps have. */
61
+ const SANS =
62
+ '-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif';
63
+ const SERIF = 'Georgia, "Times New Roman", Times, serif';
64
+ const MONO = '"SF Mono", Menlo, Consolas, "Courier New", monospace';
65
+ const GENERIC: Record<string, string> = {
66
+ "sans-serif": SANS,
67
+ "system-ui": SANS,
68
+ "ui-sans-serif": SANS,
69
+ serif: SERIF,
70
+ "ui-serif": SERIF,
71
+ monospace: MONO,
72
+ "ui-monospace": MONO,
73
+ };
74
+
75
+ /**
76
+ * A brand font list for email: `var()` entries (which email cannot resolve)
77
+ * and generic families are dropped, and a stack every client has is
78
+ * appended, serif or monospace when the brand's generic family is one.
79
+ */
80
+ function fontStack(value: string | undefined, key: string): string | undefined {
81
+ const text = value?.trim();
82
+ if (!text) return undefined;
83
+ if (!isBrandFont(text))
84
+ throw new Error(
85
+ `Invalid Mortar brand font for fonts.${key}: "${text}". Use family names, quoted names and generic families separated by commas, e.g. "Inter", sans-serif.`,
86
+ );
87
+ let fallback = SANS;
88
+ const names = text
89
+ .split(",")
90
+ .map((name) => name.trim())
91
+ .filter((name) => {
92
+ if (/^var\(/i.test(name)) return false;
93
+ const generic = GENERIC[name.toLowerCase()];
94
+ if (generic) fallback = generic;
95
+ return !generic;
96
+ });
97
+ return [...names, fallback].join(", ");
98
+ }
99
+
100
+ /* Colour parsing: the opaque colour syntax a brand can resolve without a
101
+ browser. Everything is converted to sRGB and written as #rrggbb. */
102
+ type Rgb = [number, number, number];
103
+
104
+ const linear = (v: number) =>
105
+ v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
106
+ const gamma = (v: number) =>
107
+ v <= 0.0031308 ? v * 12.92 : 1.055 * v ** (1 / 2.4) - 0.055;
108
+
109
+ function toOklab([r, g, b]: Rgb): Rgb {
110
+ const [lr, lg, lb] = [r, g, b].map(linear);
111
+ const l = Math.cbrt(
112
+ 0.4122214708 * lr + 0.5363325363 * lg + 0.0514459929 * lb,
113
+ );
114
+ const m = Math.cbrt(
115
+ 0.2119034982 * lr + 0.6806995451 * lg + 0.1073969566 * lb,
116
+ );
117
+ const s = Math.cbrt(
118
+ 0.0883024619 * lr + 0.2817188376 * lg + 0.6299787005 * lb,
119
+ );
120
+ return [
121
+ 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
122
+ 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
123
+ 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
124
+ ];
125
+ }
126
+ function fromOklab([L, a, b]: Rgb): Rgb {
127
+ const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
128
+ const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
129
+ const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
130
+ return [
131
+ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
132
+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
133
+ -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,
134
+ ].map(gamma) as Rgb;
135
+ }
136
+
137
+ /** sRGB channels in 0–1 as #rrggbb, clipped to the sRGB gamut. */
138
+ function hex(rgb: Rgb): string {
139
+ return `#${rgb
140
+ .map((v) =>
141
+ Math.round(Math.min(1, Math.max(0, v)) * 255)
142
+ .toString(16)
143
+ .padStart(2, "0"),
144
+ )
145
+ .join("")}`;
146
+ }
147
+
148
+ /** A number, or a percentage of `whole`. */
149
+ function amount(value: string, whole: number): number {
150
+ const n = parseFloat(value);
151
+ if (!/^[+-]?(?:\d+\.?\d*|\.\d+)%?$/.test(value) || Number.isNaN(n))
152
+ throw new Error();
153
+ return value.endsWith("%") ? (n / 100) * whole : n;
154
+ }
155
+ function hue(value: string): number {
156
+ const m = /^([+-]?(?:\d+\.?\d*|\.\d+))(deg|turn|rad)?$/.exec(value);
157
+ if (!m) throw new Error();
158
+ const n = parseFloat(m[1]);
159
+ return m[2] === "turn" ? n * 360 : m[2] === "rad" ? (n * 180) / Math.PI : n;
160
+ }
161
+
162
+ function hslToRgb(h: number, s: number, l: number): Rgb {
163
+ const k = (n: number) => (n + h / 30) % 12;
164
+ const a = s * Math.min(l, 1 - l);
165
+ return [0, 8, 4].map(
166
+ (n) => l - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1)),
167
+ ) as Rgb;
168
+ }
169
+
170
+ function parseColour(value: string): Rgb {
171
+ const text = value.trim().toLowerCase();
172
+ if (text === "white") return [1, 1, 1];
173
+ if (text === "black") return [0, 0, 0];
174
+ const short = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(text);
175
+ if (short) return short.slice(1).map((d) => parseInt(d + d, 16) / 255) as Rgb;
176
+ const long = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/.exec(text);
177
+ if (long) return long.slice(1).map((d) => parseInt(d, 16) / 255) as Rgb;
178
+ const fn = /^(rgba?|hsla?|oklab|oklch)\(([^()]*)\)$/.exec(text);
179
+ if (!fn) throw new Error();
180
+ const [channels, alpha] = fn[2].split("/");
181
+ const parts = channels.trim().split(/[\s,]+/);
182
+ const extraAlpha = parts.length === 4 ? parts.pop() : undefined;
183
+ const opacity = alpha ?? extraAlpha;
184
+ if (opacity !== undefined && amount(opacity.trim(), 1) !== 1)
185
+ throw new Error();
186
+ if (parts.length !== 3) throw new Error();
187
+ const [x, y, z] = parts;
188
+ switch (fn[1]) {
189
+ case "rgb":
190
+ case "rgba":
191
+ return [x, y, z].map((v) => amount(v, 255) / 255) as Rgb;
192
+ case "hsl":
193
+ case "hsla":
194
+ return hslToRgb(hue(x), amount(y, 100) / 100, amount(z, 100) / 100);
195
+ case "oklab":
196
+ return fromOklab([amount(x, 1), amount(y, 0.4), amount(z, 0.4)]);
197
+ default: {
198
+ const c = amount(y, 0.4),
199
+ h = (hue(z) * Math.PI) / 180;
200
+ return fromOklab([amount(x, 1), c * Math.cos(h), c * Math.sin(h)]);
201
+ }
202
+ }
203
+ }
204
+
205
+ function colour(value: string | undefined, key: string): string | undefined {
206
+ const text = value?.trim();
207
+ if (!text) return undefined;
208
+ try {
209
+ return hex(parseColour(text));
210
+ } catch {
211
+ throw new Error(
212
+ `Mortar email colours must be literal and opaque, for light.${key}: "${text}". Use a hex value, white, black, or rgb(), hsl(), oklab() or oklch().`,
213
+ );
214
+ }
215
+ }
216
+
217
+ /** color-mix(in oklab, a p%, b) as #rrggbb. */
218
+ function mix(a: string, b: string, percentA: number): string {
219
+ const t = percentA / 100;
220
+ const [x, y] = [toOklab(parseColour(a)), toOklab(parseColour(b))];
221
+ return hex(fromOklab(x.map((v, i) => v * t + y[i] * (1 - t)) as Rgb));
222
+ }
223
+
224
+ /**
225
+ * The email theme for a brand, in its light appearance: emails render light,
226
+ * since most clients ignore or override a dark one. Without a brand, Mortar's
227
+ * neutral defaults. Brand colours must be literal (`var()`, `color-mix()`
228
+ * and `light-dark()` need a browser) and opaque; the accent gradient is not
229
+ * used, as most clients cannot paint one, so accents use the flat `accent`.
230
+ */
231
+ export function emailTheme(brand?: BrandDefinition): EmailTheme {
232
+ const light = brand?.light ?? {};
233
+ const paper = colour(light.paper, "paper") ?? DEFAULTS.paper;
234
+ const primary = colour(light.primary, "primary") ?? DEFAULTS.primary;
235
+ const onPrimary = colour(light.onPrimary, "onPrimary") ?? DEFAULTS.onPrimary;
236
+ const font = fontStack(brand?.fonts?.body, "body") ?? SANS;
237
+ return {
238
+ ...DEFAULTS,
239
+ paper,
240
+ surface: colour(light.surface, "surface") ?? DEFAULTS.surface,
241
+ sunken: colour(light.sunken, "sunken") ?? DEFAULTS.sunken,
242
+ primary,
243
+ onPrimary,
244
+ accent: colour(light.accent, "accent") ?? primary,
245
+ onAccent: colour(light.onAccent, "onAccent") ?? onPrimary,
246
+ link: colour(light.link, "link") ?? primary,
247
+ selected:
248
+ colour(light.selected, "selected") ??
249
+ (brand ? mix(primary, paper, 8) : NEUTRAL_SELECTED),
250
+ font,
251
+ fontHeading: fontStack(brand?.fonts?.heading, "heading") ?? font,
252
+ mono: MONO,
253
+ };
254
+ }
package/src/email.tsx ADDED
@@ -0,0 +1,413 @@
1
+ /* Transactional email: @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
+ Html,
20
+ Img,
21
+ Link,
22
+ Preview,
23
+ Text,
24
+ render,
25
+ } from "@react-email/components";
26
+ import { emailTheme, type EmailTheme } from "./email-theme.js";
27
+
28
+ export { emailTheme } from "./email-theme.js";
29
+ export type { EmailTheme } from "./email-theme.js";
30
+
31
+ const ThemeContext = createContext<EmailTheme | undefined>(undefined);
32
+ let neutral: EmailTheme | undefined;
33
+ /** The theme from the enclosing EmailShell, or Mortar's neutral theme. */
34
+ function useTheme(): EmailTheme {
35
+ return useContext(ThemeContext) ?? (neutral ??= emailTheme());
36
+ }
37
+
38
+ /* Links leave the mail client, so only web and mail addresses are allowed. */
39
+ function assertHref(href: string, component: string, mail = false) {
40
+ if (!(mail ? /^(?:https?:|mailto:)/i : /^https?:\/\//i).test(href.trim()))
41
+ throw new Error(
42
+ `Mortar ${component} needs an absolute ${mail ? "http(s) or mailto" : "http(s)"} URL: "${href}"`,
43
+ );
44
+ }
45
+
46
+ /* A one-cell layout table. Outlook for Windows ignores padding, margins and
47
+ backgrounds on tables, so spacing and fills go on the cell. */
48
+ function Cell({
49
+ style,
50
+ children,
51
+ }: {
52
+ style: CSSProperties;
53
+ children: ReactNode;
54
+ }) {
55
+ return (
56
+ <table
57
+ role="presentation"
58
+ width="100%"
59
+ border={0}
60
+ cellPadding={0}
61
+ cellSpacing={0}
62
+ >
63
+ <tbody>
64
+ <tr>
65
+ <td style={style}>{children}</td>
66
+ </tr>
67
+ </tbody>
68
+ </table>
69
+ );
70
+ }
71
+
72
+ export interface EmailLogo {
73
+ /** An absolute URL: the email is read away from your site. */
74
+ src: string;
75
+ alt: string;
76
+ width: number;
77
+ height: number;
78
+ }
79
+
80
+ export interface EmailShellProps {
81
+ /** The inbox preview line shown after the subject. */
82
+ preview: string;
83
+ /** From `emailTheme(brand)`; Mortar's neutral theme by default. */
84
+ theme?: EmailTheme;
85
+ logo?: EmailLogo;
86
+ /** Why the person received the email, and what to do if it wasn't for them. */
87
+ footer?: ReactNode;
88
+ lang?: string;
89
+ dir?: "ltr" | "rtl";
90
+ children: ReactNode;
91
+ }
92
+ /**
93
+ * The whole email: a card up to 600px wide on the sunken backdrop, with an
94
+ * optional logo above it and footer below. It sets the theme for the email
95
+ * components inside, and marks the email light-only so mail apps don't
96
+ * recolour the brand.
97
+ */
98
+ export function EmailShell({
99
+ preview,
100
+ theme: given,
101
+ logo,
102
+ footer,
103
+ lang = "en",
104
+ dir = "ltr",
105
+ children,
106
+ }: EmailShellProps) {
107
+ const theme = given ?? emailTheme();
108
+ if (logo) assertHref(logo.src, "EmailShell logo");
109
+ return (
110
+ <ThemeContext.Provider value={theme}>
111
+ <Html lang={lang} dir={dir}>
112
+ <Head>
113
+ <meta name="color-scheme" content="light" />
114
+ <meta name="supported-color-schemes" content="light" />
115
+ </Head>
116
+ <Preview>{preview}</Preview>
117
+ <Body
118
+ style={{
119
+ margin: 0,
120
+ padding: "32px 12px",
121
+ backgroundColor: theme.sunken,
122
+ color: theme.ink,
123
+ fontFamily: theme.font,
124
+ }}
125
+ >
126
+ <Container style={{ width: "100%", maxWidth: "600px" }}>
127
+ {logo && (
128
+ <Cell style={{ padding: "0 0 24px" }}>
129
+ <Img
130
+ src={logo.src}
131
+ alt={logo.alt}
132
+ width={logo.width}
133
+ height={logo.height}
134
+ />
135
+ </Cell>
136
+ )}
137
+ <Cell
138
+ style={{
139
+ backgroundColor: theme.surface,
140
+ border: `1px solid ${theme.line}`,
141
+ borderRadius: "12px",
142
+ padding: "32px",
143
+ }}
144
+ >
145
+ {children}
146
+ </Cell>
147
+ {footer && (
148
+ <Cell style={{ padding: "24px 32px 0" }}>
149
+ <Text
150
+ style={{
151
+ margin: 0,
152
+ fontFamily: theme.font,
153
+ fontSize: "12px",
154
+ lineHeight: "18px",
155
+ color: theme.muted,
156
+ }}
157
+ >
158
+ {footer}
159
+ </Text>
160
+ </Cell>
161
+ )}
162
+ </Container>
163
+ </Body>
164
+ </Html>
165
+ </ThemeContext.Provider>
166
+ );
167
+ }
168
+
169
+ export interface EmailHeadingProps {
170
+ /** 1 for the email's title (once per email), 2 for a section. */
171
+ level?: 1 | 2;
172
+ children: ReactNode;
173
+ }
174
+ export function EmailHeading({ level = 1, children }: EmailHeadingProps) {
175
+ const theme = useTheme();
176
+ return (
177
+ <Heading
178
+ as={level === 1 ? "h1" : "h2"}
179
+ style={{
180
+ margin: "0 0 16px",
181
+ fontFamily: theme.fontHeading,
182
+ fontSize: level === 1 ? "24px" : "18px",
183
+ lineHeight: level === 1 ? "32px" : "26px",
184
+ fontWeight: 600,
185
+ letterSpacing: "-0.02em",
186
+ color: theme.ink,
187
+ }}
188
+ >
189
+ {children}
190
+ </Heading>
191
+ );
192
+ }
193
+
194
+ export interface EmailTextProps {
195
+ /** `muted` for secondary details such as an expiry time. */
196
+ tone?: "default" | "muted";
197
+ size?: "md" | "sm";
198
+ children: ReactNode;
199
+ }
200
+ /** A paragraph. 16px by default: email is read on phones, at arm's length. */
201
+ export function EmailText({
202
+ tone = "default",
203
+ size = "md",
204
+ children,
205
+ }: EmailTextProps) {
206
+ const theme = useTheme();
207
+ return (
208
+ <Text
209
+ style={{
210
+ margin: "0 0 16px",
211
+ fontFamily: theme.font,
212
+ fontSize: size === "md" ? "16px" : "14px",
213
+ lineHeight: size === "md" ? "24px" : "20px",
214
+ color: tone === "muted" ? theme.muted : theme.ink,
215
+ }}
216
+ >
217
+ {children}
218
+ </Text>
219
+ );
220
+ }
221
+
222
+ export interface EmailButtonProps {
223
+ /** An absolute http(s) URL. */
224
+ href: string;
225
+ children: ReactNode;
226
+ }
227
+ /**
228
+ * The email's main action, on its own line. Padding is applied in a way
229
+ * Outlook for Windows keeps, so the whole button is clickable there too.
230
+ * Follow it with the URL as an EmailLink for clients that block buttons.
231
+ */
232
+ export function EmailButton({ href, children }: EmailButtonProps) {
233
+ const theme = useTheme();
234
+ assertHref(href, "EmailButton");
235
+ return (
236
+ <Cell style={{ padding: "8px 0 24px" }}>
237
+ <Button
238
+ href={href}
239
+ style={{
240
+ display: "inline-block",
241
+ backgroundColor: theme.primary,
242
+ color: theme.onPrimary,
243
+ fontFamily: theme.font,
244
+ fontSize: "16px",
245
+ lineHeight: "24px",
246
+ fontWeight: 600,
247
+ textDecoration: "none",
248
+ padding: "12px 24px",
249
+ borderRadius: "8px",
250
+ }}
251
+ >
252
+ {children}
253
+ </Button>
254
+ </Cell>
255
+ );
256
+ }
257
+
258
+ export interface EmailLinkProps {
259
+ /** An absolute http(s) or mailto URL. */
260
+ href: string;
261
+ /** The URL itself when omitted, for "paste this link" fallbacks. */
262
+ children?: ReactNode;
263
+ }
264
+ export function EmailLink({ href, children }: EmailLinkProps) {
265
+ const theme = useTheme();
266
+ assertHref(href, "EmailLink", true);
267
+ return (
268
+ <Link
269
+ href={href}
270
+ style={{
271
+ color: theme.link,
272
+ textDecoration: "underline",
273
+ wordBreak: "break-all",
274
+ }}
275
+ >
276
+ {children ?? href}
277
+ </Link>
278
+ );
279
+ }
280
+
281
+ export interface EmailCodeProps {
282
+ /** A one-time code, shown large and spaced for reading and copying. */
283
+ code: string;
284
+ }
285
+ export function EmailCode({ code }: EmailCodeProps) {
286
+ const theme = useTheme();
287
+ return (
288
+ <Cell style={{ padding: "8px 0 24px" }}>
289
+ <Cell
290
+ style={{
291
+ backgroundColor: theme.sunken,
292
+ borderRadius: "8px",
293
+ padding: "16px",
294
+ textAlign: "center",
295
+ }}
296
+ >
297
+ <Text
298
+ style={{
299
+ margin: 0,
300
+ fontFamily: theme.mono,
301
+ fontSize: "28px",
302
+ lineHeight: "36px",
303
+ fontWeight: 600,
304
+ letterSpacing: "0.2em",
305
+ color: theme.ink,
306
+ }}
307
+ >
308
+ {code}
309
+ </Text>
310
+ </Cell>
311
+ </Cell>
312
+ );
313
+ }
314
+
315
+ export interface RenderedEmail {
316
+ html: string;
317
+ /** The plain-text alternative: send it with the HTML. */
318
+ text: string;
319
+ }
320
+ /**
321
+ * An email element as HTML and plain text, ready for a sending service
322
+ * (Resend, SES, Postmark…). Keep the HTML under about 100 KB: Gmail clips
323
+ * longer messages.
324
+ */
325
+ export async function renderEmail(element: ReactNode): Promise<RenderedEmail> {
326
+ const [html, text] = await Promise.all([
327
+ render(element),
328
+ render(element, { plainText: true }),
329
+ ]);
330
+ return { html, text };
331
+ }
332
+
333
+ /* Templates */
334
+
335
+ export interface VerifyEmailProps {
336
+ /** Your product, as the person knows it. */
337
+ productName: string;
338
+ /** A one-time code to type in, shown large. */
339
+ code?: string;
340
+ /** A confirmation link, shown as a button. Give `code`, `href` or both. */
341
+ href?: string;
342
+ /** The address being confirmed. */
343
+ recipient?: string;
344
+ /** Preformatted, e.g. "10 minutes". */
345
+ expiresIn?: string;
346
+ theme?: EmailTheme;
347
+ logo?: EmailLogo;
348
+ /** Replaces the default "if this wasn't you" footer. */
349
+ footer?: ReactNode;
350
+ lang?: string;
351
+ }
352
+ /**
353
+ * Confirms an email address with a code, a link or both: the email for the
354
+ * auth flow's verify-email step.
355
+ */
356
+ export function VerifyEmail({
357
+ productName,
358
+ code,
359
+ href,
360
+ recipient,
361
+ expiresIn,
362
+ theme,
363
+ logo,
364
+ footer,
365
+ lang,
366
+ }: VerifyEmailProps) {
367
+ if (!code && !href)
368
+ throw new Error("Mortar VerifyEmail needs a `code`, an `href` or both.");
369
+ const address = recipient ?? "your email address";
370
+ return (
371
+ <EmailShell
372
+ preview={`Confirm your email address for ${productName}`}
373
+ theme={theme}
374
+ logo={logo}
375
+ lang={lang}
376
+ footer={
377
+ footer ??
378
+ `You received this email because this address was used to sign up for ${productName}. If that wasn't you, you can ignore it.`
379
+ }
380
+ >
381
+ <EmailHeading>Confirm your email address</EmailHeading>
382
+ {code && (
383
+ <>
384
+ <EmailText>
385
+ Enter this code in {productName} to confirm {address}:
386
+ </EmailText>
387
+ <EmailCode code={code} />
388
+ </>
389
+ )}
390
+ {href && (
391
+ <>
392
+ <EmailText>
393
+ {code
394
+ ? "Or confirm with one click:"
395
+ : `Confirm ${address} to finish setting up your ${productName} account.`}
396
+ </EmailText>
397
+ <EmailButton href={href}>Confirm email address</EmailButton>
398
+ <EmailText tone="muted" size="sm">
399
+ If the button doesn't work, paste this link into your browser:{" "}
400
+ <EmailLink href={href} />
401
+ </EmailText>
402
+ </>
403
+ )}
404
+ {expiresIn && (
405
+ <EmailText tone="muted" size="sm">
406
+ {code && href
407
+ ? `This code and link expire in ${expiresIn}.`
408
+ : `This ${code ? "code" : "link"} expires in ${expiresIn}.`}
409
+ </EmailText>
410
+ )}
411
+ </EmailShell>
412
+ );
413
+ }