@comet/mail-react 9.0.0-beta.1 → 9.0.0-beta.2

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.
Files changed (47) hide show
  1. package/lib/__stories__/examples/CustomNestedFooterTheme.stories.d.ts +5 -0
  2. package/lib/__stories__/examples/CustomNestedFooterTheme.stories.js +32 -0
  3. package/lib/__stories__/examples/NotificationEmail.stories.d.ts +5 -0
  4. package/lib/__stories__/examples/NotificationEmail.stories.js +25 -0
  5. package/lib/__stories__/examples/TextWithImageEmail.stories.d.ts +5 -0
  6. package/lib/__stories__/examples/TextWithImageEmail.stories.js +56 -0
  7. package/lib/components/inlineLink/HtmlInlineLink.d.ts +10 -0
  8. package/lib/components/inlineLink/HtmlInlineLink.js +35 -0
  9. package/lib/components/inlineLink/__stories__/HtmlInlineLink.stories.d.ts +12 -0
  10. package/lib/components/inlineLink/__stories__/HtmlInlineLink.stories.js +56 -0
  11. package/lib/components/mailRoot/MjmlMailRoot.js +1 -1
  12. package/lib/components/mailRoot/__stories__/MjmlMailRoot.stories.d.ts +1 -0
  13. package/lib/components/mailRoot/__stories__/MjmlMailRoot.stories.js +6 -1
  14. package/lib/components/section/MjmlSection.d.ts +1 -1
  15. package/lib/components/section/MjmlSection.js +3 -2
  16. package/lib/components/section/__stories__/MjmlSection.stories.d.ts +1 -0
  17. package/lib/components/section/__stories__/MjmlSection.stories.js +6 -0
  18. package/lib/components/text/HtmlText.d.ts +48 -0
  19. package/lib/components/text/HtmlText.js +47 -0
  20. package/lib/components/text/MjmlText.d.ts +37 -0
  21. package/lib/components/text/MjmlText.js +65 -0
  22. package/lib/components/text/OutlookTextStyleContext.d.ts +9 -0
  23. package/lib/components/text/OutlookTextStyleContext.js +10 -0
  24. package/lib/components/text/__stories__/HtmlText.stories.d.ts +12 -0
  25. package/lib/components/text/__stories__/HtmlText.stories.js +77 -0
  26. package/lib/components/text/__stories__/MjmlText.stories.d.ts +10 -0
  27. package/lib/components/text/__stories__/MjmlText.stories.js +71 -0
  28. package/lib/components/text/__tests__/HtmlText.test.d.ts +1 -0
  29. package/lib/components/text/__tests__/HtmlText.test.js +157 -0
  30. package/lib/components/text/__tests__/MjmlText.test.d.ts +1 -0
  31. package/lib/components/text/__tests__/MjmlText.test.js +112 -0
  32. package/lib/components/text/textStyles.d.ts +12 -0
  33. package/lib/components/text/textStyles.js +69 -0
  34. package/lib/index.d.ts +8 -2
  35. package/lib/index.js +4 -1
  36. package/lib/storybook/MailRendererDecorator.d.ts +7 -1
  37. package/lib/storybook/MailRendererDecorator.js +2 -2
  38. package/lib/theme/__stories__/ThemeProvider.stories.js +2 -2
  39. package/lib/theme/createTheme.d.ts +5 -1
  40. package/lib/theme/createTheme.js +6 -0
  41. package/lib/theme/createTheme.test.js +32 -0
  42. package/lib/theme/defaultTheme.js +12 -0
  43. package/lib/theme/responsiveValue.d.ts +6 -0
  44. package/lib/theme/responsiveValue.js +10 -0
  45. package/lib/theme/responsiveValue.test.js +18 -1
  46. package/lib/theme/themeTypes.d.ts +59 -0
  47. package/package.json +7 -4
