@codeandmoney/soelma 0.0.0-dev.1 → 0.0.0-dev.10
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/.eslintignore +1 -0
- package/.eslintrc.js +27 -0
- package/.github/workflows/nodejs.yml +33 -0
- package/.size-limit.json +6 -0
- package/babel.config.js +3 -0
- package/biome.jsonc +73 -0
- package/docs/api.md +103 -0
- package/docs/appearance.md +54 -0
- package/docs/dark-mode.md +46 -0
- package/docs/dimensions.md +29 -0
- package/docs/i18n.md +67 -0
- package/docs/logo.png +0 -0
- package/docs/media-query.md +274 -0
- package/docs/orientation.md +44 -0
- package/docs/safe-area.md +62 -0
- package/docs/testting.md +51 -0
- package/docs/ts.md +127 -0
- package/example/AppStyleX/.watchmanconfig +1 -0
- package/example/AppStyleX/android/build.gradle +26 -0
- package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/example/AppStyleX/android/gradle.properties +53 -0
- package/example/AppStyleX/android/gradlew +249 -0
- package/example/AppStyleX/android/gradlew.bat +92 -0
- package/example/AppStyleX/android/settings.gradle +12 -0
- package/example/AppStyleX/app.json +16 -0
- package/example/AppStyleX/babel.config.js +3 -0
- package/example/AppStyleX/index.js +9 -0
- package/example/AppStyleX/ios/Podfile +7 -0
- package/example/AppStyleX/ios/Podfile.lock +1252 -0
- package/example/AppStyleX/metro.config.js +51 -0
- package/example/AppStyleX/package.json +43 -0
- package/example/AppStyleX/react-native.config.js +23 -0
- package/example/AppStyleX/src/App.tsx +22 -0
- package/example/AppStyleX/src/BottomNav/index.tsx +26 -0
- package/example/AppStyleX/src/BottomNav/styles.ts +42 -0
- package/example/AppStyleX/src/Circle/index.tsx +53 -0
- package/example/AppStyleX/src/Circle/styles.ts +22 -0
- package/example/AppStyleX/src/Root/index.tsx +35 -0
- package/example/AppStyleX/src/Root/styles.ts +18 -0
- package/example/AppStyleX/src/ToggleButton/index.tsx +52 -0
- package/example/AppStyleX/src/ToggleButton/styles.ts +67 -0
- package/example/AppStyleX/src/style-system/hooks/useAnimatedBgColor.ts +5 -0
- package/example/AppStyleX/src/style-system/hooks/useAnimatedTextColor.ts +5 -0
- package/example/AppStyleX/src/style-system/hooks/useIsDark.ts +8 -0
- package/example/AppStyleX/src/style-system/palette.ts +11 -0
- package/example/AppStyleX/src/style-system/theme.ts +14 -0
- package/example/AppStyleX/src/style-system/utils.ts +8 -0
- package/example/AppStyleX/src/stylex.d.ts +6 -0
- package/example/AppStyleX/tsconfig.json +3 -0
- package/example/AppStyleX/yarn.lock +6767 -0
- package/jest.config.js +19 -0
- package/package.json +38 -3
- package/src/appearance/index.ts +30 -0
- package/src/appearance/init.ts +12 -0
- package/{context.js → src/context.ts} +4 -1
- package/src/create-event-emitter.ts +26 -0
- package/src/dark-mode/index.ts +26 -0
- package/src/dark-mode/init.ts +19 -0
- package/{dark-mode/state.js → src/dark-mode/state.ts} +2 -1
- package/src/default-theme.ts +4 -0
- package/src/dependency-registry.ts +21 -0
- package/src/dependency-usage.ts +21 -0
- package/src/dimensions/index.ts +20 -0
- package/src/dimensions/init.ts +32 -0
- package/src/dimensions/utils.ts +9 -0
- package/src/i18n.ts +15 -0
- package/src/index.ts +7 -0
- package/{makeUseStyles/createUseStylesTheme.js → src/make-use-styles/create-use-styles-theme.js} +23 -6
- package/src/make-use-styles/create-use-styles-theme.test.js +137 -0
- package/{makeUseStyles/createUseStylesWithoutTheme.js → src/make-use-styles/create-use-styles-without-theme.js} +20 -4
- package/src/make-use-styles/create-use-styles-without-theme.test.js +63 -0
- package/src/make-use-styles/index.d.ts +20 -0
- package/src/make-use-styles/index.js +12 -0
- package/src/make-use-styles/index.test.js +28 -0
- package/src/make-use-styles/types.ts +43 -0
- package/{makeUseStyles → src/make-use-styles}/utils.js +5 -10
- package/src/media-query/base.ts +32 -0
- package/src/media-query/breakpoints.ts +96 -0
- package/src/media-query/index.ts +12 -0
- package/src/orientation.ts +13 -0
- package/{safe-area/eventEmitter.js → src/safe-area/event-emitter.ts} +2 -1
- package/src/safe-area/index.tsx +16 -0
- package/src/safe-area/init.tsx +6 -0
- package/src/safe-area/safe-area-provider.tsx +18 -0
- package/{safe-area/state.js → src/safe-area/state.ts} +7 -5
- package/src/safe-area/stylex-save-area-consumer.ts +22 -0
- package/{safe-area/types.d.ts → src/safe-area/types.ts} +7 -6
- package/src/tests/createBreakpoints.test.ts +152 -0
- package/src/tests/createBreakpointsMatcher.test.ts +188 -0
- package/src/tests/createBreakpointsMatcher.types-test.ts +81 -0
- package/src/tests/createEventEmitter.test.ts +37 -0
- package/src/tests/dark-mode.test.ts +56 -0
- package/src/tests/dependencyRegistry.test.ts +16 -0
- package/src/tests/dependencyUsage.test.ts +13 -0
- package/src/tests/dimensions.test.ts +33 -0
- package/src/tests/makeUseStyles.types-test.ts +69 -0
- package/src/tests/media-query.test.ts +196 -0
- package/src/tests/orientation.test.ts +61 -0
- package/src/tests/useTheme.test.ts +26 -0
- package/src/tests/withStyles.types-test.tsx +172 -0
- package/src/use-color-transition.ts +50 -0
- package/src/use-theme.ts +14 -0
- package/src/with-styles.tsx +22 -0
- package/tsconfig.build.json +31 -0
- package/tsconfig.json +30 -0
- package/DefaultTheme.d.ts +0 -2
- package/DefaultTheme.js +0 -1
- package/appearance/consts.d.ts +0 -1
- package/appearance/index.d.ts +0 -8
- package/appearance/index.js +0 -18
- package/appearance/init.d.ts +0 -1
- package/appearance/init.js +0 -7
- package/context.d.ts +0 -4
- package/createEventEmitter.d.ts +0 -8
- package/createEventEmitter.js +0 -11
- package/dark-mode/consts.d.ts +0 -1
- package/dark-mode/index.d.ts +0 -7
- package/dark-mode/index.js +0 -16
- package/dark-mode/init.d.ts +0 -1
- package/dark-mode/init.js +0 -13
- package/dark-mode/state.d.ts +0 -3
- package/dependencyRegistry.d.ts +0 -5
- package/dependencyRegistry.js +0 -12
- package/dependencyUsage.d.ts +0 -7
- package/dependencyUsage.js +0 -10
- package/dimensions/consts.d.ts +0 -2
- package/dimensions/index.d.ts +0 -4
- package/dimensions/index.js +0 -13
- package/dimensions/init.d.ts +0 -1
- package/dimensions/init.js +0 -21
- package/dimensions/utils.d.ts +0 -1
- package/dimensions/utils.js +0 -7
- package/i18n.d.ts +0 -7
- package/i18n.js +0 -9
- package/index.d.ts +0 -7
- package/index.js +0 -5
- package/makeUseStyles/index.d.ts +0 -7
- package/makeUseStyles/index.js +0 -12
- package/media-query/base.d.ts +0 -12
- package/media-query/base.js +0 -18
- package/media-query/breakpoints.d.ts +0 -18
- package/media-query/breakpoints.js +0 -60
- package/media-query/index.d.ts +0 -2
- package/media-query/index.js +0 -2
- package/orientation.d.ts +0 -7
- package/orientation.js +0 -7
- package/safe-area/SafeAreaProvider.d.ts +0 -3
- package/safe-area/SafeAreaProvider.js +0 -9
- package/safe-area/StylexSaveAreaConsumer.d.ts +0 -2
- package/safe-area/StylexSaveAreaConsumer.js +0 -15
- package/safe-area/consts.d.ts +0 -1
- package/safe-area/eventEmitter.d.ts +0 -1
- package/safe-area/index.d.ts +0 -5
- package/safe-area/index.js +0 -10
- package/safe-area/init.d.ts +0 -1
- package/safe-area/init.js +0 -4
- package/safe-area/state.d.ts +0 -8
- package/safe-area/types.js +0 -1
- package/useColorTransition.d.ts +0 -5
- package/useColorTransition.js +0 -38
- package/useTheme.d.ts +0 -2
- package/useTheme.js +0 -9
- package/withStyles.d.ts +0 -7
- package/withStyles.js +0 -13
- /package/{appearance/consts.js → src/appearance/consts.ts} +0 -0
- /package/{dark-mode/consts.js → src/dark-mode/consts.ts} +0 -0
- /package/{dimensions/consts.js → src/dimensions/consts.ts} +0 -0
- /package/{makeUseStyles → src/make-use-styles}/test-type.js +0 -0
- /package/{safe-area/consts.js → src/safe-area/consts.ts} +0 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { landscapeOrientation, portraitOrientation } from "../orientation";
|
|
2
|
+
|
|
3
|
+
import { Dimensions } from "react-native";
|
|
4
|
+
|
|
5
|
+
const mockStyle = { color: "black" };
|
|
6
|
+
|
|
7
|
+
const mockGetDimensions = (dimensions: any) => {
|
|
8
|
+
Dimensions.get = () => dimensions;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
describe("landscapeOrientation", () => {
|
|
12
|
+
it("should return style when screen height less than width", () => {
|
|
13
|
+
const dimensions = { height: 1, width: 2 };
|
|
14
|
+
|
|
15
|
+
mockGetDimensions(dimensions);
|
|
16
|
+
|
|
17
|
+
expect(landscapeOrientation(mockStyle)).toEqual(mockStyle);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should return 'undefined' when screen height equal width", () => {
|
|
21
|
+
const dimensions = { height: 1, width: 1 };
|
|
22
|
+
|
|
23
|
+
mockGetDimensions(dimensions);
|
|
24
|
+
|
|
25
|
+
expect(landscapeOrientation(mockStyle)).toBeUndefined();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should return 'null' when screen height more than width", () => {
|
|
29
|
+
const dimensions = { height: 2, width: 1 };
|
|
30
|
+
|
|
31
|
+
mockGetDimensions(dimensions);
|
|
32
|
+
|
|
33
|
+
expect(landscapeOrientation(mockStyle)).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("portraitOrientation", () => {
|
|
38
|
+
it("should return 'undefined' when screen height less than width", () => {
|
|
39
|
+
const dimensions = { height: 1, width: 2 };
|
|
40
|
+
|
|
41
|
+
mockGetDimensions(dimensions);
|
|
42
|
+
|
|
43
|
+
expect(portraitOrientation(mockStyle)).toBeUndefined();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should return 'mockStyle' when screen height equal width", () => {
|
|
47
|
+
const dimensions = { height: 1, width: 1 };
|
|
48
|
+
|
|
49
|
+
mockGetDimensions(dimensions);
|
|
50
|
+
|
|
51
|
+
expect(portraitOrientation(mockStyle)).toEqual(mockStyle);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should return 'mockStyle' when screen height more than width", () => {
|
|
55
|
+
const dimensions = { height: 2, width: 1 };
|
|
56
|
+
|
|
57
|
+
mockGetDimensions(dimensions);
|
|
58
|
+
|
|
59
|
+
expect(portraitOrientation(mockStyle)).toEqual(mockStyle);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
+
import { useTheme } from "../use-theme";
|
|
3
|
+
import { ThemeProvider } from "../context";
|
|
4
|
+
|
|
5
|
+
it("should throw an error when context value wasn't passed", () => {
|
|
6
|
+
expect(() => {
|
|
7
|
+
const { result } = renderHook(() => useTheme());
|
|
8
|
+
|
|
9
|
+
// trigger invoking passed hook
|
|
10
|
+
result.current;
|
|
11
|
+
}).toThrow();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should not throw an error", () => {
|
|
15
|
+
const theme = { test: "theme" };
|
|
16
|
+
|
|
17
|
+
expect(() => {
|
|
18
|
+
const { result } = renderHook(() => useTheme(), {
|
|
19
|
+
wrapper: ThemeProvider,
|
|
20
|
+
initialProps: { value: theme },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// trigger invoking passed hook
|
|
24
|
+
result.current;
|
|
25
|
+
}).not.toThrow();
|
|
26
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
import { FC, forwardRef } from "react";
|
|
4
|
+
import { TextInput } from "react-native";
|
|
5
|
+
import { InferInjectedStyledProps, withStyles } from "../with-styles";
|
|
6
|
+
import { makeUseStyles } from "../make-use-styles";
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
const useStyles = makeUseStyles(() => ({
|
|
10
|
+
root: {
|
|
11
|
+
color: "red",
|
|
12
|
+
},
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
interface Props extends InferInjectedStyledProps<typeof useStyles> {
|
|
16
|
+
a: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function Component(props: Props): React.JSX.Element | null {
|
|
20
|
+
props.styles.root.color = "";
|
|
21
|
+
|
|
22
|
+
// @ts-expect-error 'a' not exists
|
|
23
|
+
props.styles.a = {};
|
|
24
|
+
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const ComponentWithStyles = withStyles(useStyles)(Component);
|
|
29
|
+
|
|
30
|
+
<ComponentWithStyles a={false} />;
|
|
31
|
+
<ComponentWithStyles
|
|
32
|
+
// @ts-expect-error: string is not a boolean
|
|
33
|
+
a={"not bool"}
|
|
34
|
+
/>;
|
|
35
|
+
|
|
36
|
+
<ComponentWithStyles
|
|
37
|
+
a
|
|
38
|
+
// @ts-expect-error: already ibjected by hook
|
|
39
|
+
styles={{
|
|
40
|
+
root: {},
|
|
41
|
+
}}
|
|
42
|
+
/>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
{
|
|
46
|
+
interface MyTheme {
|
|
47
|
+
colors: {
|
|
48
|
+
red: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const useStyles = makeUseStyles((theme: MyTheme) => ({
|
|
53
|
+
root: {
|
|
54
|
+
color: theme.colors.red,
|
|
55
|
+
// @ts-expect-error: 'gold' not exists
|
|
56
|
+
borderColor: theme.colors.gold,
|
|
57
|
+
},
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
interface Props extends InferInjectedStyledProps<typeof useStyles> {
|
|
61
|
+
a: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const WithRef = forwardRef<TextInput, Props>(function Component(props, ref): React.JSX.Element | null {
|
|
65
|
+
props.styles.root.color = "";
|
|
66
|
+
|
|
67
|
+
// @ts-expect-error 'a' not exists
|
|
68
|
+
props.styles.a = {};
|
|
69
|
+
|
|
70
|
+
return <TextInput ref={ref} />;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const ComponentWithStylesAndRef = withStyles(useStyles)(WithRef);
|
|
74
|
+
|
|
75
|
+
<ComponentWithStylesAndRef a={false} />;
|
|
76
|
+
|
|
77
|
+
<ComponentWithStylesAndRef
|
|
78
|
+
a={false}
|
|
79
|
+
ref={(instance) => {
|
|
80
|
+
instance?.focus();
|
|
81
|
+
|
|
82
|
+
// @ts-expect-error 'abc' not exists
|
|
83
|
+
instance?.abc();
|
|
84
|
+
}}
|
|
85
|
+
/>;
|
|
86
|
+
<ComponentWithStylesAndRef
|
|
87
|
+
// @ts-expect-error: string is not a boolean
|
|
88
|
+
a={"not bool"}
|
|
89
|
+
/>;
|
|
90
|
+
|
|
91
|
+
<ComponentWithStylesAndRef
|
|
92
|
+
a
|
|
93
|
+
// @ts-expect-error: already ibjected by hook
|
|
94
|
+
styles={{
|
|
95
|
+
root: {},
|
|
96
|
+
}}
|
|
97
|
+
/>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
{
|
|
101
|
+
interface MyTheme {
|
|
102
|
+
colors: {
|
|
103
|
+
red: string;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const useStyles = makeUseStyles((theme: MyTheme) => ({
|
|
108
|
+
root: {
|
|
109
|
+
color: theme.colors.red,
|
|
110
|
+
// @ts-expect-error: 'gold' not exists
|
|
111
|
+
borderColor: theme.colors.gold,
|
|
112
|
+
},
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
interface Props extends InferInjectedStyledProps<typeof useStyles> {
|
|
116
|
+
a: boolean;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
class MyCls extends React.Component<Props> {
|
|
120
|
+
focus() {}
|
|
121
|
+
render() {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const ComponentWithStylesAndRef = withStyles(useStyles)(MyCls);
|
|
127
|
+
|
|
128
|
+
<ComponentWithStylesAndRef a={false} />;
|
|
129
|
+
|
|
130
|
+
<ComponentWithStylesAndRef
|
|
131
|
+
a={false}
|
|
132
|
+
ref={(instance) => {
|
|
133
|
+
instance?.focus();
|
|
134
|
+
|
|
135
|
+
// @ts-expect-error 'abc' not exists
|
|
136
|
+
instance?.abc();
|
|
137
|
+
}}
|
|
138
|
+
/>;
|
|
139
|
+
<ComponentWithStylesAndRef
|
|
140
|
+
// @ts-expect-error: string is not a boolean
|
|
141
|
+
a={"not bool"}
|
|
142
|
+
/>;
|
|
143
|
+
|
|
144
|
+
<ComponentWithStylesAndRef
|
|
145
|
+
a
|
|
146
|
+
// @ts-expect-error: already ibjected by hook
|
|
147
|
+
styles={{
|
|
148
|
+
root: {},
|
|
149
|
+
}}
|
|
150
|
+
/>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
{
|
|
154
|
+
const useStyles = makeUseStyles(() => ({
|
|
155
|
+
root: {
|
|
156
|
+
color: "red",
|
|
157
|
+
},
|
|
158
|
+
}));
|
|
159
|
+
|
|
160
|
+
interface Props extends InferInjectedStyledProps<typeof useStyles> {}
|
|
161
|
+
|
|
162
|
+
const MyCmp: FC<Props> = () => null;
|
|
163
|
+
|
|
164
|
+
const StyledMyCmp = withStyles(useStyles)(MyCmp);
|
|
165
|
+
|
|
166
|
+
<StyledMyCmp
|
|
167
|
+
ref={(e) => {
|
|
168
|
+
// @ts-expect-error: StyledMyCmp doesn't have 'ref' type
|
|
169
|
+
e?.aa();
|
|
170
|
+
}}
|
|
171
|
+
/>;
|
|
172
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { Animated } from "react-native";
|
|
3
|
+
import { DefaultTheme } from "./default-theme";
|
|
4
|
+
import { useTheme } from "./use-theme";
|
|
5
|
+
|
|
6
|
+
const { Value, timing } = Animated;
|
|
7
|
+
|
|
8
|
+
const INITIAL_VALUE = 0;
|
|
9
|
+
const defaultOptions = { duration: 250 };
|
|
10
|
+
|
|
11
|
+
export function useColorTransition<Theme = DefaultTheme>(
|
|
12
|
+
colorGetterFn: (theme: Theme) => string,
|
|
13
|
+
options = defaultOptions,
|
|
14
|
+
): Animated.AnimatedInterpolation<string> {
|
|
15
|
+
const theme = useTheme<Theme>();
|
|
16
|
+
const currentColor = colorGetterFn(theme);
|
|
17
|
+
const animatedValue = useRef(new Value(INITIAL_VALUE));
|
|
18
|
+
const colors = useRef({
|
|
19
|
+
toValue: INITIAL_VALUE,
|
|
20
|
+
prev: currentColor,
|
|
21
|
+
current: currentColor,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (currentColor !== colors.current.current) {
|
|
25
|
+
colors.current = {
|
|
26
|
+
toValue: colors.current.toValue === 0 ? 1 : 0,
|
|
27
|
+
prev: colors.current.current,
|
|
28
|
+
current: currentColor,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const { toValue, prev, current } = colors.current;
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
timing(animatedValue.current, {
|
|
36
|
+
toValue,
|
|
37
|
+
useNativeDriver: false,
|
|
38
|
+
...options,
|
|
39
|
+
}).start();
|
|
40
|
+
}, [toValue]);
|
|
41
|
+
|
|
42
|
+
return useMemo(() => {
|
|
43
|
+
const outputRange = toValue === 1 ? [prev, current] : [current, prev];
|
|
44
|
+
|
|
45
|
+
return animatedValue.current.interpolate({
|
|
46
|
+
inputRange: [0, 1],
|
|
47
|
+
outputRange,
|
|
48
|
+
});
|
|
49
|
+
}, [prev, current]);
|
|
50
|
+
}
|
package/src/use-theme.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
|
|
3
|
+
import { themeContext } from "./context";
|
|
4
|
+
import type { DefaultTheme } from "./default-theme";
|
|
5
|
+
|
|
6
|
+
export const useTheme = <Theme = DefaultTheme>(): Theme => {
|
|
7
|
+
const contextValue = useContext(themeContext);
|
|
8
|
+
|
|
9
|
+
if (!contextValue) {
|
|
10
|
+
throw new Error("[react-native-stylex]: Please make sure that you wrapped your component with <ThemeProvider/>.");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return contextValue as Theme;
|
|
14
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { ComponentProps, ComponentType, forwardRef, Ref, ComponentRef } from "react";
|
|
2
|
+
|
|
3
|
+
interface InjectedStyledProps<Styles> {
|
|
4
|
+
styles: Styles;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type InferInjectedStyledProps<Fn extends (...args: any) => any> = InjectedStyledProps<ReturnType<Fn>>;
|
|
8
|
+
|
|
9
|
+
export function withStyles<Styles>(useStyles: () => Styles) {
|
|
10
|
+
function WithStyles<TComponent extends ComponentType<any>>(Component: TComponent) {
|
|
11
|
+
const renderComponent = (props: Omit<ComponentProps<TComponent>, "styles">, ref: Ref<ComponentRef<TComponent>>) => {
|
|
12
|
+
const styles = useStyles();
|
|
13
|
+
// @ts-expect-error: 'ref' as never
|
|
14
|
+
return <Component {...props} ref={ref} styles={styles} />;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
return forwardRef(renderComponent);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return WithStyles;
|
|
22
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "ESNext",
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"lib": ["ESNext"],
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"jsx": "react-native",
|
|
10
|
+
"strict": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"noImplicitAny": true,
|
|
14
|
+
"strictNullChecks": true,
|
|
15
|
+
"strictFunctionTypes": true,
|
|
16
|
+
"strictBindCallApply": true,
|
|
17
|
+
"strictPropertyInitialization": true,
|
|
18
|
+
"noImplicitThis": true,
|
|
19
|
+
"alwaysStrict": true,
|
|
20
|
+
"noUnusedLocals": false,
|
|
21
|
+
"noUnusedParameters": true,
|
|
22
|
+
"noImplicitReturns": true,
|
|
23
|
+
"noFallthroughCasesInSwitch": true,
|
|
24
|
+
"noUncheckedIndexedAccess": true,
|
|
25
|
+
"forceConsistentCasingInFileNames": true,
|
|
26
|
+
"moduleResolution": "node",
|
|
27
|
+
"outDir": "./lib"
|
|
28
|
+
},
|
|
29
|
+
"include": ["./src"],
|
|
30
|
+
"exclude": ["./src/tests"]
|
|
31
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "ESNext",
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"lib": ["ESNext"],
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"jsx": "react-native",
|
|
10
|
+
"strict": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"noImplicitAny": true,
|
|
14
|
+
"strictNullChecks": true,
|
|
15
|
+
"strictFunctionTypes": true,
|
|
16
|
+
"strictBindCallApply": true,
|
|
17
|
+
"strictPropertyInitialization": true,
|
|
18
|
+
"noImplicitThis": true,
|
|
19
|
+
"alwaysStrict": true,
|
|
20
|
+
"noUnusedLocals": false,
|
|
21
|
+
"noUnusedParameters": true,
|
|
22
|
+
"noImplicitReturns": true,
|
|
23
|
+
"noFallthroughCasesInSwitch": true,
|
|
24
|
+
"noUncheckedIndexedAccess": true,
|
|
25
|
+
"forceConsistentCasingInFileNames": true,
|
|
26
|
+
"moduleResolution": "node",
|
|
27
|
+
"outDir": "./lib"
|
|
28
|
+
},
|
|
29
|
+
"include": ["./src"]
|
|
30
|
+
}
|
package/DefaultTheme.d.ts
DELETED
package/DefaultTheme.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/appearance/consts.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const UI_MODE_DEPENDENCY_KEY = "react-native-appearance";
|
package/appearance/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import "./init";
|
|
2
|
-
export type ColorSchemeName = "light" | "dark" | "default";
|
|
3
|
-
export declare function appearance<T>({ dark, light, default: defaultScheme, }: {
|
|
4
|
-
[mode in ColorSchemeName]?: T;
|
|
5
|
-
}): T | undefined;
|
|
6
|
-
export declare const darkAppearance: <T>(dark: T) => T | undefined;
|
|
7
|
-
export declare const lightAppearance: <T>(light: T) => T | undefined;
|
|
8
|
-
export declare const noPreferenceAppearance: <T>(defaultScheme: T) => T | undefined;
|
package/appearance/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import "./init";
|
|
2
|
-
import { Appearance } from "react-native";
|
|
3
|
-
import { onUse } from "../dependencyUsage";
|
|
4
|
-
import { UI_MODE_DEPENDENCY_KEY } from "./consts";
|
|
5
|
-
export function appearance({ dark, light, default: defaultScheme, }) {
|
|
6
|
-
onUse(UI_MODE_DEPENDENCY_KEY);
|
|
7
|
-
// Note: getColorScheme() will always return light when debugging with Chrome.
|
|
8
|
-
if (Appearance.getColorScheme() === "light") {
|
|
9
|
-
return light;
|
|
10
|
-
}
|
|
11
|
-
if (Appearance.getColorScheme() === "dark") {
|
|
12
|
-
return dark;
|
|
13
|
-
}
|
|
14
|
-
return defaultScheme;
|
|
15
|
-
}
|
|
16
|
-
export const darkAppearance = (dark) => appearance({ dark });
|
|
17
|
-
export const lightAppearance = (light) => appearance({ light });
|
|
18
|
-
export const noPreferenceAppearance = (defaultScheme) => appearance({ default: defaultScheme });
|
package/appearance/init.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/appearance/init.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Appearance } from "react-native";
|
|
2
|
-
import { addDependency } from "../dependencyRegistry";
|
|
3
|
-
import { createEventEmitter } from "../createEventEmitter";
|
|
4
|
-
import { UI_MODE_DEPENDENCY_KEY } from "./consts";
|
|
5
|
-
const { on, emit } = createEventEmitter(UI_MODE_DEPENDENCY_KEY);
|
|
6
|
-
addDependency(UI_MODE_DEPENDENCY_KEY, (handler) => on(handler));
|
|
7
|
-
Appearance.addChangeListener(emit);
|
package/context.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { DefaultTheme } from "./DefaultTheme";
|
|
3
|
-
export declare const themeContext: import("react").Context<DefaultTheme | null>;
|
|
4
|
-
export declare const ThemeProvider: import("react").Provider<DefaultTheme | null>, ThemeConsumer: import("react").Consumer<DefaultTheme | null>;
|
package/createEventEmitter.d.ts
DELETED
package/createEventEmitter.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const events = {};
|
|
2
|
-
export function createEventEmitter(event) {
|
|
3
|
-
const emit = () => (events[event] || []).forEach((fn) => fn());
|
|
4
|
-
const on = (cb) => {
|
|
5
|
-
(events[event] = events[event] || []).push(cb);
|
|
6
|
-
return () => {
|
|
7
|
-
events[event] = events[event].filter((fn) => fn !== cb);
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
return { on, emit };
|
|
11
|
-
}
|
package/dark-mode/consts.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const UI_MODE_DEPENDENCY_KEY = "react-native-dark-mode";
|
package/dark-mode/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import "./init";
|
|
2
|
-
export type UiType = "dark" | "light";
|
|
3
|
-
export declare function uiMode<T>({ dark, light, }: {
|
|
4
|
-
[mode in UiType]?: T;
|
|
5
|
-
}): T | undefined;
|
|
6
|
-
export declare const darkUiMode: <T>(dark: T) => T | undefined;
|
|
7
|
-
export declare const lightUiMode: <T>(light: T) => T | undefined;
|
package/dark-mode/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import "./init";
|
|
2
|
-
import { onUse } from "../dependencyUsage";
|
|
3
|
-
import { UI_MODE_DEPENDENCY_KEY } from "./consts";
|
|
4
|
-
import { state } from "./state";
|
|
5
|
-
export function uiMode({ dark, light, }) {
|
|
6
|
-
onUse(UI_MODE_DEPENDENCY_KEY);
|
|
7
|
-
if (state.mode === "dark") {
|
|
8
|
-
return dark;
|
|
9
|
-
}
|
|
10
|
-
if (state.mode === "light") {
|
|
11
|
-
return light;
|
|
12
|
-
}
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
export const darkUiMode = (dark) => uiMode({ dark });
|
|
16
|
-
export const lightUiMode = (light) => uiMode({ light });
|
package/dark-mode/init.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dark-mode/init.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { eventEmitter } from "react-native-dark-mode";
|
|
2
|
-
import { addDependency } from "../dependencyRegistry";
|
|
3
|
-
import { createEventEmitter } from "../createEventEmitter";
|
|
4
|
-
import { UI_MODE_DEPENDENCY_KEY } from "./consts";
|
|
5
|
-
import { state } from "./state";
|
|
6
|
-
const { on, emit } = createEventEmitter(UI_MODE_DEPENDENCY_KEY);
|
|
7
|
-
addDependency(UI_MODE_DEPENDENCY_KEY, (handler) => on(handler));
|
|
8
|
-
eventEmitter.on("currentModeChanged", (newMode) => {
|
|
9
|
-
if (state.mode !== newMode) {
|
|
10
|
-
state.mode = newMode;
|
|
11
|
-
emit();
|
|
12
|
-
}
|
|
13
|
-
});
|
package/dark-mode/state.d.ts
DELETED
package/dependencyRegistry.d.ts
DELETED
package/dependencyRegistry.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const registry = {};
|
|
2
|
-
export function addDependency(name, onChange) {
|
|
3
|
-
if (!registry[name]) {
|
|
4
|
-
Object.defineProperty(registry, name, {
|
|
5
|
-
value: onChange,
|
|
6
|
-
writable: false,
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export function getDependency(name) {
|
|
11
|
-
return registry[name];
|
|
12
|
-
}
|
package/dependencyUsage.d.ts
DELETED
package/dependencyUsage.js
DELETED
package/dimensions/consts.d.ts
DELETED
package/dimensions/index.d.ts
DELETED
package/dimensions/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import "./init";
|
|
2
|
-
import { Dimensions } from "react-native";
|
|
3
|
-
import { onUse } from "../dependencyUsage";
|
|
4
|
-
import { WINDOW_DEPENDENCY_KEY, SCREEN_DEPENDENCY_KEY } from "./consts";
|
|
5
|
-
const get = (dim) => Dimensions.get(dim);
|
|
6
|
-
export function getWindowDimensions() {
|
|
7
|
-
onUse(WINDOW_DEPENDENCY_KEY);
|
|
8
|
-
return get("window");
|
|
9
|
-
}
|
|
10
|
-
export function getScreenDimensions() {
|
|
11
|
-
onUse(SCREEN_DEPENDENCY_KEY);
|
|
12
|
-
return get("screen");
|
|
13
|
-
}
|
package/dimensions/init.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dimensions/init.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Dimensions } from "react-native";
|
|
2
|
-
import { createEventEmitter } from "../createEventEmitter";
|
|
3
|
-
import { addDependency } from "../dependencyRegistry";
|
|
4
|
-
import { SCREEN_DEPENDENCY_KEY, WINDOW_DEPENDENCY_KEY } from "./consts";
|
|
5
|
-
const { get, addEventListener } = Dimensions;
|
|
6
|
-
const state = { window: get("window"), screen: get("screen") };
|
|
7
|
-
const windowEventEmitter = createEventEmitter(WINDOW_DEPENDENCY_KEY);
|
|
8
|
-
const screenEventEmitter = createEventEmitter(SCREEN_DEPENDENCY_KEY);
|
|
9
|
-
const isNotEqual = (a, b) => a.width !== b.width || a.height !== b.height;
|
|
10
|
-
addDependency(WINDOW_DEPENDENCY_KEY, (handler) => windowEventEmitter.on(handler));
|
|
11
|
-
addDependency(SCREEN_DEPENDENCY_KEY, (handler) => screenEventEmitter.on(handler));
|
|
12
|
-
addEventListener("change", ({ window, screen }) => {
|
|
13
|
-
if (isNotEqual(screen, state.screen)) {
|
|
14
|
-
state.screen = screen;
|
|
15
|
-
screenEventEmitter.emit();
|
|
16
|
-
}
|
|
17
|
-
if (isNotEqual(window, state.window)) {
|
|
18
|
-
state.window = window;
|
|
19
|
-
windowEventEmitter.emit();
|
|
20
|
-
}
|
|
21
|
-
});
|
package/dimensions/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const optimizeDependencies: (keys: Record<string, boolean>) => Record<string, boolean>;
|
package/dimensions/utils.js
DELETED
package/i18n.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
type LayoutDirectionType = "rtl" | "ltr";
|
|
2
|
-
export declare function i18n<T>({ rtl, ltr, }: {
|
|
3
|
-
[direction in LayoutDirectionType]?: T;
|
|
4
|
-
}): T | undefined;
|
|
5
|
-
export declare const rtl: <T>(styles: T) => T | undefined;
|
|
6
|
-
export declare const ltr: <T>(styles: T) => T | undefined;
|
|
7
|
-
export {};
|
package/i18n.js
DELETED