Skip to content

Commit 5d000c4

Browse files
committed
fix: convert space-* on breakpoints when paste tailwind (#5308)
Ref #2651 Didn't consider spaces on breakpoints when converted space-* to gap for example `md:space-x-6` -> `md:gap-x-6`
1 parent be4f2e0 commit 5d000c4

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

apps/builder/app/shared/tailwind/tailwind.test.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,8 @@ test("generate space without display property", async () => {
584584
await generateFragmentFromTailwind(
585585
renderTemplate(
586586
<>
587-
<ws.element ws:tag="div" class="space-x-4"></ws.element>
588-
<ws.element ws:tag="div" class="space-y-4"></ws.element>
587+
<ws.element ws:tag="div" class="space-x-4 md:space-x-6"></ws.element>
588+
<ws.element ws:tag="div" class="space-y-4 md:space-y-6"></ws.element>
589589
</>
590590
)
591591
)
@@ -596,7 +596,10 @@ test("generate space without display property", async () => {
596596
ws:tag="div"
597597
ws:style={css`
598598
display: flex;
599-
column-gap: 1rem;
599+
@media (max-width: 767px) {
600+
column-gap: 1rem;
601+
}
602+
column-gap: 1.5rem;
600603
`}
601604
></ws.element>
602605
<ws.element
@@ -605,7 +608,10 @@ test("generate space without display property", async () => {
605608
display: flex;
606609
flex-direction: column;
607610
align-items: start;
608-
row-gap: 1rem;
611+
@media (max-width: 767px) {
612+
row-gap: 1rem;
613+
}
614+
row-gap: 1.5rem;
609615
`}
610616
></ws.element>
611617
</>

apps/builder/app/shared/tailwind/tailwind.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,13 @@ const parseTailwindClasses = async (classes: string) => {
198198
.map((item) => {
199199
// styles data cannot express space-x and space-y selectors
200200
// with lobotomized owl so replace with gaps
201-
const spaceX = "space-x-";
202-
if (item.startsWith(spaceX)) {
201+
if (item.includes("space-x-")) {
203202
hasColumnGaps = true;
204-
return `gap-x-${item.slice(spaceX.length)}`;
203+
return item.replace("space-x-", "gap-x-");
205204
}
206-
const spaceY = "space-y-";
207-
if (item.startsWith(spaceY)) {
205+
if (item.includes("space-y-")) {
208206
hasRowGaps = true;
209-
return `gap-y-${item.slice(spaceY.length)}`;
207+
return item.replace("space-y-", "gap-y-");
210208
}
211209
hasFlexOrGrid ||= item.endsWith("flex") || item.endsWith("grid");
212210
hasContainer ||= item === "container";

0 commit comments

Comments
 (0)