@tonycodes-ui/mortar 0.14.0 → 0.16.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/dist/email.js CHANGED
@@ -1,152 +1,5 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- /* Transactional email: @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, Html, Img, Link, Preview, Text, render, } from "@react-email/components";
9
- import { emailTheme } from "./email-theme.js";
1
+ /* @tonycodes-ui/mortar/email: transactional email built on React Email
2
+ (the optional peer dependency @react-email/components). See docs/email.md. */
10
3
  export { emailTheme } from "./email-theme.js";
11
- const ThemeContext = createContext(undefined);
12
- let neutral;
13
- /** The theme from the enclosing EmailShell, or Mortar's neutral theme. */
14
- function useTheme() {
15
- return useContext(ThemeContext) ?? (neutral ??= emailTheme());
16
- }
17
- /* Links leave the mail client, so only web and mail addresses are allowed. */
18
- function assertHref(href, component, mail = false) {
19
- if (!(mail ? /^(?:https?:|mailto:)/i : /^https?:\/\//i).test(href.trim()))
20
- throw new Error(`Mortar ${component} needs an absolute ${mail ? "http(s) or mailto" : "http(s)"} URL: "${href}"`);
21
- }
22
- /* A one-cell layout table. Outlook for Windows ignores padding, margins and
23
- backgrounds on tables, so spacing and fills go on the cell. */
24
- function Cell({ style, children, }) {
25
- 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 }) }) }) }));
26
- }
27
- /**
28
- * The whole email: a card up to 600px wide on the sunken backdrop, with an
29
- * optional logo above it and footer below. It sets the theme for the email
30
- * components inside, and marks the email light-only so mail apps don't
31
- * recolour the brand.
32
- */
33
- export function EmailShell({ preview, theme: given, logo, footer, lang = "en", dir = "ltr", children, }) {
34
- const theme = given ?? emailTheme();
35
- if (logo)
36
- assertHref(logo.src, "EmailShell logo");
37
- return (_jsx(ThemeContext.Provider, { value: theme, 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: {
38
- margin: 0,
39
- padding: "32px 12px",
40
- backgroundColor: theme.sunken,
41
- color: theme.ink,
42
- fontFamily: theme.font,
43
- }, 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: {
44
- backgroundColor: theme.surface,
45
- border: `1px solid ${theme.line}`,
46
- borderRadius: "12px",
47
- padding: "32px",
48
- }, children: children }), footer && (_jsx(Cell, { style: { padding: "24px 32px 0" }, children: _jsx(Text, { style: {
49
- margin: 0,
50
- fontFamily: theme.font,
51
- fontSize: "12px",
52
- lineHeight: "18px",
53
- color: theme.muted,
54
- }, children: footer }) }))] }) })] }) }));
55
- }
56
- export function EmailHeading({ level = 1, children }) {
57
- const theme = useTheme();
58
- return (_jsx(Heading, { as: level === 1 ? "h1" : "h2", style: {
59
- margin: "0 0 16px",
60
- fontFamily: theme.fontHeading,
61
- fontSize: level === 1 ? "24px" : "18px",
62
- lineHeight: level === 1 ? "32px" : "26px",
63
- fontWeight: 600,
64
- letterSpacing: "-0.02em",
65
- color: theme.ink,
66
- }, children: children }));
67
- }
68
- /** A paragraph. 16px by default: email is read on phones, at arm's length. */
69
- export function EmailText({ tone = "default", size = "md", children, }) {
70
- const theme = useTheme();
71
- return (_jsx(Text, { style: {
72
- margin: "0 0 16px",
73
- fontFamily: theme.font,
74
- fontSize: size === "md" ? "16px" : "14px",
75
- lineHeight: size === "md" ? "24px" : "20px",
76
- color: tone === "muted" ? theme.muted : theme.ink,
77
- }, children: children }));
78
- }
79
- /**
80
- * The email's main action, on its own line. Padding is applied in a way
81
- * Outlook for Windows keeps, so the whole button is clickable there too.
82
- * Follow it with the URL as an EmailLink for clients that block buttons.
83
- */
84
- export function EmailButton({ href, children }) {
85
- const theme = useTheme();
86
- assertHref(href, "EmailButton");
87
- return (_jsx(Cell, { style: { padding: "8px 0 24px" }, children: _jsx(Button, { href: href, style: {
88
- display: "inline-block",
89
- backgroundColor: theme.primary,
90
- color: theme.onPrimary,
91
- fontFamily: theme.font,
92
- fontSize: "16px",
93
- lineHeight: "24px",
94
- fontWeight: 600,
95
- textDecoration: "none",
96
- padding: "12px 24px",
97
- borderRadius: "8px",
98
- }, children: children }) }));
99
- }
100
- export function EmailLink({ href, children }) {
101
- const theme = useTheme();
102
- assertHref(href, "EmailLink", true);
103
- return (_jsx(Link, { href: href, style: {
104
- color: theme.link,
105
- textDecoration: "underline",
106
- wordBreak: "break-all",
107
- }, children: children ?? href }));
108
- }
109
- export function EmailCode({ code }) {
110
- const theme = useTheme();
111
- return (_jsx(Cell, { style: { padding: "8px 0 24px" }, children: _jsx(Cell, { style: {
112
- backgroundColor: theme.sunken,
113
- borderRadius: "8px",
114
- padding: "16px",
115
- textAlign: "center",
116
- }, children: _jsx(Text, { style: {
117
- margin: 0,
118
- fontFamily: theme.mono,
119
- fontSize: "28px",
120
- lineHeight: "36px",
121
- fontWeight: 600,
122
- letterSpacing: "0.2em",
123
- color: theme.ink,
124
- }, children: code }) }) }));
125
- }
126
- /**
127
- * An email element as HTML and plain text, ready for a sending service
128
- * (Resend, SES, Postmark…). Keep the HTML under about 100 KB: Gmail clips
129
- * longer messages.
130
- */
131
- export async function renderEmail(element) {
132
- const [html, text] = await Promise.all([
133
- render(element),
134
- render(element, { plainText: true }),
135
- ]);
136
- return { html, text };
137
- }
138
- /**
139
- * Confirms an email address with a code, a link or both: the email for the
140
- * auth flow's verify-email step.
141
- */
142
- export function VerifyEmail({ productName, code, href, recipient, expiresIn, theme, logo, footer, lang, }) {
143
- if (!code && !href)
144
- throw new Error("Mortar VerifyEmail needs a `code`, an `href` or both.");
145
- const address = recipient ?? "your email address";
146
- return (_jsxs(EmailShell, { preview: `Confirm your email address for ${productName}`, theme: theme, logo: logo, lang: lang, footer: footer ??
147
- `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
148
- ? "Or confirm with one click:"
149
- : `Confirm ${address} to finish setting up your ${productName} account.` }), _jsx(EmailButton, { href: href, children: "Confirm email address" }), _jsxs(EmailText, { tone: "muted", size: "sm", children: ["If the button doesn't work, paste this link into your browser:", " ", _jsx(EmailLink, { href: href })] })] })), expiresIn && (_jsx(EmailText, { tone: "muted", size: "sm", children: code && href
150
- ? `This code and link expire in ${expiresIn}.`
151
- : `This ${code ? "code" : "link"} expires in ${expiresIn}.` }))] }));
152
- }
4
+ export { EmailShell, EmailHeading, EmailText, EmailButton, EmailLink, EmailCode, EmailCallout, EmailDivider, EmailSummary, renderEmail, } from "./email-components.js";
5
+ export { VerifyEmail, MagicLink, PasswordReset, Invite, Receipt, Notification, } from "./email-templates.js";
package/docs/agents.md CHANGED
@@ -63,7 +63,7 @@ In a project without Mortar installed, `npx -y @tonycodes-ui/mortar mcp` downloa
63
63
  | `search_components` | `query`, optional `kit`, `category`, `limit` | Ranked components: name, kit, category, description, capabilities. |
64
64
  | `get_component` | `name` | The full contract: props with types, required flags and defaults; usage, avoid and accessibility notes; the components it renders; its `data-m-component` marker; tested states; page templates; a JSX example; the import line. |
65
65
  | `get_build_packet` | `components` and/or `brief` | The chosen components (for a brief, with the reason for each, starting from the purpose shell), their dependency closure, install, CSS and ThemeProvider setup, the import line, the design principles and API conventions, and matching page templates. |
66
- | `get_guide` | `topic` | A guide as markdown: `design`, `conventions`, `theming`, `auth-flows`, `migrating-0.6`, `contributing`, `testing` or `agents`. |
66
+ | `get_guide` | `topic` | A guide as markdown: `design`, `conventions`, `theming`, `auth-flows`, `email`, `migrating-0.6`, `contributing`, `testing` or `agents`. |
67
67
  | `list_kits` | none | Kits → categories → components, and the page templates. |
68
68
  | `audit_app` | `path` | A read-only audit of an application: findings with file, line, rule, message and a suggested fix. |
69
69
 
@@ -100,13 +100,15 @@ Add `--json` for machine-readable output. `mortar audit` exits with status 1 whe
100
100
  | `not-installed` | error | Mortar imported but not in node_modules |
101
101
  | `version-mismatch` | error | The installed version does not satisfy the package.json range |
102
102
  | `unknown-export` | error | A named import the installed version does not export, with the replacement for names removed in 0.6 |
103
- | `deep-import` | error | Imports or aliases into the package's `src` or `dist` |
103
+ | `deep-import` | error | Imports or aliases into the package's `src` or `dist`, or an entry other than the package, `/styles.css`, `/brand` and `/email` |
104
104
  | `unknown-prop` | error | A prop the component's contract does not declare, with the 0.6 rename where there is one |
105
105
  | `invalid-value` | error | A literal outside the prop's declared union, such as `layout="centered"` (now `center`) |
106
106
  | `css-override` | error | Consumer CSS selecting Mortar's `.m-*` classes or `[data-m-component]` |
107
107
  | `class-override` | error | A Tailwind arbitrary variant that targets `.m-*` classes, such as `[&_.m-button]:rounded-none` |
108
108
  | `local-copy` | error | A copy of a Mortar source file, or code rendering Mortar's component marker |
109
109
  | `raw-element` | error | A raw `<table>`, `<select>`, `<textarea>`, `<dialog>`, `<progress>` or `<input>` (by type; not `hidden`, `file`, `range`, `color` or `image`) anywhere in an app that uses Mortar, naming the component to use instead. A raw `<button>` is a warning. The mapping comes from each contract's `replaces` field, so new components extend it |
110
+ | `email-app-import` | error | In an email (a file importing `@tonycodes-ui/mortar/email` or React Email), an app component or `styles.css`, naming the email component to use. Raw elements in emails are not reported: email layout is tables |
111
+ | `email-peer-missing` | error | `@tonycodes-ui/mortar/email` is imported but `@react-email/components` is not in package.json |
110
112
  | `missing-styles` | error | No import of `@tonycodes-ui/mortar/styles.css` |
111
113
  | `styles-order` | warning | Mortar's styles imported before Tailwind |
112
114
  | `missing-theme-provider` | warning | Mortar components rendered without a `ThemeProvider` |
@@ -27,7 +27,7 @@ The playground has a page template for each step (`?recipe=<id>`).
27
27
  | Verify email | `verify-email` | AuthLayout, CodeInput, Button, a resend Button with a countdown, a "Change your email" link | `CodeInput` (`one-time-code`, `inputmode="numeric"`) |
28
28
  | Two-factor | `two-factor` | AuthLayout, CodeInput, Button, a ghost Button that switches to a recovery code | Authenticator: `CodeInput`. Recovery: `CodeInput alphanumeric length={8}` |
29
29
 
30
- The email for the verify-email step is `VerifyEmail` from `@tonycodes-ui/mortar/email`. See [Transactional email](email.md).
30
+ The emails for these steps come from `@tonycodes-ui/mortar/email`: `VerifyEmail` for verify email, `PasswordReset` for forgot password, and `MagicLink` for a passwordless sign-in with SignInPanel. See [Transactional email](email.md).
31
31
 
32
32
  ## Validation and errors
33
33
 
package/docs/email.md CHANGED
@@ -58,38 +58,53 @@ Emails render light. Most clients either ignore a dark design or recolour it the
58
58
 
59
59
  ## Components
60
60
 
61
- | Component | Use |
62
- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
63
- | `EmailShell` | The whole email: the inbox `preview` line, an optional `logo`, a card up to 600px wide and a `footer`. It sets the theme for the components inside it. |
64
- | `EmailHeading` | `level={1}` is the email's title (once per email); `level={2}` is a section. |
65
- | `EmailText` | A paragraph, 16px. `tone="muted"` and `size="sm"` are for details such as an expiry time. |
66
- | `EmailButton` | The main action. It keeps its padding in Outlook for Windows. Follow it with the URL as an `EmailLink`, for clients that block buttons. |
67
- | `EmailLink` | An inline link. Without children it shows the URL itself. |
68
- | `EmailCode` | A one-time code, large and spaced. |
69
-
70
- Links and the logo need absolute `https://` URLs (`EmailLink` also takes `mailto:`), because the email is read away from your site. Anything else throws.
61
+ | Component | Use |
62
+ | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
63
+ | `EmailShell` | The whole email: the inbox `preview` line, an optional `logo`, a card up to 600px wide and a `footer`. It sets the theme for the components inside it. |
64
+ | `EmailHeading` | `level={1}` is the email's title (once per email); `level={2}` is a section. |
65
+ | `EmailText` | A paragraph, 16px. `tone="muted"` and `size="sm"` are for details such as an expiry time. |
66
+ | `EmailButton` | The main action. It keeps its padding in Outlook for Windows. Follow it with the URL as an `EmailLink`, for clients that block buttons. |
67
+ | `EmailLink` | An inline link. Without children it shows the URL itself. |
68
+ | `EmailCode` | A one-time code, large and spaced. |
69
+ | `EmailCallout` | A highlighted block with an optional `title`. `tone` (`info`, `success`, `warning`, `danger`) colours its edge; `neutral`, the default, is an aside such as a quoted message. |
70
+ | `EmailDivider` | A rule between sections. |
71
+ | `EmailSummary` | A receipt's `items` (name, preformatted `price`, optional `quantity` and `meta`), cost `lines` and `total`, as OrderSummary takes them. In the plain-text part it reads as rows. |
72
+
73
+ `EmailShell` takes `dir="rtl"`, and the components that place things at the start or end follow it: the callout's edge and the summary's amounts.
74
+
75
+ Links and the logo need absolute `http://` or `https://` URLs (`EmailLink` also takes `mailto:`), because the email is read away from your site. Anything else, such as a relative or `javascript:` URL, throws.
71
76
 
72
77
  Compose your own email from these:
73
78
 
74
79
  ```tsx
75
80
  <EmailShell
76
- preview="Ana invited you to Hive"
81
+ preview="3 tasks are due this week"
77
82
  theme={theme}
78
- footer="Sent by Hive."
83
+ footer="You get this summary every Monday."
79
84
  >
80
- <EmailHeading>Join Ana on Hive</EmailHeading>
81
- <EmailText>Ana invited you to the Design workspace.</EmailText>
82
- <EmailButton href={inviteUrl}>Accept invitation</EmailButton>
85
+ <EmailHeading>Your week in Hive</EmailHeading>
86
+ <EmailText>3 tasks are due this week.</EmailText>
87
+ <EmailCallout tone="warning" title="Overdue">
88
+ Launch checklist, due Friday
89
+ </EmailCallout>
90
+ <EmailButton href={tasksUrl}>Open your tasks</EmailButton>
83
91
  </EmailShell>
84
92
  ```
85
93
 
86
94
  ## Templates
87
95
 
88
- | Template | Auth step | Props |
89
- | ------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------- |
90
- | `VerifyEmail` | [Verify email](auth-flows.md#steps) | `productName`, and a `code`, an `href` or both; optional `recipient`, `expiresIn`, `logo`, `footer` |
96
+ Every template takes `productName`, and optionally `theme`, `logo`, `footer` (replacing its "why you got this" line), `lang` and `dir`. Times and amounts are preformatted strings, so you choose the locale.
97
+
98
+ | Template | Use | Props |
99
+ | --------------- | ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
100
+ | `VerifyEmail` | The [verify-email step](auth-flows.md#steps) | A `code`, an `href` or both; optional `recipient`, `expiresIn` |
101
+ | `MagicLink` | A passwordless sign-in link, as SignInPanel sends | `href`; optional `expiresIn`, `requestedFrom` (e.g. "Chrome on macOS, near London") |
102
+ | `PasswordReset` | The [reset-password step](auth-flows.md#steps) | `href`; optional `recipient`, `expiresIn`, `requestedFrom` |
103
+ | `Invite` | An invitation to a workspace | `inviterName`, `href`; optional `workspaceName`, `message` (the inviter's note, quoted), `expiresIn` |
104
+ | `Receipt` | An order confirmation or receipt | `orderNumber`, `date`, `items`, `total`; optional `lines`, `paymentMethod`, `href` ("View order"), `title` |
105
+ | `Notification` | A product notification | `title`, `children` (a string becomes a paragraph); optional `action` (`{ label, href }`), `preview`, `preferencesHref` |
91
106
 
92
- More templates (magic link, password reset, invite, receipt and notification) are planned in [#91](https://github.com/tonycodes/mortar/issues/91).
107
+ Send a password reset only to an address that has an account, and show the same "check your email" page either way, so the form never reveals whether an account exists.
93
108
 
94
109
  ## Rules
95
110
 
@@ -99,3 +114,13 @@ More templates (magic link, password reset, invite, receipt and notification) ar
99
114
  - Don't rely on hover, scripts or forms. Email clients remove them.
100
115
  - Keep each email under about 100 KB of HTML. Gmail clips longer messages behind a "View entire message" link.
101
116
  - Before a release, check new emails in real clients (Gmail, Outlook for Windows, Apple Mail) with a service such as Litmus or Email on Acid.
117
+
118
+ ## Checks
119
+
120
+ `npx mortar audit` (or the MCP `audit_app` tool) treats a file that imports `@tonycodes-ui/mortar/email` or React Email as an email:
121
+
122
+ - **`email-app-import`** reports an app component or `styles.css` imported into an email, and names the email component to use (`Button` → `EmailButton`, `Notice` → `EmailCallout`, `OrderSummary` → `EmailSummary`).
123
+ - **`email-peer-missing`** reports a project that imports the email entry without `@react-email/components` in its package.json.
124
+ - Named imports from `@tonycodes-ui/mortar/email` are checked against what it exports.
125
+ - Raw `<table>` and other elements in an email are not reported, because email layout is tables.
126
+ - A service that only sends email isn't asked for `styles.css` or a ThemeProvider.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonycodes-ui/mortar",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "Mortar: a shared design foundation, application and marketing UI for React and Tailwind.",
5
5
  "type": "module",
6
6
  "files": [
@@ -12,8 +12,9 @@ Mortar is an MIT React 19 + Tailwind 4 UI kit. Its agent tooling ships in the pa
12
12
  1. **Discover.** Before writing UI, call `search_components` (or `list_kits`) for what the brief needs. Without the MCP server, run `npx mortar search "<need>"`.
13
13
  2. **Packet.** Call `get_build_packet` with the chosen components or the brief (`npx mortar packet <Name…> --json`, or `--brief "…"`). Start composing when the packet answers the brief; read extra source or guides only for a specific gap (`get_component`, `get_guide`).
14
14
  3. **Compose** following the defaults below.
15
- 4. **Audit.** Run `audit_app` on the application (`npx mortar audit`), fix every error and review the warnings, then rerun it with the app's build and typecheck.
16
- 5. **Verify** in a browser and report the actual results.
15
+ 4. **Emails.** Build transactional emails from `@tonycodes-ui/mortar/email` (`get_guide email`), never from the app components.
16
+ 5. **Audit.** Run `audit_app` on the application (`npx mortar audit`), fix every error and review the warnings, then rerun it with the app's build and typecheck.
17
+ 6. **Verify** in a browser and report the actual results.
17
18
 
18
19
  ## Defaults
19
20