@react-native-styled-system/core 1.4.1 → 1.4.4

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.
Files changed (107) hide show
  1. package/lib/commonjs/@types/AnyStyle.js +6 -0
  2. package/lib/commonjs/@types/AnyStyle.js.map +1 -0
  3. package/lib/commonjs/@types/ThemedDict.js +4 -0
  4. package/lib/commonjs/@types/ThemedDict.js.map +1 -1
  5. package/lib/commonjs/hook/useSx.js.map +1 -1
  6. package/lib/commonjs/hook/useSxTokens.js.map +1 -1
  7. package/lib/commonjs/internal/TokenParser/RadiiParser.js.map +1 -1
  8. package/lib/commonjs/internal/TokenParser/SizesParser.js.map +1 -1
  9. package/lib/commonjs/internal/TokenParser/SpaceParser.js.map +1 -1
  10. package/lib/commonjs/internal/TokenParser/TypographyParser.js +1 -1
  11. package/lib/commonjs/internal/TokenParser/TypographyParser.js.map +1 -1
  12. package/lib/commonjs/internal/util/StyleHash.js +1 -1
  13. package/lib/commonjs/internal/util/StyleHash.js.map +1 -1
  14. package/lib/commonjs/package.json +1 -0
  15. package/lib/commonjs/provider/StyledSystemProvider.js +6 -4
  16. package/lib/commonjs/provider/StyledSystemProvider.js.map +1 -1
  17. package/lib/commonjs/util/createSxComponent.js +8 -7
  18. package/lib/commonjs/util/createSxComponent.js.map +1 -1
  19. package/lib/commonjs/util/propsToThemedStyle.js +0 -2
  20. package/lib/commonjs/util/propsToThemedStyle.js.map +1 -1
  21. package/lib/module/@types/AnyStyle.js +4 -0
  22. package/lib/module/@types/AnyStyle.js.map +1 -0
  23. package/lib/module/@types/SxProps.js +2 -0
  24. package/lib/module/@types/SxProps.js.map +1 -1
  25. package/lib/module/@types/ThemedDict.js +6 -0
  26. package/lib/module/@types/ThemedDict.js.map +1 -1
  27. package/lib/module/@types/ThemedTypings.js +2 -0
  28. package/lib/module/@types/Token.js +2 -0
  29. package/lib/module/hook/useSx.js +2 -0
  30. package/lib/module/hook/useSx.js.map +1 -1
  31. package/lib/module/hook/useSxStyle.js +2 -0
  32. package/lib/module/hook/useSxStyle.js.map +1 -1
  33. package/lib/module/hook/useSxTokens.js +2 -0
  34. package/lib/module/hook/useSxTokens.js.map +1 -1
  35. package/lib/module/index.js +2 -0
  36. package/lib/module/index.js.map +1 -1
  37. package/lib/module/internal/TokenParser/ColorsParser.js +2 -0
  38. package/lib/module/internal/TokenParser/ColorsParser.js.map +1 -1
  39. package/lib/module/internal/TokenParser/RadiiParser.js +2 -0
  40. package/lib/module/internal/TokenParser/RadiiParser.js.map +1 -1
  41. package/lib/module/internal/TokenParser/SizesParser.js +2 -0
  42. package/lib/module/internal/TokenParser/SizesParser.js.map +1 -1
  43. package/lib/module/internal/TokenParser/SpaceParser.js +2 -0
  44. package/lib/module/internal/TokenParser/SpaceParser.js.map +1 -1
  45. package/lib/module/internal/TokenParser/TokenParser.js +2 -0
  46. package/lib/module/internal/TokenParser/TokenParser.js.map +1 -1
  47. package/lib/module/internal/TokenParser/TypographyParser.js +2 -0
  48. package/lib/module/internal/TokenParser/TypographyParser.js.map +1 -1
  49. package/lib/module/internal/useStableCallback.js +2 -0
  50. package/lib/module/internal/useStableCallback.js.map +1 -1
  51. package/lib/module/internal/util/StyleHash.js +2 -0
  52. package/lib/module/internal/util/StyleHash.js.map +1 -1
  53. package/lib/module/internal/util/fillNullishThemeKey.js +2 -0
  54. package/lib/module/internal/util/fillNullishThemeKey.js.map +1 -1
  55. package/lib/module/internal/util/fillStyleIfNotNullish.js +2 -0
  56. package/lib/module/internal/util/fillStyleIfNotNullish.js.map +1 -1
  57. package/lib/module/internal/util/mutateShortcutPropToOriginalKeys.js +2 -0
  58. package/lib/module/internal/util/mutateShortcutPropToOriginalKeys.js.map +1 -1
  59. package/lib/module/internal/util/parsePxSuffixNumber.js +2 -0
  60. package/lib/module/internal/util/parsePxSuffixNumber.js.map +1 -1
  61. package/lib/module/internal/util/printWarning.js +2 -0
  62. package/lib/module/internal/util/printWarning.js.map +1 -1
  63. package/lib/module/provider/StyledSystemProvider.js +7 -3
  64. package/lib/module/provider/StyledSystemProvider.js.map +1 -1
  65. package/lib/module/util/createSxComponent.js +9 -5
  66. package/lib/module/util/createSxComponent.js.map +1 -1
  67. package/lib/module/util/propsToThemedStyle.js +1 -1
  68. package/lib/module/util/propsToThemedStyle.js.map +1 -1
  69. package/lib/typescript/src/@types/AnyStyle.d.ts +3 -0
  70. package/lib/typescript/src/@types/AnyStyle.d.ts.map +1 -0
  71. package/lib/typescript/src/@types/ThemedDict.d.ts.map +1 -1
  72. package/lib/typescript/src/@types/ThemedTypings.d.ts.map +1 -1
  73. package/lib/typescript/src/@types/Token.d.ts +3 -0
  74. package/lib/typescript/src/@types/Token.d.ts.map +1 -1
  75. package/lib/typescript/src/hook/useSx.d.ts +5 -4
  76. package/lib/typescript/src/hook/useSx.d.ts.map +1 -1
  77. package/lib/typescript/src/hook/useSxStyle.d.ts.map +1 -1
  78. package/lib/typescript/src/hook/useSxTokens.d.ts.map +1 -1
  79. package/lib/typescript/src/internal/TokenParser/ColorsParser.d.ts +1 -1
  80. package/lib/typescript/src/internal/TokenParser/ColorsParser.d.ts.map +1 -1
  81. package/lib/typescript/src/internal/TokenParser/RadiiParser.d.ts +1 -1
  82. package/lib/typescript/src/internal/TokenParser/RadiiParser.d.ts.map +1 -1
  83. package/lib/typescript/src/internal/TokenParser/SizesParser.d.ts +1 -1
  84. package/lib/typescript/src/internal/TokenParser/SizesParser.d.ts.map +1 -1
  85. package/lib/typescript/src/internal/TokenParser/SpaceParser.d.ts +2 -2
  86. package/lib/typescript/src/internal/TokenParser/SpaceParser.d.ts.map +1 -1
  87. package/lib/typescript/src/internal/TokenParser/TokenParser.d.ts +6 -6
  88. package/lib/typescript/src/internal/TokenParser/TokenParser.d.ts.map +1 -1
  89. package/lib/typescript/src/internal/TokenParser/TypographyParser.d.ts +1 -1
  90. package/lib/typescript/src/internal/TokenParser/TypographyParser.d.ts.map +1 -1
  91. package/lib/typescript/src/internal/util/fillNullishThemeKey.d.ts.map +1 -1
  92. package/lib/typescript/src/internal/util/printWarning.d.ts.map +1 -1
  93. package/lib/typescript/src/provider/StyledSystemProvider.d.ts.map +1 -1
  94. package/lib/typescript/src/util/createSxComponent.d.ts +4 -4
  95. package/lib/typescript/src/util/createSxComponent.d.ts.map +1 -1
  96. package/lib/typescript/src/util/propsToThemedStyle.d.ts +5 -5
  97. package/lib/typescript/src/util/propsToThemedStyle.d.ts.map +1 -1
  98. package/package.json +14 -17
  99. package/src/@types/AnyStyle.ts +3 -0
  100. package/src/@types/ThemedDict.ts +3 -0
  101. package/src/@types/ThemedTypings.ts +3 -0
  102. package/src/@types/Token.ts +3 -0
  103. package/src/hook/useSx.test.ts +1 -1
  104. package/src/hook/useSx.ts +8 -7
  105. package/src/hook/useSxStyle.test.ts +1 -1
  106. package/src/hook/useSxTokens.test.ts +1 -1
  107. package/src/util/propsToThemedStyle.ts +7 -5