@@ -0,0 +1,77 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { MjmlColumn, MjmlRaw } from "@faire/mjml-react";
3
+ import { createTheme } from "../../../theme/createTheme.js";
4
+ import { MjmlSection } from "../../section/MjmlSection.js";
5
+ import { HtmlText } from "../HtmlText.js";
6
+ const config = {
7
+ title: "Components/HtmlText",
8
+ component: HtmlText,
9
+ tags: ["autodocs"],
10
+ };
11
+ export default config;
12
+ export const Default = {
13
+ render: () => (_jsx(MjmlSection, { children: _jsx(MjmlColumn, { children: _jsx(MjmlRaw, { children: _jsx("table", { children: _jsx("tr", { children: _jsx(HtmlText, { children: "Default text with base theme styles" }) }) }) }) }) })),
14
+ };
15
+ export const WithVariants = {
16
+ parameters: {
17
+ theme: createTheme({
18
+ text: {
19
+ variants: {
20
+ heading: { fontSize: "32px", fontWeight: 700, lineHeight: "40px" },
21
+ body: { fontSize: "16px", lineHeight: "24px" },
22
+ caption: { fontSize: "12px", lineHeight: "16px", color: "#666666" },
23
+ },
24
+ },
25
+ }),
26
+ },
27
+ render: () => (_jsx(MjmlSection, { children: _jsx(MjmlColumn, { children: _jsx(MjmlRaw, { children: _jsxs("table", { children: [_jsx("tr", { children: _jsx(HtmlText, { variant: "heading", children: "Heading variant" }) }), _jsx("tr", { children: _jsx(HtmlText, { variant: "body", children: "Body variant" }) }), _jsx("tr", { children: _jsx(HtmlText, { variant: "caption", children: "Caption variant" }) })] }) }) }) })),
28
+ };
29
+ export const ResponsiveVariants = {
30
+ parameters: {
31
+ theme: createTheme({
32
+ text: {
33
+ variants: {
34
+ heading: {
35
+ fontSize: { default: "32px", mobile: "24px" },
36
+ lineHeight: { default: "40px", mobile: "30px" },
37
+ fontWeight: 700,
38
+ },
39
+ },
40
+ },
41
+ }),
42
+ },
43
+ render: () => (_jsx(MjmlSection, { children: _jsx(MjmlColumn, { children: _jsx(MjmlRaw, { children: _jsx("table", { children: _jsx("tr", { children: _jsx(HtmlText, { variant: "heading", children: "Responsive heading \u2014 shrinks on mobile" }) }) }) }) }) })),
44
+ };
45
+ export const BottomSpacing = {
46
+ parameters: {
47
+ theme: createTheme({
48
+ text: {
49
+ bottomSpacing: "20px",
50
+ variants: {
51
+ heading: { fontSize: "32px", fontWeight: 700, bottomSpacing: { default: "24px", mobile: "16px" } },
52
+ },
53
+ },
54
+ }),
55
+ },
56
+ render: () => (_jsx(MjmlSection, { children: _jsx(MjmlColumn, { children: _jsx(MjmlRaw, { children: _jsxs("table", { children: [_jsx("tr", { children: _jsx(HtmlText, { variant: "heading", bottomSpacing: true, children: "Heading with bottom spacing" }) }), _jsx("tr", { children: _jsx(HtmlText, { bottomSpacing: true, children: "Base text with bottom spacing" }) }), _jsx("tr", { children: _jsx(HtmlText, { children: "Text without bottom spacing" }) })] }) }) }) })),
57
+ };
58
+ export const DefaultVariant = {
59
+ parameters: {
60
+ theme: createTheme({
61
+ text: {
62
+ defaultVariant: "body",
63
+ variants: {
64
+ body: { fontSize: "14px", lineHeight: "22px" },
65
+ heading: { fontSize: "28px", fontWeight: 700 },
66
+ },
67
+ },
68
+ }),
69
+ },
70
+ render: () => (_jsx(MjmlSection, { children: _jsx(MjmlColumn, { children: _jsx(MjmlRaw, { children: _jsxs("table", { children: [_jsx("tr", { children: _jsx(HtmlText, { children: "Uses the default \"body\" variant automatically" }) }), _jsx("tr", { children: _jsx(HtmlText, { variant: "heading", children: "Explicit heading variant" }) })] }) }) }) })),
71
+ };
72
+ export const ElementPropAsDiv = {
73
+ render: () => (_jsx(MjmlSection, { children: _jsx(MjmlColumn, { children: _jsx(MjmlRaw, { children: _jsx(HtmlText, { element: "div", children: "Rendered as a div with theme styles" }) }) }) })),
74
+ };
75
+ export const ElementPropAsAnchor = {
76
+ render: () => (_jsx(MjmlSection, { children: _jsx(MjmlColumn, { children: _jsx(MjmlRaw, { children: _jsx(HtmlText, { element: "a", href: "https://example.com", style: { textDecoration: "underline" }, children: "Rendered as an anchor with href" }) }) }) })),
77
+ };
@@ -0,0 +1,10 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite";
2
+ import { MjmlText } from "../MjmlText.js";
3
+ type Story = StoryObj<typeof MjmlText>;
4
+ declare const config: Meta<typeof MjmlText>;
5
+ export default config;
6
+ export declare const Default: Story;
7
+ export declare const WithVariants: Story;
8
+ export declare const ResponsiveVariants: Story;
9
+ export declare const BottomSpacing: Story;
10
+ export declare const DefaultVariant: Story;
@@ -0,0 +1,71 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { MjmlColumn } from "@faire/mjml-react";
3
+ import { createTheme } from "../../../theme/createTheme.js";
4
+ import { MjmlSection } from "../../section/MjmlSection.js";
5
+ import { MjmlText } from "../MjmlText.js";
6
+ const config = {
7
+ title: "Components/MjmlText",
8
+ component: MjmlText,
9
+ tags: ["autodocs"],
10
+ };
11
+ export default config;
12
+ export const Default = {
13
+ render: () => (_jsx(MjmlSection, { indent: true, children: _jsx(MjmlColumn, { children: _jsx(MjmlText, { children: "Default text with base theme styles" }) }) })),
14
+ };
15
+ export const WithVariants = {
16
+ parameters: {
17
+ theme: createTheme({
18
+ text: {
19
+ variants: {
20
+ heading: { fontSize: "32px", fontWeight: 700, lineHeight: "40px" },
21
+ body: { fontSize: "16px", lineHeight: "24px" },
22
+ caption: { fontSize: "12px", lineHeight: "16px", color: "#666666" },
23
+ },
24
+ },
25
+ }),
26
+ },
27
+ render: () => (_jsx(MjmlSection, { indent: true, children: _jsxs(MjmlColumn, { children: [_jsx(MjmlText, { variant: "heading", children: "Heading variant" }), _jsx(MjmlText, { variant: "body", children: "Body variant" }), _jsx(MjmlText, { variant: "caption", children: "Caption variant" })] }) })),
28
+ };
29
+ export const ResponsiveVariants = {
30
+ parameters: {
31
+ theme: createTheme({
32
+ text: {
33
+ variants: {
34
+ heading: {
35
+ fontSize: { default: "32px", mobile: "24px" },
36
+ lineHeight: { default: "40px", mobile: "30px" },
37
+ fontWeight: 700,
38
+ },
39
+ },
40
+ },
41
+ }),
42
+ },
43
+ render: () => (_jsx(MjmlSection, { indent: true, children: _jsx(MjmlColumn, { children: _jsx(MjmlText, { variant: "heading", children: "Responsive heading \u2014 shrinks on mobile" }) }) })),
44
+ };
45
+ export const BottomSpacing = {
46
+ parameters: {
47
+ theme: createTheme({
48
+ text: {
49
+ bottomSpacing: "20px",
50
+ variants: {
51
+ heading: { fontSize: "32px", fontWeight: 700, bottomSpacing: { default: "24px", mobile: "16px" } },
52
+ },
53
+ },
54
+ }),
55
+ },
56
+ render: () => (_jsx(MjmlSection, { indent: true, children: _jsxs(MjmlColumn, { children: [_jsx(MjmlText, { variant: "heading", bottomSpacing: true, children: "Heading with bottom spacing" }), _jsx(MjmlText, { bottomSpacing: true, children: "Base text with bottom spacing" }), _jsx(MjmlText, { children: "Text without bottom spacing" })] }) })),
57
+ };
58
+ export const DefaultVariant = {
59
+ parameters: {
60
+ theme: createTheme({
61
+ text: {
62
+ defaultVariant: "body",
63
+ variants: {
64
+ body: { fontSize: "14px", lineHeight: "22px" },
65
+ heading: { fontSize: "28px", fontWeight: 700 },
66
+ },
67
+ },
68
+ }),
69
+ },
70
+ render: () => (_jsx(MjmlSection, { indent: true, children: _jsxs(MjmlColumn, { children: [_jsx(MjmlText, { children: "Uses the default \"body\" variant automatically" }), _jsx(MjmlText, { variant: "heading", children: "Explicit heading variant" })] }) })),
71
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,157 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { renderToStaticMarkup } from "react-dom/server";
3
+ import { describe, expect, it } from "vitest";
4
+ import { createTheme } from "../../../theme/createTheme.js";
5
+ import { ThemeProvider } from "../../../theme/ThemeProvider.js";
6
+ import { HtmlText } from "../HtmlText.js";
7
+ // Type-level tests — validated by tsc, not at runtime.
8
+ // An unused @ts-expect-error directive causes a compile error if the overloads
9
+ // stop rejecting the invalid usage, so these act as regression guards.
10
+ // @ts-expect-error href is not valid on the default <td>
11
+ void (_jsx(HtmlText, { href: "/foo", children: "text" }));
12
+ void ((
13
+ // @ts-expect-error colSpan is not valid on <a>
14
+ _jsx(HtmlText, { element: "a", colSpan: 2, children: "text" })));
15
+ // Own props are always accepted regardless of element — no error expected
16
+ void (_jsx(HtmlText, { element: "div", variant: "heading", bottomSpacing: true, children: "text" }));
17
+ void (_jsx(HtmlText, { variant: "heading", bottomSpacing: true, children: "text" }));
18
+ function renderHtmlText(element) {
19
+ return renderToStaticMarkup(element);
20
+ }
21
+ describe("HtmlText", () => {
22
+ it("renders a <td> with base theme styles as inline styles", () => {
23
+ const theme = createTheme();
24
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { children: "Hello" }) }));
25
+ expect(html).toContain("<td");
26
+ expect(html).toContain("Hello");
27
+ expect(html).toContain("font-family:Arial, sans-serif");
28
+ expect(html).toContain("font-size:16px");
29
+ expect(html).toContain("line-height:20px");
30
+ });
31
+ it("applies variant styles over base styles", () => {
32
+ const theme = createTheme({
33
+ text: {
34
+ variants: {
35
+ heading: { fontSize: { default: "32px", mobile: "24px" }, fontWeight: 700 },
36
+ },
37
+ },
38
+ });
39
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { variant: "heading", children: "Title" }) }));
40
+ expect(html).toContain("font-size:32px");
41
+ expect(html).toContain("font-weight:700");
42
+ });
43
+ it("inherits base styles not overridden by variant", () => {
44
+ const theme = createTheme({
45
+ text: {
46
+ fontFamily: "Georgia, serif",
47
+ variants: {
48
+ heading: { fontSize: "32px" },
49
+ },
50
+ },
51
+ });
52
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { variant: "heading", children: "Title" }) }));
53
+ expect(html).toContain("font-family:Georgia, serif");
54
+ expect(html).toContain("font-size:32px");
55
+ });
56
+ it("applies defaultVariant when no variant prop is specified", () => {
57
+ const theme = createTheme({
58
+ text: {
59
+ defaultVariant: "body",
60
+ variants: {
61
+ body: { fontSize: "14px" },
62
+ },
63
+ },
64
+ });
65
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { children: "Text" }) }));
66
+ expect(html).toContain("font-size:14px");
67
+ });
68
+ it("applies bottomSpacing as padding-bottom", () => {
69
+ const theme = createTheme({ text: { bottomSpacing: "16px" } });
70
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { bottomSpacing: true, children: "Text" }) }));
71
+ expect(html).toContain("padding-bottom:16px");
72
+ });
73
+ it("uses variant bottomSpacing over base", () => {
74
+ const theme = createTheme({
75
+ text: {
76
+ bottomSpacing: "16px",
77
+ variants: {
78
+ heading: { bottomSpacing: { default: "24px", mobile: "16px" } },
79
+ },
80
+ },
81
+ });
82
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { variant: "heading", bottomSpacing: true, children: "Title" }) }));
83
+ expect(html).toContain("padding-bottom:24px");
84
+ });
85
+ it("does not apply padding-bottom when bottomSpacing is not set", () => {
86
+ const theme = createTheme({ text: { bottomSpacing: "16px" } });
87
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { children: "Text" }) }));
88
+ expect(html).not.toContain("padding-bottom");
89
+ });
90
+ it("always applies the htmlText base class", () => {
91
+ const theme = createTheme();
92
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { children: "Hello" }) }));
93
+ expect(html).toContain('class="htmlText"');
94
+ });
95
+ it("applies variant modifier class", () => {
96
+ const theme = createTheme({
97
+ text: { variants: { heading: { fontSize: "32px" } } },
98
+ });
99
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { variant: "heading", children: "Title" }) }));
100
+ expect(html).toContain("htmlText--heading");
101
+ });
102
+ it("applies bottomSpacing modifier class", () => {
103
+ const theme = createTheme();
104
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { bottomSpacing: true, children: "Text" }) }));
105
+ expect(html).toContain("htmlText--bottomSpacing");
106
+ });
107
+ it("merges consumer className", () => {
108
+ const theme = createTheme();
109
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { className: "custom", children: "Text" }) }));
110
+ expect(html).toContain("htmlText");
111
+ expect(html).toContain("custom");
112
+ });
113
+ it("lets user style prop override theme styles", () => {
114
+ const theme = createTheme({ text: { fontFamily: "Arial, sans-serif" } });
115
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { style: { fontFamily: "Georgia" }, children: "Hello" }) }));
116
+ expect(html).toContain("font-family:Georgia");
117
+ });
118
+ it("forwards standard td attributes", () => {
119
+ const theme = createTheme();
120
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { colSpan: 2, align: "center", children: "Hello" }) }));
121
+ expect(html).toContain('colSpan="2"');
122
+ expect(html).toContain('align="center"');
123
+ });
124
+ it("renders a <div> when element is 'div'", () => {
125
+ const theme = createTheme();
126
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { element: "div", children: "Hello" }) }));
127
+ expect(html).toContain("<div");
128
+ expect(html).not.toContain("<td");
129
+ expect(html).toContain("Hello");
130
+ expect(html).toContain("font-family:Arial, sans-serif");
131
+ });
132
+ it("renders an <a> with href when element is 'a'", () => {
133
+ const theme = createTheme();
134
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { element: "a", href: "/link", children: "Click" }) }));
135
+ expect(html).toContain("<a");
136
+ expect(html).not.toContain("<td");
137
+ expect(html).toContain('href="/link"');
138
+ expect(html).toContain("Click");
139
+ });
140
+ it("applies theme styles and CSS classes to non-td elements", () => {
141
+ const theme = createTheme({
142
+ text: {
143
+ variants: {
144
+ heading: { fontSize: "32px", fontWeight: 700 },
145
+ },
146
+ },
147
+ });
148
+ const html = renderHtmlText(_jsx(ThemeProvider, { theme: theme, children: _jsx(HtmlText, { element: "div", variant: "heading", bottomSpacing: true, className: "custom", children: "Title" }) }));
149
+ expect(html).toContain("<div");
150
+ expect(html).toContain("font-size:32px");
151
+ expect(html).toContain("font-weight:700");
152
+ expect(html).toContain("htmlText");
153
+ expect(html).toContain("htmlText--heading");
154
+ expect(html).toContain("htmlText--bottomSpacing");
155
+ expect(html).toContain("custom");
156
+ });
157
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,112 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { MjmlColumn } from "@faire/mjml-react";
3
+ import { describe, expect, it } from "vitest";
4
+ import { renderMailHtml } from "../../../server/renderMailHtml.js";
5
+ import { createTheme } from "../../../theme/createTheme.js";
6
+ import { MjmlMailRoot } from "../../mailRoot/MjmlMailRoot.js";
7
+ import { MjmlSection } from "../../section/MjmlSection.js";
8
+ import { generateTextStyles, MjmlText } from "../MjmlText.js";
9
+ describe("MjmlText integration", () => {
10
+ // Full render pipeline: mjml2html must report no errors for this MjmlText + theme setup.
11
+ it("produces no MJML warnings with a variant theme", () => {
12
+ const theme = createTheme({
13
+ text: {
14
+ variants: {
15
+ heading: {
16
+ fontSize: { default: "32px", mobile: "24px" },
17
+ fontWeight: 700,
18
+ lineHeight: { default: "40px", mobile: "30px" },
19
+ },
20
+ body: { fontSize: "14px", lineHeight: "22px" },
21
+ },
22
+ },
23
+ });
24
+ const { mjmlWarnings } = renderMailHtml(_jsx(MjmlMailRoot, { theme: theme, children: _jsx(MjmlSection, { children: _jsxs(MjmlColumn, { children: [_jsx(MjmlText, { variant: "heading", bottomSpacing: true, children: "Heading" }), _jsx(MjmlText, { variant: "body", children: "Body text" }), _jsx(MjmlText, { children: "Base text" })] }) }) }));
25
+ expect(mjmlWarnings).toEqual([]);
26
+ });
27
+ });
28
+ describe("generateTextStyles", () => {
29
+ it("returns empty CSS when no variants are defined", () => {
30
+ const theme = createTheme();
31
+ const result = generateTextStyles(theme);
32
+ expect(result).toBe("");
33
+ });
34
+ it("emits style overrides with correct selector for a variant", () => {
35
+ const theme = createTheme({
36
+ text: {
37
+ variants: {
38
+ heading: {
39
+ fontSize: { default: "32px", mobile: "24px" },
40
+ },
41
+ },
42
+ },
43
+ });
44
+ const result = generateTextStyles(theme);
45
+ expect(result).toContain(".mjmlText--heading > div");
46
+ expect(result).toContain("font-size: 24px !important");
47
+ });
48
+ it("groups multiple properties into a single media query per breakpoint", () => {
49
+ const theme = createTheme({
50
+ text: {
51
+ variants: {
52
+ heading: {
53
+ fontSize: { default: "32px", mobile: "24px" },
54
+ lineHeight: { default: "40px", mobile: "30px" },
55
+ },
56
+ },
57
+ },
58
+ });
59
+ const result = generateTextStyles(theme);
60
+ const mobileMediaQuery = `@media (max-width: ${theme.breakpoints.mobile.value - 1}px)`;
61
+ expect(result).toContain(mobileMediaQuery);
62
+ // Both declarations should appear within the same media query block
63
+ const mediaBlockStart = result.indexOf(mobileMediaQuery);
64
+ const blockContent = result.slice(mediaBlockStart);
65
+ expect(blockContent).toContain("font-size: 24px !important");
66
+ expect(blockContent).toContain("line-height: 30px !important");
67
+ });
68
+ it("uses compound selector for responsive bottomSpacing", () => {
69
+ const theme = createTheme({
70
+ text: {
71
+ variants: {
72
+ heading: {
73
+ bottomSpacing: { default: "24px", mobile: "16px" },
74
+ },
75
+ },
76
+ },
77
+ });
78
+ const result = generateTextStyles(theme);
79
+ expect(result).toContain(".mjmlText--bottomSpacing.mjmlText--heading");
80
+ expect(result).toContain("padding-bottom: 16px !important");
81
+ });
82
+ it("emits no media queries for non-responsive variant", () => {
83
+ const theme = createTheme({
84
+ text: {
85
+ variants: {
86
+ body: { fontSize: "14px", lineHeight: "22px" },
87
+ },
88
+ },
89
+ });
90
+ const result = generateTextStyles(theme);
91
+ expect(result).not.toContain("@media");
92
+ });
93
+ it("keeps style and bottomSpacing overrides separate", () => {
94
+ const theme = createTheme({
95
+ text: {
96
+ variants: {
97
+ heading: {
98
+ fontSize: { default: "32px", mobile: "24px" },
99
+ bottomSpacing: { default: "24px", mobile: "16px" },
100
+ },
101
+ },
102
+ },
103
+ });
104
+ const result = generateTextStyles(theme);
105
+ // Style overrides use "> div" selector
106
+ expect(result).toContain(".mjmlText--heading > div");
107
+ expect(result).toContain("font-size: 24px !important");
108
+ // Spacing overrides use compound selector (no "> div")
109
+ expect(result).toContain(".mjmlText--bottomSpacing.mjmlText--heading");
110
+ expect(result).toContain("padding-bottom: 16px !important");
111
+ });
112
+ });
@@ -0,0 +1,12 @@
1
+ import type { TextVariantStyles, Theme } from "../../theme/themeTypes.js";
2
+ type StylePropertyKey = Exclude<keyof TextVariantStyles, "bottomSpacing">;
3
+ export declare const textStyleCssProperties: ReadonlyArray<[StylePropertyKey, string]>;
4
+ interface GenerateResponsiveTextCssOptions {
5
+ /** Selector for text style overrides, given a variant name. */
6
+ styleSelector: (variantName: string) => string;
7
+ /** Selector for bottomSpacing overrides, given a variant name. */
8
+ spacingSelector: (variantName: string) => string;
9
+ }
10
+ /** Generates responsive CSS media queries for text variant overrides. */
11
+ export declare function generateResponsiveTextCss(theme: Theme, options: GenerateResponsiveTextCssOptions): string;
12
+ export {};
@@ -0,0 +1,69 @@
1
+ import { getResponsiveOverrides } from "../../theme/responsiveValue.js";
2
+ import { css } from "../../utils/css.js";
3
+ export const textStyleCssProperties = [
4
+ ["fontFamily", "font-family"],
5
+ ["fontSize", "font-size"],
6
+ ["fontWeight", "font-weight"],
7
+ ["fontStyle", "font-style"],
8
+ ["lineHeight", "line-height"],
9
+ ["letterSpacing", "letter-spacing"],
10
+ ["textDecoration", "text-decoration"],
11
+ ["textTransform", "text-transform"],
12
+ ["color", "color"],
13
+ ];
14
+ /** Generates responsive CSS media queries for text variant overrides. */
15
+ export function generateResponsiveTextCss(theme, options) {
16
+ const { variants } = theme.text;
17
+ if (!variants)
18
+ return css ``;
19
+ const cssChunks = [];
20
+ for (const [variantName, variantStyles] of Object.entries(variants)) {
21
+ if (!variantStyles)
22
+ continue;
23
+ const styleOverrides = new Map();
24
+ const spacingOverrides = new Map();
25
+ for (const [themeKey, cssProperty] of textStyleCssProperties) {
26
+ const value = variantStyles[themeKey];
27
+ if (value === undefined)
28
+ continue;
29
+ for (const { breakpointKey, value: breakpointValue } of getResponsiveOverrides(value)) {
30
+ const declarations = styleOverrides.get(breakpointKey) ?? [];
31
+ declarations.push(`${cssProperty}: ${String(breakpointValue)} !important`);
32
+ styleOverrides.set(breakpointKey, declarations);
33
+ }
34
+ }
35
+ const bottomSpacingValue = variantStyles.bottomSpacing;
36
+ if (bottomSpacingValue !== undefined) {
37
+ for (const { breakpointKey, value: breakpointValue } of getResponsiveOverrides(bottomSpacingValue)) {
38
+ const declarations = spacingOverrides.get(breakpointKey) ?? [];
39
+ declarations.push(`padding-bottom: ${String(breakpointValue)} !important`);
40
+ spacingOverrides.set(breakpointKey, declarations);
41
+ }
42
+ }
43
+ for (const [breakpointKey, declarations] of styleOverrides) {
44
+ const breakpoint = theme.breakpoints[breakpointKey];
45
+ if (!breakpoint)
46
+ continue;
47
+ cssChunks.push(css `
48
+ ${breakpoint.belowMediaQuery} {
49
+ ${options.styleSelector(variantName)} {
50
+ ${declarations.join(";\n")}
51
+ }
52
+ }
53
+ `);
54
+ }
55
+ for (const [breakpointKey, declarations] of spacingOverrides) {
56
+ const breakpoint = theme.breakpoints[breakpointKey];
57
+ if (!breakpoint)
58
+ continue;
59
+ cssChunks.push(css `
60
+ ${breakpoint.belowMediaQuery} {
61
+ ${options.spacingSelector(variantName)} {
62
+ ${declarations.join(";\n")}
63
+ }
64
+ }
65
+ `);
66
+ }
67
+ }
68
+ return cssChunks.join("\n");
69
+ }
package/lib/index.d.ts CHANGED
@@ -4,17 +4,23 @@ export { OneOfBlock } from "./blocks/factories/OneOfBlock.js";
4
4
  export { OptionalBlock } from "./blocks/factories/OptionalBlock.js";
