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.
Files changed (110) hide show
  1. package/cxx/UnistylesRuntime.h +6 -6
  2. package/lib/commonjs/common.js +15 -15
  3. package/lib/commonjs/common.js.map +1 -1
  4. package/lib/commonjs/core/UnistylesRuntime.js +1 -1
  5. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
  6. package/lib/commonjs/createStyleSheet.js +1 -6
  7. package/lib/commonjs/createStyleSheet.js.map +1 -1
  8. package/lib/commonjs/hooks/index.js +7 -0
  9. package/lib/commonjs/hooks/index.js.map +1 -1
  10. package/lib/commonjs/hooks/useUnistyles.js +4 -7
  11. package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
  12. package/lib/commonjs/hooks/useVariants.js +24 -0
  13. package/lib/commonjs/hooks/useVariants.js.map +1 -0
  14. package/lib/commonjs/plugins/normalizer/normalizer.js +1 -1
  15. package/lib/commonjs/plugins/normalizer/normalizer.js.map +1 -1
  16. package/lib/commonjs/types/{mq.js → stylesheet.js} +1 -1
  17. package/lib/commonjs/types/{mq.js.map → stylesheet.js.map} +1 -1
  18. package/lib/commonjs/useStyles.js +5 -4
  19. package/lib/commonjs/useStyles.js.map +1 -1
  20. package/lib/commonjs/utils/index.js +0 -6
  21. package/lib/commonjs/utils/index.js.map +1 -1
  22. package/lib/commonjs/utils/mq.js +36 -68
  23. package/lib/commonjs/utils/mq.js.map +1 -1
  24. package/lib/commonjs/utils/styles.js +14 -8
  25. package/lib/commonjs/utils/styles.js.map +1 -1
  26. package/lib/commonjs/utils/variants.js +33 -13
  27. package/lib/commonjs/utils/variants.js.map +1 -1
  28. package/lib/module/common.js +14 -14
  29. package/lib/module/common.js.map +1 -1
  30. package/lib/module/core/UnistylesRuntime.js +1 -1
  31. package/lib/module/core/UnistylesRuntime.js.map +1 -1
  32. package/lib/module/createStyleSheet.js +1 -6
  33. package/lib/module/createStyleSheet.js.map +1 -1
  34. package/lib/module/hooks/index.js +1 -0
  35. package/lib/module/hooks/index.js.map +1 -1
  36. package/lib/module/hooks/useUnistyles.js +5 -8
  37. package/lib/module/hooks/useUnistyles.js.map +1 -1
  38. package/lib/module/hooks/useVariants.js +17 -0
  39. package/lib/module/hooks/useVariants.js.map +1 -0
  40. package/lib/module/plugins/normalizer/normalizer.js +1 -1
  41. package/lib/module/plugins/normalizer/normalizer.js.map +1 -1
  42. package/lib/module/types/stylesheet.js +2 -0
  43. package/lib/module/types/{mq.js.map → stylesheet.js.map} +1 -1
  44. package/lib/module/useStyles.js +6 -5
  45. package/lib/module/useStyles.js.map +1 -1
  46. package/lib/module/utils/index.js +1 -1
  47. package/lib/module/utils/index.js.map +1 -1
  48. package/lib/module/utils/mq.js +35 -67
  49. package/lib/module/utils/mq.js.map +1 -1
  50. package/lib/module/utils/styles.js +15 -9
  51. package/lib/module/utils/styles.js.map +1 -1
  52. package/lib/module/utils/variants.js +31 -11
  53. package/lib/module/utils/variants.js.map +1 -1
  54. package/lib/typescript/src/common.d.ts +10 -10
  55. package/lib/typescript/src/common.d.ts.map +1 -1
  56. package/lib/typescript/src/createStyleSheet.d.ts +2 -2
  57. package/lib/typescript/src/createStyleSheet.d.ts.map +1 -1
  58. package/lib/typescript/src/global.d.ts.map +1 -1
  59. package/lib/typescript/src/hooks/index.d.ts +1 -0
  60. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  61. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -1
  62. package/lib/typescript/src/hooks/useVariants.d.ts +3 -0
  63. package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -0
  64. package/lib/typescript/src/plugins/normalizer/normalizer.d.ts.map +1 -1
  65. package/lib/typescript/src/types/breakpoints.d.ts +24 -15
  66. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  67. package/lib/typescript/src/types/core.d.ts +5 -29
  68. package/lib/typescript/src/types/core.d.ts.map +1 -1
  69. package/lib/typescript/src/types/index.d.ts +2 -2
  70. package/lib/typescript/src/types/index.d.ts.map +1 -1
  71. package/lib/typescript/src/types/stylesheet.d.ts +40 -0
  72. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -0
  73. package/lib/typescript/src/types/unistyles.d.ts +5 -6
  74. package/lib/typescript/src/types/unistyles.d.ts.map +1 -1
  75. package/lib/typescript/src/types/variants.d.ts +13 -7
  76. package/lib/typescript/src/types/variants.d.ts.map +1 -1
  77. package/lib/typescript/src/useStyles.d.ts +3 -3
  78. package/lib/typescript/src/useStyles.d.ts.map +1 -1
  79. package/lib/typescript/src/utils/index.d.ts +1 -1
  80. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  81. package/lib/typescript/src/utils/mq.d.ts +15 -14
  82. package/lib/typescript/src/utils/mq.d.ts.map +1 -1
  83. package/lib/typescript/src/utils/styles.d.ts +3 -3
  84. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  85. package/lib/typescript/src/utils/variants.d.ts +2 -2
  86. package/lib/typescript/src/utils/variants.d.ts.map +1 -1
  87. package/package.json +15 -15
  88. package/src/common.ts +10 -10
  89. package/src/core/UnistylesRuntime.ts +1 -1
  90. package/src/createStyleSheet.ts +2 -8
  91. package/src/global.ts +1 -0
  92. package/src/hooks/index.ts +1 -0
  93. package/src/hooks/useUnistyles.ts +5 -8
  94. package/src/hooks/useVariants.ts +23 -0
  95. package/src/plugins/normalizer/normalizer.ts +3 -3
  96. package/src/types/breakpoints.ts +51 -27
  97. package/src/types/core.ts +8 -45
  98. package/src/types/index.ts +1 -2
  99. package/src/types/stylesheet.ts +49 -0
  100. package/src/types/unistyles.ts +5 -6
  101. package/src/types/variants.ts +17 -9
  102. package/src/useStyles.ts +15 -15
  103. package/src/utils/index.ts +1 -1
  104. package/src/utils/mq.ts +31 -84
  105. package/src/utils/styles.ts +18 -17
  106. package/src/utils/variants.ts +41 -17
  107. package/lib/module/types/mq.js +0 -2
  108. package/lib/typescript/src/types/mq.d.ts +0 -3
  109. package/lib/typescript/src/types/mq.d.ts.map +0 -1
  110. package/src/types/mq.ts +0 -3
