Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pixel-based-preset-radius-max-width.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-email": patch
---

Make `pixelBasedPreset` also convert the border radius and max width scales to pixels, so `rounded-*` and `max-w-*` no longer emit `rem`.
4 changes: 2 additions & 2 deletions packages/react-email/src/cli/commands/testing/export.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test('email export', { retry: 3 }, async () => {
cellpadding="0"
cellspacing="0"
role="presentation"
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)">
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)">
<tbody>
<tr style="width:100%">
<td style="padding:20px">
Expand Down Expand Up @@ -167,7 +167,7 @@ test('email export', { retry: 3 }, async () => {
<tr>
<td>
<a
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"
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"
target="_blank"
><span
><!--[if mso]><i style="mso-font-width:500%;mso-text-raise:18px" hidden>&#8202;&#8202;</i><![endif]--></span
Expand Down
51 changes: 50 additions & 1 deletion packages/react-email/src/components/tailwind/tailwind.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Link } from '../link/index.js';
import { Row } from '../row/index.js';
import { Section } from '../section/index.js';
import type { TailwindConfig } from './tailwind.js';
import { Tailwind } from './tailwind.js';
import { pixelBasedPreset, Tailwind } from './tailwind.js';

describe('Tailwind component', () => {
const headMissingError =
Expand Down Expand Up @@ -1695,4 +1695,53 @@ describe('Tailwind component', () => {
`);
});
});

describe('with pixelBasedPreset', () => {
const styleFor = async (className: string) => {
const html = await render(
<Tailwind config={{ presets: [pixelBasedPreset] }}>
<div className={className} />
</Tailwind>,
);
return html.match(/style="([^"]*)"/)?.[1];
};

it.each([
['rounded', 'border-radius:4px'],
['rounded-sm', 'border-radius:4px'],
['rounded-md', 'border-radius:6px'],
['rounded-lg', 'border-radius:8px'],
['rounded-4xl', 'border-radius:32px'],
['max-w-md', 'max-width:448px'],
['max-w-7xl', 'max-width:1280px'],
])('converts %s to pixels', async (className, expected) => {
expect(await styleFor(className)).toBe(expected);
});

it('does not leave rem in the radius or max-width scales', async () => {
const classes = [
...['xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl'].map(
(size) => `rounded-${size}`,
),
...[
'3xs',
'2xs',
'xs',
'sm',
'md',
'lg',
'xl',
'2xl',
'3xl',
'4xl',
'5xl',
'6xl',
'7xl',
].map((size) => `max-w-${size}`),
];
for (const className of classes) {
expect(await styleFor(className), className).not.toContain('rem');
}
});
});
});
26 changes: 26 additions & 0 deletions packages/react-email/src/components/tailwind/tailwind.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ export const pixelBasedPreset: TailwindConfig = {
80: '320px',
96: '384px',
},
borderRadius: {
DEFAULT: '4px',
xs: '2px',
sm: '4px',
md: '6px',
lg: '8px',
xl: '12px',
'2xl': '16px',
'3xl': '24px',
'4xl': '32px',
},
maxWidth: {
'3xs': '256px',
'2xs': '288px',
xs: '320px',
sm: '384px',
md: '448px',
lg: '512px',
xl: '576px',
'2xl': '672px',
'3xl': '768px',
'4xl': '896px',
'5xl': '1024px',
'6xl': '1152px',
'7xl': '1280px',
},
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/utils/get-email-component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('getEmailComponent()', () => {
cellpadding="0"
cellspacing="0"
role="presentation"
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)">
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)">
<tbody>
<tr style="width:100%">
<td style="padding:20px">
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('getEmailComponent()', () => {
<td>
<a
href="https://vercel.com"
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"
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"
target="_blank"
><span
><!--[if mso]><i style="mso-font-width:500%;mso-text-raise:18px" hidden>&#8202;&#8202;</i><![endif]--></span
Expand Down
Loading