5
5
  export type { SupportedBlocks } from "./blocks/factories/types.js";
6
6
  export type { PropsWithData } from "./blocks/helpers/PropsWithData.js";
7
+ export type { HtmlInlineLinkProps } from "./components/inlineLink/HtmlInlineLink.js";
8
+ export { HtmlInlineLink } from "./components/inlineLink/HtmlInlineLink.js";
7
9
  export { MjmlMailRoot } from "./components/mailRoot/MjmlMailRoot.js";
8
10
  export type { MjmlSectionProps } from "./components/section/MjmlSection.js";
9
11
  export { MjmlSection } from "./components/section/MjmlSection.js";
12
+ export type { HtmlTextProps } from "./components/text/HtmlText.js";
13
+ export { HtmlText } from "./components/text/HtmlText.js";
14
+ export type { MjmlTextProps } from "./components/text/MjmlText.js";
15
+ export { MjmlText } from "./components/text/MjmlText.js";
10
16
  export { registerStyles } from "./styles/registerStyles.js";
11
17
  export { createBreakpoint } from "./theme/createBreakpoint.js";
12
18
  export { createTheme } from "./theme/createTheme.js";
13
19
  export type { ResponsiveValue } from "./theme/responsiveValue.js";
14
20
  export { getDefaultFromResponsiveValue, getResponsiveOverrides } from "./theme/responsiveValue.js";
