@niibase/uniwind 1.6.0 โ 1.6.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/CHANGELOG.md +21 -0
- package/dist/common/components/web/generateDataSet.js +2 -1
- package/dist/common/core/web/getWebStyles.js +12 -1
- package/dist/common/hoc/withUniwind.js +7 -4
- package/dist/common/hoc/withUniwind.native.js +4 -4
- package/dist/common/hooks/useResolveClassNames.js +1 -1
- package/dist/metro/metro-transformer.cjs +2 -1
- package/dist/metro/metro-transformer.mjs +2 -1
- package/dist/module/components/web/generateDataSet.d.ts +1 -1
- package/dist/module/components/web/generateDataSet.js +2 -1
- package/dist/module/core/web/getWebStyles.d.ts +1 -1
- package/dist/module/core/web/getWebStyles.js +12 -1
- package/dist/module/hoc/withUniwind.js +7 -4
- package/dist/module/hoc/withUniwind.native.js +4 -4
- package/dist/module/hooks/useResolveClassNames.js +2 -2
- package/dist/module/hooks/useUniwind.d.ts +2 -1
- package/package.json +2 -1
- package/src/components/web/generateDataSet.ts +4 -2
- package/src/core/web/getWebStyles.ts +20 -1
- package/src/hoc/withUniwind.native.tsx +4 -4
- package/src/hoc/withUniwind.tsx +5 -2
- package/src/hooks/useResolveClassNames.ts +2 -2
- package/src/hooks/useUniwind.ts +2 -2
- package/src/metro/processor/color.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## What's Changed in 1.6.1
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### ๐ Bug Fixes
|
|
6
|
+
|
|
7
|
+
* pass data attributes to withUniwind (#477) by @Brentlok
|
|
8
|
+
* p3 color parsing (#476) by @Brentlok
|
|
9
|
+
|
|
10
|
+
### ๐งช Testing
|
|
11
|
+
|
|
12
|
+
* advanced type check for ThemeName (#465) by @Brentlok
|
|
13
|
+
|
|
14
|
+
### ๐ฆ Other
|
|
15
|
+
|
|
16
|
+
* Merge branch 'prepare-release' by @divineniiquaye
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
**Full Changelog**: https://github.com/divineniiquaye/uniwind/compare/v1.6.0...v1.6.1
|
|
20
|
+
|
|
21
|
+
|
|
1
22
|
## What's Changed in 1.6.0
|
|
2
23
|
|
|
3
24
|
|
|
@@ -4,13 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.generateDataSet = void 0;
|
|
7
|
+
const toCamelCase = str => str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
7
8
|
const generateDataSet = props => {
|
|
8
9
|
const dataSet = props.dataSet !== void 0 ? {
|
|
9
10
|
...props.dataSet
|
|
10
11
|
} : {};
|
|
11
12
|
Object.entries(props).forEach(([key, value]) => {
|
|
12
13
|
if (key.startsWith("data-")) {
|
|
13
|
-
dataSet[key.slice(5)] = value;
|
|
14
|
+
dataSet[toCamelCase(key.slice(5))] = value;
|
|
14
15
|
}
|
|
15
16
|
});
|
|
16
17
|
return dataSet;
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getWebVariable = exports.getWebStyles = void 0;
|
|
7
|
+
var _generateDataSet = require("../../components/web/generateDataSet");
|
|
7
8
|
var _cssListener = require("./cssListener");
|
|
8
9
|
var _parseCSSValue = require("./parseCSSValue");
|
|
9
10
|
const dummyParent = typeof document !== "undefined" ? Object.assign(document.createElement("div"), {
|
|
@@ -38,7 +39,7 @@ const getActiveStylesForClass = className => {
|
|
|
38
39
|
});
|
|
39
40
|
return extractedStyles;
|
|
40
41
|
};
|
|
41
|
-
const getWebStyles = (className, uniwindContext) => {
|
|
42
|
+
const getWebStyles = (className, componentProps, uniwindContext) => {
|
|
42
43
|
if (className === void 0) {
|
|
43
44
|
return {};
|
|
44
45
|
}
|
|
@@ -51,7 +52,17 @@ const getWebStyles = (className, uniwindContext) => {
|
|
|
51
52
|
dummyParent?.removeAttribute("class");
|
|
52
53
|
}
|
|
53
54
|
dummy.className = className;
|
|
55
|
+
const dataSet = (0, _generateDataSet.generateDataSet)(componentProps ?? {});
|
|
56
|
+
Object.entries(dataSet).forEach(([key, value]) => {
|
|
57
|
+
if (value === false || value === void 0) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
dummy.dataset[key] = String(value);
|
|
61
|
+
});
|
|
54
62
|
const computedStyles = getActiveStylesForClass(className);
|
|
63
|
+
Object.keys(dataSet).forEach(key => {
|
|
64
|
+
delete dummy.dataset[key];
|
|
65
|
+
});
|
|
55
66
|
return Object.fromEntries(Object.entries(computedStyles).map(([key, value]) => {
|
|
56
67
|
const parsedKey = key[0] === "-" ? key : key.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
57
68
|
return [parsedKey, (0, _parseCSSValue.parseCSSValue)(value)];
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.withUniwind = void 0;
|
|
7
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
8
|
var _react = require("react");
|
|
9
|
+
var _generateDataSet = require("../components/web/generateDataSet");
|
|
9
10
|
var _context = require("../core/context");
|
|
10
11
|
var _web = require("../core/web");
|
|
11
12
|
var _withUniwindUtils = require("./withUniwindUtils");
|
|
@@ -23,7 +24,7 @@ const withAutoUniwind = Component2 => props => {
|
|
|
23
24
|
return acc;
|
|
24
25
|
}
|
|
25
26
|
const className = propValue;
|
|
26
|
-
const color = (0, _web.getWebStyles)(className, uniwindContext).accentColor;
|
|
27
|
+
const color = (0, _web.getWebStyles)(className, props, uniwindContext).accentColor;
|
|
27
28
|
acc.generatedProps[colorProp] = color !== void 0 ? (0, _web.formatColor)(color) : void 0;
|
|
28
29
|
acc.classNames += `${className} `;
|
|
29
30
|
return acc;
|
|
@@ -54,7 +55,8 @@ const withAutoUniwind = Component2 => props => {
|
|
|
54
55
|
}, [classNames]);
|
|
55
56
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(Component2, {
|
|
56
57
|
...props,
|
|
57
|
-
...generatedProps
|
|
58
|
+
...generatedProps,
|
|
59
|
+
dataSet: (0, _generateDataSet.generateDataSet)(props)
|
|
58
60
|
});
|
|
59
61
|
};
|
|
60
62
|
const withManualUniwind = (Component2, options) => props => {
|
|
@@ -71,7 +73,7 @@ const withManualUniwind = (Component2, options) => props => {
|
|
|
71
73
|
if (props[propName] !== void 0) {
|
|
72
74
|
return acc;
|
|
73
75
|
}
|
|
74
|
-
const value = (0, _web.getWebStyles)(className, uniwindContext)[option.styleProperty];
|
|
76
|
+
const value = (0, _web.getWebStyles)(className, props, uniwindContext)[option.styleProperty];
|
|
75
77
|
const transformedValue = value !== void 0 && option.styleProperty.toLowerCase().includes("color") ? (0, _web.formatColor)(value) : value;
|
|
76
78
|
acc.classNames += `${className} `;
|
|
77
79
|
acc.generatedProps[propName] = transformedValue;
|
|
@@ -93,6 +95,7 @@ const withManualUniwind = (Component2, options) => props => {
|
|
|
93
95
|
}, [classNames]);
|
|
94
96
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(Component2, {
|
|
95
97
|
...props,
|
|
96
|
-
...generatedProps
|
|
98
|
+
...generatedProps,
|
|
99
|
+
dataSet: (0, _generateDataSet.generateDataSet)(props)
|
|
97
100
|
});
|
|
98
101
|
};
|
|
@@ -26,7 +26,7 @@ const withAutoUniwind = Component2 => props => {
|
|
|
26
26
|
const {
|
|
27
27
|
styles,
|
|
28
28
|
dependencies: dependencies2
|
|
29
|
-
} = _native.UniwindStore.getStyles(propValue,
|
|
29
|
+
} = _native.UniwindStore.getStyles(propValue, props, void 0, uniwindContext);
|
|
30
30
|
acc.dependencies.push(...dependencies2);
|
|
31
31
|
acc.generatedProps[colorProp] = styles.accentColor;
|
|
32
32
|
return acc;
|
|
@@ -36,7 +36,7 @@ const withAutoUniwind = Component2 => props => {
|
|
|
36
36
|
const {
|
|
37
37
|
styles,
|
|
38
38
|
dependencies: dependencies2
|
|
39
|
-
} = _native.UniwindStore.getStyles(propValue,
|
|
39
|
+
} = _native.UniwindStore.getStyles(propValue, props, void 0, uniwindContext);
|
|
40
40
|
acc.dependencies.push(...dependencies2);
|
|
41
41
|
acc.generatedProps[styleProp] ??= [];
|
|
42
42
|
acc.generatedProps[styleProp][0] = styles;
|
|
@@ -83,7 +83,7 @@ const withManualUniwind = (Component2, options) => props => {
|
|
|
83
83
|
const {
|
|
84
84
|
styles: styles2,
|
|
85
85
|
dependencies: dependencies3
|
|
86
|
-
} = _native.UniwindStore.getStyles(className,
|
|
86
|
+
} = _native.UniwindStore.getStyles(className, props, void 0, uniwindContext);
|
|
87
87
|
acc.generatedProps[propName] = styles2[option.styleProperty];
|
|
88
88
|
acc.dependencies.push(...dependencies3);
|
|
89
89
|
return acc;
|
|
@@ -91,7 +91,7 @@ const withManualUniwind = (Component2, options) => props => {
|
|
|
91
91
|
const {
|
|
92
92
|
styles,
|
|
93
93
|
dependencies: dependencies2
|
|
94
|
-
} = _native.UniwindStore.getStyles(className,
|
|
94
|
+
} = _native.UniwindStore.getStyles(className, props, void 0, uniwindContext);
|
|
95
95
|
acc.dependencies.push(...dependencies2);
|
|
96
96
|
if (!(0, _withUniwindUtils.isStyleProperty)(propName)) {
|
|
97
97
|
acc.generatedProps[propName] = styles;
|
|
@@ -10,7 +10,7 @@ var _web = require("../core/web");
|
|
|
10
10
|
const emptyState = {};
|
|
11
11
|
const useResolveClassNames = className => {
|
|
12
12
|
const uniwindContext = (0, _context.useUniwindContext)();
|
|
13
|
-
const [styles, recreate] = (0, _react.useReducer)(() => className !== "" ? (0, _web.getWebStyles)(className, uniwindContext) : emptyState, void 0, () => className !== "" ? (0, _web.getWebStyles)(className, uniwindContext) : emptyState);
|
|
13
|
+
const [styles, recreate] = (0, _react.useReducer)(() => className !== "" ? (0, _web.getWebStyles)(className, void 0, uniwindContext) : emptyState, void 0, () => className !== "" ? (0, _web.getWebStyles)(className, void 0, uniwindContext) : emptyState);
|
|
14
14
|
(0, _react.useLayoutEffect)(() => {
|
|
15
15
|
if (className === "") {
|
|
16
16
|
return;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const generateDataSet: (props: Record<PropertyKey, any>) => DataSet;
|
|
2
|
-
type DataSet = Record<string, string | boolean>;
|
|
2
|
+
type DataSet = Record<string, string | boolean | undefined>;
|
|
3
3
|
declare module 'react-native' {
|
|
4
4
|
interface SwitchProps {
|
|
5
5
|
dataSet?: DataSet;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
const toCamelCase = (str) => str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
1
2
|
export const generateDataSet = (props) => {
|
|
2
3
|
const dataSet = props.dataSet !== void 0 ? { ...props.dataSet } : {};
|
|
3
4
|
Object.entries(props).forEach(([key, value]) => {
|
|
4
5
|
if (key.startsWith("data-")) {
|
|
5
|
-
dataSet[key.slice(5)] = value;
|
|
6
|
+
dataSet[toCamelCase(key.slice(5))] = value;
|
|
6
7
|
}
|
|
7
8
|
});
|
|
8
9
|
return dataSet;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { RNStyle, UniwindContextType } from '../types';
|
|
2
|
-
export declare const getWebStyles: (className: string | undefined, uniwindContext: UniwindContextType) => RNStyle;
|
|
2
|
+
export declare const getWebStyles: (className: string | undefined, componentProps: Record<string, unknown> | undefined, uniwindContext: UniwindContextType) => RNStyle;
|
|
3
3
|
export declare const getWebVariable: (name: string, uniwindContext: UniwindContextType) => string | undefined;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { generateDataSet } from "../../components/web/generateDataSet.js";
|
|
1
2
|
import { CSSListener } from "./cssListener.js";
|
|
2
3
|
import { parseCSSValue } from "./parseCSSValue.js";
|
|
3
4
|
const dummyParent = typeof document !== "undefined" ? Object.assign(document.createElement("div"), {
|
|
@@ -33,7 +34,7 @@ const getActiveStylesForClass = (className) => {
|
|
|
33
34
|
});
|
|
34
35
|
return extractedStyles;
|
|
35
36
|
};
|
|
36
|
-
export const getWebStyles = (className, uniwindContext) => {
|
|
37
|
+
export const getWebStyles = (className, componentProps, uniwindContext) => {
|
|
37
38
|
if (className === void 0) {
|
|
38
39
|
return {};
|
|
39
40
|
}
|
|
@@ -46,7 +47,17 @@ export const getWebStyles = (className, uniwindContext) => {
|
|
|
46
47
|
dummyParent?.removeAttribute("class");
|
|
47
48
|
}
|
|
48
49
|
dummy.className = className;
|
|
50
|
+
const dataSet = generateDataSet(componentProps ?? {});
|
|
51
|
+
Object.entries(dataSet).forEach(([key, value]) => {
|
|
52
|
+
if (value === false || value === void 0) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
dummy.dataset[key] = String(value);
|
|
56
|
+
});
|
|
49
57
|
const computedStyles = getActiveStylesForClass(className);
|
|
58
|
+
Object.keys(dataSet).forEach((key) => {
|
|
59
|
+
delete dummy.dataset[key];
|
|
60
|
+
});
|
|
50
61
|
return Object.fromEntries(
|
|
51
62
|
Object.entries(computedStyles).map(([key, value]) => {
|
|
52
63
|
const parsedKey = key[0] === "-" ? key : key.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useLayoutEffect, useReducer } from "react";
|
|
3
|
+
import { generateDataSet } from "../components/web/generateDataSet.js";
|
|
3
4
|
import { useUniwindContext } from "../core/context.js";
|
|
4
5
|
import { CSSListener, formatColor, getWebStyles } from "../core/web/index.js";
|
|
5
6
|
import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from "./withUniwindUtils.js";
|
|
@@ -13,7 +14,7 @@ const withAutoUniwind = (Component2) => (props) => {
|
|
|
13
14
|
return acc;
|
|
14
15
|
}
|
|
15
16
|
const className = propValue;
|
|
16
|
-
const color = getWebStyles(className, uniwindContext).accentColor;
|
|
17
|
+
const color = getWebStyles(className, props, uniwindContext).accentColor;
|
|
17
18
|
acc.generatedProps[colorProp] = color !== void 0 ? formatColor(color) : void 0;
|
|
18
19
|
acc.classNames += `${className} `;
|
|
19
20
|
return acc;
|
|
@@ -40,7 +41,8 @@ const withAutoUniwind = (Component2) => (props) => {
|
|
|
40
41
|
Component2,
|
|
41
42
|
{
|
|
42
43
|
...props,
|
|
43
|
-
...generatedProps
|
|
44
|
+
...generatedProps,
|
|
45
|
+
dataSet: generateDataSet(props)
|
|
44
46
|
}
|
|
45
47
|
);
|
|
46
48
|
};
|
|
@@ -55,7 +57,7 @@ const withManualUniwind = (Component2, options) => (props) => {
|
|
|
55
57
|
if (props[propName] !== void 0) {
|
|
56
58
|
return acc;
|
|
57
59
|
}
|
|
58
|
-
const value = getWebStyles(className, uniwindContext)[option.styleProperty];
|
|
60
|
+
const value = getWebStyles(className, props, uniwindContext)[option.styleProperty];
|
|
59
61
|
const transformedValue = value !== void 0 && option.styleProperty.toLowerCase().includes("color") ? formatColor(value) : value;
|
|
60
62
|
acc.classNames += `${className} `;
|
|
61
63
|
acc.generatedProps[propName] = transformedValue;
|
|
@@ -73,7 +75,8 @@ const withManualUniwind = (Component2, options) => (props) => {
|
|
|
73
75
|
Component2,
|
|
74
76
|
{
|
|
75
77
|
...props,
|
|
76
|
-
...generatedProps
|
|
78
|
+
...generatedProps,
|
|
79
|
+
dataSet: generateDataSet(props)
|
|
77
80
|
}
|
|
78
81
|
);
|
|
79
82
|
};
|
|
@@ -13,14 +13,14 @@ const withAutoUniwind = (Component2) => (props) => {
|
|
|
13
13
|
if (props[colorProp] !== void 0) {
|
|
14
14
|
return acc;
|
|
15
15
|
}
|
|
16
|
-
const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(propValue,
|
|
16
|
+
const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(propValue, props, void 0, uniwindContext);
|
|
17
17
|
acc.dependencies.push(...dependencies2);
|
|
18
18
|
acc.generatedProps[colorProp] = styles.accentColor;
|
|
19
19
|
return acc;
|
|
20
20
|
}
|
|
21
21
|
if (isClassProperty(propName)) {
|
|
22
22
|
const styleProp = classToStyle(propName);
|
|
23
|
-
const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(propValue,
|
|
23
|
+
const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(propValue, props, void 0, uniwindContext);
|
|
24
24
|
acc.dependencies.push(...dependencies2);
|
|
25
25
|
acc.generatedProps[styleProp] ??= [];
|
|
26
26
|
acc.generatedProps[styleProp][0] = styles;
|
|
@@ -61,12 +61,12 @@ const withManualUniwind = (Component2, options) => (props) => {
|
|
|
61
61
|
if (props[propName] !== void 0) {
|
|
62
62
|
return acc;
|
|
63
63
|
}
|
|
64
|
-
const { styles: styles2, dependencies: dependencies3 } = UniwindStore.getStyles(className,
|
|
64
|
+
const { styles: styles2, dependencies: dependencies3 } = UniwindStore.getStyles(className, props, void 0, uniwindContext);
|
|
65
65
|
acc.generatedProps[propName] = styles2[option.styleProperty];
|
|
66
66
|
acc.dependencies.push(...dependencies3);
|
|
67
67
|
return acc;
|
|
68
68
|
}
|
|
69
|
-
const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(className,
|
|
69
|
+
const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(className, props, void 0, uniwindContext);
|
|
70
70
|
acc.dependencies.push(...dependencies2);
|
|
71
71
|
if (!isStyleProperty(propName)) {
|
|
72
72
|
acc.generatedProps[propName] = styles;
|
|
@@ -5,9 +5,9 @@ const emptyState = {};
|
|
|
5
5
|
export const useResolveClassNames = (className) => {
|
|
6
6
|
const uniwindContext = useUniwindContext();
|
|
7
7
|
const [styles, recreate] = useReducer(
|
|
8
|
-
() => className !== "" ? getWebStyles(className, uniwindContext) : emptyState,
|
|
8
|
+
() => className !== "" ? getWebStyles(className, void 0, uniwindContext) : emptyState,
|
|
9
9
|
void 0,
|
|
10
|
-
() => className !== "" ? getWebStyles(className, uniwindContext) : emptyState
|
|
10
|
+
() => className !== "" ? getWebStyles(className, void 0, uniwindContext) : emptyState
|
|
11
11
|
);
|
|
12
12
|
useLayoutEffect(() => {
|
|
13
13
|
if (className === "") {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "@niibase/uniwind",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.1",
|
|
5
5
|
"description": "A fork of Uniwind with Reanimated 4 support",
|
|
6
6
|
"homepage": "https://uniwind.dev",
|
|
7
7
|
"author": "Unistack",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"postinstall": "node scripts/postinstall.mjs",
|
|
22
22
|
"test:native": "jest --config jest.config.native.js",
|
|
23
23
|
"test:web": "jest --config jest.config.web.js",
|
|
24
|
+
"test:types": "tsc --project tests/type-test/tsconfig.json",
|
|
24
25
|
"test:e2e": "playwright test",
|
|
25
26
|
"release": "release-it"
|
|
26
27
|
},
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
const toCamelCase = (str: string) => str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
|
|
2
|
+
|
|
1
3
|
export const generateDataSet = (props: Record<PropertyKey, any>) => {
|
|
2
4
|
const dataSet: DataSet = props.dataSet !== undefined ? { ...props.dataSet } : {}
|
|
3
5
|
|
|
4
6
|
Object.entries(props).forEach(([key, value]) => {
|
|
5
7
|
if (key.startsWith('data-')) {
|
|
6
8
|
// Remove data- prefix
|
|
7
|
-
dataSet[key.slice(5)] = value
|
|
9
|
+
dataSet[toCamelCase(key.slice(5))] = value
|
|
8
10
|
}
|
|
9
11
|
})
|
|
10
12
|
|
|
11
13
|
return dataSet
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
type DataSet = Record<string, string | boolean>
|
|
16
|
+
type DataSet = Record<string, string | boolean | undefined>
|
|
15
17
|
|
|
16
18
|
declare module 'react-native' {
|
|
17
19
|
interface SwitchProps {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { generateDataSet } from '../../components/web/generateDataSet'
|
|
1
2
|
import { RNStyle, UniwindContextType } from '../types'
|
|
2
3
|
import { CSSListener } from './cssListener'
|
|
3
4
|
import { parseCSSValue } from './parseCSSValue'
|
|
@@ -52,7 +53,11 @@ const getActiveStylesForClass = (className: string) => {
|
|
|
52
53
|
return extractedStyles
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
export const getWebStyles = (
|
|
56
|
+
export const getWebStyles = (
|
|
57
|
+
className: string | undefined,
|
|
58
|
+
componentProps: Record<string, unknown> | undefined,
|
|
59
|
+
uniwindContext: UniwindContextType,
|
|
60
|
+
): RNStyle => {
|
|
56
61
|
if (className === undefined) {
|
|
57
62
|
return {}
|
|
58
63
|
}
|
|
@@ -69,8 +74,22 @@ export const getWebStyles = (className: string | undefined, uniwindContext: Uniw
|
|
|
69
74
|
|
|
70
75
|
dummy.className = className
|
|
71
76
|
|
|
77
|
+
const dataSet = generateDataSet(componentProps ?? {})
|
|
78
|
+
|
|
79
|
+
Object.entries(dataSet).forEach(([key, value]) => {
|
|
80
|
+
if (value === false || value === undefined) {
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
dummy.dataset[key] = String(value)
|
|
85
|
+
})
|
|
86
|
+
|
|
72
87
|
const computedStyles = getActiveStylesForClass(className)
|
|
73
88
|
|
|
89
|
+
Object.keys(dataSet).forEach(key => {
|
|
90
|
+
delete dummy.dataset[key]
|
|
91
|
+
})
|
|
92
|
+
|
|
74
93
|
return Object.fromEntries(
|
|
75
94
|
Object.entries(computedStyles)
|
|
76
95
|
.map(([key, value]) => {
|
|
@@ -26,7 +26,7 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
|
|
|
26
26
|
return acc
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const { styles, dependencies } = UniwindStore.getStyles(propValue,
|
|
29
|
+
const { styles, dependencies } = UniwindStore.getStyles(propValue, props, undefined, uniwindContext)
|
|
30
30
|
|
|
31
31
|
acc.dependencies.push(...dependencies)
|
|
32
32
|
acc.generatedProps[colorProp] = styles.accentColor
|
|
@@ -36,7 +36,7 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
|
|
|
36
36
|
|
|
37
37
|
if (isClassProperty(propName)) {
|
|
38
38
|
const styleProp = classToStyle(propName)
|
|
39
|
-
const { styles, dependencies } = UniwindStore.getStyles(propValue,
|
|
39
|
+
const { styles, dependencies } = UniwindStore.getStyles(propValue, props, undefined, uniwindContext)
|
|
40
40
|
|
|
41
41
|
acc.dependencies.push(...dependencies)
|
|
42
42
|
acc.generatedProps[styleProp] ??= []
|
|
@@ -90,7 +90,7 @@ const withManualUniwind = (Component: Component<AnyObject>, options: Record<Prop
|
|
|
90
90
|
return acc
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
const { styles, dependencies } = UniwindStore.getStyles(className,
|
|
93
|
+
const { styles, dependencies } = UniwindStore.getStyles(className, props, undefined, uniwindContext)
|
|
94
94
|
|
|
95
95
|
acc.generatedProps[propName] = styles[option.styleProperty]
|
|
96
96
|
acc.dependencies.push(...dependencies)
|
|
@@ -98,7 +98,7 @@ const withManualUniwind = (Component: Component<AnyObject>, options: Record<Prop
|
|
|
98
98
|
return acc
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
const { styles, dependencies } = UniwindStore.getStyles(className,
|
|
101
|
+
const { styles, dependencies } = UniwindStore.getStyles(className, props, undefined, uniwindContext)
|
|
102
102
|
acc.dependencies.push(...dependencies)
|
|
103
103
|
|
|
104
104
|
if (!isStyleProperty(propName)) {
|
package/src/hoc/withUniwind.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ComponentProps, useLayoutEffect, useReducer } from 'react'
|
|
2
|
+
import { generateDataSet } from '../components/web/generateDataSet'
|
|
2
3
|
import { useUniwindContext } from '../core/context'
|
|
3
4
|
import { CSSListener, formatColor, getWebStyles } from '../core/web'
|
|
4
5
|
import { AnyObject, Component, OptionMapping, WithUniwind } from './types'
|
|
@@ -26,7 +27,7 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
const className = propValue
|
|
29
|
-
const color = getWebStyles(className, uniwindContext).accentColor
|
|
30
|
+
const color = getWebStyles(className, props, uniwindContext).accentColor
|
|
30
31
|
|
|
31
32
|
acc.generatedProps[colorProp] = color !== undefined
|
|
32
33
|
? formatColor(color)
|
|
@@ -67,6 +68,7 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
|
|
|
67
68
|
<Component
|
|
68
69
|
{...props}
|
|
69
70
|
{...generatedProps}
|
|
71
|
+
dataSet={generateDataSet(props)}
|
|
70
72
|
/>
|
|
71
73
|
)
|
|
72
74
|
}
|
|
@@ -87,7 +89,7 @@ const withManualUniwind = (Component: Component<AnyObject>, options: Record<Prop
|
|
|
87
89
|
return acc
|
|
88
90
|
}
|
|
89
91
|
|
|
90
|
-
const value = getWebStyles(className, uniwindContext)[option.styleProperty]
|
|
92
|
+
const value = getWebStyles(className, props, uniwindContext)[option.styleProperty]
|
|
91
93
|
const transformedValue = value !== undefined && option.styleProperty.toLowerCase().includes('color')
|
|
92
94
|
? formatColor(value as string)
|
|
93
95
|
: value
|
|
@@ -115,6 +117,7 @@ const withManualUniwind = (Component: Component<AnyObject>, options: Record<Prop
|
|
|
115
117
|
<Component
|
|
116
118
|
{...props}
|
|
117
119
|
{...generatedProps}
|
|
120
|
+
dataSet={generateDataSet(props)}
|
|
118
121
|
/>
|
|
119
122
|
)
|
|
120
123
|
}
|
|
@@ -8,9 +8,9 @@ const emptyState = {} as RNStyle
|
|
|
8
8
|
export const useResolveClassNames = (className: string) => {
|
|
9
9
|
const uniwindContext = useUniwindContext()
|
|
10
10
|
const [styles, recreate] = useReducer(
|
|
11
|
-
() => className !== '' ? getWebStyles(className, uniwindContext) : emptyState,
|
|
11
|
+
() => className !== '' ? getWebStyles(className, undefined, uniwindContext) : emptyState,
|
|
12
12
|
undefined,
|
|
13
|
-
() => className !== '' ? getWebStyles(className, uniwindContext) : emptyState,
|
|
13
|
+
() => className !== '' ? getWebStyles(className, undefined, uniwindContext) : emptyState,
|
|
14
14
|
)
|
|
15
15
|
|
|
16
16
|
useLayoutEffect(() => {
|
package/src/hooks/useUniwind.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { UniwindListener } from '../core/listener'
|
|
|
5
5
|
import { ThemeName } from '../core/types'
|
|
6
6
|
import { StyleDependency } from '../types'
|
|
7
7
|
|
|
8
|
-
export const useUniwind = () => {
|
|
8
|
+
export const useUniwind = (): { theme: ThemeName; hasAdaptiveThemes: boolean } => {
|
|
9
9
|
const uniwindContext = useUniwindContext()
|
|
10
10
|
const [theme, setTheme] = useState(Uniwind.currentTheme)
|
|
11
11
|
const [hasAdaptiveThemes, setHasAdaptiveThemes] = useState(Uniwind.hasAdaptiveThemes)
|
|
@@ -26,7 +26,7 @@ export const useUniwind = () => {
|
|
|
26
26
|
}, [uniwindContext])
|
|
27
27
|
|
|
28
28
|
return {
|
|
29
|
-
theme: uniwindContext.scopedTheme ?? theme
|
|
29
|
+
theme: uniwindContext.scopedTheme ?? theme,
|
|
30
30
|
hasAdaptiveThemes: uniwindContext.scopedTheme !== null ? false : hasAdaptiveThemes,
|
|
31
31
|
}
|
|
32
32
|
}
|