@mgcrea/react-native-tailwind 0.15.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/babel/index.cjs +5 -0
- package/dist/parser/spacing.d.ts +1 -1
- package/dist/parser/spacing.js +1 -1
- package/dist/parser/spacing.test.js +1 -1
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.cjs.map +3 -3
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +3 -3
- package/package.json +1 -1
- package/src/parser/spacing.test.ts +37 -0
- package/src/parser/spacing.ts +10 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mgcrea/react-native-tailwind",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"description": "Compile-time Tailwind CSS for React Native with zero runtime overhead",
|
|
5
5
|
"author": "Olivier Louvignes <olivier@mgcrea.io> (https://github.com/mgcrea)",
|
|
6
6
|
"homepage": "https://github.com/mgcrea/react-native-tailwind#readme",
|
|
@@ -416,6 +416,43 @@ describe("parseSpacing - logical padding (RTL-aware)", () => {
|
|
|
416
416
|
});
|
|
417
417
|
});
|
|
418
418
|
|
|
419
|
+
describe("parseSpacing - auto margin", () => {
|
|
420
|
+
it("should parse m-auto", () => {
|
|
421
|
+
expect(parseSpacing("m-auto")).toEqual({ margin: "auto" });
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it("should parse mx-auto", () => {
|
|
425
|
+
expect(parseSpacing("mx-auto")).toEqual({ marginHorizontal: "auto" });
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it("should parse my-auto", () => {
|
|
429
|
+
expect(parseSpacing("my-auto")).toEqual({ marginVertical: "auto" });
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it("should parse directional auto margins", () => {
|
|
433
|
+
expect(parseSpacing("mt-auto")).toEqual({ marginTop: "auto" });
|
|
434
|
+
expect(parseSpacing("mr-auto")).toEqual({ marginRight: "auto" });
|
|
435
|
+
expect(parseSpacing("mb-auto")).toEqual({ marginBottom: "auto" });
|
|
436
|
+
expect(parseSpacing("ml-auto")).toEqual({ marginLeft: "auto" });
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it("should parse logical auto margins (RTL-aware)", () => {
|
|
440
|
+
expect(parseSpacing("ms-auto")).toEqual({ marginStart: "auto" });
|
|
441
|
+
expect(parseSpacing("me-auto")).toEqual({ marginEnd: "auto" });
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
it("should not parse padding auto (not valid in Tailwind)", () => {
|
|
445
|
+
expect(parseSpacing("p-auto")).toBeNull();
|
|
446
|
+
expect(parseSpacing("px-auto")).toBeNull();
|
|
447
|
+
expect(parseSpacing("py-auto")).toBeNull();
|
|
448
|
+
expect(parseSpacing("pt-auto")).toBeNull();
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("should not parse gap auto (not valid in Tailwind)", () => {
|
|
452
|
+
expect(parseSpacing("gap-auto")).toBeNull();
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
|
|
419
456
|
describe("parseSpacing - custom spacing", () => {
|
|
420
457
|
const customSpacing = {
|
|
421
458
|
xs: 4,
|
package/src/parser/spacing.ts
CHANGED
|
@@ -69,7 +69,7 @@ function parseArbitrarySpacing(value: string): number | null {
|
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Parse spacing classes (margin, padding, gap)
|
|
72
|
-
* Examples: m-4, mx-2, mt-8, p-4, px-2, pt-8, gap-4, m-[16px], pl-[4.5px], -m-4, -mt-[10px], ms-4, pe-2
|
|
72
|
+
* Examples: m-4, mx-2, mt-8, p-4, px-2, pt-8, gap-4, m-[16px], pl-[4.5px], -m-4, -mt-[10px], ms-4, pe-2, mx-auto
|
|
73
73
|
* @param cls - The class name to parse
|
|
74
74
|
* @param customSpacing - Optional custom spacing values from tailwind.config
|
|
75
75
|
*/
|
|
@@ -77,6 +77,14 @@ export function parseSpacing(cls: string, customSpacing?: Record<string, number>
|
|
|
77
77
|
// Merge custom spacing with defaults (custom takes precedence)
|
|
78
78
|
const spacingMap = customSpacing ? { ...SPACING_SCALE, ...customSpacing } : SPACING_SCALE;
|
|
79
79
|
|
|
80
|
+
// Auto margins: m-auto, mx-auto, my-auto, mt-auto, mr-auto, mb-auto, ml-auto, ms-auto, me-auto
|
|
81
|
+
// Note: Only margins support auto values (not padding or gap)
|
|
82
|
+
const autoMarginMatch = cls.match(/^m([xytrblse]?)-auto$/);
|
|
83
|
+
if (autoMarginMatch) {
|
|
84
|
+
const dir = autoMarginMatch[1];
|
|
85
|
+
return getMarginStyle(dir, "auto");
|
|
86
|
+
}
|
|
87
|
+
|
|
80
88
|
// Margin: m-4, mx-2, mt-8, ms-4, me-2, m-[16px], -m-4, -mt-2, etc.
|
|
81
89
|
// Supports negative values for margins (but not padding or gap)
|
|
82
90
|
// s = start (RTL-aware), e = end (RTL-aware)
|
|
@@ -143,7 +151,7 @@ export function parseSpacing(cls: string, customSpacing?: Record<string, number>
|
|
|
143
151
|
/**
|
|
144
152
|
* Get margin style object based on direction
|
|
145
153
|
*/
|
|
146
|
-
function getMarginStyle(dir: string, value: number): StyleObject {
|
|
154
|
+
function getMarginStyle(dir: string, value: number | "auto"): StyleObject {
|
|
147
155
|
switch (dir) {
|
|
148
156
|
case "":
|
|
149
157
|
return { margin: value };
|