15
21
  export { ThemeProvider, useTheme } from "./theme/ThemeProvider.js";
16
- export type { Theme, ThemeBreakpoint, ThemeBreakpoints, ThemeSizes } from "./theme/themeTypes.js";
22
+ export type { TextStyles, TextVariants, TextVariantStyles, Theme, ThemeBackgroundColors, ThemeBreakpoint, ThemeBreakpoints, ThemeColors, ThemeSizes, ThemeText, } from "./theme/themeTypes.js";
17
23
  export { css } from "./utils/css.js";
18
- export { Mjml, MjmlAccordion, MjmlAccordionElement, type IMjmlAccordionElementProps as MjmlAccordionElementProps, type IMjmlAccordionProps as MjmlAccordionProps, MjmlAccordionText, type IMjmlAccordionTextProps as MjmlAccordionTextProps, MjmlAccordionTitle, type IMjmlAccordionTitleProps as MjmlAccordionTitleProps, MjmlAll, type IMjmlAllProps as MjmlAllProps, MjmlAttributes, type IMjmlAttributesProps as MjmlAttributesProps, MjmlBody, type IMjmlBodyProps as MjmlBodyProps, MjmlBreakpoint, type IMjmlBreakpointProps as MjmlBreakpointProps, MjmlButton, type IMjmlButtonProps as MjmlButtonProps, MjmlCarousel, MjmlCarouselImage, type IMjmlCarouselImageProps as MjmlCarouselImageProps, type IMjmlCarouselProps as MjmlCarouselProps, MjmlClass, type IMjmlClassProps as MjmlClassProps, MjmlColumn, type IMjmlColumnProps as MjmlColumnProps, MjmlDivider, type IMjmlDividerProps as MjmlDividerProps, MjmlFont, type IMjmlFontProps as MjmlFontProps, MjmlGroup, type IMjmlGroupProps as MjmlGroupProps, MjmlHead, type IMjmlHeadProps as MjmlHeadProps, MjmlHero, type IMjmlHeroProps as MjmlHeroProps, MjmlHtmlAttribute, type IMjmlHtmlAttributeProps as MjmlHtmlAttributeProps, MjmlHtmlAttributes, type IMjmlHtmlAttributesProps as MjmlHtmlAttributesProps, MjmlImage, type IMjmlImageProps as MjmlImageProps, MjmlInclude, type IMjmlIncludeProps as MjmlIncludeProps, MjmlNavbar, MjmlNavbarLink, type IMjmlNavbarLinkProps as MjmlNavbarLinkProps, type IMjmlNavbarProps as MjmlNavbarProps, MjmlPreview, type IMjmlPreviewProps as MjmlPreviewProps, type IMjmlProps as MjmlProps, MjmlRaw, type IMjmlRawProps as MjmlRawProps, MjmlSelector, type IMjmlSelectorProps as MjmlSelectorProps, MjmlSocial, MjmlSocialElement, type IMjmlSocialElementProps as MjmlSocialElementProps, type IMjmlSocialProps as MjmlSocialProps, MjmlSpacer, type IMjmlSpacerProps as MjmlSpacerProps, MjmlStyle, type IMjmlStyleProps as MjmlStyleProps, MjmlTable, type IMjmlTableProps as MjmlTableProps, MjmlText, type IMjmlTextProps as MjmlTextProps, MjmlTitle, type IMjmlTitleProps as MjmlTitleProps, MjmlWrapper, type IMjmlWrapperProps as MjmlWrapperProps, } from "@faire/mjml-react";
24
+ export { Mjml, MjmlAccordion, MjmlAccordionElement, type IMjmlAccordionElementProps as MjmlAccordionElementProps, type IMjmlAccordionProps as MjmlAccordionProps, MjmlAccordionText, type IMjmlAccordionTextProps as MjmlAccordionTextProps, MjmlAccordionTitle, type IMjmlAccordionTitleProps as MjmlAccordionTitleProps, MjmlAll, type IMjmlAllProps as MjmlAllProps, MjmlAttributes, type IMjmlAttributesProps as MjmlAttributesProps, MjmlBody, type IMjmlBodyProps as MjmlBodyProps, MjmlBreakpoint, type IMjmlBreakpointProps as MjmlBreakpointProps, MjmlButton, type IMjmlButtonProps as MjmlButtonProps, MjmlCarousel, MjmlCarouselImage, type IMjmlCarouselImageProps as MjmlCarouselImageProps, type IMjmlCarouselProps as MjmlCarouselProps, MjmlClass, type IMjmlClassProps as MjmlClassProps, MjmlColumn, type IMjmlColumnProps as MjmlColumnProps, MjmlDivider, type IMjmlDividerProps as MjmlDividerProps, MjmlFont, type IMjmlFontProps as MjmlFontProps, MjmlGroup, type IMjmlGroupProps as MjmlGroupProps, MjmlHead, type IMjmlHeadProps as MjmlHeadProps, MjmlHero, type IMjmlHeroProps as MjmlHeroProps, MjmlHtmlAttribute, type IMjmlHtmlAttributeProps as MjmlHtmlAttributeProps, MjmlHtmlAttributes, type IMjmlHtmlAttributesProps as MjmlHtmlAttributesProps, MjmlImage, type IMjmlImageProps as MjmlImageProps, MjmlInclude, type IMjmlIncludeProps as MjmlIncludeProps, MjmlNavbar, MjmlNavbarLink, type IMjmlNavbarLinkProps as MjmlNavbarLinkProps, type IMjmlNavbarProps as MjmlNavbarProps, MjmlPreview, type IMjmlPreviewProps as MjmlPreviewProps, type IMjmlProps as MjmlProps, MjmlRaw, type IMjmlRawProps as MjmlRawProps, MjmlSelector, type IMjmlSelectorProps as MjmlSelectorProps, MjmlSocial, MjmlSocialElement, type IMjmlSocialElementProps as MjmlSocialElementProps, type IMjmlSocialProps as MjmlSocialProps, MjmlSpacer, type IMjmlSpacerProps as MjmlSpacerProps, MjmlStyle, type IMjmlStyleProps as MjmlStyleProps, MjmlTable, type IMjmlTableProps as MjmlTableProps, MjmlTitle, type IMjmlTitleProps as MjmlTitleProps, MjmlWrapper, type IMjmlWrapperProps as MjmlWrapperProps, } from "@faire/mjml-react";
19
25
  export { MjmlComment, MjmlConditionalComment, MjmlHtml, MjmlTrackingPixel, MjmlYahooStyle } from "@faire/mjml-react/extensions/index.js";
