@react-native-styled-system/core 1.4.2 → 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.
- package/lib/commonjs/@types/AnyStyle.js +6 -0
- package/lib/commonjs/@types/AnyStyle.js.map +1 -0
- package/lib/commonjs/@types/ThemedDict.js +4 -0
- package/lib/commonjs/@types/ThemedDict.js.map +1 -1
- package/lib/commonjs/hook/useSx.js.map +1 -1
- package/lib/commonjs/hook/useSxTokens.js.map +1 -1
- package/lib/commonjs/internal/TokenParser/RadiiParser.js.map +1 -1
- package/lib/commonjs/internal/TokenParser/SizesParser.js.map +1 -1
- package/lib/commonjs/internal/TokenParser/SpaceParser.js.map +1 -1
- package/lib/commonjs/internal/TokenParser/TypographyParser.js +1 -1
- package/lib/commonjs/internal/TokenParser/TypographyParser.js.map +1 -1
- package/lib/commonjs/internal/util/StyleHash.js +1 -1
- package/lib/commonjs/internal/util/StyleHash.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/provider/StyledSystemProvider.js +6 -4
- package/lib/commonjs/provider/StyledSystemProvider.js.map +1 -1
- package/lib/commonjs/util/createSxComponent.js +8 -7
- package/lib/commonjs/util/createSxComponent.js.map +1 -1
- package/lib/commonjs/util/propsToThemedStyle.js +0 -2
- package/lib/commonjs/util/propsToThemedStyle.js.map +1 -1
- package/lib/module/@types/AnyStyle.js +4 -0
- package/lib/module/@types/AnyStyle.js.map +1 -0
- package/lib/module/@types/SxProps.js +2 -0
- package/lib/module/@types/SxProps.js.map +1 -1
- package/lib/module/@types/ThemedDict.js +6 -0
- package/lib/module/@types/ThemedDict.js.map +1 -1
- package/lib/module/@types/ThemedTypings.js +2 -0
- package/lib/module/@types/Token.js +2 -0
- package/lib/module/hook/useSx.js +2 -0
- package/lib/module/hook/useSx.js.map +1 -1
- package/lib/module/hook/useSxStyle.js +2 -0
- package/lib/module/hook/useSxStyle.js.map +1 -1
- package/lib/module/hook/useSxTokens.js +2 -0
- package/lib/module/hook/useSxTokens.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal/TokenParser/ColorsParser.js +2 -0
- package/lib/module/internal/TokenParser/ColorsParser.js.map +1 -1
- package/lib/module/internal/TokenParser/RadiiParser.js +2 -0
- package/lib/module/internal/TokenParser/RadiiParser.js.map +1 -1
- package/lib/module/internal/TokenParser/SizesParser.js +2 -0
- package/lib/module/internal/TokenParser/SizesParser.js.map +1 -1
- package/lib/module/internal/TokenParser/SpaceParser.js +2 -0
- package/lib/module/internal/TokenParser/SpaceParser.js.map +1 -1
- package/lib/module/internal/TokenParser/TokenParser.js +2 -0
- package/lib/module/internal/TokenParser/TokenParser.js.map +1 -1
- package/lib/module/internal/TokenParser/TypographyParser.js +2 -0
- package/lib/module/internal/TokenParser/TypographyParser.js.map +1 -1
- package/lib/module/internal/useStableCallback.js +2 -0
- package/lib/module/internal/useStableCallback.js.map +1 -1
- package/lib/module/internal/util/StyleHash.js +2 -0
- package/lib/module/internal/util/StyleHash.js.map +1 -1
- package/lib/module/internal/util/fillNullishThemeKey.js +2 -0
- package/lib/module/internal/util/fillNullishThemeKey.js.map +1 -1
- package/lib/module/internal/util/fillStyleIfNotNullish.js +2 -0
- package/lib/module/internal/util/fillStyleIfNotNullish.js.map +1 -1
- package/lib/module/internal/util/mutateShortcutPropToOriginalKeys.js +2 -0
- package/lib/module/internal/util/mutateShortcutPropToOriginalKeys.js.map +1 -1
- package/lib/module/internal/util/parsePxSuffixNumber.js +2 -0
- package/lib/module/internal/util/parsePxSuffixNumber.js.map +1 -1
- package/lib/module/internal/util/printWarning.js +2 -0
- package/lib/module/internal/util/printWarning.js.map +1 -1
- package/lib/module/provider/StyledSystemProvider.js +7 -3
- package/lib/module/provider/StyledSystemProvider.js.map +1 -1
- package/lib/module/util/createSxComponent.js +9 -5
- package/lib/module/util/createSxComponent.js.map +1 -1
- package/lib/module/util/propsToThemedStyle.js +1 -1
- package/lib/module/util/propsToThemedStyle.js.map +1 -1
- package/lib/typescript/src/@types/AnyStyle.d.ts +3 -0
- package/lib/typescript/src/@types/AnyStyle.d.ts.map +1 -0
- package/lib/typescript/src/@types/ThemedDict.d.ts.map +1 -1
- package/lib/typescript/src/@types/ThemedTypings.d.ts.map +1 -1
- package/lib/typescript/src/@types/Token.d.ts +3 -0
- package/lib/typescript/src/@types/Token.d.ts.map +1 -1
- package/lib/typescript/src/hook/useSx.d.ts +5 -4
- package/lib/typescript/src/hook/useSx.d.ts.map +1 -1
- package/lib/typescript/src/hook/useSxStyle.d.ts.map +1 -1
- package/lib/typescript/src/hook/useSxTokens.d.ts.map +1 -1
- package/lib/typescript/src/internal/TokenParser/ColorsParser.d.ts +1 -1
- package/lib/typescript/src/internal/TokenParser/ColorsParser.d.ts.map +1 -1
- package/lib/typescript/src/internal/TokenParser/RadiiParser.d.ts +1 -1
- package/lib/typescript/src/internal/TokenParser/RadiiParser.d.ts.map +1 -1
- package/lib/typescript/src/internal/TokenParser/SizesParser.d.ts +1 -1
- package/lib/typescript/src/internal/TokenParser/SizesParser.d.ts.map +1 -1
- package/lib/typescript/src/internal/TokenParser/SpaceParser.d.ts +2 -2
- package/lib/typescript/src/internal/TokenParser/SpaceParser.d.ts.map +1 -1
- package/lib/typescript/src/internal/TokenParser/TokenParser.d.ts +6 -6
- package/lib/typescript/src/internal/TokenParser/TokenParser.d.ts.map +1 -1
- package/lib/typescript/src/internal/TokenParser/TypographyParser.d.ts +1 -1
- package/lib/typescript/src/internal/TokenParser/TypographyParser.d.ts.map +1 -1
- package/lib/typescript/src/internal/util/fillNullishThemeKey.d.ts.map +1 -1
- package/lib/typescript/src/internal/util/printWarning.d.ts.map +1 -1
- package/lib/typescript/src/provider/StyledSystemProvider.d.ts.map +1 -1
- package/lib/typescript/src/util/createSxComponent.d.ts +4 -4
- package/lib/typescript/src/util/createSxComponent.d.ts.map +1 -1
- package/lib/typescript/src/util/propsToThemedStyle.d.ts +5 -5
- package/lib/typescript/src/util/propsToThemedStyle.d.ts.map +1 -1
- package/package.json +12 -15
- package/src/@types/AnyStyle.ts +3 -0
- package/src/@types/ThemedDict.ts +3 -0
- package/src/@types/ThemedTypings.ts +3 -0
- package/src/@types/Token.ts +3 -0
- package/src/hook/useSx.test.ts +1 -1
- package/src/hook/useSx.ts +8 -7
- package/src/hook/useSxStyle.test.ts +1 -1
- package/src/hook/useSxTokens.test.ts +1 -1
- 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
|
|
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:
|
|
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 = <
|
|
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<
|
|
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({}) })
|
|
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
|
|
87
|
+
return ret;
|
|
87
88
|
}
|
|
88
89
|
} else {
|
|
89
90
|
if (cache) {
|
|
90
91
|
return getCachedStyle(composedStyle);
|
|
91
92
|
} else {
|
|
92
|
-
return composedStyle
|
|
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-
|
|
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,6 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
}):
|
|
23
|
-
const ret:
|
|
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',
|