@@ -1,37 +1,61 @@
1
- import type { Optional, CustomNamedStyles, NestedStyle } from '../types'
1
+ import type { Optional, StyleSheet, NestedStyle } from '../types'
2
2
 
3
- const getKeyForVariant = (value: Record<string, NestedStyle>, variant?: string): Optional<string> => {
4
- if (variant && variant in value) {
5
- return variant
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
- if ('default' in value) {
9
- return 'default'
16
+ return undefined
17
+ })
18
+ .filter(Boolean) as Array<[string, string]>
10
19
  }
11
20
 
12
- return undefined
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 getStyleWithVariant = <T>(
16
- style: CustomNamedStyles<T>,
17
- variant?: string
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 variantKey = getKeyForVariant(
46
+ const keys = getKeysForVariants(
24
47
  style.variants as Record<string, NestedStyle>,
25
- variant
48
+ Object.entries(variantValues || {})
26
49
  )
27
- const variantValue = variantKey
28
- ? (style.variants as Record<string, NestedStyle>)[variantKey]
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
- ...variantValue
59
+ ...variantsValues
36
60
  }
37
61
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=mq.js.map
@@ -1,3 +0,0 @@
1
- import { MQSymbol } from '../utils';
2
- export type MediaQuery = typeof MQSymbol;
3
- //# sourceMappingURL=mq.d.ts.map
@@ -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
@@ -1,3 +0,0 @@
1
- import { MQSymbol } from '../utils'
2
-
3
- export type MediaQuery = typeof MQSymbol