rn-css 1.4.3 → 1.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 +10 -0
- package/dist/convertStyle.js +7 -7
- package/dist/convertUnits.js +5 -3
- package/dist/cssToRN/index.js +13 -13
- package/dist/cssToRN/mediaQueries.js +2 -2
- package/dist/features.js +5 -6
- package/dist/index.d.ts +129 -216
- package/dist/index.js +5 -6
- package/dist/styleComponent.d.ts +1 -0
- package/dist/styleComponent.js +12 -12
- package/dist/useTheme.d.ts +17 -0
- package/dist/useTheme.js +31 -0
- package/package.json +33 -33
- package/src/convertUnits.ts +1 -0
- package/src/features.tsx +2 -2
- package/src/index.tsx +1 -5
- package/src/styleComponent.tsx +2 -2
- package/src/useTheme.tsx +27 -0
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This is basically [styled-components](https://github.com/styled-components/styled-components) with a much better support for React-Native, and some awesome additional features. You can check the docs of [styled-components](https://github.com/styled-components/styled-components) for more details about the basic API. I'll focus here on the differences.
|
|
4
4
|
|
|
5
|
+
**Current version: 1.5** [See the Changelog](./CHANGELOG.md)
|
|
6
|
+
|
|
5
7
|
---
|
|
6
8
|
|
|
7
9
|
## Purpose
|
|
@@ -331,6 +333,14 @@ const View = styled.View`
|
|
|
331
333
|
|
|
332
334
|
---
|
|
333
335
|
|
|
336
|
+
## Theming:
|
|
337
|
+
|
|
338
|
+
To match the API of styled-components, we offer the same abilities for theming [See the documentation](https://styled-components.com/docs/advanced).
|
|
339
|
+
|
|
340
|
+
This relies on the [SharedValue](#shared-value) context. This means that you cannot use the Shared Value system **and** this theming système. Pick the one that best suits your needs.
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
334
344
|
## Coming later:
|
|
335
345
|
|
|
336
346
|
linear-gradient, background-repeat, transitions, animations
|
package/dist/convertStyle.js
CHANGED
|
@@ -9,7 +9,7 @@ const convertStyle = (rnStyle, units) => {
|
|
|
9
9
|
['width', 'height'].forEach(key => {
|
|
10
10
|
if (!units[key] && rnStyle[key]) {
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
12
|
-
const converted = convertUnits_1.convertValue(key, rnStyle[key], units);
|
|
12
|
+
const converted = (0, convertUnits_1.convertValue)(key, rnStyle[key], units);
|
|
13
13
|
if (!Number.isNaN(converted))
|
|
14
14
|
units[key] = converted;
|
|
15
15
|
}
|
|
@@ -21,24 +21,24 @@ const convertStyle = (rnStyle, units) => {
|
|
|
21
21
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
22
22
|
convertedStyle.transform = rnStyle.transform.map(transformation => {
|
|
23
23
|
const result = {};
|
|
24
|
-
Object.keys(transformation).forEach(k => (result[k] = convertUnits_1.convertValue(k, transformation[k], units)));
|
|
24
|
+
Object.keys(transformation).forEach(k => (result[k] = (0, convertUnits_1.convertValue)(k, transformation[k], units)));
|
|
25
25
|
return result;
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
else if (key === 'shadowOffset' && rnStyle.shadowOffset) {
|
|
29
29
|
convertedStyle.shadowOffset = {
|
|
30
30
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
31
|
-
width: convertUnits_1.convertValue(key, rnStyle.shadowOffset.width || '0', units),
|
|
31
|
+
width: (0, convertUnits_1.convertValue)(key, rnStyle.shadowOffset.width || '0', units),
|
|
32
32
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
33
|
-
height: convertUnits_1.convertValue(key, rnStyle.shadowOffset.height || '0', units)
|
|
33
|
+
height: (0, convertUnits_1.convertValue)(key, rnStyle.shadowOffset.height || '0', units)
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
else if (key === 'textShadowOffset' && rnStyle.textShadowOffset) {
|
|
37
37
|
convertedStyle.textShadowOffset = {
|
|
38
38
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
39
|
-
width: convertUnits_1.convertValue(key, rnStyle.textShadowOffset.width || '0', units),
|
|
39
|
+
width: (0, convertUnits_1.convertValue)(key, rnStyle.textShadowOffset.width || '0', units),
|
|
40
40
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
41
|
-
height: convertUnits_1.convertValue(key, rnStyle.textShadowOffset.height || '0', units)
|
|
41
|
+
height: (0, convertUnits_1.convertValue)(key, rnStyle.textShadowOffset.height || '0', units)
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
// Font family should not be transformed (same as cursor for web in case of base64 value)
|
|
@@ -48,7 +48,7 @@ const convertStyle = (rnStyle, units) => {
|
|
|
48
48
|
else {
|
|
49
49
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
50
50
|
// @ts-ignore
|
|
51
|
-
convertedStyle[key] = convertUnits_1.convertValue(key, value, units);
|
|
51
|
+
convertedStyle[key] = (0, convertUnits_1.convertValue)(key, value, units);
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
return convertedStyle;
|
package/dist/convertUnits.js
CHANGED
|
@@ -53,11 +53,13 @@ function convertValue(key, value, units) {
|
|
|
53
53
|
});
|
|
54
54
|
// We handle extra calculations (calc, min, max, parsing...)
|
|
55
55
|
if (convertedValue.startsWith('calc('))
|
|
56
|
-
return maths_1.calculate(convertedValue.substring(4)); // remove calc. We can keep the parenthesis
|
|
56
|
+
return (0, maths_1.calculate)(convertedValue.substring(4)); // remove calc. We can keep the parenthesis
|
|
57
57
|
else if (convertedValue.startsWith('max('))
|
|
58
|
-
return maths_1.max(convertedValue.substring(4, convertedValue.length - 1)); // Remove max()
|
|
58
|
+
return (0, maths_1.max)(convertedValue.substring(4, convertedValue.length - 1)); // Remove max()
|
|
59
59
|
else if (convertedValue.startsWith('min('))
|
|
60
|
-
return maths_1.min(convertedValue.substring(4, convertedValue.length - 1)); // remove min()
|
|
60
|
+
return (0, maths_1.min)(convertedValue.substring(4, convertedValue.length - 1)); // remove min()
|
|
61
|
+
else if (key === 'fontWeight')
|
|
62
|
+
return convertedValue; // fontWeight must be a string even when it is an integer value.
|
|
61
63
|
else if (parseFloat(convertedValue) + '' === convertedValue)
|
|
62
64
|
return parseFloat(convertedValue);
|
|
63
65
|
else
|
package/dist/cssToRN/index.js
CHANGED
|
@@ -18,7 +18,7 @@ function cssToStyle(css) {
|
|
|
18
18
|
const result = {};
|
|
19
19
|
// Find media queries
|
|
20
20
|
const cssWithoutMediaQueries = css.replace(/@media(.*?){[^{}]*}/gmis, res => {
|
|
21
|
-
const { css, isValid } = mediaQueries_1.createMedia(res);
|
|
21
|
+
const { css, isValid } = (0, mediaQueries_1.createMedia)(res);
|
|
22
22
|
const style = cssChunkToStyle(css);
|
|
23
23
|
const mediaQuery = (context) => isValid(context) && style;
|
|
24
24
|
if (!result.media)
|
|
@@ -56,7 +56,7 @@ function cssToRNStyle(css, units = {}) {
|
|
|
56
56
|
...units
|
|
57
57
|
};
|
|
58
58
|
const rnStyle = cssChunkToStyle(css);
|
|
59
|
-
return convertStyle_1.default(rnStyle, finalUnits);
|
|
59
|
+
return (0, convertStyle_1.default)(rnStyle, finalUnits);
|
|
60
60
|
}
|
|
61
61
|
exports.cssToRNStyle = cssToRNStyle;
|
|
62
62
|
function cssChunkToStyle(css) {
|
|
@@ -74,43 +74,43 @@ function cssChunkToStyle(css) {
|
|
|
74
74
|
case 'borderLeft':
|
|
75
75
|
case 'borderRight':
|
|
76
76
|
case 'borderBottom':
|
|
77
|
-
Object.assign(result, convert_1.border(key, value));
|
|
77
|
+
Object.assign(result, (0, convert_1.border)(key, value));
|
|
78
78
|
break;
|
|
79
79
|
case 'borderWidth':
|
|
80
|
-
Object.assign(result, convert_1.sideValue('border', value, 'Width'));
|
|
80
|
+
Object.assign(result, (0, convert_1.sideValue)('border', value, 'Width'));
|
|
81
81
|
break;
|
|
82
82
|
case 'background':
|
|
83
83
|
Object.assign(result, { backgroundColor: value });
|
|
84
84
|
break;
|
|
85
85
|
case 'padding':
|
|
86
86
|
case 'margin':
|
|
87
|
-
Object.assign(result, convert_1.sideValue(key, value));
|
|
87
|
+
Object.assign(result, (0, convert_1.sideValue)(key, value));
|
|
88
88
|
break;
|
|
89
89
|
case 'borderRadius':
|
|
90
|
-
Object.assign(result, convert_1.cornerValue('border', value, 'Radius'));
|
|
90
|
+
Object.assign(result, (0, convert_1.cornerValue)('border', value, 'Radius'));
|
|
91
91
|
break;
|
|
92
92
|
case 'font':
|
|
93
|
-
Object.assign(result, convert_1.font(value));
|
|
93
|
+
Object.assign(result, (0, convert_1.font)(value));
|
|
94
94
|
break;
|
|
95
95
|
case 'textDecoration':
|
|
96
|
-
Object.assign(result, convert_1.textDecoration(value));
|
|
96
|
+
Object.assign(result, (0, convert_1.textDecoration)(value));
|
|
97
97
|
break;
|
|
98
98
|
case 'placeContent':
|
|
99
|
-
Object.assign(result, convert_1.placeContent(value));
|
|
99
|
+
Object.assign(result, (0, convert_1.placeContent)(value));
|
|
100
100
|
break;
|
|
101
101
|
case 'flex':
|
|
102
|
-
Object.assign(result, convert_1.flex(value));
|
|
102
|
+
Object.assign(result, (0, convert_1.flex)(value));
|
|
103
103
|
break;
|
|
104
104
|
case 'flexFlow':
|
|
105
|
-
Object.assign(result, convert_1.flexFlow(value));
|
|
105
|
+
Object.assign(result, (0, convert_1.flexFlow)(value));
|
|
106
106
|
break;
|
|
107
107
|
case 'transform':
|
|
108
|
-
Object.assign(result, convert_1.transform(value));
|
|
108
|
+
Object.assign(result, (0, convert_1.transform)(value));
|
|
109
109
|
break;
|
|
110
110
|
case 'boxShadow':
|
|
111
111
|
case 'textShadow':
|
|
112
112
|
// We need to replace boxShadow by shadow
|
|
113
|
-
Object.assign(result, convert_1.shadow(key === 'boxShadow' ? 'shadow' : key, value));
|
|
113
|
+
Object.assign(result, (0, convert_1.shadow)(key === 'boxShadow' ? 'shadow' : key, value));
|
|
114
114
|
break;
|
|
115
115
|
// Other keys don't require any special treatment
|
|
116
116
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -54,7 +54,7 @@ function convertAnyValue(key, value, units) {
|
|
|
54
54
|
dppx: 'px',
|
|
55
55
|
x: 'px'
|
|
56
56
|
};
|
|
57
|
-
const [num, unit] = convertUnits_1.parseValue(value);
|
|
57
|
+
const [num, unit] = (0, convertUnits_1.parseValue)(value);
|
|
58
58
|
return num + densityUnitsEquivalence[unit];
|
|
59
59
|
}
|
|
60
60
|
else if (key === 'deviceAspectRatio' || key === 'aspectRatio') {
|
|
@@ -62,7 +62,7 @@ function convertAnyValue(key, value, units) {
|
|
|
62
62
|
const [w, h] = value.split('/').map(v => parseInt(v, 10));
|
|
63
63
|
return w / h;
|
|
64
64
|
}
|
|
65
|
-
return convertUnits_1.convertValue(key, value, units);
|
|
65
|
+
return (0, convertUnits_1.convertValue)(key, value, units);
|
|
66
66
|
}
|
|
67
67
|
/** Check if a constraint is respected by the provided context */
|
|
68
68
|
function evaluateConstraint(constraint, context) {
|
package/dist/features.js
CHANGED
|
@@ -14,7 +14,7 @@ exports.FontSizeContext = react_1.default.createContext(16);
|
|
|
14
14
|
exports.zIndexContext = react_1.default.createContext((_zIndex) => { });
|
|
15
15
|
/** HOC that will apply the screen size to the styles defined with vmin, vmax, vw, vh units, and handle media queries constraints */
|
|
16
16
|
const useScreenSize = () => {
|
|
17
|
-
const { width, height } = react_native_1.useWindowDimensions();
|
|
17
|
+
const { width, height } = (0, react_native_1.useWindowDimensions)();
|
|
18
18
|
return { vw: width / 100, vh: height / 100, vmin: Math.min(width, height) / 100, vmax: Math.max(width, height) / 100 };
|
|
19
19
|
};
|
|
20
20
|
exports.useScreenSize = useScreenSize;
|
|
@@ -37,7 +37,7 @@ exports.useHover = useHover;
|
|
|
37
37
|
/** HOC that will apply the style provided in the media queries */
|
|
38
38
|
const useMediaQuery = (media, units) => {
|
|
39
39
|
if (media) {
|
|
40
|
-
const context = mediaQueries_1.createContext(units);
|
|
40
|
+
const context = (0, mediaQueries_1.createContext)(units);
|
|
41
41
|
const mediaStyles = media.map(m => m(context)).filter(m => m);
|
|
42
42
|
if (!mediaStyles.length)
|
|
43
43
|
return;
|
|
@@ -59,9 +59,8 @@ const useLayout = (onLayout) => {
|
|
|
59
59
|
if (unmounted.current)
|
|
60
60
|
return;
|
|
61
61
|
const { width, height } = event.nativeEvent.layout;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}, [onLayout, layout.width, layout.height]);
|
|
62
|
+
setLayout(layout => layout.width === width && layout.height === height ? layout : { width, height });
|
|
63
|
+
}, [onLayout]);
|
|
65
64
|
return { onLayout: updateLayout, ...layout };
|
|
66
65
|
};
|
|
67
66
|
exports.useLayout = useLayout;
|
|
@@ -70,7 +69,7 @@ const useFontSize = (setFontSize, rem = 16) => {
|
|
|
70
69
|
const em = react_1.default.useContext(exports.FontSizeContext);
|
|
71
70
|
if (!setFontSize)
|
|
72
71
|
return { em };
|
|
73
|
-
const [fontSize, fontUnit] = convertUnits_1.parseValue(setFontSize);
|
|
72
|
+
const [fontSize, fontUnit] = (0, convertUnits_1.parseValue)(setFontSize);
|
|
74
73
|
const isRelative = ['rem', 'em', '%'].includes(fontUnit || '');
|
|
75
74
|
if (isRelative) {
|
|
76
75
|
const newSize = fontUnit === 'em' ? em * fontSize
|