Skip to content

Commit f60c4bf

Browse files
committed
fix: 'auto' values for margin and position values
1 parent b3faba3 commit f60c4bf

File tree

3 files changed

+69
-29
lines changed

3 files changed

+69
-29
lines changed

src/__tests__/vendor/tailwind/layout.test.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -830,26 +830,22 @@ describe("Layout - Top Right Bottom Left", () => {
830830
});
831831
test("top-auto", async () => {
832832
expect(await renderCurrentTest()).toStrictEqual({
833-
props: {},
834-
warnings: { values: { top: "auto" } },
833+
props: { style: { top: "auto" } },
835834
});
836835
});
837836
test("right-auto", async () => {
838837
expect(await renderCurrentTest()).toStrictEqual({
839-
props: {},
840-
warnings: { values: { right: "auto" } },
838+
props: { style: { right: "auto" } },
841839
});
842840
});
843841
test("bottom-auto", async () => {
844842
expect(await renderCurrentTest()).toStrictEqual({
845-
props: {},
846-
warnings: { values: { bottom: "auto" } },
843+
props: { style: { bottom: "auto" } },
847844
});
848845
});
849846
test("left-auto", async () => {
850847
expect(await renderCurrentTest()).toStrictEqual({
851-
props: {},
852-
warnings: { values: { left: "auto" } },
848+
props: { style: { left: "auto" } },
853849
});
854850
});
855851
});

src/__tests__/vendor/tailwind/spacing.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,31 @@ describe("Spacing - Margin", () => {
9999
props: { style: { margin: "auto" } },
100100
});
101101
});
102+
test("mt-auto", async () => {
103+
expect(await renderCurrentTest()).toStrictEqual({
104+
props: { style: { marginTop: "auto" } },
105+
});
106+
});
107+
test("mb-auto", async () => {
108+
expect(await renderCurrentTest()).toStrictEqual({
109+
props: { style: { marginBottom: "auto" } },
110+
});
111+
});
112+
test("ms-auto", async () => {
113+
expect(await renderCurrentTest()).toStrictEqual({
114+
props: { style: { marginInlineStart: "auto" } },
115+
});
116+
});
117+
test("me-auto", async () => {
118+
expect(await renderCurrentTest()).toStrictEqual({
119+
props: { style: { marginInlineEnd: "auto" } },
120+
});
121+
});
122+
test("mx-auto", async () => {
123+
expect(await renderCurrentTest()).toStrictEqual({
124+
props: { style: { marginInline: "auto" } },
125+
});
126+
});
102127
});
103128