20
26
  export { renderToMjml } from "@faire/mjml-react/utils/renderToMjml.js";
package/lib/index.js CHANGED
@@ -2,14 +2,17 @@ export { BlocksBlock } from "./blocks/factories/BlocksBlock.js";
2
2
  export { ListBlock } from "./blocks/factories/ListBlock.js";
3
3
  export { OneOfBlock } from "./blocks/factories/OneOfBlock.js";
4
4
  export { OptionalBlock } from "./blocks/factories/OptionalBlock.js";
5
+ export { HtmlInlineLink } from "./components/inlineLink/HtmlInlineLink.js";
5
6
  export { MjmlMailRoot } from "./components/mailRoot/MjmlMailRoot.js";
6
7
  export { MjmlSection } from "./components/section/MjmlSection.js";
8
+ export { HtmlText } from "./components/text/HtmlText.js";
9
+ export { MjmlText } from "./components/text/MjmlText.js";
7
10
  export { registerStyles } from "./styles/registerStyles.js";
8
11
  export { createBreakpoint } from "./theme/createBreakpoint.js";
9
12
  export { createTheme } from "./theme/createTheme.js";
10
13
  export { getDefaultFromResponsiveValue, getResponsiveOverrides } from "./theme/responsiveValue.js";
11
14
  export { ThemeProvider, useTheme } from "./theme/ThemeProvider.js";
