diff --git a/.changeset/pixel-based-preset-radius-max-width.md b/.changeset/pixel-based-preset-radius-max-width.md new file mode 100644 index 0000000000..04e1fe4bdf --- /dev/null +++ b/.changeset/pixel-based-preset-radius-max-width.md @@ -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`. diff --git a/packages/react-email/src/cli/commands/testing/export.spec.ts b/packages/react-email/src/cli/commands/testing/export.spec.ts index da17efaa94..7f5963247b 100644 --- a/packages/react-email/src/cli/commands/testing/export.spec.ts +++ b/packages/react-email/src/cli/commands/testing/export.spec.ts @@ -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)"> @@ -167,7 +167,7 @@ test('email export', { retry: 3 }, async () => { { const headMissingError = @@ -1695,4 +1695,53 @@ describe('Tailwind component', () => { `); }); }); + + describe('with pixelBasedPreset', () => { + const styleFor = async (className: string) => { + const html = await render( + +
+ , + ); + 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'); + } + }); + }); }); diff --git a/packages/react-email/src/components/tailwind/tailwind.tsx b/packages/react-email/src/components/tailwind/tailwind.tsx index 90d93c0dc7..df6f103889 100644 --- a/packages/react-email/src/components/tailwind/tailwind.tsx +++ b/packages/react-email/src/components/tailwind/tailwind.tsx @@ -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', + }, }, }, }; diff --git a/packages/ui/src/utils/get-email-component.spec.ts b/packages/ui/src/utils/get-email-component.spec.ts index 5ae034350a..220383d2dd 100644 --- a/packages/ui/src/utils/get-email-component.spec.ts +++ b/packages/ui/src/utils/get-email-component.spec.ts @@ -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)"> @@ -179,7 +179,7 @@ describe('getEmailComponent()', () => {