react-native-unistyles 1.0.0-beta.2 → 1.0.0-beta.3
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/createUnistyles.js +2 -2
- package/lib/commonjs/createUnistyles.js.map +1 -1
- package/lib/commonjs/hooks/index.js +13 -0
- package/lib/commonjs/hooks/index.js.map +1 -0
- package/lib/commonjs/hooks/useDimensions.js +19 -0
- package/lib/commonjs/hooks/useDimensions.js.map +1 -0
- package/lib/commonjs/hooks/useDimensions.web.js +31 -0
- package/lib/commonjs/hooks/useDimensions.web.js.map +1 -0
- package/lib/commonjs/utils/styles.js +21 -10
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/commonjs/utils/styles.spec.js +66 -0
- package/lib/commonjs/utils/styles.spec.js.map +1 -1
- package/lib/module/createUnistyles.js +2 -2
- package/lib/module/createUnistyles.js.map +1 -1
- package/lib/module/hooks/index.js +2 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useDimensions.js +12 -0
- package/lib/module/hooks/useDimensions.js.map +1 -0
- package/lib/module/hooks/useDimensions.web.js +24 -0
- package/lib/module/hooks/useDimensions.web.js.map +1 -0
- package/lib/module/utils/styles.js +21 -10
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/module/utils/styles.spec.js +66 -0
- package/lib/module/utils/styles.spec.js.map +1 -1
- package/lib/typescript/src/createUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/hooks/index.d.ts +2 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useDimensions.d.ts +3 -0
- package/lib/typescript/src/hooks/useDimensions.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useDimensions.web.d.ts +3 -0
- package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +1 -0
- package/lib/typescript/src/utils/styles.d.ts +1 -3
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/createUnistyles.ts +2 -2
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useDimensions.ts +11 -0
- package/src/hooks/useDimensions.web.ts +30 -0
- package/src/utils/styles.ts +34 -13
@@ -5,16 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.createUnistyles = void 0;
|
7
7
|
var _react = require("react");
|
8
|
-
var _reactNative = require("react-native");
|
9
8
|
var _UnistylesTheme = require("./UnistylesTheme");
|
10
9
|
var _utils = require("./utils");
|
10
|
+
var _hooks = require("./hooks");
|
11
11
|
const createUnistyles = breakpoints => {
|
12
12
|
const sortedBreakpoints = (0, _utils.sortAndValidateBreakpoints)(breakpoints);
|
13
13
|
return {
|
14
14
|
createStyles: styles => styles,
|
15
15
|
useStyles: stylesheet => {
|
16
16
|
const theme = (0, _react.useContext)(_UnistylesTheme.UnistylesContext);
|
17
|
-
const dimensions = (0,
|
17
|
+
const dimensions = (0, _hooks.useDimensions)();
|
18
18
|
const breakpoint = (0, _utils.getBreakpointFromScreenWidth)(dimensions.width, sortedBreakpoints);
|
19
19
|
const screenSize = {
|
20
20
|
width: dimensions.width,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","require","
|
1
|
+
{"version":3,"names":["_react","require","_UnistylesTheme","_utils","_hooks","createUnistyles","breakpoints","sortedBreakpoints","sortAndValidateBreakpoints","createStyles","styles","useStyles","stylesheet","theme","useContext","UnistylesContext","dimensions","useDimensions","breakpoint","getBreakpointFromScreenWidth","width","screenSize","height","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","x","proxifyFunction","parseStyle","exports"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,MAAMI,eAAe,GAA8CC,WAAc,IAAK;EACzF,MAAMC,iBAAiB,GAAG,IAAAC,iCAA0B,EAACF,WAAW,CAAM;E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AACL,CAAC;AAAAW,OAAA,CAAA9B,eAAA,GAAAA,eAAA"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "useDimensions", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _useDimensions.useDimensions;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
var _useDimensions = require("./useDimensions");
|
13
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_useDimensions","require"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useDimensions = void 0;
|
7
|
+
var _reactNative = require("react-native");
|
8
|
+
const useDimensions = () => {
|
9
|
+
const {
|
10
|
+
width,
|
11
|
+
height
|
12
|
+
} = (0, _reactNative.useWindowDimensions)();
|
13
|
+
return {
|
14
|
+
width,
|
15
|
+
height
|
16
|
+
};
|
17
|
+
};
|
18
|
+
exports.useDimensions = useDimensions;
|
19
|
+
//# sourceMappingURL=useDimensions.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_reactNative","require","useDimensions","width","height","useWindowDimensions","exports"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAG,IAAAC,gCAAmB,EAAC,CAAC;EAE/C,OAAO;IACHF,KAAK;IACLC;EACJ,CAAC;AACL,CAAC;AAAAE,OAAA,CAAAJ,aAAA,GAAAA,aAAA"}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useDimensions = void 0;
|
7
|
+
var _react = require("react");
|
8
|
+
const useDimensions = () => {
|
9
|
+
const timerRef = (0, _react.useRef)();
|
10
|
+
const [screenSize, setScreenSize] = (0, _react.useState)({
|
11
|
+
width: window.innerWidth,
|
12
|
+
height: window.innerHeight
|
13
|
+
});
|
14
|
+
(0, _react.useEffect)(() => {
|
15
|
+
const handleResize = () => {
|
16
|
+
clearTimeout(timerRef.current);
|
17
|
+
timerRef.current = setTimeout(() => setScreenSize({
|
18
|
+
width: window.innerWidth,
|
19
|
+
height: window.innerHeight
|
20
|
+
}), 100);
|
21
|
+
};
|
22
|
+
window.addEventListener('resize', handleResize);
|
23
|
+
return () => {
|
24
|
+
window.removeEventListener('resize', handleResize);
|
25
|
+
clearTimeout(timerRef.current);
|
26
|
+
};
|
27
|
+
}, []);
|
28
|
+
return screenSize;
|
29
|
+
};
|
30
|
+
exports.useDimensions = useDimensions;
|
31
|
+
//# sourceMappingURL=useDimensions.web.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_react","require","useDimensions","timerRef","useRef","screenSize","setScreenSize","useState","width","window","innerWidth","height","innerHeight","useEffect","handleResize","clearTimeout","current","setTimeout","addEventListener","removeEventListener","exports"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.web.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAMC,QAAQ,GAAG,IAAAC,aAAM,EAAgC,CAAC;EACxD,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAAa;IACrDC,KAAK,EAAEC,MAAM,CAACC,UAAU;IACxBC,MAAM,EAAEF,MAAM,CAACG;EACnB,CAAC,CAAC;EAEF,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,YAAY,GAAGA,CAAA,KAAM;MACvBC,YAAY,CAACZ,QAAQ,CAACa,OAAO,CAAC;MAE9Bb,QAAQ,CAACa,OAAO,GAAGC,UAAU,CAAC,MAAMX,aAAa,CAAC;QAC9CE,KAAK,EAAEC,MAAM,CAACC,UAAU;QACxBC,MAAM,EAAEF,MAAM,CAACG;MACnB,CAAC,CAAC,EAAE,GAAG,CAAC;IACZ,CAAC;IAEDH,MAAM,CAACS,gBAAgB,CAAC,QAAQ,EAAEJ,YAAY,CAAC;IAE/C,OAAO,MAAM;MACTL,MAAM,CAACU,mBAAmB,CAAC,QAAQ,EAAEL,YAAY,CAAC;MAClDC,YAAY,CAACZ,QAAQ,CAACa,OAAO,CAAC;IAClC,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOX,UAAU;AACrB,CAAC;AAAAe,OAAA,CAAAlB,aAAA,GAAAA,aAAA"}
|
@@ -56,15 +56,26 @@ const proxifyFunction = (fn, breakpoint, screenSize, breakpoints) => new Proxy(f
|
|
56
56
|
* // { fontSize: '12px' }
|
57
57
|
*/
|
58
58
|
exports.proxifyFunction = proxifyFunction;
|
59
|
-
const parseStyle = (style, breakpoint, screenSize, breakpoints) =>
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
59
|
+
const parseStyle = (style, breakpoint, screenSize, breakpoints) => {
|
60
|
+
const entries = Object.entries(style);
|
61
|
+
return Object.fromEntries(entries.map(_ref => {
|
62
|
+
let [key, value] = _ref;
|
63
|
+
const isNestedStyle = key === 'shadowOffset';
|
64
|
+
if (isNestedStyle) {
|
65
|
+
return [key, parseStyle(value, breakpoint, screenSize, breakpoints)];
|
66
|
+
}
|
67
|
+
const isTransform = key === 'transform';
|
68
|
+
if (isTransform && Array.isArray(value)) {
|
69
|
+
return [key, value.map(value => parseStyle(value, breakpoint, screenSize, breakpoints))];
|
70
|
+
}
|
71
|
+
const isDynamicFunction = typeof value === 'function';
|
72
|
+
const isValidStyle = typeof value !== 'object';
|
73
|
+
if (isDynamicFunction || isValidStyle) {
|
74
|
+
return [key, value];
|
75
|
+
}
|
76
|
+
const valueWithBreakpoint = value;
|
77
|
+
return [key, (0, _breakpoints.getValueForBreakpoint)(valueWithBreakpoint, breakpoint, screenSize, breakpoints)];
|
78
|
+
}));
|
79
|
+
};
|
69
80
|
exports.parseStyle = parseStyle;
|
70
81
|
//# sourceMappingURL=styles.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_breakpoints","require","proxifyFunction","fn","breakpoint","screenSize","breakpoints","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","style","
|
1
|
+
{"version":3,"names":["_breakpoints","require","proxifyFunction","fn","breakpoint","screenSize","breakpoints","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","style","entries","Object","fromEntries","map","_ref","key","value","isNestedStyle","isTransform","Array","isArray","isDynamicFunction","isValidStyle","valueWithBreakpoint","getValueForBreakpoint"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,eAAe,GAAGA,CAC3BC,EAAY,EAAEC,UAA4B,EAC1CC,UAAsB,EACtBC,WAAc,KACH,IAAIC,KAAK,CAACJ,EAAE,EAAE;EACzBK,KAAK,EAAEA,CAACC,MAAM,EAAEC,OAAO,EAAEC,aAAa,KAClCC,UAAU,CAACH,MAAM,CAACD,KAAK,CAACE,OAAO,EAAEC,aAAa,CAAC,EAAEP,UAAU,EAAEC,UAAU,EAAEC,WAAW;AAC5F,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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CAAAD,UAAA,GAAAA,UAAA"}
|
@@ -93,6 +93,72 @@ describe('styles', () => {
|
|
93
93
|
fontWeight: 'bold'
|
94
94
|
});
|
95
95
|
});
|
96
|
+
it('should correctly parse transform styles', () => {
|
97
|
+
const screenSize = {
|
98
|
+
width: 400,
|
99
|
+
height: 800
|
100
|
+
};
|
101
|
+
const breakpoint = 'sm';
|
102
|
+
const breakpoints = {
|
103
|
+
xs: 0,
|
104
|
+
sm: 400,
|
105
|
+
md: 800
|
106
|
+
};
|
107
|
+
const style = {
|
108
|
+
transform: [{
|
109
|
+
translateX: {
|
110
|
+
sm: 120,
|
111
|
+
md: 200
|
112
|
+
},
|
113
|
+
translateY: 200
|
114
|
+
}]
|
115
|
+
};
|
116
|
+
expect((0, _styles.parseStyle)(style, breakpoint, screenSize, breakpoints)).toEqual({
|
117
|
+
transform: [{
|
118
|
+
translateX: 120,
|
119
|
+
translateY: 200
|
120
|
+
}]
|
121
|
+
});
|
122
|
+
});
|
123
|
+
it('should correctly parse shadowOffset styles', () => {
|
124
|
+
const screenSize = {
|
125
|
+
width: 400,
|
126
|
+
height: 800
|
127
|
+
};
|
128
|
+
const breakpoint = 'sm';
|
129
|
+
const breakpoints = {
|
130
|
+
xs: 0,
|
131
|
+
sm: 400,
|
132
|
+
md: 800
|
133
|
+
};
|
134
|
+
const style = {
|
135
|
+
shadowOffset: {
|
136
|
+
width: 0,
|
137
|
+
height: 4
|
138
|
+
}
|
139
|
+
};
|
140
|
+
const styleWithBreakpoints = {
|
141
|
+
shadowOffset: {
|
142
|
+
width: 0,
|
143
|
+
height: {
|
144
|
+
sm: 10,
|
145
|
+
md: 20
|
146
|
+
}
|
147
|
+
}
|
148
|
+
};
|
149
|
+
expect((0, _styles.parseStyle)(style, breakpoint, screenSize, breakpoints)).toEqual({
|
150
|
+
shadowOffset: {
|
151
|
+
width: 0,
|
152
|
+
height: 4
|
153
|
+
}
|
154
|
+
});
|
155
|
+
expect((0, _styles.parseStyle)(styleWithBreakpoints, breakpoint, screenSize, breakpoints)).toEqual({
|
156
|
+
shadowOffset: {
|
157
|
+
width: 0,
|
158
|
+
height: 10
|
159
|
+
}
|
160
|
+
});
|
161
|
+
});
|
96
162
|
});
|
97
163
|
});
|
98
164
|
//# sourceMappingURL=styles.spec.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_styles","require","describe","it","screenSize","width","height","breakpoint","breakpoints","xs","sm","md","dynamicFunction","isEven","backgroundColor","expect","proxifyFunction","toEqual","style","fontSize","fontWeight","parseStyle"],"sourceRoot":"../../../src","sources":["utils/styles.spec.ts"],"mappings":";;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAGAC,QAAQ,CAAC,QAAQ,EAAE,MAAM;EACrBA,QAAQ,CAAC,iBAAiB,EAAE,MAAM;IAC9BC,EAAE,CAAC,yCAAyC,EAAE,MAAM;MAChD,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMC,eAAe,GAAIC,MAAe,KAAM;QAC1CC,eAAe,EAAE;UACbJ,EAAE,EAAEG,MAAM,GACJ,OAAO,GACP,KAAK;UACXF,EAAE,EAAEE,MAAM,GACJ,QAAQ,GACR;QACV;MACJ,CAAC,CAAC;MAEFE,MAAM,CAAC,IAAAC,uBAAe,EAACJ,eAAe,EAAEL,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAACS,OAAO,CAAC;QACxFH,eAAe,EAAE;MACrB,CAAC,CAAC;IACN,CAAC,CAAC;IAEFX,EAAE,CAAC,yDAAyD,EAAE,MAAM;MAChE,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CA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,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMO,KAAK,GAAG;QACVC,QAAQ,EAAE;UACNT,EAAE,EAAE,EAAE;UACNC,EAAE,EAAE;QACR,CAAC;QACDG,eAAe,EAAE;UACbL,EAAE,EAAE,MAAM;UACVE,EAAE,EAAE;QACR,CAAC;QACDS,UAAU,EAAE;MAChB,CAAC;MAEDL,MAAM,CAAC,IAAAM,kBAAU,EAACH,KAAK,EAAyDX,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,CAACS,OAAO,CAAC;QAC1HE,QAAQ,EAAE,EAAE;QACZL,eAAe,EAAE,MAAM;QACvBM,UAAU,EAAE;MAChB,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC"}
|
1
|
+
{"version":3,"names":["_styles","require","describe","it","screenSize","width","height","breakpoint","breakpoints","xs","sm","md","dynamicFunction","isEven","backgroundColor","expect","proxifyFunction","toEqual","style","fontSize","fontWeight","parseStyle","transform","translateX","translateY","shadowOffset","styleWithBreakpoints"],"sourceRoot":"../../../src","sources":["utils/styles.spec.ts"],"mappings":";;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAGAC,QAAQ,CAAC,QAAQ,EAAE,MAAM;EACrBA,QAAQ,CAAC,iBAAiB,EAAE,MAAM;IAC9BC,EAAE,CAAC,yCAAyC,EAAE,MAAM;MAChD,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMC,eAAe,GAAIC,MAAe,KAAM;QAC1CC,eAAe,EAAE;UACbJ,EAAE,E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K,EAAE,CAAC;UACRC,MAAM,EAAE;QACZ;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC"}
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import { useContext } from 'react';
|
2
|
-
import { useWindowDimensions } from 'react-native';
|
3
2
|
import { UnistylesContext } from './UnistylesTheme';
|
4
3
|
import { getBreakpointFromScreenWidth, proxifyFunction, parseStyle, sortAndValidateBreakpoints } from './utils';
|
4
|
+
import { useDimensions } from './hooks';
|
5
5
|
export const createUnistyles = breakpoints => {
|
6
6
|
const sortedBreakpoints = sortAndValidateBreakpoints(breakpoints);
|
7
7
|
return {
|
8
8
|
createStyles: styles => styles,
|
9
9
|
useStyles: stylesheet => {
|
10
10
|
const theme = useContext(UnistylesContext);
|
11
|
-
const dimensions =
|
11
|
+
const dimensions = useDimensions();
|
12
12
|
const breakpoint = getBreakpointFromScreenWidth(dimensions.width, sortedBreakpoints);
|
13
13
|
const screenSize = {
|
14
14
|
width: dimensions.width,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useContext","
|
1
|
+
{"version":3,"names":["useContext","UnistylesContext","getBreakpointFromScreenWidth","proxifyFunction","parseStyle","sortAndValidateBreakpoints","useDimensions","createUnistyles","breakpoints","sortedBreakpoints","createStyles","styles","useStyles","stylesheet","theme","dimensions","breakpoint","width","screenSize","height","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","x"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAElC,SAASC,gBAAgB,QAAQ,kBAAkB;AACnD,SAASC,4BAA4B,EAAEC,eAAe,EAAEC,UAAU,EAAEC,0BAA0B,QAAQ,SAAS;AAC/G,SAASC,aAAa,QAAQ,SAAS;AAEvC,OAAO,MAAMC,eAAe,GAA8CC,WAAc,IAAK;EACzF,MAAMC,iBAAiB,GAAGJ,0BAA0B,CAACG,WAAW,CAAM;EAE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
|
1
|
+
{"version":3,"names":["useDimensions"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":"AAAA,SAASA,aAAa,QAAQ,iBAAiB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["useWindowDimensions","useDimensions","width","height"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.ts"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,cAAc;AAGlD,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGH,mBAAmB,CAAC,CAAC;EAE/C,OAAO;IACHE,KAAK;IACLC;EACJ,CAAC;AACL,CAAC"}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
2
|
+
export const useDimensions = () => {
|
3
|
+
const timerRef = useRef();
|
4
|
+
const [screenSize, setScreenSize] = useState({
|
5
|
+
width: window.innerWidth,
|
6
|
+
height: window.innerHeight
|
7
|
+
});
|
8
|
+
useEffect(() => {
|
9
|
+
const handleResize = () => {
|
10
|
+
clearTimeout(timerRef.current);
|
11
|
+
timerRef.current = setTimeout(() => setScreenSize({
|
12
|
+
width: window.innerWidth,
|
13
|
+
height: window.innerHeight
|
14
|
+
}), 100);
|
15
|
+
};
|
16
|
+
window.addEventListener('resize', handleResize);
|
17
|
+
return () => {
|
18
|
+
window.removeEventListener('resize', handleResize);
|
19
|
+
clearTimeout(timerRef.current);
|
20
|
+
};
|
21
|
+
}, []);
|
22
|
+
return screenSize;
|
23
|
+
};
|
24
|
+
//# sourceMappingURL=useDimensions.web.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","useState","useDimensions","timerRef","screenSize","setScreenSize","width","window","innerWidth","height","innerHeight","handleResize","clearTimeout","current","setTimeout","addEventListener","removeEventListener"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.web.ts"],"mappings":"AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAGnD,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAMC,QAAQ,GAAGH,MAAM,CAAgC,CAAC;EACxD,MAAM,CAACI,UAAU,EAAEC,aAAa,CAAC,GAAGJ,QAAQ,CAAa;IACrDK,KAAK,EAAEC,MAAM,CAACC,UAAU;IACxBC,MAAM,EAAEF,MAAM,CAACG;EACnB,CAAC,CAAC;EAEFX,SAAS,CAAC,MAAM;IACZ,MAAMY,YAAY,GAAGA,CAAA,KAAM;MACvBC,YAAY,CAACT,QAAQ,CAACU,OAAO,CAAC;MAE9BV,QAAQ,CAACU,OAAO,GAAGC,UAAU,CAAC,MAAMT,aAAa,CAAC;QAC9CC,KAAK,EAAEC,MAAM,CAACC,UAAU;QACxBC,MAAM,EAAEF,MAAM,CAACG;MACnB,CAAC,CAAC,EAAE,GAAG,CAAC;IACZ,CAAC;IAEDH,MAAM,CAACQ,gBAAgB,CAAC,QAAQ,EAAEJ,YAAY,CAAC;IAE/C,OAAO,MAAM;MACTJ,MAAM,CAACS,mBAAmB,CAAC,QAAQ,EAAEL,YAAY,CAAC;MAClDC,YAAY,CAACT,QAAQ,CAACU,OAAO,CAAC;IAClC,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOT,UAAU;AACrB,CAAC"}
|
@@ -50,14 +50,25 @@ export const proxifyFunction = (fn, breakpoint, screenSize, breakpoints) => new
|
|
50
50
|
* const parsedStyle = parseStyle(style, 'sm', screenSize, breakpoints)
|
51
51
|
* // { fontSize: '12px' }
|
52
52
|
*/
|
53
|
-
export const parseStyle = (style, breakpoint, screenSize, breakpoints) =>
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
53
|
+
export const parseStyle = (style, breakpoint, screenSize, breakpoints) => {
|
54
|
+
const entries = Object.entries(style);
|
55
|
+
return Object.fromEntries(entries.map(_ref => {
|
56
|
+
let [key, value] = _ref;
|
57
|
+
const isNestedStyle = key === 'shadowOffset';
|
58
|
+
if (isNestedStyle) {
|
59
|
+
return [key, parseStyle(value, breakpoint, screenSize, breakpoints)];
|
60
|
+
}
|
61
|
+
const isTransform = key === 'transform';
|
62
|
+
if (isTransform && Array.isArray(value)) {
|
63
|
+
return [key, value.map(value => parseStyle(value, breakpoint, screenSize, breakpoints))];
|
64
|
+
}
|
65
|
+
const isDynamicFunction = typeof value === 'function';
|
66
|
+
const isValidStyle = typeof value !== 'object';
|
67
|
+
if (isDynamicFunction || isValidStyle) {
|
68
|
+
return [key, value];
|
69
|
+
}
|
70
|
+
const valueWithBreakpoint = value;
|
71
|
+
return [key, getValueForBreakpoint(valueWithBreakpoint, breakpoint, screenSize, breakpoints)];
|
72
|
+
}));
|
73
|
+
};
|
63
74
|
//# sourceMappingURL=styles.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["getValueForBreakpoint","proxifyFunction","fn","breakpoint","screenSize","breakpoints","Proxy","apply","target","thisArg","argumentsList","parseStyle","style","
|
1
|
+
{"version":3,"names":["getValueForBreakpoint","proxifyFunction","fn","breakpoint","screenSize","breakpoints","Proxy","apply","target","thisArg","argumentsList","parseStyle","style","entries","Object","fromEntries","map","_ref","key","value","isNestedStyle","isTransform","Array","isArray","isDynamicFunction","isValidStyle","valueWithBreakpoint"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":"AACA,SAASA,qBAAqB,QAAQ,eAAe;;AAErD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,GAAGA,CAC3BC,EAAY,EAAEC,UAA4B,EAC1CC,UAAsB,EACtBC,WAAc,KACH,IAAIC,KAAK,CAACJ,EAAE,EAAE;EACzBK,KAAK,EAAEA,CAACC,MAAM,EAAEC,OAAO,EAAEC,aAAa,KAClCC,UAAU,CA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AElB,qBAAqB,CAAI0B,mBAAmB,EAAEvB,UAAU,EAAEC,UAAU,EAAEC,WAAW,CAAC,CAAC;EACpG,CAAC,CACL,CAAC;AACT,CAAC"}
|
@@ -91,6 +91,72 @@ describe('styles', () => {
|
|
91
91
|
fontWeight: 'bold'
|
92
92
|
});
|
93
93
|
});
|
94
|
+
it('should correctly parse transform styles', () => {
|
95
|
+
const screenSize = {
|
96
|
+
width: 400,
|
97
|
+
height: 800
|
98
|
+
};
|
99
|
+
const breakpoint = 'sm';
|
100
|
+
const breakpoints = {
|
101
|
+
xs: 0,
|
102
|
+
sm: 400,
|
103
|
+
md: 800
|
104
|
+
};
|
105
|
+
const style = {
|
106
|
+
transform: [{
|
107
|
+
translateX: {
|
108
|
+
sm: 120,
|
109
|
+
md: 200
|
110
|
+
},
|
111
|
+
translateY: 200
|
112
|
+
}]
|
113
|
+
};
|
114
|
+
expect(parseStyle(style, breakpoint, screenSize, breakpoints)).toEqual({
|
115
|
+
transform: [{
|
116
|
+
translateX: 120,
|
117
|
+
translateY: 200
|
118
|
+
}]
|
119
|
+
});
|
120
|
+
});
|
121
|
+
it('should correctly parse shadowOffset styles', () => {
|
122
|
+
const screenSize = {
|
123
|
+
width: 400,
|
124
|
+
height: 800
|
125
|
+
};
|
126
|
+
const breakpoint = 'sm';
|
127
|
+
const breakpoints = {
|
128
|
+
xs: 0,
|
129
|
+
sm: 400,
|
130
|
+
md: 800
|
131
|
+
};
|
132
|
+
const style = {
|
133
|
+
shadowOffset: {
|
134
|
+
width: 0,
|
135
|
+
height: 4
|
136
|
+
}
|
137
|
+
};
|
138
|
+
const styleWithBreakpoints = {
|
139
|
+
shadowOffset: {
|
140
|
+
width: 0,
|
141
|
+
height: {
|
142
|
+
sm: 10,
|
143
|
+
md: 20
|
144
|
+
}
|
145
|
+
}
|
146
|
+
};
|
147
|
+
expect(parseStyle(style, breakpoint, screenSize, breakpoints)).toEqual({
|
148
|
+
shadowOffset: {
|
149
|
+
width: 0,
|
150
|
+
height: 4
|
151
|
+
}
|
152
|
+
});
|
153
|
+
expect(parseStyle(styleWithBreakpoints, breakpoint, screenSize, breakpoints)).toEqual({
|
154
|
+
shadowOffset: {
|
155
|
+
width: 0,
|
156
|
+
height: 10
|
157
|
+
}
|
158
|
+
});
|
159
|
+
});
|
94
160
|
});
|
95
161
|
});
|
96
162
|
//# sourceMappingURL=styles.spec.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["parseStyle","proxifyFunction","describe","it","screenSize","width","height","breakpoint","breakpoints","xs","sm","md","dynamicFunction","isEven","backgroundColor","expect","toEqual","style","fontSize","fontWeight"],"sourceRoot":"../../../src","sources":["utils/styles.spec.ts"],"mappings":"AAAA,SAASA,UAAU,EAAEC,eAAe,QAAQ,UAAU;AAGtDC,QAAQ,CAAC,QAAQ,EAAE,MAAM;EACrBA,QAAQ,CAAC,iBAAiB,EAAE,MAAM;IAC9BC,EAAE,CAAC,yCAAyC,EAAE,MAAM;MAChD,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMC,eAAe,GAAIC,MAAe,KAAM;QAC1CC,eAAe,EAAE;UACbJ,EAAE,EAAEG,MAAM,GACJ,OAAO,GACP,KAAK;UACXF,EAAE,EAAEE,MAAM,GACJ,QAAQ,GACR;QACV;MACJ,CAAC,CAAC;MAEFE,MAAM,CAACd,eAAe,CAACW,eAAe,EAAEL,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAACQ,OAAO,CAAC;QACxFF,eAAe,EAAE;MACrB,CAAC,CAAC;IACN,CAAC,CAAC;IAEFX,EAAE,CAAC,yDAAyD,EAAE,MAAM;MAChE,MAAMC,UAAs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VC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMM,KAAK,GAAG;QACVC,QAAQ,EAAE;UACNR,EAAE,EAAE,EAAE;UACNC,EAAE,EAAE;QACR,CAAC;QACDG,eAAe,EAAE;UACbL,EAAE,EAAE,MAAM;UACVE,EAAE,EAAE;QACR,CAAC;QACDQ,UAAU,EAAE;MAChB,CAAC;MAEDJ,MAAM,CAACf,UAAU,CAACiB,KAAK,EAAyDV,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,CAACQ,OAAO,CAAC;QAC1HE,QAAQ,EAAE,EAAE;QACZJ,eAAe,EAAE,MAAM;QACvBK,UAAU,EAAE;MAChB,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC"}
|
1
|
+
{"version":3,"names":["parseStyle","proxifyFunction","describe","it","screenSize","width","height","breakpoint","breakpoints","xs","sm","md","dynamicFunction","isEven","backgroundColor","expect","toEqual","style","fontSize","fontWeight","transform","translateX","translateY","shadowOffset","styleWithBreakpoints"],"sourceRoot":"../../../src","sources":["utils/styles.spec.ts"],"mappings":"AAAA,SAASA,UAAU,EAAEC,eAAe,QAAQ,UAAU;AAGtDC,QAAQ,CAAC,QAAQ,EAAE,MAAM;EACrBA,QAAQ,CAAC,iBAAiB,EAAE,MAAM;IAC9BC,EAAE,CAAC,yCAAyC,EAAE,MAAM;MAChD,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMC,eAAe,GAAIC,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,EAAE,CAAC;UACRC,MAAM,EAAE;QACZ;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createUnistyles.d.ts","sourceRoot":"","sources":["../../../src/createUnistyles.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"createUnistyles.d.ts","sourceRoot":"","sources":["../../../src/createUnistyles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAc,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAK3H,eAAO,MAAM,eAAe;;;;;;CAiD3B,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useDimensions.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useDimensions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,eAAO,MAAM,aAAa,QAAO,UAOhC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useDimensions.web.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useDimensions.web.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,eAAO,MAAM,aAAa,QAAO,UA0BhC,CAAA"}
|
@@ -46,7 +46,5 @@ export declare const proxifyFunction: <B extends Record<string, number>>(fn: Fun
|
|
46
46
|
* const parsedStyle = parseStyle(style, 'sm', screenSize, breakpoints)
|
47
47
|
* // { fontSize: '12px' }
|
48
48
|
*/
|
49
|
-
export declare const parseStyle: <T, B extends Record<string, number>>(style: CustomNamedStyles<T, B>, breakpoint: keyof B & string, screenSize: ScreenSize, breakpoints: B) =>
|
50
|
-
[k: string]: unknown;
|
51
|
-
};
|
49
|
+
export declare const parseStyle: <T, B extends Record<string, number>>(style: CustomNamedStyles<T, B>, breakpoint: keyof B & string, screenSize: ScreenSize, breakpoints: B) => T;
|
52
50
|
//# sourceMappingURL=styles.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAG7D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,eAAe,yCACpB,QAAQ,4CACA,UAAU,qBAEvB,QAGD,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,kHAGP,UAAU
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAG7D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,eAAe,yCACpB,QAAQ,4CACA,UAAU,qBAEvB,QAGD,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,kHAGP,UAAU,sBAsCzB,CAAA"}
|
package/package.json
CHANGED
package/src/createUnistyles.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { useContext } from 'react'
|
2
|
-
import { useWindowDimensions } from 'react-native'
|
3
2
|
import type { CreateStylesFactory, CustomNamedStyles, ScreenSize, ExtractBreakpoints, RemoveKeysWithPrefix } from './types'
|
4
3
|
import { UnistylesContext } from './UnistylesTheme'
|
5
4
|
import { getBreakpointFromScreenWidth, proxifyFunction, parseStyle, sortAndValidateBreakpoints } from './utils'
|
5
|
+
import { useDimensions } from './hooks'
|
6
6
|
|
7
7
|
export const createUnistyles = <B extends Record<string, number>, T = {}>(breakpoints: B) => {
|
8
8
|
const sortedBreakpoints = sortAndValidateBreakpoints(breakpoints) as B
|
@@ -11,7 +11,7 @@ export const createUnistyles = <B extends Record<string, number>, T = {}>(breakp
|
|
11
11
|
createStyles: <S extends CustomNamedStyles<S, B>>(styles: S | CreateStylesFactory<S, T>) => styles as S,
|
12
12
|
useStyles: <ST extends CustomNamedStyles<ST, B>>(stylesheet?: ST | CreateStylesFactory<ST, T>) => {
|
13
13
|
const theme = useContext(UnistylesContext) as T
|
14
|
-
const dimensions =
|
14
|
+
const dimensions = useDimensions()
|
15
15
|
const breakpoint = getBreakpointFromScreenWidth<B>(dimensions.width, sortedBreakpoints)
|
16
16
|
const screenSize: ScreenSize = {
|
17
17
|
width: dimensions.width,
|
@@ -0,0 +1 @@
|
|
1
|
+
export { useDimensions } from './useDimensions'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
2
|
+
import type { ScreenSize } from '../types'
|
3
|
+
|
4
|
+
export const useDimensions = (): ScreenSize => {
|
5
|
+
const timerRef = useRef<ReturnType<typeof setTimeout>>()
|
6
|
+
const [screenSize, setScreenSize] = useState<ScreenSize>({
|
7
|
+
width: window.innerWidth,
|
8
|
+
height: window.innerHeight
|
9
|
+
})
|
10
|
+
|
11
|
+
useEffect(() => {
|
12
|
+
const handleResize = () => {
|
13
|
+
clearTimeout(timerRef.current)
|
14
|
+
|
15
|
+
timerRef.current = setTimeout(() => setScreenSize({
|
16
|
+
width: window.innerWidth,
|
17
|
+
height: window.innerHeight
|
18
|
+
}), 100)
|
19
|
+
}
|
20
|
+
|
21
|
+
window.addEventListener('resize', handleResize)
|
22
|
+
|
23
|
+
return () => {
|
24
|
+
window.removeEventListener('resize', handleResize)
|
25
|
+
clearTimeout(timerRef.current)
|
26
|
+
}
|
27
|
+
}, [])
|
28
|
+
|
29
|
+
return screenSize
|
30
|
+
}
|
package/src/utils/styles.ts
CHANGED
@@ -61,19 +61,40 @@ export const parseStyle = <T, B extends Record<string, number>>(
|
|
61
61
|
breakpoint: keyof B & string,
|
62
62
|
screenSize: ScreenSize,
|
63
63
|
breakpoints: B
|
64
|
-
) =>
|
65
|
-
.
|
66
|
-
.entries(style)
|
67
|
-
.map(([key, value]) => {
|
68
|
-
const isDynamicFunction = typeof value === 'function'
|
69
|
-
const isValidStyle = typeof value !== 'object' || key === 'transform'
|
64
|
+
): T => {
|
65
|
+
const entries = Object.entries(style) as [[keyof T, CustomNamedStyles<T, B>]]
|
70
66
|
|
71
|
-
|
72
|
-
|
73
|
-
|
67
|
+
return Object
|
68
|
+
.fromEntries(entries
|
69
|
+
.map(([key, value]) => {
|
70
|
+
const isNestedStyle = key === 'shadowOffset'
|
74
71
|
|
75
|
-
|
72
|
+
if (isNestedStyle) {
|
73
|
+
return [
|
74
|
+
key,
|
75
|
+
parseStyle(value, breakpoint, screenSize, breakpoints)
|
76
|
+
]
|
77
|
+
}
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
-
|
79
|
+
const isTransform = key === 'transform'
|
80
|
+
|
81
|
+
if (isTransform && Array.isArray(value)) {
|
82
|
+
return [
|
83
|
+
key,
|
84
|
+
value.map(value => parseStyle(value, breakpoint, screenSize, breakpoints))
|
85
|
+
]
|
86
|
+
}
|
87
|
+
|
88
|
+
const isDynamicFunction = typeof value === 'function'
|
89
|
+
const isValidStyle = typeof value !== 'object'
|
90
|
+
|
91
|
+
if (isDynamicFunction || isValidStyle) {
|
92
|
+
return [key, value]
|
93
|
+
}
|
94
|
+
|
95
|
+
const valueWithBreakpoint = value as Record<keyof B & string, string | number>
|
96
|
+
|
97
|
+
return [key, getValueForBreakpoint<B>(valueWithBreakpoint, breakpoint, screenSize, breakpoints)]
|
98
|
+
})
|
99
|
+
)
|
100
|
+
}
|