12
15
  export { css } from "./utils/css.js";
13
- export { Mjml, MjmlAccordion, MjmlAccordionElement, MjmlAccordionText, MjmlAccordionTitle, MjmlAll, MjmlAttributes, MjmlBody, MjmlBreakpoint, MjmlButton, MjmlCarousel, MjmlCarouselImage, MjmlClass, MjmlColumn, MjmlDivider, MjmlFont, MjmlGroup, MjmlHead, MjmlHero, MjmlHtmlAttribute, MjmlHtmlAttributes, MjmlImage, MjmlInclude, MjmlNavbar, MjmlNavbarLink, MjmlPreview, MjmlRaw, MjmlSelector, MjmlSocial, MjmlSocialElement, MjmlSpacer, MjmlStyle, MjmlTable, MjmlText, MjmlTitle, MjmlWrapper, } from "@faire/mjml-react";
16
+ export { Mjml, MjmlAccordion, MjmlAccordionElement, MjmlAccordionText, MjmlAccordionTitle, MjmlAll, MjmlAttributes, MjmlBody, MjmlBreakpoint, MjmlButton, MjmlCarousel, MjmlCarouselImage, MjmlClass, MjmlColumn, MjmlDivider, MjmlFont, MjmlGroup, MjmlHead, MjmlHero, MjmlHtmlAttribute, MjmlHtmlAttributes, MjmlImage, MjmlInclude, MjmlNavbar, MjmlNavbarLink, MjmlPreview, MjmlRaw, MjmlSelector, MjmlSocial, MjmlSocialElement, MjmlSpacer, MjmlStyle, MjmlTable, MjmlTitle, MjmlWrapper, } from "@faire/mjml-react";
14
17
  export { MjmlComment, MjmlConditionalComment, MjmlHtml, MjmlTrackingPixel, MjmlYahooStyle } from "@faire/mjml-react/extensions/index.js";
