@idealyst/theme 1.2.104 → 1.2.105
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/package.json +2 -2
- package/src/babel/plugin.js +24 -8
- package/src/styleBuilder.ts +24 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idealyst/theme",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.105",
|
|
4
4
|
"description": "Theming system for Idealyst Framework",
|
|
5
5
|
"readme": "README.md",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"publish:npm": "npm publish"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@idealyst/tooling": "^1.2.
|
|
66
|
+
"@idealyst/tooling": "^1.2.105"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"react-native-unistyles": ">=3.0.0"
|
package/src/babel/plugin.js
CHANGED
|
@@ -945,16 +945,24 @@ module.exports = function idealystStylesPlugin({ types: t }) {
|
|
|
945
945
|
if (t.isIdentifier(node.callee, { name: 'extendStyle' })) {
|
|
946
946
|
debug(`FOUND extendStyle in: ${filename}`);
|
|
947
947
|
|
|
948
|
-
const [componentNameArg,
|
|
948
|
+
const [componentNameArg, stylesArg] = node.arguments;
|
|
949
949
|
|
|
950
950
|
if (!t.isStringLiteral(componentNameArg)) {
|
|
951
951
|
debug(` SKIP - componentName is not a string literal`);
|
|
952
952
|
return;
|
|
953
953
|
}
|
|
954
954
|
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
955
|
+
// Accept either a function callback or a plain object
|
|
956
|
+
let stylesCallback = stylesArg;
|
|
957
|
+
if (t.isObjectExpression(stylesArg)) {
|
|
958
|
+
// Wrap plain object in an arrow function: (theme) => ({ ... })
|
|
959
|
+
stylesCallback = t.arrowFunctionExpression(
|
|
960
|
+
[t.identifier('theme')],
|
|
961
|
+
t.parenthesizedExpression(stylesArg)
|
|
962
|
+
);
|
|
963
|
+
} else if (!t.isArrowFunctionExpression(stylesArg) &&
|
|
964
|
+
!t.isFunctionExpression(stylesArg)) {
|
|
965
|
+
debug(` SKIP - second argument is not a function or object`);
|
|
958
966
|
return;
|
|
959
967
|
}
|
|
960
968
|
|
|
@@ -991,16 +999,24 @@ module.exports = function idealystStylesPlugin({ types: t }) {
|
|
|
991
999
|
if (t.isIdentifier(node.callee, { name: 'overrideStyle' })) {
|
|
992
1000
|
debug(`FOUND overrideStyle in: ${filename}`);
|
|
993
1001
|
|
|
994
|
-
const [componentNameArg,
|
|
1002
|
+
const [componentNameArg, stylesArg] = node.arguments;
|
|
995
1003
|
|
|
996
1004
|
if (!t.isStringLiteral(componentNameArg)) {
|
|
997
1005
|
debug(` SKIP - componentName is not a string literal`);
|
|
998
1006
|
return;
|
|
999
1007
|
}
|
|
1000
1008
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1009
|
+
// Accept either a function callback or a plain object
|
|
1010
|
+
let stylesCallback = stylesArg;
|
|
1011
|
+
if (t.isObjectExpression(stylesArg)) {
|
|
1012
|
+
// Wrap plain object in an arrow function: (theme) => ({ ... })
|
|
1013
|
+
stylesCallback = t.arrowFunctionExpression(
|
|
1014
|
+
[t.identifier('theme')],
|
|
1015
|
+
t.parenthesizedExpression(stylesArg)
|
|
1016
|
+
);
|
|
1017
|
+
} else if (!t.isArrowFunctionExpression(stylesArg) &&
|
|
1018
|
+
!t.isFunctionExpression(stylesArg)) {
|
|
1019
|
+
debug(` SKIP - second argument is not a function or object`);
|
|
1004
1020
|
return;
|
|
1005
1021
|
}
|
|
1006
1022
|
|
package/src/styleBuilder.ts
CHANGED
|
@@ -102,18 +102,27 @@ export function defineStyle<TTheme, TStyles extends Record<string, unknown>>(
|
|
|
102
102
|
/**
|
|
103
103
|
* Extend existing component styles (merged at build time).
|
|
104
104
|
* Import BEFORE components for extensions to apply.
|
|
105
|
+
*
|
|
106
|
+
* Accepts either a plain style object or a theme callback:
|
|
107
|
+
* ```typescript
|
|
108
|
+
* // Plain object (no theme access needed)
|
|
109
|
+
* extendStyle('Text', { text: { fontFamily: 'MyFont' } });
|
|
110
|
+
*
|
|
111
|
+
* // Theme callback (when you need theme tokens)
|
|
112
|
+
* extendStyle('Text', (theme) => ({ text: { color: theme.colors.text.primary } }));
|
|
113
|
+
* ```
|
|
105
114
|
*/
|
|
106
115
|
export function extendStyle<K extends keyof ComponentStyleRegistry>(
|
|
107
116
|
componentName: K,
|
|
108
|
-
styles: (theme: any) => ExtendStyleDef<K>
|
|
117
|
+
styles: ExtendStyleDef<K> | ((theme: any) => ExtendStyleDef<K>)
|
|
109
118
|
): void;
|
|
110
119
|
export function extendStyle<K extends string>(
|
|
111
120
|
componentName: K,
|
|
112
|
-
styles: (theme: any) => Record<string, any>
|
|
121
|
+
styles: Record<string, any> | ((theme: any) => Record<string, any>)
|
|
113
122
|
): void;
|
|
114
123
|
export function extendStyle(
|
|
115
124
|
_componentName: string,
|
|
116
|
-
_styles:
|
|
125
|
+
_styles: any
|
|
117
126
|
): void {
|
|
118
127
|
// Babel removes this call and merges into defineStyle
|
|
119
128
|
}
|
|
@@ -121,18 +130,27 @@ export function extendStyle(
|
|
|
121
130
|
/**
|
|
122
131
|
* Override component styles completely (replaces base at build time).
|
|
123
132
|
* Import BEFORE components for overrides to apply.
|
|
133
|
+
*
|
|
134
|
+
* Accepts either a plain style object or a theme callback:
|
|
135
|
+
* ```typescript
|
|
136
|
+
* // Plain object
|
|
137
|
+
* overrideStyle('Text', { text: { fontFamily: 'MyFont' } });
|
|
138
|
+
*
|
|
139
|
+
* // Theme callback
|
|
140
|
+
* overrideStyle('Text', (theme) => ({ text: { color: theme.colors.text.primary } }));
|
|
141
|
+
* ```
|
|
124
142
|
*/
|
|
125
143
|
export function overrideStyle<K extends keyof ComponentStyleRegistry>(
|
|
126
144
|
componentName: K,
|
|
127
|
-
styles: (theme: any) => OverrideStyleDef<K>
|
|
145
|
+
styles: OverrideStyleDef<K> | ((theme: any) => OverrideStyleDef<K>)
|
|
128
146
|
): void;
|
|
129
147
|
export function overrideStyle<K extends string>(
|
|
130
148
|
componentName: K,
|
|
131
|
-
styles: (theme: any) => Record<string, any>
|
|
149
|
+
styles: Record<string, any> | ((theme: any) => Record<string, any>)
|
|
132
150
|
): void;
|
|
133
151
|
export function overrideStyle(
|
|
134
152
|
_componentName: string,
|
|
135
|
-
_styles:
|
|
153
|
+
_styles: any
|
|
136
154
|
): void {
|
|
137
155
|
// Babel removes this call and replaces defineStyle
|
|
138
156
|
}
|