Skip to content

Commit cf5651d

Browse files
authored
fix: 'auto' values for margin and position values (#132)
1 parent ce565af commit cf5651d

3 files changed

Lines changed: 69 additions & 29 deletions

File tree

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -828,26 +828,22 @@ describe("Layout - Top Right Bottom Left", () => {
828828
});
829829
test("top-auto", async () => {
830830
expect(await renderCurrentTest()).toStrictEqual({
831-
props: {},
832-
warnings: { values: { top: "auto" } },
831+
props: { style: { top: "auto" } },
833832
});
834833
});
835834
test("right-auto", async () => {
836835
expect(await renderCurrentTest()).toStrictEqual({
837-
props: {},
838-
warnings: { values: { right: "auto" } },
836+
props: { style: { right: "auto" } },
839837
});
840838
});
841839
test("bottom-auto", async () => {
842840
expect(await renderCurrentTest()).toStrictEqual({
843-
props: {},
844-
warnings: { values: { bottom: "auto" } },
841+
props: { style: { bottom: "auto" } },
845842
});
846843
});
847844
test("left-auto", async () => {
848845
expect(await renderCurrentTest()).toStrictEqual({
849-
props: {},
850-
warnings: { values: { left: "auto" } },
846+
props: { style: { left: "auto" } },
851847
});
852848
});
853849
});

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
"box-sizing": parseBoxSizing,
152152
"caret-color": parseColorOrAutoDeclaration,
@@ -159,7 +159,7 @@ const parsers: {
159159
"fill": parseSVGPaint,
160160
"filter": parseFilter,
161161
"flex": parseFlex,
162-
"flex-basis": parseLengthPercentageOrAutoDeclaration,
162+
"flex-basis": parseLengthPercentageDeclaration,
163163
"flex-direction": ({ value }) => value,
164164
"flex-flow": parseFlexFlow,
165165
"flex-grow": ({ value }) => value,
@@ -176,26 +176,26 @@ const parsers: {
176176
"inline-size": parseSizeDeclaration,
177177
"inset": parseInset,
178178
"inset-block": parseInsetBlock,
179-
"inset-block-end": parseLengthPercentageOrAutoDeclaration,
180-
"inset-block-start": parseLengthPercentageOrAutoDeclaration,
179+
"inset-block-end": parseLengthPercentageDeclaration,
180+
"inset-block-start": parseLengthPercentageDeclaration,
181181
"inset-inline": parseInsetInline,
182-
"inset-inline-end": parseLengthPercentageOrAutoDeclaration,
183-
"inset-inline-start": parseLengthPercentageOrAutoDeclaration,
182+
"inset-inline-end": parseLengthPercentageDeclaration,
183+
"inset-inline-start": parseLengthPercentageDeclaration,
184184
"justify-content": parseJustifyContent,
185-
"left": parseSizeDeclaration,
185+
"left": parseSizeWithAutoDeclaration,
186186
"letter-spacing": parseLetterSpacing,
187187
"line-height": parseLineHeightDeclaration,
188188
"margin": parseMargin,
189189
"margin-block": parseMarginBlock,
190190
"margin-block-end": parseLengthPercentageOrAutoDeclaration,
191191
"margin-block-start": parseLengthPercentageOrAutoDeclaration,
192-
"margin-bottom": parseSizeDeclaration,
192+
"margin-bottom": parseSizeWithAutoDeclaration,
193193
"margin-inline": parseMarginInline,
194194
"margin-inline-end": parseLengthPercentageOrAutoDeclaration,
195195
"margin-inline-start": parseLengthPercentageOrAutoDeclaration,
196-
"margin-left": parseSizeDeclaration,
197-
"margin-right": parseSizeDeclaration,
198-
"margin-top": parseSizeDeclaration,
196+
"margin-left": parseSizeWithAutoDeclaration,
197+
"margin-right": parseSizeWithAutoDeclaration,
198+
"margin-top": parseSizeWithAutoDeclaration,
199199
"max-block-size": parseSizeDeclaration,
200200
"max-height": parseSizeDeclaration,
201201
"max-inline-size": parseSizeDeclaration,
@@ -206,23 +206,22 @@ const parsers: {
206206
"min-width": parseSizeDeclaration,
207207
"opacity": ({ value }) => value,
208208
"outline-color": parseColorDeclaration,
209-
// "outline-offset": parseColorDeclaration,
210209
"outline-style": parseOutlineStyle,
211210
"outline-width": parseBorderSideWidthDeclaration,
212211
"overflow": parseOverflow,
213212
"padding": parsePadding,
214213
"padding-block": parsePaddingBlock,
215-
"padding-block-end": parseLengthPercentageOrAutoDeclaration,
216-
"padding-block-start": parseLengthPercentageOrAutoDeclaration,
214+
"padding-block-end": parseLengthPercentageDeclaration,
215+
"padding-block-start": parseLengthPercentageDeclaration,
217216
"padding-bottom": parseSizeDeclaration,
218217
"padding-inline": parsePaddingInline,
219-
"padding-inline-end": parseLengthPercentageOrAutoDeclaration,
220-
"padding-inline-start": parseLengthPercentageOrAutoDeclaration,
218+
"padding-inline-end": parseLengthPercentageDeclaration,
219+
"padding-inline-start": parseLengthPercentageDeclaration,
221220
"padding-left": parseSizeDeclaration,
222221
"padding-right": parseSizeDeclaration,
223222
"padding-top": parseSizeDeclaration,
224223
"position": parsePosition,
225-
"right": parseSizeDeclaration,
224+
"right": parseSizeWithAutoDeclaration,
226225
"rotate": parseRotate,
227226
"row-gap": parseGap,
228227
"scale": parseScale,
@@ -235,7 +234,7 @@ const parsers: {
235234
"text-decoration-style": parseTextDecorationStyle,
236235
"text-shadow": parseTextShadow,
237236
"text-transform": ({ value }) => value.case,
238-
"top": parseSizeDeclaration,
237+
"top": parseSizeWithAutoDeclaration,
239238
"transform": parseTransform,
240239
"transition": addTransitionValue,
241240
"transition-delay": addTransitionValue,
@@ -616,8 +615,11 @@ function parseMarginBlock(
616615
"margin-block-start": parseLengthPercentageOrAuto(
617616
value.blockStart,
618617
builder,
618+
{ allowAuto: true },
619619
),
620-
"margin-block-end": parseLengthPercentageOrAuto(value.blockEnd, builder),
620+
"margin-block-end": parseLengthPercentageOrAuto(value.blockEnd, builder, {
621+
allowAuto: true,
622+
}),
621623
});
622624
}
623625

@@ -629,8 +631,11 @@ function parseMarginInline(
629631
"margin-inline-start": parseLengthPercentageOrAuto(
630632
value.inlineStart,
631633
builder,
634+
{ allowAuto: true },
632635
),
633-
"margin-inline-end": parseLengthPercentageOrAuto(value.inlineEnd, builder),
636+
"margin-inline-end": parseLengthPercentageOrAuto(value.inlineEnd, builder, {
637+
allowAuto: true,
638+
}),
634639
});
635640
}
636641

@@ -1468,6 +1473,13 @@ export function parseSizeDeclaration(
14681473
return parseSize(declaration.value, builder);
14691474
}
14701475

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

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

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

0 commit comments

Comments
 (0)