Skip to content

Commit d1691db

Browse files
authored
feat(web): wrap tailwind copy-paste component code with <Tailwind> (#2699)
1 parent d89af46 commit d1691db

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { wrapWithTailwind } from './component-code-view';
2+
3+
const code = `<Section className="my-[16px] text-center">
4+
<Section className="inline-block w-full max-w-[250px] text-left align-top">
5+
<Text className="m-0 font-semibold text-[16px] text-indigo-600 leading-[24px]">
6+
What's new
7+
</Text>
8+
<Text className="m-0 mt-[8px] font-semibold text-[20px] text-gray-900 leading-[28px]">
9+
Versatile Comfort
10+
</Text>
11+
<Text className="mt-[8px] text-[16px] text-gray-500 leading-[24px]">
12+
Experience ultimate comfort and versatility with our furniture
13+
collection, designed to adapt to your ever-changing needs.
14+
</Text>
15+
<Link className="text-indigo-600 underline" href="https://react.email">
16+
Read more
17+
</Link>
18+
</Section>
19+
<Section className="my-[8px] inline-block w-full max-w-[220px] align-top">
20+
<Img
21+
alt="An aesthetic picture taken of an Iphone, flowers, glasses and a card that reads 'Gucci, bloom' coming out of a leathered bag with a ziper"
22+
className="rounded-[8px] object-cover"
23+
height={220}
24+
src="/static/versatile-comfort.jpg"
25+
width={220}
26+
/>
27+
</Section>
28+
</Section>`;
29+
30+
test('wrapWithTailwind()', () => {
31+
expect(wrapWithTailwind(code)).toMatchInlineSnapshot(`
32+
"<Tailwind>
33+
<Section className="my-[16px] text-center">
34+
<Section className="inline-block w-full max-w-[250px] text-left align-top">
35+
<Text className="m-0 font-semibold text-[16px] text-indigo-600 leading-[24px]">
36+
What's new
37+
</Text>
38+
<Text className="m-0 mt-[8px] font-semibold text-[20px] text-gray-900 leading-[28px]">
39+
Versatile Comfort
40+
</Text>
41+
<Text className="mt-[8px] text-[16px] text-gray-500 leading-[24px]">
42+
Experience ultimate comfort and versatility with our furniture
43+
collection, designed to adapt to your ever-changing needs.
44+
</Text>
45+
<Link className="text-indigo-600 underline" href="https://react.email">
46+
Read more
47+
</Link>
48+
</Section>
49+
<Section className="my-[8px] inline-block w-full max-w-[220px] align-top">
50+
<Img
51+
alt="An aesthetic picture taken of an Iphone, flowers, glasses and a card that reads 'Gucci, bloom' coming out of a leathered bag with a ziper"
52+
className="rounded-[8px] object-cover"
53+
height={220}
54+
src="/static/versatile-comfort.jpg"
55+
width={220}
56+
/>
57+
</Section>
58+
</Section>
59+
</Tailwind>"
60+
`);
61+
});

apps/web/src/components/component-code-view.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import { TabTrigger } from './tab-trigger';
1515

1616
type ReactCodeVariant = Exclude<CodeVariant, 'html' | 'react'>;
1717

18+
export function wrapWithTailwind(jsx: string) {
19+
return `<Tailwind>
20+
${jsx.replaceAll(/[^\n\r]*(\n|\r|\r\n)?/g, (match) => ` ${match}`)}
21+
</Tailwind>`;
22+
}
23+
1824
export function ComponentCodeView({
1925
component,
2026
}: {
@@ -51,6 +57,11 @@ export function ComponentCodeView({
5157
Object.keys(allReactEmailComponents),
5258
);
5359

60+
if (selectedReactCodeVariant === 'tailwind') {
61+
importsReactEmail.push('Tailwind');
62+
code = wrapWithTailwind(code);
63+
}
64+
5465
let importStatements = '';
5566

5667
if (importsReactEmail.length > 0) {

0 commit comments

Comments
 (0)