rn-css 1.11.9 → 2.0.0
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/dist/convertUnits.js +3 -3
- package/dist/features.d.ts +11 -11
- package/dist/index.d.ts +1469 -1705
- package/dist/index.js +1 -3
- package/dist/styleComponent.d.ts +15 -15
- package/dist/styleComponent.js +3 -2
- package/dist/useTheme.d.ts +1 -1
- package/package.json +37 -16
- package/src/convertUnits.ts +3 -3
- package/src/features.tsx +8 -8
- package/src/index.tsx +1 -3
- package/src/styleComponent.tsx +16 -15
- package/src/useTheme.tsx +2 -2
package/dist/index.js
CHANGED
|
@@ -40,11 +40,9 @@ styled.Image = styled(RN.Image);
|
|
|
40
40
|
styled.ImageBackground = styled(RN.ImageBackground);
|
|
41
41
|
styled.KeyboardAvoidingView = styled(RN.KeyboardAvoidingView);
|
|
42
42
|
styled.Modal = styled(RN.Modal);
|
|
43
|
-
styled.
|
|
43
|
+
styled.Pressable = styled(RN.Pressable);
|
|
44
44
|
styled.ScrollView = styled(RN.ScrollView);
|
|
45
|
-
styled.SnapshotViewIOS = styled(RN.SnapshotViewIOS);
|
|
46
45
|
styled.Switch = styled(RN.Switch);
|
|
47
|
-
styled.RecyclerViewBackedScrollView = styled(RN.RecyclerViewBackedScrollView);
|
|
48
46
|
styled.RefreshControl = styled(RN.RefreshControl);
|
|
49
47
|
styled.SafeAreaView = styled(RN.SafeAreaView);
|
|
50
48
|
styled.Text = styled(RN.Text);
|
package/dist/styleComponent.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { MouseEvent } from 'react';
|
|
2
|
-
import { FlatListProps, SectionListProps, StyleProp, TouchableHighlightProps, ViewProps, VirtualizedListProps } from 'react-native';
|
|
2
|
+
import { FlatListProps, PressableProps, SectionListProps, StyleProp, TouchableHighlightProps, ViewProps, VirtualizedListProps } from 'react-native';
|
|
3
3
|
import { FocusEventListener, BlurEventListener } from './features';
|
|
4
4
|
import type { CompleteStyle, Units } from './types';
|
|
5
5
|
export declare const defaultUnits: Units;
|
|
@@ -18,15 +18,15 @@ declare type OptionalProps = {
|
|
|
18
18
|
rnCSS?: `${string};`;
|
|
19
19
|
onFocus?: FocusEventListener;
|
|
20
20
|
onBlur?: BlurEventListener;
|
|
21
|
-
onPressIn?: TouchableHighlightProps['onPressIn'];
|
|
22
|
-
onPressOut?: TouchableHighlightProps['onPressOut'];
|
|
23
|
-
onResponderStart?: ViewProps['onResponderStart'];
|
|
24
|
-
onResponderRelease?: ViewProps['onResponderRelease'];
|
|
25
|
-
onStartShouldSetResponder?: ViewProps['onStartShouldSetResponder'];
|
|
26
|
-
onMouseEnter?: (event: MouseEvent) => void;
|
|
27
|
-
onMouseLeave?: (event: MouseEvent) => void;
|
|
21
|
+
onPressIn?: TouchableHighlightProps['onPressIn'] | null;
|
|
22
|
+
onPressOut?: TouchableHighlightProps['onPressOut'] | null;
|
|
23
|
+
onResponderStart?: ViewProps['onResponderStart'] | null;
|
|
24
|
+
onResponderRelease?: ViewProps['onResponderRelease'] | null;
|
|
25
|
+
onStartShouldSetResponder?: ViewProps['onStartShouldSetResponder'] | null;
|
|
26
|
+
onMouseEnter?: ((event: MouseEvent) => void) | null;
|
|
27
|
+
onMouseLeave?: ((event: MouseEvent) => void) | null;
|
|
28
28
|
onLayout?: ViewProps['onLayout'];
|
|
29
|
-
children?:
|
|
29
|
+
children?: PressableProps['children'];
|
|
30
30
|
};
|
|
31
31
|
declare const styled: <StyleType, InitialProps extends {
|
|
32
32
|
style?: StyleProp<StyleType>;
|
|
@@ -38,14 +38,14 @@ declare const styled: <StyleType, InitialProps extends {
|
|
|
38
38
|
};
|
|
39
39
|
export default styled;
|
|
40
40
|
export declare const styledFlatList: {
|
|
41
|
-
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & FlatListProps<any> & OptionalProps>)[]): <Type>(props: S & OptionalProps & FlatListProps<Type>) => JSX.Element;
|
|
42
|
-
attrs<S_1, Result extends Partial<S_1 & FlatListProps<any> & OptionalProps> = {}>(opts: Result | ((props: S_1 & OptionalProps & FlatListProps<any>) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1>)[]) => <Props>(componentProps: Omit<FlatListProps<Props> & OptionalProps, keyof Result> & S_1 & Partial<Result>) => JSX.Element;
|
|
41
|
+
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & FlatListProps<any> & OptionalProps>)[]): <Type>(props: S & OptionalProps & FlatListProps<Type>) => React.JSX.Element;
|
|
42
|
+
attrs<S_1, Result extends Partial<S_1 & FlatListProps<any> & OptionalProps> = {}>(opts: Result | ((props: S_1 & OptionalProps & FlatListProps<any>) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1>)[]) => <Props>(componentProps: Omit<FlatListProps<Props> & OptionalProps, keyof Result> & S_1 & Partial<Result>) => React.JSX.Element;
|
|
43
43
|
};
|
|
44
44
|
export declare const styledSectionList: {
|
|
45
|
-
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & SectionListProps<any, import("react-native").DefaultSectionT> & OptionalProps>)[]): <Type>(props: S & OptionalProps & SectionListProps<Type, import("react-native").DefaultSectionT>) => JSX.Element;
|
|
46
|
-
attrs<S_1, Result extends Partial<S_1 & SectionListProps<any, import("react-native").DefaultSectionT> & OptionalProps> = {}>(opts: Result | ((props: S_1 & OptionalProps & SectionListProps<any, import("react-native").DefaultSectionT>) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1>)[]) => <Props>(componentProps: Omit<SectionListProps<Props, import("react-native").DefaultSectionT> & OptionalProps, keyof Result> & S_1 & Partial<Result>) => JSX.Element;
|
|
45
|
+
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & SectionListProps<any, import("react-native").DefaultSectionT> & OptionalProps>)[]): <Type>(props: S & OptionalProps & SectionListProps<Type, import("react-native").DefaultSectionT>) => React.JSX.Element;
|
|
46
|
+
attrs<S_1, Result extends Partial<S_1 & SectionListProps<any, import("react-native").DefaultSectionT> & OptionalProps> = {}>(opts: Result | ((props: S_1 & OptionalProps & SectionListProps<any, import("react-native").DefaultSectionT>) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1>)[]) => <Props>(componentProps: Omit<SectionListProps<Props, import("react-native").DefaultSectionT> & OptionalProps, keyof Result> & S_1 & Partial<Result>) => React.JSX.Element;
|
|
47
47
|
};
|
|
48
48
|
export declare const styledVirtualizedList: {
|
|
49
|
-
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & VirtualizedListProps<any> & OptionalProps>)[]): <Type>(props: S & OptionalProps & VirtualizedListProps<Type>) => JSX.Element;
|
|
50
|
-
attrs<S_1, Result extends Partial<S_1 & VirtualizedListProps<any> & OptionalProps> = {}>(opts: Result | ((props: S_1 & OptionalProps & VirtualizedListProps<any>) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1>)[]) => <Props>(componentProps: Omit<VirtualizedListProps<Props> & OptionalProps, keyof Result> & S_1 & Partial<Result>) => JSX.Element;
|
|
49
|
+
<S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & VirtualizedListProps<any> & OptionalProps>)[]): <Type>(props: S & OptionalProps & VirtualizedListProps<Type>) => React.JSX.Element;
|
|
50
|
+
attrs<S_1, Result extends Partial<S_1 & VirtualizedListProps<any> & OptionalProps> = {}>(opts: Result | ((props: S_1 & OptionalProps & VirtualizedListProps<any>) => Result)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1>)[]) => <Props>(componentProps: Omit<VirtualizedListProps<Props> & OptionalProps, keyof Result> & S_1 & Partial<Result>) => React.JSX.Element;
|
|
51
51
|
};
|
package/dist/styleComponent.js
CHANGED
|
@@ -158,8 +158,9 @@ const styled = (Component) => {
|
|
|
158
158
|
const ComponentWithAttrs = styledComponent(chunks, ...functs);
|
|
159
159
|
// We need to limit the props control to only Result https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABBATgUwIZTQUQB7ZgAmaRAwnALYAOAPAAopzUDOAfABQU0BciH1Jqz6NmLAJSIAvG0QYwAT0kBvAFCJkCFlET5CJYt2rT+gsSKETpstRo3ooIFEiMDL49YgC+nvWmL+5FTUAHRYUCgsJrQASmgsIAA2OmgEgVH0GCiwGIkMlmyc4ZF8cQnJkjKItnYQWjqMaHVgwDAA5k5YpEYmbua6eBCJICT5YgA0iGVJUGyVNp52iA5OLsEcyiFbZqyTW2FQESxeHks+SyvOiI3NrR0oXUE0nufLaI5XfgGGwao+qqBILAEIgen1hNVENhtHxtCgYGA2pNtApEmhYREEW1vCpPJckDsWH9VM1tNd0Ld2j0pMh0F0viQntQuMFxAcjhsofEoHwAORwADWvJxqhuCDurmUiBRaL50KgwpOQA
|
|
160
160
|
const ForwardRefComponent = react_1.default.forwardRef((props, ref) => {
|
|
161
|
-
const
|
|
162
|
-
|
|
161
|
+
const castProps = props;
|
|
162
|
+
const attrs = (opts instanceof Function) ? opts(castProps) : opts;
|
|
163
|
+
return react_1.default.createElement(ComponentWithAttrs, { ref: ref, ...castProps, ...attrs });
|
|
163
164
|
});
|
|
164
165
|
// TODO : Find a way to remove from the Props the properties affected by opts
|
|
165
166
|
return ForwardRefComponent;
|
package/dist/useTheme.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { DefaultTheme } from './styleComponent';
|
|
|
4
4
|
export declare const ThemeProvider: ({ theme, children }: {
|
|
5
5
|
theme: DefaultTheme;
|
|
6
6
|
children: React.ReactNode;
|
|
7
|
-
}) => JSX.Element;
|
|
7
|
+
}) => React.JSX.Element;
|
|
8
8
|
/**
|
|
9
9
|
* Returns the Theme
|
|
10
10
|
* @returns The Theme object
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-css",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"import": "./dist/index.js",
|
|
@@ -33,19 +33,29 @@
|
|
|
33
33
|
"web": "webpack serve --open --mode development"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"react": ">=
|
|
37
|
-
"react-native": ">=0.
|
|
36
|
+
"react": ">=19.0.0",
|
|
37
|
+
"react-native": ">=0.82.0",
|
|
38
|
+
"react-native-web": ">=0.21.0",
|
|
39
|
+
"react-dom": ">=19.0.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"react-native-web": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"react-dom": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
38
48
|
},
|
|
39
49
|
"devDependencies": {
|
|
40
50
|
"@babel/core": "^7.16.5",
|
|
51
|
+
"@babel/preset-typescript": "^7.26.0",
|
|
41
52
|
"@babel/runtime": "^7.16.5",
|
|
42
53
|
"@react-native-community/eslint-config": "^3.0.1",
|
|
43
|
-
"@types/jest": "^
|
|
44
|
-
"@types/react": "^
|
|
45
|
-
"@types/react-native": "^0.66.9",
|
|
54
|
+
"@types/jest": "^29.5.12",
|
|
55
|
+
"@types/react": "^19.2.2",
|
|
46
56
|
"@typescript-eslint/eslint-plugin": "^5.7.0",
|
|
47
57
|
"@typescript-eslint/parser": "^5.7.0",
|
|
48
|
-
"babel-jest": "^
|
|
58
|
+
"babel-jest": "^29.7.0",
|
|
49
59
|
"babel-loader": "^8.2.3",
|
|
50
60
|
"dotenv": "^10.0.0",
|
|
51
61
|
"eslint": "^7.32.0",
|
|
@@ -60,17 +70,18 @@
|
|
|
60
70
|
"html-loader": "^3.0.1",
|
|
61
71
|
"html-webpack-plugin": "^5.5.0",
|
|
62
72
|
"husky": "^7.0.4",
|
|
63
|
-
"jest": "^
|
|
73
|
+
"jest": "^29.7.0",
|
|
74
|
+
"jest-environment-jsdom": "^30.2.0",
|
|
64
75
|
"lint-staged": "^12.1.2",
|
|
65
|
-
"metro-react-native-babel-preset": "^0.
|
|
66
|
-
"react": "^
|
|
67
|
-
"react-dom": "^
|
|
68
|
-
"react-native": "^0.
|
|
76
|
+
"metro-react-native-babel-preset": "^0.77.0",
|
|
77
|
+
"react": "^19.2.0",
|
|
78
|
+
"react-dom": "^19.2.0",
|
|
79
|
+
"react-native": "^0.82.0",
|
|
69
80
|
"react-native-typescript-transformer": "^1.2.13",
|
|
70
|
-
"react-native-web": "^0.
|
|
71
|
-
"react-test-renderer": "
|
|
81
|
+
"react-native-web": "^0.21.1",
|
|
82
|
+
"react-test-renderer": "19.2.0",
|
|
72
83
|
"release-it": "^15.6.0",
|
|
73
|
-
"ts-jest": "^
|
|
84
|
+
"ts-jest": "^29.1.2",
|
|
74
85
|
"ts-loader": "^9.2.6",
|
|
75
86
|
"typescript": "^4.5.4",
|
|
76
87
|
"webpack": "^5.72.0",
|
|
@@ -78,7 +89,17 @@
|
|
|
78
89
|
"webpack-dev-server": "^4.8.1"
|
|
79
90
|
},
|
|
80
91
|
"jest": {
|
|
81
|
-
"
|
|
92
|
+
"testEnvironment": "jsdom",
|
|
93
|
+
"transform": {
|
|
94
|
+
"^.+\\.(js|jsx|ts|tsx)$": "babel-jest"
|
|
95
|
+
},
|
|
96
|
+
"setupFilesAfterEnv": [
|
|
97
|
+
"<rootDir>/tests/jest/setup.js"
|
|
98
|
+
],
|
|
99
|
+
"moduleNameMapper": {
|
|
100
|
+
"^react-native$": "<rootDir>/tests/jest/react-native-mock.js",
|
|
101
|
+
"^react-native/jest/mock$": "<rootDir>/tests/jest/rn-mock.js"
|
|
102
|
+
}
|
|
82
103
|
},
|
|
83
104
|
"files": [
|
|
84
105
|
"dist",
|
package/src/convertUnits.ts
CHANGED
|
@@ -23,8 +23,8 @@ export function convertValue (key: keyof PartialStyle | keyof Transform, value:
|
|
|
23
23
|
if (value.includes('%')) {
|
|
24
24
|
// Percentage is not supported on borders in web
|
|
25
25
|
if (Platform.OS === 'web' && (!key.toLowerCase().includes('border') || key.toLowerCase().includes('radius'))) return value
|
|
26
|
-
if (['marginTop', 'marginBottom', 'translateY'].includes(key) || key.startsWith('borderTop') || key.startsWith('borderBottom')) finalUnits['%'] = units.height
|
|
27
|
-
else if (['marginLeft', 'marginRight', 'translateX'].includes(key) || key.startsWith('borderLeft') || key.startsWith('borderRight')) finalUnits['%'] = units.width
|
|
26
|
+
if (['marginTop', 'marginBottom', 'translateY'].includes(key) || key.startsWith('borderTop') || key.startsWith('borderBottom')) finalUnits['%'] = (units.height || 0) / 100
|
|
27
|
+
else if (['marginLeft', 'marginRight', 'translateX'].includes(key) || key.startsWith('borderLeft') || key.startsWith('borderRight')) finalUnits['%'] = (units.width || 0) / 100
|
|
28
28
|
else if (key.startsWith('border') && key.endsWith('Radius')) finalUnits['%'] = ((units.width || 0) + (units.height || 0)) / 200
|
|
29
29
|
else if (['width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight', 'top', 'left', 'bottom', 'right', 'flexBasis', 'rotate3d'].includes(key)) {
|
|
30
30
|
if (value.startsWith('calc') || value.startsWith('max') || value.startsWith('min')) {
|
|
@@ -43,7 +43,7 @@ export function convertValue (key: keyof PartialStyle | keyof Transform, value:
|
|
|
43
43
|
const [val, unit] = parseValue(occ)
|
|
44
44
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
45
45
|
if (['deg', 'rad', 'turn', 's'].includes(unit!)) return occ // We don't want to convert deg, rad, turn, second units
|
|
46
|
-
return val * (finalUnits[unit as keyof Units || 'px']
|
|
46
|
+
return val * (finalUnits[unit as keyof Units || 'px'] ?? 1) + ''
|
|
47
47
|
})
|
|
48
48
|
|
|
49
49
|
// We handle extra calculations (calc, min, max, parsing...)
|
package/src/features.tsx
CHANGED
|
@@ -23,7 +23,7 @@ export const useScreenSize = () => {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** Hook that will apply the style reserved for hover state if needed */
|
|
26
|
-
export const useHover = (onMouseEnter: undefined | ((event: MouseEvent) => void), onMouseLeave: undefined | ((event: MouseEvent) => void | undefined), needsHover: boolean) => {
|
|
26
|
+
export const useHover = (onMouseEnter: null | undefined | ((event: MouseEvent) => void), onMouseLeave: null | undefined | ((event: MouseEvent) => void | undefined), needsHover: boolean) => {
|
|
27
27
|
const [hover, setHover] = React.useState(false)
|
|
28
28
|
const hoverStart = React.useMemo(() => needsHover ? (event: MouseEvent) => {
|
|
29
29
|
if (onMouseEnter) onMouseEnter(event)
|
|
@@ -38,11 +38,11 @@ export const useHover = (onMouseEnter: undefined | ((event: MouseEvent) => void)
|
|
|
38
38
|
|
|
39
39
|
/** Hook that will apply the style reserved for active state if needed */
|
|
40
40
|
export const useActive = (
|
|
41
|
-
onPressIn: undefined | ((event: GestureResponderEvent) => void),
|
|
42
|
-
onPressOut: undefined | ((event: GestureResponderEvent) => void),
|
|
43
|
-
onResponderStart: undefined | ((event: GestureResponderEvent) => void),
|
|
44
|
-
onResponderRelease: undefined | ((event: GestureResponderEvent) => void),
|
|
45
|
-
onStartShouldSetResponder: undefined | ((event: GestureResponderEvent) => void),
|
|
41
|
+
onPressIn: null | undefined | ((event: GestureResponderEvent) => void),
|
|
42
|
+
onPressOut: null | undefined | ((event: GestureResponderEvent) => void),
|
|
43
|
+
onResponderStart: null | undefined | ((event: GestureResponderEvent) => void),
|
|
44
|
+
onResponderRelease: null | undefined | ((event: GestureResponderEvent) => void),
|
|
45
|
+
onStartShouldSetResponder: null | undefined | ((event: GestureResponderEvent) => void),
|
|
46
46
|
needsTouch: boolean
|
|
47
47
|
) => {
|
|
48
48
|
const [active, setActive] = React.useState(false)
|
|
@@ -70,8 +70,8 @@ export const useActive = (
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
export type FocusEventListener = TouchableHighlightProps['onFocus'] | TextInputProps['onFocus']
|
|
74
|
-
export type BlurEventListener = TouchableHighlightProps['onBlur'] | TextInputProps['onBlur']
|
|
73
|
+
export type FocusEventListener = TouchableHighlightProps['onFocus'] | TextInputProps['onFocus'] | null
|
|
74
|
+
export type BlurEventListener = TouchableHighlightProps['onBlur'] | TextInputProps['onBlur'] | null
|
|
75
75
|
/** Hook that will apply the style reserved for active state if needed */
|
|
76
76
|
export const useFocus = (onFocus: undefined | FocusEventListener, onBlur: undefined | BlurEventListener, needsFocus: boolean) => {
|
|
77
77
|
const [focused, setFocused] = React.useState(false)
|
package/src/index.tsx
CHANGED
|
@@ -14,11 +14,9 @@ styled.Image = styled(RN.Image)
|
|
|
14
14
|
styled.ImageBackground = styled(RN.ImageBackground)
|
|
15
15
|
styled.KeyboardAvoidingView = styled(RN.KeyboardAvoidingView)
|
|
16
16
|
styled.Modal = styled(RN.Modal)
|
|
17
|
-
styled.
|
|
17
|
+
styled.Pressable = styled(RN.Pressable)
|
|
18
18
|
styled.ScrollView = styled(RN.ScrollView)
|
|
19
|
-
styled.SnapshotViewIOS = styled(RN.SnapshotViewIOS)
|
|
20
19
|
styled.Switch = styled(RN.Switch)
|
|
21
|
-
styled.RecyclerViewBackedScrollView = styled(RN.RecyclerViewBackedScrollView)
|
|
22
20
|
styled.RefreshControl = styled(RN.RefreshControl)
|
|
23
21
|
styled.SafeAreaView = styled(RN.SafeAreaView)
|
|
24
22
|
styled.Text = styled(RN.Text)
|
package/src/styleComponent.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* eslint-disable react/prop-types */
|
|
3
3
|
/* eslint-disable react/display-name */
|
|
4
4
|
import React, { MouseEvent } from 'react'
|
|
5
|
-
import { FlatList, FlatListProps, Platform, SectionList, SectionListProps, StyleProp, StyleSheet, TouchableHighlightProps, ViewProps, ViewStyle, VirtualizedList, VirtualizedListProps } from 'react-native'
|
|
5
|
+
import { FlatList, FlatListProps, Platform, PressableProps, SectionList, SectionListProps, StyleProp, StyleSheet, TouchableHighlightProps, ViewProps, ViewStyle, VirtualizedList, VirtualizedListProps } from 'react-native'
|
|
6
6
|
import convertStyle from './convertStyle'
|
|
7
7
|
import cssToStyle from './cssToRN'
|
|
8
8
|
import { useFontSize, useHover, useLayout, useScreenSize, useMediaQuery, useActive, useFocus, FocusEventListener, BlurEventListener } from './features'
|
|
@@ -26,15 +26,15 @@ type OptionalProps = {
|
|
|
26
26
|
rnCSS?: `${string};`;
|
|
27
27
|
onFocus?: FocusEventListener;
|
|
28
28
|
onBlur?: BlurEventListener;
|
|
29
|
-
onPressIn?: TouchableHighlightProps['onPressIn'];
|
|
30
|
-
onPressOut?: TouchableHighlightProps['onPressOut'];
|
|
31
|
-
onResponderStart?: ViewProps['onResponderStart'];
|
|
32
|
-
onResponderRelease?: ViewProps['onResponderRelease'];
|
|
33
|
-
onStartShouldSetResponder?: ViewProps['onStartShouldSetResponder'];
|
|
34
|
-
onMouseEnter?: (event: MouseEvent) => void;
|
|
35
|
-
onMouseLeave?: (event: MouseEvent) => void;
|
|
29
|
+
onPressIn?: TouchableHighlightProps['onPressIn'] | null;
|
|
30
|
+
onPressOut?: TouchableHighlightProps['onPressOut'] | null;
|
|
31
|
+
onResponderStart?: ViewProps['onResponderStart'] | null;
|
|
32
|
+
onResponderRelease?: ViewProps['onResponderRelease'] | null;
|
|
33
|
+
onStartShouldSetResponder?: ViewProps['onStartShouldSetResponder'] | null;
|
|
34
|
+
onMouseEnter?: ((event: MouseEvent) => void) | null;
|
|
35
|
+
onMouseLeave?: ((event: MouseEvent) => void) | null;
|
|
36
36
|
onLayout?: ViewProps['onLayout'];
|
|
37
|
-
children?:
|
|
37
|
+
children?: PressableProps['children'];
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/** Converts the tagged template string into a css string */
|
|
@@ -69,11 +69,11 @@ function removeStyle (hash: string) {
|
|
|
69
69
|
|
|
70
70
|
const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }, Props extends InitialProps & OptionalProps = InitialProps & OptionalProps>(Component: React.ComponentType<InitialProps>) => {
|
|
71
71
|
const styledComponent = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & Props>)[]) => {
|
|
72
|
-
const ForwardRefComponent = React.forwardRef<any, S & Props>((props
|
|
72
|
+
const ForwardRefComponent = React.forwardRef<any, S & Props>((props, ref) => {
|
|
73
73
|
const rem = React.useContext(RemContext)
|
|
74
74
|
const shared = React.useContext(SharedValue)
|
|
75
75
|
// Build the css string with the context
|
|
76
|
-
const css = React.useMemo(() => buildCSSString(chunks, functs, props, shared), [props, shared])
|
|
76
|
+
const css = React.useMemo(() => buildCSSString(chunks, functs, (props as unknown as S & Props), shared), [props, shared])
|
|
77
77
|
// Store the style in RN format
|
|
78
78
|
const rnStyle = React.useMemo(() => cssToStyle(css), [css])
|
|
79
79
|
|
|
@@ -172,11 +172,11 @@ const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }
|
|
|
172
172
|
// em !== parentEm alone is a bit dangerous as the component would rerender when the font size change
|
|
173
173
|
if (em !== parentEm || finalStyle.fontSize !== undefined) {
|
|
174
174
|
return <FontSizeContext.Provider value={em}>
|
|
175
|
-
<Component ref={ref} {...props} {...newProps} />
|
|
175
|
+
<Component ref={ref} {...(props as unknown as InitialProps)} {...(newProps as unknown as InitialProps)} />
|
|
176
176
|
</FontSizeContext.Provider>
|
|
177
177
|
}
|
|
178
178
|
else {
|
|
179
|
-
return <Component ref={ref} {...props} {...newProps} />
|
|
179
|
+
return <Component ref={ref} {...(props as unknown as InitialProps)} {...(newProps as unknown as InitialProps)} />
|
|
180
180
|
}
|
|
181
181
|
})
|
|
182
182
|
return ForwardRefComponent as React.ForwardRefExoticComponent<Props & S & { ref?: React.Ref<any> }>
|
|
@@ -187,8 +187,9 @@ const styled = <StyleType, InitialProps extends { style?: StyleProp<StyleType> }
|
|
|
187
187
|
const ComponentWithAttrs = styledComponent(chunks, ...functs)
|
|
188
188
|
// We need to limit the props control to only Result https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABBATgUwIZTQUQB7ZgAmaRAwnALYAOAPAAopzUDOAfABQU0BciH1Jqz6NmLAJSIAvG0QYwAT0kBvAFCJkCFlET5CJYt2rT+gsSKETpstRo3ooIFEiMDL49YgC+nvWmL+5FTUAHRYUCgsJrQASmgsIAA2OmgEgVH0GCiwGIkMlmyc4ZF8cQnJkjKItnYQWjqMaHVgwDAA5k5YpEYmbua6eBCJICT5YgA0iGVJUGyVNp52iA5OLsEcyiFbZqyTW2FQESxeHks+SyvOiI3NrR0oXUE0nufLaI5XfgGGwao+qqBILAEIgen1hNVENhtHxtCgYGA2pNtApEmhYREEW1vCpPJckDsWH9VM1tNd0Ld2j0pMh0F0viQntQuMFxAcjhsofEoHwAORwADWvJxqhuCDurmUiBRaL50KgwpOQA
|
|
189
189
|
const ForwardRefComponent = React.forwardRef<any, Omit<Props, keyof Result> & Part & Partial<Pick<Props, Extract<keyof Props, keyof Result>>>>((props, ref) => {
|
|
190
|
-
const
|
|
191
|
-
|
|
190
|
+
const castProps = props as unknown as Props & Part
|
|
191
|
+
const attrs = (opts instanceof Function) ? opts(castProps) : opts
|
|
192
|
+
return <ComponentWithAttrs ref={ref} {...castProps} {...attrs} />
|
|
192
193
|
})
|
|
193
194
|
// TODO : Find a way to remove from the Props the properties affected by opts
|
|
194
195
|
return ForwardRefComponent
|
package/src/useTheme.tsx
CHANGED
|
@@ -20,9 +20,9 @@ export const useTheme = () => React.useContext(SharedValue)
|
|
|
20
20
|
* @returns A component with the theme prop
|
|
21
21
|
*/
|
|
22
22
|
export const withTheme = <T, >(Component: React.ComponentType<T>) => {
|
|
23
|
-
const ThemedComponent = React.forwardRef<React.Component, T>((props
|
|
23
|
+
const ThemedComponent = React.forwardRef<React.Component, T>((props, ref) => {
|
|
24
24
|
const theme = useTheme()
|
|
25
|
-
return <Component ref={ref} theme={theme} {...props} />
|
|
25
|
+
return <Component ref={ref} theme={theme} {...(props as unknown as T)} />
|
|
26
26
|
})
|
|
27
27
|
ThemedComponent.displayName = 'ThemedComponent'
|
|
28
28
|
return ThemedComponent
|