15
18
  export { renderToMjml } from "@faire/mjml-react/utils/renderToMjml.js";
@@ -1 +1,7 @@
1
- export declare function MailRendererDecorator(Story: () => React.JSX.Element): import("react/jsx-runtime").JSX.Element;
1
+ import type { Theme } from "../theme/themeTypes.js";
2
+ export declare function MailRendererDecorator(Story: () => React.JSX.Element, context: {
3
+ parameters: {
4
+ mailRoot?: boolean;
5
+ theme?: Theme;
6
+ };
7
+ }): import("react/jsx-runtime").JSX.Element;
@@ -4,10 +4,10 @@ import { renderMailHtml } from "../client/renderMailHtml.js";
4
4
  import { MjmlMailRoot } from "../components/mailRoot/MjmlMailRoot.js";
5
5
  import { replaceImagesWithPublicUrl } from "./replaceImagesWithPublicUrl.js";
6
6
  const RENDER_RESULT_EVENT = "comet-mail-render-result";
7
- export function MailRendererDecorator(Story) {
7
+ export function MailRendererDecorator(Story, context) {
8
8
  const [globals] = useGlobals();
9
9
  const emit = useChannel({});
10
- const { html: rawHtml, mjmlWarnings } = renderMailHtml(_jsx(MjmlMailRoot, { children: _jsx(Story, {}) }));
10
+ const { html: rawHtml, mjmlWarnings } = renderMailHtml(context.parameters.mailRoot === false ? (_jsx(Story, {})) : (_jsx(MjmlMailRoot, { theme: context.parameters.theme, children: _jsx(Story, {}) })));
11
11
  for (const warning of mjmlWarnings) {
12
12
  console.warn("MJML warning:", warning);
13
13
  }
@@ -11,7 +11,7 @@ const config = {
11
11
  };
12
12
  export default config;
13
13
  export const Basic = {
14
- render: () => (_jsx(MjmlSection, { children: _jsx(MjmlColumn, { children: _jsx(MjmlText, { children: "Using the default theme from the decorator." }) }) })),
14
+ render: () => (_jsx(MjmlSection, { indent: true, children: _jsx(MjmlColumn, { children: _jsx(MjmlText, { children: "Using the default theme from the decorator." }) }) })),
15
15
  };
16
16
  const narrowTheme = createTheme({
17
17
  sizes: { bodyWidth: 400 },
@@ -19,5 +19,5 @@ const narrowTheme = createTheme({
19
19
  });
20
20
  export const CustomTheme = {
21
21
  parameters: { theme: narrowTheme },
22
- render: () => (_jsx(MjmlSection, { children: _jsx(MjmlColumn, { children: _jsx(MjmlText, { children: "This email uses a 400px body width and 360px mobile breakpoint." }) }) })),
22
+ render: () => (_jsx(MjmlSection, { indent: true, children: _jsx(MjmlColumn, { children: _jsx(MjmlText, { children: "This email uses a 400px body width and 360px mobile breakpoint." }) }) })),
23
23
  };
@@ -1,7 +1,11 @@
1
- import type { Theme, ThemeBreakpoints, ThemeSizes } from "./themeTypes.js";
1
+ import type { Theme, ThemeBackgroundColors, ThemeBreakpoints, ThemeColors, ThemeSizes, ThemeText } from "./themeTypes.js";
2
2
  type CreateThemeOverrides = {
3
3
  sizes?: Partial<ThemeSizes>;
4
4
  breakpoints?: Partial<ThemeBreakpoints>;
5
+ text?: Partial<ThemeText>;
6
+ colors?: {
7
+ background?: Partial<ThemeBackgroundColors>;
8
+ } & Partial<Omit<ThemeColors, "background">>;
5
9
  };
6
10
  /**
7
11
  * Creates a complete theme by merging optional overrides onto the default
@@ -20,5 +20,11 @@ export function createTheme(overrides) {
20
20
  default: createBreakpoint(resolvedSizes.bodyWidth),
21
21
  ...overrides?.breakpoints,
22
22
  },
23
+ text: { ...defaultTheme.text, ...overrides?.text },
24
+ colors: {
25
+ ...defaultTheme.colors,
26
+ ...overrides?.colors,
27
+ background: { ...defaultTheme.colors.background, ...overrides?.colors?.background },
28
+ },
23
29
  };
24
30
  }