Skip to content

Commit bd2ca02

Browse files
fix(react-email): convert border radius and max width to px in pixelBasedPreset (#3846)
Co-authored-by: Felipe Freitag <felipe.freitag@resend.com>
1 parent c2b937f commit bd2ca02

5 files changed

Lines changed: 85 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-email": patch
3+
---
4+
5+
Make `pixelBasedPreset` also convert the border radius and max width scales to pixels, so `rounded-*` and `max-w-*` no longer emit `rem`.

‎packages/react-email/src/cli/commands/testing/export.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ test('email export', { retry: 3 }, async () => {
5858
cellpadding="0"
5959
cellspacing="0"
6060
role="presentation"
61-
style="max-width:465px;margin-right:auto;margin-left:auto;margin-bottom:40px;margin-top:40px;border-radius:0.25rem;border-style:solid;border-width:1px;border-color:rgb(234,234,234)">
61+
style="max-width:465px;margin-right:auto;margin-left:auto;margin-bottom:40px;margin-top:40px;border-radius:4px;border-style:solid;border-width:1px;border-color:rgb(234,234,234)">
6262
<tbody>
6363
<tr style="width:100%">
6464
<td style="padding:20px">
@@ -167,7 +167,7 @@ test('email export', { retry: 3 }, async () => {
167167
<tr>
168168
<td>
169169
<a
170-
style="line-height:100%;text-decoration:none;display:inline-block;max-width:100%;mso-padding-alt:0px;border-radius:0.25rem;background-color:rgb(0,0,0);padding-right:20px;padding-left:20px;padding-bottom:12px;padding-top:12px;text-align:center;font-weight:600;font-size:12px;color:rgb(255,255,255);text-decoration-line:none"
170+
style="line-height:100%;text-decoration:none;display:inline-block;max-width:100%;mso-padding-alt:0px;border-radius:4px;background-color:rgb(0,0,0);padding-right:20px;padding-left:20px;padding-bottom:12px;padding-top:12px;text-align:center;font-weight:600;font-size:12px;color:rgb(255,255,255);text-decoration-line:none"
171171
target="_blank"
172172
><span
173173
><!--[if mso]><i style="mso-font-width:500%;mso-text-raise:18px" hidden>&#8202;&#8202;</i><![endif]--></span

‎packages/react-email/src/components/tailwind/tailwind.spec.tsx‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Link } from '../link/index.js';
1313
import { Row } from '../row/index.js';
1414
import { Section } from '../section/index.js';
1515
import type { TailwindConfig } from './tailwind.js';
16-
import { Tailwind } from './tailwind.js';
16+
import { pixelBasedPreset, Tailwind } from './tailwind.js';
1717

1818
describe('Tailwind component', () => {
1919
const headMissingError =
@@ -1695,4 +1695,53 @@ describe('Tailwind component', () => {
16951695
`);
16961696
});
16971697
});
1698+
1699+
describe('with pixelBasedPreset', () => {
1700+
const styleFor = async (className: string) => {
1701+
const html = await render(
1702+
<Tailwind config={{ presets: [pixelBasedPreset] }}>
1703+
<div className={className} />
1704+
</Tailwind>,
1705+
);
1706+
return html.match(/style="([^"]*)"/)?.[1];
1707+
};
1708+
1709+
it.each([
1710+
['rounded', 'border-radius:4px'],
1711+
['rounded-sm', 'border-radius:4px'],
1712+
['rounded-md', 'border-radius:6px'],
1713+
['rounded-lg', 'border-radius:8px'],
1714+
['rounded-4xl', 'border-radius:32px'],
1715+
['max-w-md', 'max-width:448px'],
1716+
['max-w-7xl', 'max-width:1280px'],
1717+
])('converts %s to pixels', async (className, expected) => {
1718+
expect(await styleFor(className)).toBe(expected);
1719+
});
1720+
1721+
it('does not leave rem in the radius or max-width scales', async () => {
1722+
const classes = [
1723+
...['xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl'].map(
1724+
(size) => `rounded-${size}`,
1725+
),
1726+
...[
1727+
'3xs',
1728+
'2xs',
1729+
'xs',
1730+
'sm',
1731+
'md',
1732+
'lg',
1733+
'xl',
1734+
'2xl',
1735+
'3xl',
1736+
'4xl',
1737+
'5xl',
1738+
'6xl',
1739+
'7xl',
1740+
].map((size) => `max-w-${size}`),
1741+
];
1742+
for (const className of classes) {
1743+
expect(await styleFor(className), className).not.toContain('rem');
1744+
}
1745+
});
1746+
});
16981747
});

‎packages/react-email/src/components/tailwind/tailwind.tsx‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,32 @@ export const pixelBasedPreset: TailwindConfig = {
7575
80: '320px',
7676
96: '384px',
7777
},
78+
borderRadius: {
79+
DEFAULT: '4px',
80+
xs: '2px',
81+
sm: '4px',
82+
md: '6px',
83+
lg: '8px',
84+
xl: '12px',
85+
'2xl': '16px',
86+
'3xl': '24px',
87+
'4xl': '32px',
88+
},
89+
maxWidth: {
90+
'3xs': '256px',
91+
'2xs': '288px',
92+
xs: '320px',
93+
sm: '384px',
94+
md: '448px',
95+
lg: '512px',
96+
xl: '576px',
97+
'2xl': '672px',
98+
'3xl': '768px',
99+
'4xl': '896px',
100+
'5xl': '1024px',
101+
'6xl': '1152px',
102+
'7xl': '1280px',
103+
},
78104
},
79105
},
80106
};

‎packages/ui/src/utils/get-email-component.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('getEmailComponent()', () => {
6666
cellpadding="0"
6767
cellspacing="0"
6868
role="presentation"
69-
style="max-width:465px;margin-right:auto;margin-left:auto;margin-bottom:40px;margin-top:40px;border-radius:0.25rem;border-style:solid;border-width:1px;border-color:rgb(234,234,234)">
69+
style="max-width:465px;margin-right:auto;margin-left:auto;margin-bottom:40px;margin-top:40px;border-radius:4px;border-style:solid;border-width:1px;border-color:rgb(234,234,234)">
7070
<tbody>
7171
<tr style="width:100%">
7272
<td style="padding:20px">
@@ -179,7 +179,7 @@ describe('getEmailComponent()', () => {
179179
<td>
180180
<a
181181
href="https://vercel.com"
182-
style="line-height:100%;text-decoration:none;display:inline-block;max-width:100%;mso-padding-alt:0px;border-radius:0.25rem;background-color:rgb(0,0,0);padding-right:20px;padding-left:20px;padding-bottom:12px;padding-top:12px;text-align:center;font-weight:600;font-size:12px;color:rgb(255,255,255);text-decoration-line:none"
182+
style="line-height:100%;text-decoration:none;display:inline-block;max-width:100%;mso-padding-alt:0px;border-radius:4px;background-color:rgb(0,0,0);padding-right:20px;padding-left:20px;padding-bottom:12px;padding-top:12px;text-align:center;font-weight:600;font-size:12px;color:rgb(255,255,255);text-decoration-line:none"
183183
target="_blank"
184184
><span
185185
><!--[if mso]><i style="mso-font-width:500%;mso-text-raise:18px" hidden>&#8202;&#8202;</i><![endif]--></span

0 commit comments

Comments
 (0)