react-native-unistyles 2.0.0-alpha.14 → 2.0.0-alpha.16
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/UnistylesRuntime.h +6 -6
- package/lib/commonjs/common.js +15 -15
- package/lib/commonjs/common.js.map +1 -1
- package/lib/commonjs/core/UnistylesRuntime.js +1 -1
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
- package/lib/commonjs/createStyleSheet.js +1 -6
- package/lib/commonjs/createStyleSheet.js.map +1 -1
- package/lib/commonjs/hooks/index.js +7 -0
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useUnistyles.js +4 -7
- package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
- package/lib/commonjs/hooks/useVariants.js +24 -0
- package/lib/commonjs/hooks/useVariants.js.map +1 -0
- package/lib/commonjs/plugins/normalizer/normalizer.js +1 -1
- package/lib/commonjs/plugins/normalizer/normalizer.js.map +1 -1
- package/lib/commonjs/types/{mq.js → stylesheet.js} +1 -1
- package/lib/commonjs/types/{mq.js.map → stylesheet.js.map} +1 -1
- package/lib/commonjs/useStyles.js +5 -4
- package/lib/commonjs/useStyles.js.map +1 -1
- package/lib/commonjs/utils/index.js +0 -6
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/mq.js +36 -68
- package/lib/commonjs/utils/mq.js.map +1 -1
- package/lib/commonjs/utils/styles.js +14 -8
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/commonjs/utils/variants.js +33 -13
- package/lib/commonjs/utils/variants.js.map +1 -1
- package/lib/module/common.js +14 -14
- package/lib/module/common.js.map +1 -1
- package/lib/module/core/UnistylesRuntime.js +1 -1
- package/lib/module/core/UnistylesRuntime.js.map +1 -1
- package/lib/module/createStyleSheet.js +1 -6
- package/lib/module/createStyleSheet.js.map +1 -1
- package/lib/module/hooks/index.js +1 -0
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useUnistyles.js +5 -8
- package/lib/module/hooks/useUnistyles.js.map +1 -1
- package/lib/module/hooks/useVariants.js +17 -0
- package/lib/module/hooks/useVariants.js.map +1 -0
- package/lib/module/plugins/normalizer/normalizer.js +1 -1
- package/lib/module/plugins/normalizer/normalizer.js.map +1 -1
- package/lib/module/types/stylesheet.js +2 -0
- package/lib/module/types/{mq.js.map → stylesheet.js.map} +1 -1
- package/lib/module/useStyles.js +6 -5
- package/lib/module/useStyles.js.map +1 -1
- package/lib/module/utils/index.js +1 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/mq.js +35 -67
- package/lib/module/utils/mq.js.map +1 -1
- package/lib/module/utils/styles.js +15 -9
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/module/utils/variants.js +31 -11
- package/lib/module/utils/variants.js.map +1 -1
- package/lib/typescript/src/common.d.ts +10 -10
- package/lib/typescript/src/common.d.ts.map +1 -1
- package/lib/typescript/src/createStyleSheet.d.ts +2 -2
- package/lib/typescript/src/createStyleSheet.d.ts.map +1 -1
- package/lib/typescript/src/global.d.ts.map +1 -1
- package/lib/typescript/src/hooks/index.d.ts +1 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useVariants.d.ts +3 -0
- package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -0
- package/lib/typescript/src/plugins/normalizer/normalizer.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +24 -15
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/core.d.ts +5 -29
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +2 -2
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +40 -0
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -0
- package/lib/typescript/src/types/unistyles.d.ts +5 -6
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -1
- package/lib/typescript/src/types/variants.d.ts +13 -7
- package/lib/typescript/src/types/variants.d.ts.map +1 -1
- package/lib/typescript/src/useStyles.d.ts +3 -3
- package/lib/typescript/src/useStyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +1 -1
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mq.d.ts +15 -14
- package/lib/typescript/src/utils/mq.d.ts.map +1 -1
- package/lib/typescript/src/utils/styles.d.ts +3 -3
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/lib/typescript/src/utils/variants.d.ts +2 -2
- package/lib/typescript/src/utils/variants.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/common.ts +10 -10
- package/src/core/UnistylesRuntime.ts +1 -1
- package/src/createStyleSheet.ts +2 -8
- package/src/global.ts +1 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useUnistyles.ts +5 -8
- package/src/hooks/useVariants.ts +23 -0
- package/src/plugins/normalizer/normalizer.ts +3 -3
- package/src/types/breakpoints.ts +51 -27
- package/src/types/core.ts +8 -45
- package/src/types/index.ts +1 -2
- package/src/types/stylesheet.ts +49 -0
- package/src/types/unistyles.ts +5 -6
- package/src/types/variants.ts +17 -9
- package/src/useStyles.ts +15 -15
- package/src/utils/index.ts +1 -1
- package/src/utils/mq.ts +31 -84
- package/src/utils/styles.ts +18 -17
- package/src/utils/variants.ts +41 -17
- package/lib/module/types/mq.js +0 -2
- package/lib/typescript/src/types/mq.d.ts +0 -3
- package/lib/typescript/src/types/mq.d.ts.map +0 -1
- package/src/types/mq.ts +0 -3
package/src/utils/variants.ts
CHANGED
@@ -1,37 +1,61 @@
|
|
1
|
-
import type { Optional,
|
1
|
+
import type { Optional, StyleSheet, NestedStyle } from '../types'
|
2
2
|
|
3
|
-
const
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
const getKeysForVariants = (
|
4
|
+
value: Record<string, NestedStyle>,
|
5
|
+
variants: Array<[string, Optional<string>]>
|
6
|
+
): Array<[string, string]> => {
|
7
|
+
// case for no specified variants by user, we should fallback to 'default'
|
8
|
+
if (!variants.length) {
|
9
|
+
return Object
|
10
|
+
.entries(value)
|
11
|
+
.map(([key, value]) => {
|
12
|
+
if ('default' in value) {
|
13
|
+
return [key, 'default']
|
14
|
+
}
|
7
15
|
|
8
|
-
|
9
|
-
|
16
|
+
return undefined
|
17
|
+
})
|
18
|
+
.filter(Boolean) as Array<[string, string]>
|
10
19
|
}
|
11
20
|
|
12
|
-
return
|
21
|
+
return variants
|
22
|
+
.map(([variantKey, variantValue]) => {
|
23
|
+
const variantStyle = value[variantKey]
|
24
|
+
|
25
|
+
if (variantStyle && variantValue && variantValue in variantStyle) {
|
26
|
+
return [variantKey, variantValue]
|
27
|
+
}
|
28
|
+
|
29
|
+
if (variantStyle && 'default' in variantStyle) {
|
30
|
+
return [variantKey, 'default']
|
31
|
+
}
|
32
|
+
|
33
|
+
return undefined
|
34
|
+
})
|
35
|
+
.filter(Boolean) as Array<[string, string]>
|
13
36
|
}
|
14
37
|
|
15
|
-
export const
|
16
|
-
style:
|
17
|
-
|
38
|
+
export const getStyleWithVariants = (
|
39
|
+
style: StyleSheet,
|
40
|
+
variantValues?: Record<string, Optional<string>>
|
18
41
|
) => {
|
19
42
|
if (!('variants' in style)) {
|
20
43
|
return style
|
21
44
|
}
|
22
45
|
|
23
|
-
const
|
46
|
+
const keys = getKeysForVariants(
|
24
47
|
style.variants as Record<string, NestedStyle>,
|
25
|
-
|
48
|
+
Object.entries(variantValues || {})
|
26
49
|
)
|
27
|
-
|
28
|
-
|
29
|
-
|
50
|
+
|
51
|
+
const variantsValues = keys
|
52
|
+
.map(([key, nestedKey]) => ((style.variants as Record<string, Record<string, NestedStyle>>)[key] as Record<string, NestedStyle>)[nestedKey])
|
53
|
+
.reduce((acc, styles) => ({ ...acc, ...styles }), {})
|
30
54
|
|
31
55
|
const { variants, ...otherStyles } = style
|
32
56
|
|
33
57
|
return {
|
34
58
|
...otherStyles,
|
35
|
-
...
|
59
|
+
...variantsValues
|
36
60
|
}
|
37
61
|
}
|
package/lib/module/types/mq.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"mq.d.ts","sourceRoot":"","sources":["../../../../src/types/mq.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,MAAM,MAAM,UAAU,GAAG,OAAO,QAAQ,CAAA"}
|
package/src/types/mq.ts
DELETED