104129
describe.skip("Spacing - Space Between", () => {

src/compiler/declarations.ts

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const parsers: {
146146
"border-top-style": parseBorderStyleDeclaration,
147147
"border-top-width": parseBorderSideWidthDeclaration,
148148
"border-width": parseBorderWidth,
149-
"bottom": parseSizeDeclaration,
149+
"bottom": parseSizeWithAutoDeclaration,
150150
"box-shadow": parseBoxShadow,
151151
"caret-color": parseColorOrAutoDeclaration,
152152
"color": parseFontColorDeclaration,
@@ -158,7 +158,7 @@ const parsers: {
158158
"fill": parseSVGPaint,
159159
"filter": parseFilter,
160160
"flex": parseFlex,
161-
"flex-basis": parseLengthPercentageOrAutoDeclaration,
161+
"flex-basis": parseLengthPercentageDeclaration,
162162
"flex-direction": ({ value }) => value,
163163
"flex-flow": parseFlexFlow,
164164
"flex-grow": ({ value }) => value,
@@ -175,26 +175,26 @@ const parsers: {
175175
"inline-size": parseSizeDeclaration,
176176
"inset": parseInset,
177177
"inset-block": parseInsetBlock,
178-
"inset-block-end": parseLengthPercentageOrAutoDeclaration,
179-
"inset-block-start": parseLengthPercentageOrAutoDeclaration,
178+
"inset-block-end": parseLengthPercentageDeclaration,
179+
"inset-block-start": parseLengthPercentageDeclaration,
180180
"inset-inline": parseInsetInline,
181-
"inset-inline-end": parseLengthPercentageOrAutoDeclaration,
182-
"inset-inline-start": parseLengthPercentageOrAutoDeclaration,
181+
"inset-inline-end": parseLengthPercentageDeclaration,
182+
"inset-inline-start": parseLengthPercentageDeclaration,
183183
"justify-content": parseJustifyContent,
184-
"left": parseSizeDeclaration,
184+
"left": parseSizeWithAutoDeclaration,
185185
"letter-spacing": parseLetterSpacing,
186186
"line-height": parseLineHeightDeclaration,
187187
"margin": parseMargin,
188188
"margin-block": parseMarginBlock,
189189
"margin-block-end": parseLengthPercentageOrAutoDeclaration,
190190
"margin-block-start": parseLengthPercentageOrAutoDeclaration,
191-
"margin-bottom": parseSizeDeclaration,
191+
"margin-bottom": parseSizeWithAutoDeclaration,
192192
"margin-inline": parseMarginInline,
193193
"margin-inline-end": parseLengthPercentageOrAutoDeclaration,
194194
"margin-inline-start": parseLengthPercentageOrAutoDeclaration,
195-
"margin-left": parseSizeDeclaration,
196-
"margin-right": parseSizeDeclaration,
197-
"margin-top": parseSizeDeclaration,
195+
"margin-left": parseSizeWithAutoDeclaration,
196+
"margin-right": parseSizeWithAutoDeclaration,
197+
"margin-top": parseSizeWithAutoDeclaration,
198198
"max-block-size": parseSizeDeclaration,
199199
"max-height": parseSizeDeclaration,
200200
"max-inline-size": parseSizeDeclaration,
@@ -205,23 +205,22 @@ const parsers: {
205205
"min-width": parseSizeDeclaration,
206206
"opacity": ({ value }) => value,
207207
"outline-color": parseColorDeclaration,
208-
// "outline-offset": parseColorDeclaration,
209208
"outline-style": parseOutlineStyle,
210209
"outline-width": parseBorderSideWidthDeclaration,
211210
"overflow": parseOverflow,
212211
"padding": parsePadding,
213212
"padding-block": parsePaddingBlock,
214-
"padding-block-end": parseLengthPercentageOrAutoDeclaration,
215-
"padding-block-start": parseLengthPercentageOrAutoDeclaration,
213+
"padding-block-end": parseLengthPercentageDeclaration,
214+
"padding-block-start": parseLengthPercentageDeclaration,
216215
"padding-bottom": parseSizeDeclaration,
217216
"padding-inline": parsePaddingInline,
218-
"padding-inline-end": parseLengthPercentageOrAutoDeclaration,
219-
"padding-inline-start": parseLengthPercentageOrAutoDeclaration,
217+
"padding-inline-end": parseLengthPercentageDeclaration,
218+
"padding-inline-start": parseLengthPercentageDeclaration,
220219
"padding-left": parseSizeDeclaration,
221220
"padding-right": parseSizeDeclaration,
222221
"padding-top": parseSizeDeclaration,
223222
"position": parsePosition,
224-
"right": parseSizeDeclaration,
223+
"right": parseSizeWithAutoDeclaration,
225224
"rotate": parseRotate,
226225
"row-gap": parseGap,
227226
"scale": parseScale,
@@ -234,7 +233,7 @@ const parsers: {
234233
"text-decoration-style": parseTextDecorationStyle,
235234
"text-shadow": parseTextShadow,
236235
"text-transform": ({ value }) => value.case,
237-
"top": parseSizeDeclaration,
236+
"top": parseSizeWithAutoDeclaration,
238237
"transform": parseTransform,
239238
"transition": addTransitionValue,
240239
"transition-delay": addTransitionValue,
@@ -615,8 +614,11 @@ function parseMarginBlock(
615614
"margin-block-start": parseLengthPercentageOrAuto(
616615
value.blockStart,
617616
builder,
617+
{ allowAuto: true },
618618
),
619-
"margin-block-end": parseLengthPercentageOrAuto(value.blockEnd, builder),
619+
"margin-block-end": parseLengthPercentageOrAuto(value.blockEnd, builder, {
620+
allowAuto: true,
621+
}),
620622
});
621623
}
622624

@@ -628,8 +630,11 @@ function parseMarginInline(
628630
"margin-inline-start": parseLengthPercentageOrAuto(
629631
value.inlineStart,
630632
builder,
633+
{ allowAuto: true },
631634
),
632-
"margin-inline-end": parseLengthPercentageOrAuto(value.inlineEnd, builder),
635+
"margin-inline-end": parseLengthPercentageOrAuto(value.inlineEnd, builder, {
636+
allowAuto: true,
637+
}),
633638
});
634639
}
635640

@@ -1467,6 +1472,13 @@ export function parseSizeDeclaration(
14671472
return parseSize(declaration.value, builder);
14681473
}
14691474

1475+
export function parseSizeWithAutoDeclaration(
1476+
declaration: { value: Size | MaxSize },
1477+
builder: StylesheetBuilder,
1478+
) {
1479+
return parseSize(declaration.value, builder, { allowAuto: true });
1480+
}
1481+
14701482
export function parsePointerEvents(
14711483
{ value }: { value: string },
14721484
builder: StylesheetBuilder,
@@ -1719,13 +1731,20 @@ export function parseColor(cssColor: CssColor, builder: StylesheetBuilder) {
17191731
}
17201732
}
17211733

1722-
export function parseLengthPercentageOrAutoDeclaration(
1734+
export function parseLengthPercentageDeclaration(
17231735
value: { value: LengthPercentageOrAuto },
17241736
builder: StylesheetBuilder,
17251737
) {
17261738
return parseLengthPercentageOrAuto(value.value, builder);
17271739
}
17281740

1741+
export function parseLengthPercentageOrAutoDeclaration(
1742+
value: { value: LengthPercentageOrAuto },
1743+
builder: StylesheetBuilder,
1744+
) {
1745+
return parseLengthPercentageOrAuto(value.value, builder, { allowAuto: true });
1746+
}
1747+
17291748
export function parseLengthPercentageOrAuto(
17301749
lengthPercentageOrAuto: LengthPercentageOrAuto,
17311750
builder: StylesheetBuilder,

0 commit comments

Comments
 (0)