package/src/hook/useSx.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { useContext, useMemo } from 'react';
2
- import type { StyleProp, TextStyle, ViewStyle } from 'react-native';
2
+ import type { StyleProp } from 'react-native';
3
3
  import { StyleSheet } from 'react-native';
4
4
  import { is } from '@mj-studio/js-util';
5
5
 
6
+ import type { AnyStyle } from '../@types/AnyStyle';
6
7
  import type { SxPropsKeys, TextSxProps } from '../@types/SxProps';
7
8
  import { _textStylePropList, _viewStylePropList } from '../@types/SxProps';
8
9
  import type { ThemedDict } from '../@types/ThemedDict';
@@ -16,7 +17,7 @@ import { propsToThemedStyle } from '../util/propsToThemedStyle';
16
17
 
17
18
  type Props = { style?: StyleProp<any> } & TextSxProps;
18
19
 
19
- export type StyleTransform = (style: TextStyle) => TextSxProps;
20
+ export type StyleTransform = (style: AnyStyle) => TextSxProps;
20
21
  export type StyleFallback = Omit<TextSxProps, 'sx'>;
21
22
  export type UseSxOptions = {
22
23
  theme?: ThemedDict;
@@ -26,7 +27,7 @@ export type UseSxOptions = {
26
27
  cache?: boolean;
27
28
  };
28
29
  const defaultUseSxOptions: UseSxOptions = { styleType: 'ViewStyle' };
29
- export const useSx = <S extends ViewStyle = ViewStyle, P extends Props = Props>(
30
+ export const useSx = <P extends Props = Props>(
30
31
  props?: P | null,
31
32
  {
32
33
  theme: optionTheme,
@@ -38,13 +39,13 @@ export const useSx = <S extends ViewStyle = ViewStyle, P extends Props = Props>(
38
39
  ) => {
39
40
  const styledSystemContext = useContext(StyledSystemContext);
40
41
 
41
- const getStyle = useStableCallback((): StyleProp<S> | undefined => {
42
+ const getStyle = useStableCallback((): StyleProp<AnyStyle> | undefined => {
42
43
  const skip = !props && !fallback;
43
44
  const theme = optionTheme ?? styledSystemContext?.theme;
44
45
 
45
46
  if (skip) {
46
47
  if (is.function(transform)) {
47
- return propsToThemedStyle({ theme, sx: transform({}) }) as S;
48
+ return propsToThemedStyle({ theme, sx: transform({}) });
48
49
  } else {
49
50
  return;
50
51
  }
@@ -83,13 +84,13 @@ export const useSx = <S extends ViewStyle = ViewStyle, P extends Props = Props>(
83
84
  if (cache) {
84
85
  return getCachedStyle(ret);
85
86
  } else {
86
- return ret as StyleProp<S>;
87
+ return ret;
87
88
  }
88
89
  } else {
89
90
  if (cache) {
90
91
  return getCachedStyle(composedStyle);
91
92
  } else {
92
- return composedStyle as StyleProp<S>;
93
+ return composedStyle;
93
94
  }
94
95
  }
95
96
  });
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet } from 'react-native';
2
- import { renderHook } from '@testing-library/react-hooks';
2
+ import { renderHook } from '@testing-library/react-native';
3
3
 
4
4
  import type { TextSxProps } from '../@types/SxProps';
5
5
  import type { ThemedDict } from '../@types/ThemedDict';
@@ -1,4 +1,4 @@
1
- import { renderHook } from '@testing-library/react-hooks';
1
+ import { renderHook } from '@testing-library/react-native';
2
2
 
3
3
  import type { ThemedDict } from '../@types/ThemedDict';
4
4
  import type { ThemedTypings } from '../@types/ThemedTypings';
@@ -1,6 +1,4 @@
1
- /* eslint-disable padding-line-between-statements */
2
- import type { TextStyle } from 'react-native';
3
-
1
+ import type { AnyStyle } from '../@types/AnyStyle';
4
2
  import type { TextSxProps } from '../@types/SxProps';
5
3
  import type { ThemedDict } from '../@types/ThemedDict';
6
4
  import { createTokenParsers } from '../internal/TokenParser/TokenParser';
@@ -19,11 +17,12 @@ export const propsToThemedStyle = ({
19
17
  theme?: ThemedDict;
20
18
  sx?: TextSxProps;
21
19
  styleType?: ThemedStyleType;
22
- }): TextStyle | undefined => {
23
- const ret: TextStyle = {};
20
+ }): AnyStyle | undefined => {
21
+ const ret: AnyStyle = {};
24
22
 
25
23
  if (!theme) {
26
24
  printWarning('theme not found');
25
+
27
26
  return;
28
27
  }
29
28
 
@@ -82,16 +81,19 @@ export const propsToThemedStyle = ({
82
81
  'borderTopLeftRadius',
83
82
  radii(sx.borderTopLeftRadius ?? sx.topLeftRadius),
84
83
  );
84
+
85
85
  fillViewStyleIfNotNullish(
86
86
  ret,
87
87
  'borderTopRightRadius',
88
88
  radii(sx.borderTopRightRadius ?? sx.topRightRadius),
89
89
  );
90
+
90
91
  fillViewStyleIfNotNullish(
91
92
  ret,
92
93
  'borderBottomLeftRadius',
93
94
  radii(sx.borderBottomLeftRadius ?? sx.bottomLeftRadius),
94
95
  );
96
+
95
97
  fillViewStyleIfNotNullish(
96
98
  ret,
97
99
  'borderBottomRightRadius',