@tonycodes-ui/mortar 0.14.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 +3 -2
- 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.d.ts +4 -98
- package/dist/email.js +4 -151
- package/docs/auth-flows.md +1 -1
- package/docs/email.md +34 -19
- package/package.json +1 -1
- package/src/{email.tsx → email-components.tsx} +208 -93
- package/src/email-templates.tsx +355 -0
- package/src/email.ts +47 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { Tone } from "./primitives.js";
|
|
3
|
+
import { type EmailTheme } from "./email-theme.js";
|
|
4
|
+
export declare function assertHref(href: string, component: string, mail?: boolean): void;
|
|
5
|
+
export interface EmailLogo {
|
|
6
|
+
/** An absolute URL: the email is read away from your site. */
|
|
7
|
+
src: string;
|
|
8
|
+
alt: string;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
export interface EmailShellProps {
|
|
13
|
+
/** The inbox preview line shown after the subject. */
|
|
14
|
+
preview: string;
|
|
15
|
+
/** From `emailTheme(brand)`; Mortar's neutral theme by default. */
|
|
16
|
+
theme?: EmailTheme;
|
|
17
|
+
logo?: EmailLogo;
|
|
18
|
+
/** Why the person received the email, and what to do if it wasn't for them. */
|
|
19
|
+
footer?: ReactNode;
|
|
20
|
+
lang?: string;
|
|
21
|
+
dir?: "ltr" | "rtl";
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The whole email: a card up to 600px wide on the sunken backdrop, with an
|
|
26
|
+
* optional logo above it and footer below. It sets the theme for the email
|
|
27
|
+
* components inside, and marks the email light-only so mail apps don't
|
|
28
|
+
* recolour the brand.
|
|
29
|
+
*/
|
|
30
|
+
export declare function EmailShell({ preview, theme: given, logo, footer, lang, dir, children, }: EmailShellProps): import("react").JSX.Element;
|
|
31
|
+
export interface EmailHeadingProps {
|
|
32
|
+
/** 1 for the email's title (once per email), 2 for a section. */
|
|
33
|
+
level?: 1 | 2;
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
}
|
|
36
|
+
export declare function EmailHeading({ level, children }: EmailHeadingProps): import("react").JSX.Element;
|
|
37
|
+
export interface EmailTextProps {
|
|
38
|
+
/** `muted` for secondary details such as an expiry time. */
|
|
39
|
+
tone?: "default" | "muted";
|
|
40
|
+
size?: "md" | "sm";
|
|
41
|
+
children: ReactNode;
|
|
42
|
+
}
|
|
43
|
+
/** A paragraph. 16px by default: email is read on phones, at arm's length. */
|
|
44
|
+
export declare function EmailText({ tone, size, children, }: EmailTextProps): import("react").JSX.Element;
|
|
45
|
+
export interface EmailButtonProps {
|
|
46
|
+
/** An absolute http(s) URL. */
|
|
47
|
+
href: string;
|
|
48
|
+
children: ReactNode;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The email's main action, on its own line. Padding is applied in a way
|
|
52
|
+
* Outlook for Windows keeps, so the whole button is clickable there too.
|
|
53
|
+
* Follow it with the URL as an EmailLink for clients that block buttons.
|
|
54
|
+
*/
|
|
55
|
+
export declare function EmailButton({ href, children }: EmailButtonProps): import("react").JSX.Element;
|
|
56
|
+
export interface EmailLinkProps {
|
|
57
|
+
/** An absolute http(s) or mailto URL. */
|
|
58
|
+
href: string;
|
|
59
|
+
/** The URL itself when omitted, for "paste this link" fallbacks. */
|
|
60
|
+
children?: ReactNode;
|
|
61
|
+
}
|
|
62
|
+
export declare function EmailLink({ href, children }: EmailLinkProps): import("react").JSX.Element;
|
|
63
|
+
export interface EmailCodeProps {
|
|
64
|
+
/** A one-time code, shown large and spaced for reading and copying. */
|
|
65
|
+
code: string;
|
|
66
|
+
}
|
|
67
|
+
export declare function EmailCode({ code }: EmailCodeProps): import("react").JSX.Element;
|
|
68
|
+
export interface EmailCalloutProps {
|
|
69
|
+
/** Colours the edge: a status, or `neutral` for an aside such as a quoted message. */
|
|
70
|
+
tone?: Tone;
|
|
71
|
+
title?: string;
|
|
72
|
+
children: ReactNode;
|
|
73
|
+
}
|
|
74
|
+
/** A highlighted block: a warning, a status or a quoted personal message. */
|
|
75
|
+
export declare function EmailCallout({ tone, title, children, }: EmailCalloutProps): import("react").JSX.Element;
|
|
76
|
+
/** A rule between sections of an email. */
|
|
77
|
+
export declare function EmailDivider(): import("react").JSX.Element;
|
|
78
|
+
export interface EmailSummaryItem {
|
|
79
|
+
name: string;
|
|
80
|
+
/** Preformatted, e.g. "£42.00". */
|
|
81
|
+
price: string;
|
|
82
|
+
quantity?: number;
|
|
83
|
+
/** Chosen options, e.g. "Natural · Small". */
|
|
84
|
+
meta?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface EmailSummaryProps {
|
|
87
|
+
/** Line items, each with its preformatted price. */
|
|
88
|
+
items?: EmailSummaryItem[];
|
|
89
|
+
/** Cost lines under the items, as OrderSummary takes them: subtotal, shipping, tax. */
|
|
90
|
+
lines?: {
|
|
91
|
+
label: string;
|
|
92
|
+
value: string;
|
|
93
|
+
}[];
|
|
94
|
+
total: {
|
|
95
|
+
label: string;
|
|
96
|
+
value: string;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A receipt's items, cost lines and total, as a two-column table: labels at
|
|
101
|
+
* the start, amounts at the end. Amounts are preformatted strings, as in
|
|
102
|
+
* Mortar's commerce components.
|
|
103
|
+
*/
|
|
104
|
+
export declare function EmailSummary({ items, lines, total, }: EmailSummaryProps): import("react").JSX.Element;
|
|
105
|
+
export interface RenderedEmail {
|
|
106
|
+
html: string;
|
|
107
|
+
/** The plain-text alternative: send it with the HTML. */
|
|
108
|
+
text: string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* An email element as HTML and plain text, ready for a sending service
|
|
112
|
+
* (Resend, SES, Postmark…). Keep the HTML under about 100 KB: Gmail clips
|
|
113
|
+
* longer messages.
|
|
114
|
+
*/
|
|
115
|
+
export declare function renderEmail(element: ReactNode): Promise<RenderedEmail>;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/* Email components for @tonycodes-ui/mortar/email. Built on React Email,
|
|
3
|
+
which renders the table layout and inline styles email clients need; these
|
|
4
|
+
components give it Mortar's tokens, brand and copy. Nothing here uses
|
|
5
|
+
Mortar's stylesheet or app components, which email clients cannot run.
|
|
6
|
+
Requires the optional peer dependency @react-email/components. */
|
|
7
|
+
import { createContext, useContext, } from "react";
|
|
8
|
+
import { Body, Button, Container, Head, Heading, Hr, Html, Img, Link, Preview, Text, render, } from "@react-email/components";
|
|
9
|
+
import { emailTheme } from "./email-theme.js";
|
|
10
|
+
const ShellContext = createContext(undefined);
|
|
11
|
+
let neutral;
|
|
12
|
+
/** The theme from the enclosing EmailShell, or Mortar's neutral theme. */
|
|
13
|
+
function useTheme() {
|
|
14
|
+
return useContext(ShellContext)?.theme ?? (neutral ??= emailTheme());
|
|
15
|
+
}
|
|
16
|
+
/* Email clients don't support logical properties, so the inline start and
|
|
17
|
+
end are worked out from the shell's direction. */
|
|
18
|
+
function useSides() {
|
|
19
|
+
const rtl = useContext(ShellContext)?.dir === "rtl";
|
|
20
|
+
return {
|
|
21
|
+
start: rtl ? "right" : "left",
|
|
22
|
+
end: rtl ? "left" : "right",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/* Links leave the mail client, so only web and mail addresses are allowed. */
|
|
26
|
+
export function assertHref(href, component, mail = false) {
|
|
27
|
+
if (!(mail ? /^(?:https?:|mailto:)/i : /^https?:\/\//i).test(href.trim()))
|
|
28
|
+
throw new Error(`Mortar ${component} needs an absolute ${mail ? "http(s) or mailto" : "http(s)"} URL: "${href}"`);
|
|
29
|
+
}
|
|
30
|
+
/* A one-cell layout table. Outlook for Windows ignores padding, margins and
|
|
31
|
+
backgrounds on tables, so spacing and fills go on the cell. */
|
|
32
|
+
function Cell({ style, children, }) {
|
|
33
|
+
return (_jsx("table", { role: "presentation", width: "100%", border: 0, cellPadding: 0, cellSpacing: 0, children: _jsx("tbody", { children: _jsx("tr", { children: _jsx("td", { style: style, children: children }) }) }) }));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The whole email: a card up to 600px wide on the sunken backdrop, with an
|
|
37
|
+
* optional logo above it and footer below. It sets the theme for the email
|
|
38
|
+
* components inside, and marks the email light-only so mail apps don't
|
|
39
|
+
* recolour the brand.
|
|
40
|
+
*/
|
|
41
|
+
export function EmailShell({ preview, theme: given, logo, footer, lang = "en", dir = "ltr", children, }) {
|
|
42
|
+
const theme = given ?? emailTheme();
|
|
43
|
+
if (logo)
|
|
44
|
+
assertHref(logo.src, "EmailShell logo");
|
|
45
|
+
return (_jsx(ShellContext.Provider, { value: { theme, dir }, children: _jsxs(Html, { lang: lang, dir: dir, children: [_jsxs(Head, { children: [_jsx("meta", { name: "color-scheme", content: "light" }), _jsx("meta", { name: "supported-color-schemes", content: "light" })] }), _jsx(Preview, { children: preview }), _jsx(Body, { style: {
|
|
46
|
+
margin: 0,
|
|
47
|
+
padding: "32px 12px",
|
|
48
|
+
backgroundColor: theme.sunken,
|
|
49
|
+
color: theme.ink,
|
|
50
|
+
fontFamily: theme.font,
|
|
51
|
+
}, children: _jsxs(Container, { style: { width: "100%", maxWidth: "600px" }, children: [logo && (_jsx(Cell, { style: { padding: "0 0 24px" }, children: _jsx(Img, { src: logo.src, alt: logo.alt, width: logo.width, height: logo.height }) })), _jsx(Cell, { style: {
|
|
52
|
+
backgroundColor: theme.surface,
|
|
53
|
+
border: `1px solid ${theme.line}`,
|
|
54
|
+
borderRadius: "12px",
|
|
55
|
+
padding: "32px",
|
|
56
|
+
}, children: children }), footer && (_jsx(Cell, { style: { padding: "24px 32px 0" }, children: _jsx(Text, { style: {
|
|
57
|
+
margin: 0,
|
|
58
|
+
fontFamily: theme.font,
|
|
59
|
+
fontSize: "12px",
|
|
60
|
+
lineHeight: "18px",
|
|
61
|
+
color: theme.muted,
|
|
62
|
+
}, children: footer }) }))] }) })] }) }));
|
|
63
|
+
}
|
|
64
|
+
export function EmailHeading({ level = 1, children }) {
|
|
65
|
+
const theme = useTheme();
|
|
66
|
+
return (_jsx(Heading, { as: level === 1 ? "h1" : "h2", style: {
|
|
67
|
+
margin: "0 0 16px",
|
|
68
|
+
fontFamily: theme.fontHeading,
|
|
69
|
+
fontSize: level === 1 ? "24px" : "18px",
|
|
70
|
+
lineHeight: level === 1 ? "32px" : "26px",
|
|
71
|
+
fontWeight: 600,
|
|
72
|
+
letterSpacing: "-0.02em",
|
|
73
|
+
color: theme.ink,
|
|
74
|
+
}, children: children }));
|
|
75
|
+
}
|
|
76
|
+
/** A paragraph. 16px by default: email is read on phones, at arm's length. */
|
|
77
|
+
export function EmailText({ tone = "default", size = "md", children, }) {
|
|
78
|
+
const theme = useTheme();
|
|
79
|
+
return (_jsx(Text, { style: {
|
|
80
|
+
margin: "0 0 16px",
|
|
81
|
+
fontFamily: theme.font,
|
|
82
|
+
fontSize: size === "md" ? "16px" : "14px",
|
|
83
|
+
lineHeight: size === "md" ? "24px" : "20px",
|
|
84
|
+
color: tone === "muted" ? theme.muted : theme.ink,
|
|
85
|
+
}, children: children }));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The email's main action, on its own line. Padding is applied in a way
|
|
89
|
+
* Outlook for Windows keeps, so the whole button is clickable there too.
|
|
90
|
+
* Follow it with the URL as an EmailLink for clients that block buttons.
|
|
91
|
+
*/
|
|
92
|
+
export function EmailButton({ href, children }) {
|
|
93
|
+
const theme = useTheme();
|
|
94
|
+
assertHref(href, "EmailButton");
|
|
95
|
+
return (_jsx(Cell, { style: { padding: "8px 0 24px" }, children: _jsx(Button, { href: href, style: {
|
|
96
|
+
display: "inline-block",
|
|
97
|
+
backgroundColor: theme.primary,
|
|
98
|
+
color: theme.onPrimary,
|
|
99
|
+
fontFamily: theme.font,
|
|
100
|
+
fontSize: "16px",
|
|
101
|
+
lineHeight: "24px",
|
|
102
|
+
fontWeight: 600,
|
|
103
|
+
textDecoration: "none",
|
|
104
|
+
padding: "12px 24px",
|
|
105
|
+
borderRadius: "8px",
|
|
106
|
+
}, children: children }) }));
|
|
107
|
+
}
|
|
108
|
+
export function EmailLink({ href, children }) {
|
|
109
|
+
const theme = useTheme();
|
|
110
|
+
assertHref(href, "EmailLink", true);
|
|
111
|
+
return (_jsx(Link, { href: href, style: {
|
|
112
|
+
color: theme.link,
|
|
113
|
+
textDecoration: "underline",
|
|
114
|
+
// A bare URL may break anywhere so it can't widen the email.
|
|
115
|
+
wordBreak: children === undefined ? "break-all" : undefined,
|
|
116
|
+
}, children: children ?? href }));
|
|
117
|
+
}
|
|
118
|
+
export function EmailCode({ code }) {
|
|
119
|
+
const theme = useTheme();
|
|
120
|
+
return (_jsx(Cell, { style: { padding: "8px 0 24px" }, children: _jsx(Cell, { style: {
|
|
121
|
+
backgroundColor: theme.sunken,
|
|
122
|
+
borderRadius: "8px",
|
|
123
|
+
padding: "16px",
|
|
124
|
+
textAlign: "center",
|
|
125
|
+
}, children: _jsx(Text, { style: {
|
|
126
|
+
margin: 0,
|
|
127
|
+
fontFamily: theme.mono,
|
|
128
|
+
fontSize: "28px",
|
|
129
|
+
lineHeight: "36px",
|
|
130
|
+
fontWeight: 600,
|
|
131
|
+
letterSpacing: "0.2em",
|
|
132
|
+
color: theme.ink,
|
|
133
|
+
}, children: code }) }) }));
|
|
134
|
+
}
|
|
135
|
+
/** A highlighted block: a warning, a status or a quoted personal message. */
|
|
136
|
+
export function EmailCallout({ tone = "neutral", title, children, }) {
|
|
137
|
+
const theme = useTheme();
|
|
138
|
+
const { start } = useSides();
|
|
139
|
+
const edge = tone === "neutral" ? theme.line : theme[tone];
|
|
140
|
+
return (_jsx(Cell, { style: { padding: "8px 0 24px" }, children: _jsxs(Cell, { style: {
|
|
141
|
+
backgroundColor: theme.sunken,
|
|
142
|
+
[start === "left" ? "borderLeft" : "borderRight"]: `4px solid ${edge}`,
|
|
143
|
+
padding: "16px 20px",
|
|
144
|
+
fontFamily: theme.font,
|
|
145
|
+
fontSize: "15px",
|
|
146
|
+
lineHeight: "22px",
|
|
147
|
+
color: theme.ink,
|
|
148
|
+
}, children: [title && (_jsx(Text, { style: {
|
|
149
|
+
margin: "0 0 4px",
|
|
150
|
+
fontFamily: theme.font,
|
|
151
|
+
fontSize: "15px",
|
|
152
|
+
lineHeight: "22px",
|
|
153
|
+
fontWeight: 600,
|
|
154
|
+
color: theme.ink,
|
|
155
|
+
}, children: title })), children] }) }));
|
|
156
|
+
}
|
|
157
|
+
/** A rule between sections of an email. */
|
|
158
|
+
export function EmailDivider() {
|
|
159
|
+
const theme = useTheme();
|
|
160
|
+
return (_jsx(Hr, { style: {
|
|
161
|
+
margin: "8px 0 24px",
|
|
162
|
+
border: "none",
|
|
163
|
+
borderTop: `1px solid ${theme.line}`,
|
|
164
|
+
} }));
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* A receipt's items, cost lines and total, as a two-column table: labels at
|
|
168
|
+
* the start, amounts at the end. Amounts are preformatted strings, as in
|
|
169
|
+
* Mortar's commerce components.
|
|
170
|
+
*/
|
|
171
|
+
export function EmailSummary({ items = [], lines = [], total, }) {
|
|
172
|
+
const theme = useTheme();
|
|
173
|
+
const { start, end } = useSides();
|
|
174
|
+
const cell = (side, extra = {}) => ({
|
|
175
|
+
padding: "8px 0",
|
|
176
|
+
textAlign: side === "start" ? start : end,
|
|
177
|
+
verticalAlign: "top",
|
|
178
|
+
fontFamily: theme.font,
|
|
179
|
+
fontSize: "15px",
|
|
180
|
+
lineHeight: "22px",
|
|
181
|
+
color: theme.ink,
|
|
182
|
+
...extra,
|
|
183
|
+
});
|
|
184
|
+
const rule = `1px solid ${theme.line}`;
|
|
185
|
+
return (_jsx(Cell, { style: { padding: "8px 0 24px" }, children: _jsx("table", { "data-summary": "", role: "presentation", width: "100%", border: 0, cellPadding: 0, cellSpacing: 0, children: _jsxs("tbody", { children: [items.map((item, i) => (_jsxs("tr", { children: [_jsxs("td", { style: cell("start", { borderBottom: rule }), children: [item.name, item.quantity !== undefined && item.quantity !== 1 && (_jsxs("span", { style: { color: theme.muted }, children: [" \u00D7 ", item.quantity] })), item.meta && (_jsxs(_Fragment, { children: [_jsx("br", {}), _jsx("span", { style: { fontSize: "13px", color: theme.muted }, children: item.meta })] }))] }), _jsx("td", { style: cell("end", {
|
|
186
|
+
borderBottom: rule,
|
|
187
|
+
whiteSpace: "nowrap",
|
|
188
|
+
[start === "left" ? "paddingLeft" : "paddingRight"]: "16px",
|
|
189
|
+
}), children: item.price })] }, i))), lines.map((line, i) => (_jsxs("tr", { children: [_jsx("td", { style: cell("start", { color: theme.secondary }), children: line.label }), _jsx("td", { style: cell("end", {
|
|
190
|
+
color: theme.secondary,
|
|
191
|
+
whiteSpace: "nowrap",
|
|
192
|
+
}), children: line.value })] }, `line-${i}`))), _jsxs("tr", { children: [_jsx("td", { style: cell("start", { borderTop: rule, fontWeight: 600 }), children: total.label }), _jsx("td", { style: cell("end", {
|
|
193
|
+
borderTop: rule,
|
|
194
|
+
fontWeight: 600,
|
|
195
|
+
whiteSpace: "nowrap",
|
|
196
|
+
}), children: total.value })] })] }) }) }));
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* An email element as HTML and plain text, ready for a sending service
|
|
200
|
+
* (Resend, SES, Postmark…). Keep the HTML under about 100 KB: Gmail clips
|
|
201
|
+
* longer messages.
|
|
202
|
+
*/
|
|
203
|
+
export async function renderEmail(element) {
|
|
204
|
+
const [html, text] = await Promise.all([
|
|
205
|
+
render(element),
|
|
206
|
+
render(element, {
|
|
207
|
+
plainText: true,
|
|
208
|
+
htmlToTextOptions: {
|
|
209
|
+
// A summary reads as rows of label and amount, not run together.
|
|
210
|
+
selectors: [
|
|
211
|
+
{
|
|
212
|
+
selector: "table[data-summary]",
|
|
213
|
+
format: "dataTable",
|
|
214
|
+
options: { maxColumnWidth: 48 },
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
}),
|
|
219
|
+
]);
|
|
220
|
+
return { html, text };
|
|
221
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { EmailTheme } from "./email-theme.js";
|
|
3
|
+
import { type EmailLogo, type EmailSummaryItem } from "./email-components.js";
|
|
4
|
+
/** Props every template takes. */
|
|
5
|
+
export interface EmailTemplateProps {
|
|
6
|
+
/** Your product, as the person knows it. */
|
|
7
|
+
productName: string;
|
|
8
|
+
/** From `emailTheme(brand)`; Mortar's neutral theme by default. */
|
|
9
|
+
theme?: EmailTheme;
|
|
10
|
+
logo?: EmailLogo;
|
|
11
|
+
/** Replaces the template's footer, which says why the email was sent. */
|
|
12
|
+
footer?: ReactNode;
|
|
13
|
+
lang?: string;
|
|
14
|
+
dir?: "ltr" | "rtl";
|
|
15
|
+
}
|
|
16
|
+
export interface VerifyEmailProps extends EmailTemplateProps {
|
|
17
|
+
/** A one-time code to type in, shown large. */
|
|
18
|
+
code?: string;
|
|
19
|
+
/** A confirmation link, shown as a button. Give `code`, `href` or both. */
|
|
20
|
+
href?: string;
|
|
21
|
+
/** The address being confirmed. */
|
|
22
|
+
recipient?: string;
|
|
23
|
+
/** Preformatted, e.g. "10 minutes". */
|
|
24
|
+
expiresIn?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Confirms an email address with a code, a link or both: the email for the
|
|
28
|
+
* auth flow's verify-email step.
|
|
29
|
+
*/
|
|
30
|
+
export declare function VerifyEmail({ productName, code, href, recipient, expiresIn, footer, ...shell }: VerifyEmailProps): import("react").JSX.Element;
|
|
31
|
+
export interface MagicLinkProps extends EmailTemplateProps {
|
|
32
|
+
/** The sign-in link. */
|
|
33
|
+
href: string;
|
|
34
|
+
/** Preformatted, e.g. "15 minutes". */
|
|
35
|
+
expiresIn?: string;
|
|
36
|
+
/** Where the request came from, e.g. "Chrome on macOS, near London". */
|
|
37
|
+
requestedFrom?: string;
|
|
38
|
+
}
|
|
39
|
+
/** A passwordless sign-in link: the email behind SignInPanel. */
|
|
40
|
+
export declare function MagicLink({ productName, href, expiresIn, requestedFrom, footer, ...shell }: MagicLinkProps): import("react").JSX.Element;
|
|
41
|
+
export interface PasswordResetProps extends EmailTemplateProps {
|
|
42
|
+
/** The reset link. */
|
|
43
|
+
href: string;
|
|
44
|
+
/** The account's address, shown so the person knows which account. */
|
|
45
|
+
recipient?: string;
|
|
46
|
+
/** Preformatted, e.g. "1 hour". */
|
|
47
|
+
expiresIn?: string;
|
|
48
|
+
/** Where the request came from, e.g. "Firefox on Windows". */
|
|
49
|
+
requestedFrom?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The link for the auth flow's reset-password step. Send it only to an
|
|
53
|
+
* address that has an account, and show the same "check your email" page
|
|
54
|
+
* either way, so the form never reveals whether an account exists.
|
|
55
|
+
*/
|
|
56
|
+
export declare function PasswordReset({ productName, href, recipient, expiresIn, requestedFrom, footer, ...shell }: PasswordResetProps): import("react").JSX.Element;
|
|
57
|
+
export interface InviteProps extends EmailTemplateProps {
|
|
58
|
+
/** Who sent the invitation. */
|
|
59
|
+
inviterName: string;
|
|
60
|
+
/** The team or workspace; the product when omitted. */
|
|
61
|
+
workspaceName?: string;
|
|
62
|
+
/** The link to accept. */
|
|
63
|
+
href: string;
|
|
64
|
+
/** The inviter's own note, shown quoted. */
|
|
65
|
+
message?: string;
|
|
66
|
+
/** Preformatted, e.g. "7 days". */
|
|
67
|
+
expiresIn?: string;
|
|
68
|
+
}
|
|
69
|
+
/** An invitation to join a workspace. */
|
|
70
|
+
export declare function Invite({ productName, inviterName, workspaceName, href, message, expiresIn, footer, ...shell }: InviteProps): import("react").JSX.Element;
|
|
71
|
+
export interface ReceiptProps extends EmailTemplateProps {
|
|
72
|
+
orderNumber: string;
|
|
73
|
+
/** Preformatted, e.g. "6 November 2026". */
|
|
74
|
+
date: string;
|
|
75
|
+
items: EmailSummaryItem[];
|
|
76
|
+
/** Subtotal, shipping, tax, discounts. */
|
|
77
|
+
lines?: {
|
|
78
|
+
label: string;
|
|
79
|
+
value: string;
|
|
80
|
+
}[];
|
|
81
|
+
total: {
|
|
82
|
+
label: string;
|
|
83
|
+
value: string;
|
|
84
|
+
};
|
|
85
|
+
/** e.g. "Visa ending 4242". */
|
|
86
|
+
paymentMethod?: string;
|
|
87
|
+
/** The order in your app. */
|
|
88
|
+
href?: string;
|
|
89
|
+
/** Defaults to "Thanks for your order". */
|
|
90
|
+
title?: string;
|
|
91
|
+
}
|
|
92
|
+
/** An order confirmation or receipt, with items, costs and total. */
|
|
93
|
+
export declare function Receipt({ productName, orderNumber, date, items, lines, total, paymentMethod, href, title, footer, ...shell }: ReceiptProps): import("react").JSX.Element;
|
|
94
|
+
export interface NotificationProps extends EmailTemplateProps {
|
|
95
|
+
title: string;
|
|
96
|
+
/** The inbox preview line; the title when omitted. */
|
|
97
|
+
preview?: string;
|
|
98
|
+
children: ReactNode;
|
|
99
|
+
/** One main action. */
|
|
100
|
+
action?: {
|
|
101
|
+
label: string;
|
|
102
|
+
href: string;
|
|
103
|
+
};
|
|
104
|
+
/** Where the person can change which emails they get. */
|
|
105
|
+
preferencesHref?: string;
|
|
106
|
+
}
|
|
107
|
+
/** A product notification: a title, a message and at most one action. */
|
|
108
|
+
export declare function Notification({ productName, title, preview, children, action, preferencesHref, footer, ...shell }: NotificationProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { EmailButton, EmailCallout, EmailCode, EmailHeading, EmailLink, EmailShell, EmailSummary, EmailText, } from "./email-components.js";
|
|
3
|
+
/* The main action, then its URL for clients that block buttons. */
|
|
4
|
+
function Action({ href, label }) {
|
|
5
|
+
return (_jsxs(_Fragment, { children: [_jsx(EmailButton, { href: href, children: label }), _jsxs(EmailText, { tone: "muted", size: "sm", children: ["If the button doesn't work, paste this link into your browser:", " ", _jsx(EmailLink, { href: href })] })] }));
|
|
6
|
+
}
|
|
7
|
+
function Detail({ children }) {
|
|
8
|
+
return (_jsx(EmailText, { tone: "muted", size: "sm", children: children }));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Confirms an email address with a code, a link or both: the email for the
|
|
12
|
+
* auth flow's verify-email step.
|
|
13
|
+
*/
|
|
14
|
+
export function VerifyEmail({ productName, code, href, recipient, expiresIn, footer, ...shell }) {
|
|
15
|
+
if (!code && !href)
|
|
16
|
+
throw new Error("Mortar VerifyEmail needs a `code`, an `href` or both.");
|
|
17
|
+
const address = recipient ?? "your email address";
|
|
18
|
+
return (_jsxs(EmailShell, { ...shell, preview: `Confirm your email address for ${productName}`, footer: footer ??
|
|
19
|
+
`You received this email because this address was used to sign up for ${productName}. If that wasn't you, you can ignore it.`, children: [_jsx(EmailHeading, { children: "Confirm your email address" }), code && (_jsxs(_Fragment, { children: [_jsxs(EmailText, { children: ["Enter this code in ", productName, " to confirm ", address, ":"] }), _jsx(EmailCode, { code: code })] })), href && (_jsxs(_Fragment, { children: [_jsx(EmailText, { children: code
|
|
20
|
+
? "Or confirm with one click:"
|
|
21
|
+
: `Confirm ${address} to finish setting up your ${productName} account.` }), _jsx(Action, { href: href, label: "Confirm email address" })] })), expiresIn && (_jsx(Detail, { children: code && href
|
|
22
|
+
? `This code and link expire in ${expiresIn}.`
|
|
23
|
+
: `This ${code ? "code" : "link"} expires in ${expiresIn}.` }))] }));
|
|
24
|
+
}
|
|
25
|
+
/** A passwordless sign-in link: the email behind SignInPanel. */
|
|
26
|
+
export function MagicLink({ productName, href, expiresIn, requestedFrom, footer, ...shell }) {
|
|
27
|
+
return (_jsxs(EmailShell, { ...shell, preview: `Your sign-in link for ${productName}`, footer: footer ??
|
|
28
|
+
`You received this email because someone asked to sign in to ${productName} with this address. If that wasn't you, you can ignore it.`, children: [_jsxs(EmailHeading, { children: ["Sign in to ", productName] }), _jsxs(EmailText, { children: ["Use the link below to sign in to ", productName, "."] }), _jsx(Action, { href: href, label: `Sign in to ${productName}` }), expiresIn && _jsxs(Detail, { children: ["This link expires in ", expiresIn, "."] }), requestedFrom && _jsxs(Detail, { children: ["Requested from ", requestedFrom, "."] })] }));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The link for the auth flow's reset-password step. Send it only to an
|
|
32
|
+
* address that has an account, and show the same "check your email" page
|
|
33
|
+
* either way, so the form never reveals whether an account exists.
|
|
34
|
+
*/
|
|
35
|
+
export function PasswordReset({ productName, href, recipient, expiresIn, requestedFrom, footer, ...shell }) {
|
|
36
|
+
return (_jsxs(EmailShell, { ...shell, preview: `Reset your ${productName} password`, footer: footer ??
|
|
37
|
+
"If you didn't ask to reset your password, you can ignore this email. Your password won't change.", children: [_jsx(EmailHeading, { children: "Reset your password" }), _jsxs(EmailText, { children: ["We received a request to reset the password for", " ", recipient
|
|
38
|
+
? `the ${productName} account ${recipient}`
|
|
39
|
+
: `your ${productName} account`, ". To choose a new password, use the link below."] }), _jsx(Action, { href: href, label: "Reset password" }), expiresIn && _jsxs(Detail, { children: ["This link expires in ", expiresIn, "."] }), requestedFrom && _jsxs(Detail, { children: ["Requested from ", requestedFrom, "."] })] }));
|
|
40
|
+
}
|
|
41
|
+
/** An invitation to join a workspace. */
|
|
42
|
+
export function Invite({ productName, inviterName, workspaceName, href, message, expiresIn, footer, ...shell }) {
|
|
43
|
+
const target = workspaceName ?? productName;
|
|
44
|
+
return (_jsxs(EmailShell, { ...shell, preview: `${inviterName} invited you to ${target}`, footer: footer ??
|
|
45
|
+
`You received this email because ${inviterName} invited this address to ${productName}. If you weren't expecting it, you can ignore it.`, children: [_jsxs(EmailHeading, { children: [inviterName, " invited you to ", target] }), _jsx(EmailText, { children: workspaceName
|
|
46
|
+
? `Join the ${workspaceName} workspace on ${productName} to work with ${inviterName}.`
|
|
47
|
+
: `Join ${inviterName} on ${productName}.` }), message && (_jsx(EmailCallout, { title: `Message from ${inviterName}`, children: message })), _jsx(Action, { href: href, label: "Accept invitation" }), expiresIn && _jsxs(Detail, { children: ["This invitation expires in ", expiresIn, "."] })] }));
|
|
48
|
+
}
|
|
49
|
+
/** An order confirmation or receipt, with items, costs and total. */
|
|
50
|
+
export function Receipt({ productName, orderNumber, date, items, lines, total, paymentMethod, href, title = "Thanks for your order", footer, ...shell }) {
|
|
51
|
+
return (_jsxs(EmailShell, { ...shell, preview: `Your ${productName} receipt for order ${orderNumber}`, footer: footer ??
|
|
52
|
+
`You received this receipt for order ${orderNumber} from ${productName}. Keep it for your records.`, children: [_jsx(EmailHeading, { children: title }), _jsxs(Detail, { children: ["Order ", orderNumber, ", ", date] }), _jsx(EmailSummary, { items: items, lines: lines, total: total }), paymentMethod && _jsxs(Detail, { children: ["Paid with ", paymentMethod, "."] }), href && _jsx(EmailButton, { href: href, children: "View order" })] }));
|
|
53
|
+
}
|
|
54
|
+
/** A product notification: a title, a message and at most one action. */
|
|
55
|
+
export function Notification({ productName, title, preview, children, action, preferencesHref, footer, ...shell }) {
|
|
56
|
+
return (_jsxs(EmailShell, { ...shell, preview: preview ?? title, footer: footer ?? (_jsxs(_Fragment, { children: ["You received this email because of your notification settings in", " ", productName, ".", preferencesHref && (_jsxs(_Fragment, { children: [" ", _jsx(EmailLink, { href: preferencesHref, children: "Manage email preferences" })] }))] })), children: [_jsx(EmailHeading, { children: title }), typeof children === "string" ? (_jsx(EmailText, { children: children })) : (children), action && _jsx(EmailButton, { href: action.href, children: action.label })] }));
|
|
57
|
+
}
|
package/dist/email.d.ts
CHANGED
|
@@ -1,100 +1,6 @@
|
|
|
1
|
-
import { type ReactNode } from "react";
|
|
2
|
-
import { type EmailTheme } from "./email-theme.js";
|
|
3
1
|
export { emailTheme } from "./email-theme.js";
|
|
4
2
|
export type { EmailTheme } from "./email-theme.js";
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
width: number;
|
|
10
|
-
height: number;
|
|
11
|
-
}
|
|
12
|
-
export interface EmailShellProps {
|
|
13
|
-
/** The inbox preview line shown after the subject. */
|
|
14
|
-
preview: string;
|
|
15
|
-
/** From `emailTheme(brand)`; Mortar's neutral theme by default. */
|
|
16
|
-
theme?: EmailTheme;
|
|
17
|
-
logo?: EmailLogo;
|
|
18
|
-
/** Why the person received the email, and what to do if it wasn't for them. */
|
|
19
|
-
footer?: ReactNode;
|
|
20
|
-
lang?: string;
|
|
21
|
-
dir?: "ltr" | "rtl";
|
|
22
|
-
children: ReactNode;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* The whole email: a card up to 600px wide on the sunken backdrop, with an
|
|
26
|
-
* optional logo above it and footer below. It sets the theme for the email
|
|
27
|
-
* components inside, and marks the email light-only so mail apps don't
|
|
28
|
-
* recolour the brand.
|
|
29
|
-
*/
|
|
30
|
-
export declare function EmailShell({ preview, theme: given, logo, footer, lang, dir, children, }: EmailShellProps): import("react").JSX.Element;
|
|
31
|
-
export interface EmailHeadingProps {
|
|
32
|
-
/** 1 for the email's title (once per email), 2 for a section. */
|
|
33
|
-
level?: 1 | 2;
|
|
34
|
-
children: ReactNode;
|
|
35
|
-
}
|
|
36
|
-
export declare function EmailHeading({ level, children }: EmailHeadingProps): import("react").JSX.Element;
|
|
37
|
-
export interface EmailTextProps {
|
|
38
|
-
/** `muted` for secondary details such as an expiry time. */
|
|
39
|
-
tone?: "default" | "muted";
|
|
40
|
-
size?: "md" | "sm";
|
|
41
|
-
children: ReactNode;
|
|
42
|
-
}
|
|
43
|
-
/** A paragraph. 16px by default: email is read on phones, at arm's length. */
|
|
44
|
-
export declare function EmailText({ tone, size, children, }: EmailTextProps): import("react").JSX.Element;
|
|
45
|
-
export interface EmailButtonProps {
|
|
46
|
-
/** An absolute http(s) URL. */
|
|
47
|
-
href: string;
|
|
48
|
-
children: ReactNode;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The email's main action, on its own line. Padding is applied in a way
|
|
52
|
-
* Outlook for Windows keeps, so the whole button is clickable there too.
|
|
53
|
-
* Follow it with the URL as an EmailLink for clients that block buttons.
|
|
54
|
-
*/
|
|
55
|
-
export declare function EmailButton({ href, children }: EmailButtonProps): import("react").JSX.Element;
|
|
56
|
-
export interface EmailLinkProps {
|
|
57
|
-
/** An absolute http(s) or mailto URL. */
|
|
58
|
-
href: string;
|
|
59
|
-
/** The URL itself when omitted, for "paste this link" fallbacks. */
|
|
60
|
-
children?: ReactNode;
|
|
61
|
-
}
|
|
62
|
-
export declare function EmailLink({ href, children }: EmailLinkProps): import("react").JSX.Element;
|
|
63
|
-
export interface EmailCodeProps {
|
|
64
|
-
/** A one-time code, shown large and spaced for reading and copying. */
|
|
65
|
-
code: string;
|
|
66
|
-
}
|
|
67
|
-
export declare function EmailCode({ code }: EmailCodeProps): import("react").JSX.Element;
|
|
68
|
-
export interface RenderedEmail {
|
|
69
|
-
html: string;
|
|
70
|
-
/** The plain-text alternative: send it with the HTML. */
|
|
71
|
-
text: string;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* An email element as HTML and plain text, ready for a sending service
|
|
75
|
-
* (Resend, SES, Postmark…). Keep the HTML under about 100 KB: Gmail clips
|
|
76
|
-
* longer messages.
|
|
77
|
-
*/
|
|
78
|
-
export declare function renderEmail(element: ReactNode): Promise<RenderedEmail>;
|
|
79
|
-
export interface VerifyEmailProps {
|
|
80
|
-
/** Your product, as the person knows it. */
|
|
81
|
-
productName: string;
|
|
82
|
-
/** A one-time code to type in, shown large. */
|
|
83
|
-
code?: string;
|
|
84
|
-
/** A confirmation link, shown as a button. Give `code`, `href` or both. */
|
|
85
|
-
href?: string;
|
|
86
|
-
/** The address being confirmed. */
|
|
87
|
-
recipient?: string;
|
|
88
|
-
/** Preformatted, e.g. "10 minutes". */
|
|
89
|
-
expiresIn?: string;
|
|
90
|
-
theme?: EmailTheme;
|
|
91
|
-
logo?: EmailLogo;
|
|
92
|
-
/** Replaces the default "if this wasn't you" footer. */
|
|
93
|
-
footer?: ReactNode;
|
|
94
|
-
lang?: string;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Confirms an email address with a code, a link or both: the email for the
|
|
98
|
-
* auth flow's verify-email step.
|
|
99
|
-
*/
|
|
100
|
-
export declare function VerifyEmail({ productName, code, href, recipient, expiresIn, theme, logo, footer, lang, }: VerifyEmailProps): import("react").JSX.Element;
|
|
3
|
+
export { EmailShell, EmailHeading, EmailText, EmailButton, EmailLink, EmailCode, EmailCallout, EmailDivider, EmailSummary, renderEmail, } from "./email-components.js";
|
|
4
|
+
export type { EmailLogo, EmailShellProps, EmailHeadingProps, EmailTextProps, EmailButtonProps, EmailLinkProps, EmailCodeProps, EmailCalloutProps, EmailSummaryItem, EmailSummaryProps, RenderedEmail, } from "./email-components.js";
|
|
5
|
+
export { VerifyEmail, MagicLink, PasswordReset, Invite, Receipt, Notification, } from "./email-templates.js";
|
|
6
|
+
export type { EmailTemplateProps, VerifyEmailProps, MagicLinkProps, PasswordResetProps, InviteProps, ReceiptProps, NotificationProps, } from "./email-templates.js";
|