@mgcrea/react-native-tailwind 0.5.0 → 0.5.2
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/README.md +281 -320
- package/dist/babel/index.cjs +109 -80
- package/dist/parser/__snapshots__/aspectRatio.test.js.snap +9 -0
- package/dist/parser/__snapshots__/borders.test.js.snap +23 -0
- package/dist/parser/__snapshots__/colors.test.js.snap +99 -0
- package/dist/parser/__snapshots__/shadows.test.js.snap +76 -0
- package/dist/parser/__snapshots__/sizing.test.js.snap +61 -0
- package/dist/parser/__snapshots__/spacing.test.js.snap +40 -0
- package/dist/parser/__snapshots__/typography.test.js.snap +30 -0
- package/dist/parser/layout.js +1 -1
- package/dist/parser/layout.test.js +1 -1
- package/dist/parser/shadows.d.ts +9 -13
- package/dist/parser/shadows.js +1 -1
- package/dist/parser/shadows.test.js +1 -1
- package/dist/react-native.d.ts +1 -1
- package/dist/types.d.ts +4 -6
- package/package.json +1 -1
- package/src/parser/layout.test.ts +92 -0
- package/src/parser/layout.ts +122 -16
- package/src/parser/shadows.test.ts +20 -29
- package/src/parser/shadows.ts +45 -94
- package/src/react-native.d.ts +1 -1
- package/src/types.ts +1 -3
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { SHADOW_SCALE, parseShadow, rebuildShadowScale } from "./shadows";
|
|
4
|
-
|
|
5
|
-
// Reset to iOS before each test
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
setPlatform("ios");
|
|
8
|
-
rebuildShadowScale();
|
|
9
|
-
});
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { SHADOW_SCALE, parseShadow } from "./shadows";
|
|
10
3
|
|
|
11
4
|
describe("SHADOW_SCALE", () => {
|
|
12
5
|
it("should export complete shadow scale", () => {
|
|
@@ -71,10 +64,6 @@ describe("parseShadow - basic shadows", () => {
|
|
|
71
64
|
});
|
|
72
65
|
|
|
73
66
|
describe("parseShadow - shadow properties (iOS)", () => {
|
|
74
|
-
beforeEach(() => {
|
|
75
|
-
setPlatform("ios");
|
|
76
|
-
});
|
|
77
|
-
|
|
78
67
|
it("should have increasing shadow values for larger shadows", () => {
|
|
79
68
|
const sm = parseShadow("shadow-sm");
|
|
80
69
|
const md = parseShadow("shadow-md");
|
|
@@ -104,24 +93,28 @@ describe("parseShadow - shadow properties (iOS)", () => {
|
|
|
104
93
|
|
|
105
94
|
it("should have proper shadowOffset structure", () => {
|
|
106
95
|
const result = parseShadow("shadow");
|
|
107
|
-
|
|
108
|
-
expect(
|
|
109
|
-
expect(
|
|
110
|
-
|
|
96
|
+
const shadowOffset = result?.shadowOffset;
|
|
97
|
+
expect(shadowOffset).toHaveProperty("width");
|
|
98
|
+
expect(shadowOffset).toHaveProperty("height");
|
|
99
|
+
if (typeof shadowOffset === "object" && shadowOffset !== null) {
|
|
100
|
+
expect(typeof shadowOffset.width).toBe("number");
|
|
101
|
+
expect(typeof shadowOffset.height).toBe("number");
|
|
102
|
+
}
|
|
111
103
|
});
|
|
112
104
|
|
|
113
|
-
it("should
|
|
105
|
+
it("should include both iOS shadow and Android elevation properties", () => {
|
|
114
106
|
const result = parseShadow("shadow");
|
|
115
|
-
|
|
107
|
+
// iOS properties
|
|
108
|
+
expect(result).toHaveProperty("shadowColor");
|
|
109
|
+
expect(result).toHaveProperty("shadowOffset");
|
|
110
|
+
expect(result).toHaveProperty("shadowOpacity");
|
|
111
|
+
expect(result).toHaveProperty("shadowRadius");
|
|
112
|
+
// Android property
|
|
113
|
+
expect(result).toHaveProperty("elevation");
|
|
116
114
|
});
|
|
117
115
|
});
|
|
118
116
|
|
|
119
117
|
describe("parseShadow - shadow properties (Android)", () => {
|
|
120
|
-
beforeEach(() => {
|
|
121
|
-
setPlatform("android");
|
|
122
|
-
rebuildShadowScale();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
118
|
it("should have increasing elevation values for larger shadows", () => {
|
|
126
119
|
const sm = parseShadow("shadow-sm");
|
|
127
120
|
const md = parseShadow("shadow-md");
|
|
@@ -136,12 +129,10 @@ describe("parseShadow - shadow properties (Android)", () => {
|
|
|
136
129
|
expect(xxl?.elevation).toBeGreaterThan(xl?.elevation as number);
|
|
137
130
|
});
|
|
138
131
|
|
|
139
|
-
it("should
|
|
132
|
+
it("should include elevation property for Android", () => {
|
|
140
133
|
const result = parseShadow("shadow");
|
|
141
|
-
expect(result).
|
|
142
|
-
expect(result).
|
|
143
|
-
expect(result).not.toHaveProperty("shadowOpacity");
|
|
144
|
-
expect(result).not.toHaveProperty("shadowRadius");
|
|
134
|
+
expect(result).toHaveProperty("elevation");
|
|
135
|
+
expect(typeof result?.elevation).toBe("number");
|
|
145
136
|
});
|
|
146
137
|
});
|
|
147
138
|
|
package/src/parser/shadows.ts
CHANGED
|
@@ -3,117 +3,68 @@
|
|
|
3
3
|
* iOS uses shadow* properties, Android uses elevation
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { Platform } from "react-native";
|
|
7
6
|
import type { StyleObject } from "../types";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
|
-
* Shadow scale definitions
|
|
9
|
+
* Shadow scale definitions combining iOS and Android properties
|
|
11
10
|
* Based on Tailwind CSS shadow scale, adapted for React Native
|
|
11
|
+
*
|
|
12
|
+
* Note: We include BOTH iOS shadow properties AND Android elevation in each style.
|
|
13
|
+
* React Native will automatically use the appropriate properties for each platform:
|
|
14
|
+
* - iOS uses shadowColor, shadowOffset, shadowOpacity, shadowRadius
|
|
15
|
+
* - Android uses elevation
|
|
12
16
|
*/
|
|
13
|
-
const
|
|
17
|
+
const SHADOW_SCALE: Record<string, StyleObject> = {
|
|
14
18
|
"shadow-sm": {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
android: {
|
|
22
|
-
elevation: 1,
|
|
23
|
-
},
|
|
19
|
+
shadowColor: "#000000",
|
|
20
|
+
shadowOffset: { width: 0, height: 1 },
|
|
21
|
+
shadowOpacity: 0.05,
|
|
22
|
+
shadowRadius: 1,
|
|
23
|
+
elevation: 1,
|
|
24
24
|
},
|
|
25
25
|
shadow: {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
android: {
|
|
33
|
-
elevation: 2,
|
|
34
|
-
},
|
|
26
|
+
shadowColor: "#000000",
|
|
27
|
+
shadowOffset: { width: 0, height: 1 },
|
|
28
|
+
shadowOpacity: 0.1,
|
|
29
|
+
shadowRadius: 2,
|
|
30
|
+
elevation: 2,
|
|
35
31
|
},
|
|
36
32
|
"shadow-md": {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
android: {
|
|
44
|
-
elevation: 4,
|
|
45
|
-
},
|
|
33
|
+
shadowColor: "#000000",
|
|
34
|
+
shadowOffset: { width: 0, height: 3 },
|
|
35
|
+
shadowOpacity: 0.15,
|
|
36
|
+
shadowRadius: 4,
|
|
37
|
+
elevation: 4,
|
|
46
38
|
},
|
|
47
39
|
"shadow-lg": {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
android: {
|
|
55
|
-
elevation: 8,
|
|
56
|
-
},
|
|
40
|
+
shadowColor: "#000000",
|
|
41
|
+
shadowOffset: { width: 0, height: 6 },
|
|
42
|
+
shadowOpacity: 0.2,
|
|
43
|
+
shadowRadius: 8,
|
|
44
|
+
elevation: 8,
|
|
57
45
|
},
|
|
58
46
|
"shadow-xl": {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
android: {
|
|
66
|
-
elevation: 12,
|
|
67
|
-
},
|
|
47
|
+
shadowColor: "#000000",
|
|
48
|
+
shadowOffset: { width: 0, height: 10 },
|
|
49
|
+
shadowOpacity: 0.25,
|
|
50
|
+
shadowRadius: 12,
|
|
51
|
+
elevation: 12,
|
|
68
52
|
},
|
|
69
53
|
"shadow-2xl": {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
},
|
|
76
|
-
android: {
|
|
77
|
-
elevation: 16,
|
|
78
|
-
},
|
|
54
|
+
shadowColor: "#000000",
|
|
55
|
+
shadowOffset: { width: 0, height: 20 },
|
|
56
|
+
shadowOpacity: 0.3,
|
|
57
|
+
shadowRadius: 24,
|
|
58
|
+
elevation: 16,
|
|
79
59
|
},
|
|
80
60
|
"shadow-none": {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
-
android: {
|
|
88
|
-
elevation: 0,
|
|
89
|
-
},
|
|
61
|
+
shadowColor: "transparent",
|
|
62
|
+
shadowOffset: { width: 0, height: 0 },
|
|
63
|
+
shadowOpacity: 0,
|
|
64
|
+
shadowRadius: 0,
|
|
65
|
+
elevation: 0,
|
|
90
66
|
},
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Helper function to build the shadow scale using Platform.select()
|
|
95
|
-
* This allows tests to rebuild the scale after changing the platform mock
|
|
96
|
-
*/
|
|
97
|
-
function buildShadowScale(): Record<string, StyleObject> {
|
|
98
|
-
const scale: Record<string, StyleObject> = {};
|
|
99
|
-
for (const [key, value] of Object.entries(SHADOW_DEFINITIONS)) {
|
|
100
|
-
scale[key] = Platform.select<StyleObject>(value as never);
|
|
101
|
-
}
|
|
102
|
-
return scale;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Computed shadow scale using Platform.select()
|
|
107
|
-
* This is evaluated at module load time for production use
|
|
108
|
-
*/
|
|
109
|
-
let SHADOW_SCALE = buildShadowScale();
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Rebuild the shadow scale (useful for testing with platform mocks)
|
|
113
|
-
*/
|
|
114
|
-
export function rebuildShadowScale() {
|
|
115
|
-
SHADOW_SCALE = buildShadowScale();
|
|
116
|
-
}
|
|
67
|
+
};
|
|
117
68
|
|
|
118
69
|
/**
|
|
119
70
|
* Parse shadow classes
|
|
@@ -129,5 +80,5 @@ export function parseShadow(cls: string): StyleObject | null {
|
|
|
129
80
|
return null;
|
|
130
81
|
}
|
|
131
82
|
|
|
132
|
-
// Export shadow scale
|
|
133
|
-
export {
|
|
83
|
+
// Export shadow scale for testing/advanced usage
|
|
84
|
+
export { SHADOW_SCALE };
|
package/src/react-native.d.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -6,9 +6,7 @@ import type { ImageStyle, TextStyle, ViewStyle } from "react-native";
|
|
|
6
6
|
|
|
7
7
|
export type RNStyle = ViewStyle | TextStyle | ImageStyle;
|
|
8
8
|
|
|
9
|
-
export type StyleObject = Record<
|
|
10
|
-
shadowOffset?: { width: number; height: number };
|
|
11
|
-
};
|
|
9
|
+
export type StyleObject = Record<string, string | number | { width: number; height: number } | undefined>;
|
|
12
10
|
|
|
13
11
|
export type SpacingValue = number;
|
|
14
12
|
export type ColorValue = string;
|