@mgcrea/react-native-tailwind 0.10.0 → 0.11.0
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 +30 -13
- package/dist/babel/config-loader.d.ts +12 -3
- package/dist/babel/config-loader.test.ts +14 -12
- package/dist/babel/config-loader.ts +41 -9
- package/dist/babel/index.cjs +50 -27
- package/dist/babel/plugin.d.ts +2 -1
- package/dist/babel/plugin.ts +11 -10
- package/dist/babel/utils/colorSchemeModifierProcessing.d.ts +3 -3
- package/dist/babel/utils/colorSchemeModifierProcessing.ts +4 -4
- package/dist/babel/utils/dynamicProcessing.d.ts +5 -5
- package/dist/babel/utils/dynamicProcessing.ts +11 -11
- package/dist/babel/utils/modifierProcessing.d.ts +3 -3
- package/dist/babel/utils/modifierProcessing.ts +5 -5
- package/dist/babel/utils/platformModifierProcessing.d.ts +3 -3
- package/dist/babel/utils/platformModifierProcessing.ts +4 -4
- package/dist/babel/utils/twProcessing.d.ts +3 -3
- package/dist/babel/utils/twProcessing.ts +6 -6
- package/dist/parser/index.d.ts +11 -4
- package/dist/parser/index.js +1 -1
- package/dist/parser/typography.d.ts +3 -1
- package/dist/parser/typography.js +1 -1
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.cjs.map +3 -3
- package/dist/runtime.d.ts +8 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +3 -3
- package/dist/runtime.test.js +1 -1
- package/package.json +1 -1
- package/src/babel/config-loader.test.ts +14 -12
- package/src/babel/config-loader.ts +41 -9
- package/src/babel/plugin.ts +11 -10
- package/src/babel/utils/colorSchemeModifierProcessing.ts +4 -4
- package/src/babel/utils/dynamicProcessing.ts +11 -11
- package/src/babel/utils/modifierProcessing.ts +5 -5
- package/src/babel/utils/platformModifierProcessing.ts +4 -4
- package/src/babel/utils/twProcessing.ts +6 -6
- package/src/parser/index.ts +16 -8
- package/src/parser/typography.ts +14 -2
- package/src/runtime.test.ts +7 -7
- package/src/runtime.ts +37 -14
package/src/runtime.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
-
import { clearCache, getCacheStats,
|
|
2
|
+
import { clearCache, getCacheStats, getCustomTheme, setConfig, tw, twStyle } from "./runtime";
|
|
3
3
|
|
|
4
4
|
describe("runtime", () => {
|
|
5
5
|
beforeEach(() => {
|
|
@@ -126,8 +126,8 @@ describe("runtime", () => {
|
|
|
126
126
|
},
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
const
|
|
130
|
-
expect(colors).toEqual({
|
|
129
|
+
const theme = getCustomTheme();
|
|
130
|
+
expect(theme.colors).toEqual({
|
|
131
131
|
primary: "#007AFF",
|
|
132
132
|
secondary: "#5856D6",
|
|
133
133
|
});
|
|
@@ -147,8 +147,8 @@ describe("runtime", () => {
|
|
|
147
147
|
},
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
-
const
|
|
151
|
-
expect(colors).toEqual({
|
|
150
|
+
const theme = getCustomTheme();
|
|
151
|
+
expect(theme.colors).toEqual({
|
|
152
152
|
"brand-light": "#FF6B6B",
|
|
153
153
|
"brand-dark": "#CC0000",
|
|
154
154
|
});
|
|
@@ -169,8 +169,8 @@ describe("runtime", () => {
|
|
|
169
169
|
},
|
|
170
170
|
});
|
|
171
171
|
|
|
172
|
-
const
|
|
173
|
-
expect(colors).toEqual({
|
|
172
|
+
const theme = getCustomTheme();
|
|
173
|
+
expect(theme.colors).toEqual({
|
|
174
174
|
primary: "#007AFF",
|
|
175
175
|
"brand-light": "#FF6B6B",
|
|
176
176
|
"brand-dark": "#CC0000",
|
package/src/runtime.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CustomTheme } from "./parser/index.js";
|
|
1
2
|
import { parseClassName } from "./parser/index.js";
|
|
2
3
|
import type { NativeStyle, TwStyle } from "./types/runtime.js";
|
|
3
4
|
import { flattenColors } from "./utils/flattenColors.js";
|
|
@@ -10,15 +11,13 @@ export type RuntimeConfig = {
|
|
|
10
11
|
theme?: {
|
|
11
12
|
extend?: {
|
|
12
13
|
colors?: Record<string, string | Record<string, string>>;
|
|
13
|
-
|
|
14
|
-
// spacing?: Record<string, number | string>;
|
|
15
|
-
// fontFamily?: Record<string, string[]>;
|
|
14
|
+
fontFamily?: Record<string, string | string[]>;
|
|
16
15
|
};
|
|
17
16
|
};
|
|
18
17
|
};
|
|
19
18
|
|
|
20
|
-
// Global custom
|
|
21
|
-
|
|
19
|
+
// Global custom theme configuration
|
|
20
|
+
const globalCustomTheme: CustomTheme = { colors: {}, fontFamily: {} };
|
|
22
21
|
|
|
23
22
|
// Simple memoization cache
|
|
24
23
|
const styleCache = new Map<string, TwStyle>();
|
|
@@ -52,9 +51,25 @@ const styleCache = new Map<string, TwStyle>();
|
|
|
52
51
|
export function setConfig(config: RuntimeConfig): void {
|
|
53
52
|
// Extract and flatten custom colors
|
|
54
53
|
if (config.theme?.extend?.colors) {
|
|
55
|
-
|
|
54
|
+
globalCustomTheme.colors = flattenColors(config.theme?.extend.colors);
|
|
56
55
|
} else {
|
|
57
|
-
|
|
56
|
+
globalCustomTheme.colors = {};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Extract custom fontFamily
|
|
60
|
+
if (config.theme?.extend?.fontFamily) {
|
|
61
|
+
const fontFamilyResult: Record<string, string> = {};
|
|
62
|
+
for (const [key, value] of Object.entries(config.theme.extend.fontFamily)) {
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
// Take first font in the array (React Native doesn't support font stacks)
|
|
65
|
+
fontFamilyResult[key] = value[0];
|
|
66
|
+
} else {
|
|
67
|
+
fontFamilyResult[key] = value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
globalCustomTheme.fontFamily = fontFamilyResult;
|
|
71
|
+
} else {
|
|
72
|
+
globalCustomTheme.fontFamily = {};
|
|
58
73
|
}
|
|
59
74
|
|
|
60
75
|
// Clear cache when config changes
|
|
@@ -62,10 +77,18 @@ export function setConfig(config: RuntimeConfig): void {
|
|
|
62
77
|
}
|
|
63
78
|
|
|
64
79
|
/**
|
|
65
|
-
* Get currently configured custom
|
|
80
|
+
* Get currently configured custom theme
|
|
81
|
+
*/
|
|
82
|
+
export function getCustomTheme(): CustomTheme {
|
|
83
|
+
return globalCustomTheme;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get currently configured custom colors (for backwards compatibility)
|
|
88
|
+
* @deprecated Use getCustomTheme() instead
|
|
66
89
|
*/
|
|
67
90
|
export function getCustomColors(): Record<string, string> | undefined {
|
|
68
|
-
return
|
|
91
|
+
return Object.keys(globalCustomTheme.colors ?? {}).length > 0 ? globalCustomTheme.colors : undefined;
|
|
69
92
|
}
|
|
70
93
|
|
|
71
94
|
/**
|
|
@@ -100,7 +123,7 @@ function parseAndCache(className: string): TwStyle {
|
|
|
100
123
|
// Check if className contains modifiers
|
|
101
124
|
if (!hasModifiers(className)) {
|
|
102
125
|
// No modifiers - simple case
|
|
103
|
-
const styleObject = parseClassName(className,
|
|
126
|
+
const styleObject = parseClassName(className, globalCustomTheme);
|
|
104
127
|
|
|
105
128
|
const result: TwStyle = {
|
|
106
129
|
// @ts-expect-error - StyleObject transform types are broader than React Native's strict types
|
|
@@ -118,7 +141,7 @@ function parseAndCache(className: string): TwStyle {
|
|
|
118
141
|
|
|
119
142
|
// Parse base styles
|
|
120
143
|
const baseClassName = base.join(" ");
|
|
121
|
-
const baseStyle = baseClassName ? parseClassName(baseClassName,
|
|
144
|
+
const baseStyle = baseClassName ? parseClassName(baseClassName, globalCustomTheme) : {};
|
|
122
145
|
|
|
123
146
|
// Build result object
|
|
124
147
|
const result: TwStyle = {
|
|
@@ -132,7 +155,7 @@ function parseAndCache(className: string): TwStyle {
|
|
|
132
155
|
if (activeClasses && activeClasses.length > 0) {
|
|
133
156
|
const activeClassName = activeClasses.join(" ");
|
|
134
157
|
// @ts-expect-error - StyleObject transform types are broader than React Native's strict types
|
|
135
|
-
result.activeStyle = parseClassName(activeClassName,
|
|
158
|
+
result.activeStyle = parseClassName(activeClassName, globalCustomTheme);
|
|
136
159
|
}
|
|
137
160
|
}
|
|
138
161
|
|
|
@@ -141,7 +164,7 @@ function parseAndCache(className: string): TwStyle {
|
|
|
141
164
|
if (focusClasses && focusClasses.length > 0) {
|
|
142
165
|
const focusClassName = focusClasses.join(" ");
|
|
143
166
|
// @ts-expect-error - StyleObject transform types are broader than React Native's strict types
|
|
144
|
-
result.focusStyle = parseClassName(focusClassName,
|
|
167
|
+
result.focusStyle = parseClassName(focusClassName, globalCustomTheme);
|
|
145
168
|
}
|
|
146
169
|
}
|
|
147
170
|
|
|
@@ -150,7 +173,7 @@ function parseAndCache(className: string): TwStyle {
|
|
|
150
173
|
if (disabledClasses && disabledClasses.length > 0) {
|
|
151
174
|
const disabledClassName = disabledClasses.join(" ");
|
|
152
175
|
// @ts-expect-error - StyleObject transform types are broader than React Native's strict types
|
|
153
|
-
result.disabledStyle = parseClassName(disabledClassName,
|
|
176
|
+
result.disabledStyle = parseClassName(disabledClassName, globalCustomTheme);
|
|
154
177
|
}
|
|
155
178
|
}
|
|
156
179
|
|