@codeandmoney/soelma 0.0.0-dev.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.
Files changed (111) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +31 -0
  3. package/.github/workflows/nodejs.yml +33 -0
  4. package/.size-limit.json +6 -0
  5. package/CHANGELOG.md +90 -0
  6. package/LICENSE +21 -0
  7. package/README.md +169 -0
  8. package/babel.config.js +3 -0
  9. package/docs/api.md +103 -0
  10. package/docs/appearance.md +54 -0
  11. package/docs/dark-mode.md +46 -0
  12. package/docs/dimensions.md +29 -0
  13. package/docs/i18n.md +67 -0
  14. package/docs/logo.png +0 -0
  15. package/docs/media-query.md +274 -0
  16. package/docs/orientation.md +44 -0
  17. package/docs/safe-area.md +62 -0
  18. package/docs/testting.md +51 -0
  19. package/docs/ts.md +127 -0
  20. package/example/AppStyleX/.watchmanconfig +1 -0
  21. package/example/AppStyleX/android/build.gradle +26 -0
  22. package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  23. package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  24. package/example/AppStyleX/android/gradle.properties +53 -0
  25. package/example/AppStyleX/android/gradlew +249 -0
  26. package/example/AppStyleX/android/gradlew.bat +92 -0
  27. package/example/AppStyleX/android/settings.gradle +12 -0
  28. package/example/AppStyleX/app.json +28 -0
  29. package/example/AppStyleX/babel.config.js +3 -0
  30. package/example/AppStyleX/index.js +9 -0
  31. package/example/AppStyleX/ios/Podfile +7 -0
  32. package/example/AppStyleX/ios/Podfile.lock +1252 -0
  33. package/example/AppStyleX/metro.config.js +54 -0
  34. package/example/AppStyleX/package.json +43 -0
  35. package/example/AppStyleX/react-native.config.js +23 -0
  36. package/example/AppStyleX/src/App.tsx +25 -0
  37. package/example/AppStyleX/src/BottomNav/index.tsx +32 -0
  38. package/example/AppStyleX/src/BottomNav/styles.ts +42 -0
  39. package/example/AppStyleX/src/Circle/index.tsx +53 -0
  40. package/example/AppStyleX/src/Circle/styles.ts +22 -0
  41. package/example/AppStyleX/src/Root/index.tsx +41 -0
  42. package/example/AppStyleX/src/Root/styles.ts +18 -0
  43. package/example/AppStyleX/src/ToggleButton/index.tsx +66 -0
  44. package/example/AppStyleX/src/ToggleButton/styles.ts +69 -0
  45. package/example/AppStyleX/src/style-system/hooks/useAnimatedBgColor.ts +5 -0
  46. package/example/AppStyleX/src/style-system/hooks/useAnimatedTextColor.ts +5 -0
  47. package/example/AppStyleX/src/style-system/hooks/useIsDark.ts +8 -0
  48. package/example/AppStyleX/src/style-system/palette.ts +11 -0
  49. package/example/AppStyleX/src/style-system/theme.ts +14 -0
  50. package/example/AppStyleX/src/style-system/utils.ts +11 -0
  51. package/example/AppStyleX/src/stylex.d.ts +6 -0
  52. package/example/AppStyleX/tsconfig.json +3 -0
  53. package/example/AppStyleX/yarn.lock +6767 -0
  54. package/jest.config.js +19 -0
  55. package/package.json +59 -0
  56. package/src/DefaultTheme.ts +4 -0
  57. package/src/__tests__/createBreakpoints.test.ts +152 -0
  58. package/src/__tests__/createBreakpointsMatcher.test.ts +188 -0
  59. package/src/__tests__/createBreakpointsMatcher.types-test.ts +81 -0
  60. package/src/__tests__/createEventEmitter.test.ts +37 -0
  61. package/src/__tests__/dark-mode.test.ts +56 -0
  62. package/src/__tests__/dependencyRegistry.test.ts +16 -0
  63. package/src/__tests__/dependencyUsage.test.ts +13 -0
  64. package/src/__tests__/dimensions.test.ts +36 -0
  65. package/src/__tests__/makeUseStyles.types-test.ts +69 -0
  66. package/src/__tests__/media-query.test.ts +204 -0
  67. package/src/__tests__/orientation.test.ts +61 -0
  68. package/src/__tests__/useTheme.test.ts +26 -0
  69. package/src/__tests__/withStyles.types-test.tsx +173 -0
  70. package/src/appearance/consts.ts +1 -0
  71. package/src/appearance/index.ts +37 -0
  72. package/src/appearance/init.ts +12 -0
  73. package/src/context.ts +9 -0
  74. package/src/createEventEmitter.ts +26 -0
  75. package/src/dark-mode/consts.ts +1 -0
  76. package/src/dark-mode/index.ts +29 -0
  77. package/src/dark-mode/init.ts +19 -0
  78. package/src/dark-mode/state.ts +5 -0
  79. package/src/dependencyRegistry.ts +21 -0
  80. package/src/dependencyUsage.ts +31 -0
  81. package/src/dimensions/consts.ts +2 -0
  82. package/src/dimensions/index.ts +20 -0
  83. package/src/dimensions/init.ts +37 -0
  84. package/src/dimensions/utils.ts +11 -0
  85. package/src/i18n.ts +18 -0
  86. package/src/index.ts +7 -0
  87. package/src/makeUseStyles/createUseStylesTheme.js +42 -0
  88. package/src/makeUseStyles/createUseStylesTheme.test.js +137 -0
  89. package/src/makeUseStyles/createUseStylesWithoutTheme.js +38 -0
  90. package/src/makeUseStyles/createUseStylesWithoutTheme.test.js +63 -0
  91. package/src/makeUseStyles/index.d.ts +7 -0
  92. package/src/makeUseStyles/index.js +12 -0
  93. package/src/makeUseStyles/index.test.js +28 -0
  94. package/src/makeUseStyles/test-type.js +28 -0
  95. package/src/makeUseStyles/utils.js +67 -0
  96. package/src/media-query/base.ts +43 -0
  97. package/src/media-query/breakpoints.ts +121 -0
  98. package/src/media-query/index.ts +12 -0
  99. package/src/orientation.ts +17 -0
  100. package/src/safe-area/SafeAreaProvider.tsx +17 -0
  101. package/src/safe-area/StylexSaveAreaConsumer.ts +23 -0
  102. package/src/safe-area/consts.ts +1 -0
  103. package/src/safe-area/eventEmitter.ts +4 -0
  104. package/src/safe-area/index.tsx +16 -0
  105. package/src/safe-area/init.tsx +6 -0
  106. package/src/safe-area/state.ts +12 -0
  107. package/src/safe-area/types.ts +10 -0
  108. package/src/useColorTransition.ts +50 -0
  109. package/src/useTheme.ts +16 -0
  110. package/src/withStyles.tsx +35 -0
  111. package/tsconfig.json +30 -0
package/jest.config.js ADDED
@@ -0,0 +1,19 @@
1
+ const { resolve } = require("path");
2
+ const { name: displayName } = require("./package");
3
+
4
+ module.exports = {
5
+ displayName,
6
+ testEnvironment: "node",
7
+ preset: "react-native",
8
+ cacheDirectory: resolve(__dirname, "./node_modules/.jestcache"),
9
+ moduleFileExtensions: ["ts", "tsx", "js"],
10
+ testRegex: "\\.test\\.(js|ts)x?$",
11
+ coveragePathIgnorePatterns: ["init.ts"],
12
+ coverageThreshold: {
13
+ global: {
14
+ branches: 100,
15
+ functions: 100,
16
+ statements: 100,
17
+ },
18
+ },
19
+ };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@codeandmoney/soelma",
3
+ "publishConfig": {"access": "public"},
4
+ "version": "0.0.0-dev.0",
5
+ "private": false,
6
+ "main": "index.js",
7
+ "types": "index.d.ts",
8
+ "author": "David <4661784+retyui@users.noreply.github.com>",
9
+ "description": "Fork of git@github.com:retyui/react-native-stylex.git",
10
+ "license": "MIT",
11
+ "scripts": {
12
+ "prebuild": "rm -rf lib",
13
+ "build": "tsc",
14
+ "postbuild": "mkdir lib/makeUseStyles && cp src/makeUseStyles/* lib/makeUseStyles && rm -rf lib/**/*test.* && prettier --write lib/**/*.{js,ts}",
15
+ "clean-publish": "yarn test && yarn build && node ./node_modules/clean-publish/clear-package-json.js package.json > lib/package.json && cp CHANGELOG.md LICENSE README.md lib",
16
+ "publish-next": "yarn clean-publish && cd lib && npm publish --tag next",
17
+ "presize": "yarn build",
18
+ "postinstall": "rm -rf node_modules/@types/node node_modules/@types/yauzl node_modules/@types/graceful-fs",
19
+ "lint": "eslint './src/*.{js,ts,tsx}' --quiet",
20
+ "test": "jest --coverage",
21
+ "size": "size-limit",
22
+ "ci": "yarn lint && yarn test && yarn size"
23
+ },
24
+ "peerDependencies": {
25
+ "react": ">=16.4.0",
26
+ "react-native": ">=0.59.0"
27
+ },
28
+ "peerDependenciesMeta": {
29
+ "react": {
30
+ "optional": true
31
+ },
32
+ "react-native": {
33
+ "optional": true
34
+ }
35
+ },
36
+ "devDependencies": {
37
+ "@size-limit/preset-app": "^11.0.1",
38
+ "@testing-library/react-hooks": "^8.0.1",
39
+ "@types/jest": "^29.5.11",
40
+ "@types/react": "^18.2.45",
41
+ "@typescript-eslint/eslint-plugin": "^6.14.0",
42
+ "@typescript-eslint/parser": "^6.14.0",
43
+ "clean-publish": "^4.2.0",
44
+ "eslint": "^8.56.0",
45
+ "eslint-config-prettier": "^9.1.0",
46
+ "eslint-plugin-prettier": "^5.0.1",
47
+ "eslint-plugin-react": "^7.33.2",
48
+ "jest": "^29.7.0",
49
+ "prettier": "^3.1.1",
50
+ "react": "^18.2.0",
51
+ "react-native": "^0.73.0",
52
+ "react-native-dark-mode": "^0.2.2",
53
+ "react-native-safe-area-context": "^4.8.1",
54
+ "react-native-test-app": "^2.5.34",
55
+ "react-test-renderer": "^18.2.0",
56
+ "size-limit": "^11.0.1",
57
+ "typescript": "^5.3.3"
58
+ }
59
+ }
@@ -0,0 +1,4 @@
1
+ // This interface can be augmented by users to add default types for the theme when using react-native-stylex.
2
+ // Use module augmentation to append your own type definition in a your_custom_stylex_type.d.ts file.
3
+ // https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
4
+ export interface DefaultTheme {}
@@ -0,0 +1,152 @@
1
+ import { createBreakpoints } from "../media-query/breakpoints";
2
+ import { getWindowDimensions } from "../dimensions";
3
+
4
+ jest.mock("../dimensions", () => ({
5
+ getWindowDimensions: jest.fn(),
6
+ }));
7
+
8
+ const mockWindowWidth = (width: number) => {
9
+ const mockGetWindowDimensions = getWindowDimensions as jest.Mock;
10
+ mockGetWindowDimensions.mockReturnValue({ width });
11
+ };
12
+
13
+ describe("createBreakpoints", () => {
14
+ const config = {
15
+ xs: 360,
16
+ sm: 600,
17
+ md: 960,
18
+ lg: 1280,
19
+ xl: 1920,
20
+ };
21
+ const breakpoints = createBreakpoints(config);
22
+
23
+ describe("down", () => {
24
+ const getStyles = () => ({
25
+ fontSize: 16,
26
+ ...breakpoints.down("lg", { fontSize: 18 }),
27
+ ...breakpoints.down("sm", { fontSize: 20 }),
28
+ });
29
+
30
+ it("should return small variant", () => {
31
+ mockWindowWidth(0);
32
+ expect(getStyles()).toEqual({ fontSize: 20 });
33
+ mockWindowWidth(600);
34
+ expect(getStyles()).toEqual({ fontSize: 20 });
35
+ });
36
+
37
+ it("should return large variant", () => {
38
+ mockWindowWidth(601);
39
+ expect(getStyles()).toEqual({ fontSize: 18 });
40
+ mockWindowWidth(1280);
41
+ expect(getStyles()).toEqual({ fontSize: 18 });
42
+ });
43
+
44
+ it("should return default variant", () => {
45
+ mockWindowWidth(1281);
46
+ expect(getStyles()).toEqual({ fontSize: 16 });
47
+ mockWindowWidth(1920);
48
+ expect(getStyles()).toEqual({ fontSize: 16 });
49
+ mockWindowWidth(1921);
50
+ expect(getStyles()).toEqual({ fontSize: 16 });
51
+ });
52
+ });
53
+
54
+ describe("up", () => {
55
+ const getStyles = () => ({
56
+ fontSize: 20,
57
+ ...breakpoints.up("sm", { fontSize: 18 }),
58
+ ...breakpoints.up("lg", { fontSize: 16 }),
59
+ });
60
+
61
+ it("should return small variant", () => {
62
+ mockWindowWidth(0);
63
+ expect(getStyles()).toEqual({ fontSize: 20 });
64
+ mockWindowWidth(599);
65
+ expect(getStyles()).toEqual({ fontSize: 20 });
66
+ });
67
+
68
+ it("should return large variant", () => {
69
+ mockWindowWidth(600);
70
+ expect(getStyles()).toEqual({ fontSize: 18 });
71
+ mockWindowWidth(1279);
72
+ expect(getStyles()).toEqual({ fontSize: 18 });
73
+ });
74
+
75
+ it("should return default variant", () => {
76
+ mockWindowWidth(1280);
77
+ expect(getStyles()).toEqual({ fontSize: 16 });
78
+ mockWindowWidth(1920);
79
+ expect(getStyles()).toEqual({ fontSize: 16 });
80
+ mockWindowWidth(1921);
81
+ expect(getStyles()).toEqual({ fontSize: 16 });
82
+ });
83
+ });
84
+
85
+ describe("only", () => {
86
+ it("should work properly", () => {
87
+ const getStyles = () => ({
88
+ fontSize: 16,
89
+ ...breakpoints.only("md", { fontSize: 20 }),
90
+ });
91
+ // window width : 0...xs...sm...md...lg...xl...∞
92
+ // fontSize : .............[20...20]...........
93
+
94
+ mockWindowWidth(0);
95
+ expect(getStyles()).toEqual({ fontSize: 16 });
96
+ mockWindowWidth(config.md - 0.5);
97
+ expect(getStyles()).toEqual({ fontSize: 16 });
98
+
99
+ mockWindowWidth(config.md);
100
+ expect(getStyles()).toEqual({ fontSize: 20 });
101
+ mockWindowWidth(config.lg - 0.5);
102
+ expect(getStyles()).toEqual({ fontSize: 20 });
103
+
104
+ mockWindowWidth(config.lg);
105
+ expect(getStyles()).toEqual({ fontSize: 16 });
106
+ });
107
+
108
+ it("should call up on last breakpoint", () => {
109
+ const getStyles = () => ({
110
+ fontSize: 16,
111
+ ...breakpoints.only("xl", { fontSize: 20 }),
112
+ });
113
+ // window width : 0...xs...sm...md...lg...xl...∞
114
+ // fontSize : .......................[20.......
115
+
116
+ mockWindowWidth(config.xl - 0.5);
117
+ expect(getStyles()).toEqual({ fontSize: 16 });
118
+
119
+ mockWindowWidth(config.xl);
120
+ expect(getStyles()).toEqual({ fontSize: 20 });
121
+ mockWindowWidth(config.xl + 0.5);
122
+ expect(getStyles()).toEqual({ fontSize: 20 });
123
+ });
124
+ });
125
+
126
+ describe("between", () => {
127
+ const getStyles = () => ({
128
+ fontSize: 16,
129
+ ...breakpoints.between("sm", "lg", { fontSize: 20 }),
130
+ });
131
+
132
+ it("should work properly", () => {
133
+ // window width : 0...xs...sm...md...lg...xl...∞
134
+ // fontSize : ........[20........20]...........
135
+
136
+ mockWindowWidth(0);
137
+ expect(getStyles()).toEqual({ fontSize: 16 });
138
+ mockWindowWidth(config.sm - 0.5);
139
+ expect(getStyles()).toEqual({ fontSize: 16 });
140
+
141
+ mockWindowWidth(config.sm);
142
+ expect(getStyles()).toEqual({ fontSize: 20 });
143
+ mockWindowWidth(config.md);
144
+ expect(getStyles()).toEqual({ fontSize: 20 });
145
+ mockWindowWidth(config.lg - 0.5);
146
+ expect(getStyles()).toEqual({ fontSize: 20 });
147
+
148
+ mockWindowWidth(config.lg);
149
+ expect(getStyles()).toEqual({ fontSize: 16 });
150
+ });
151
+ });
152
+ });
@@ -0,0 +1,188 @@
1
+ import { createBreakpointsMatcher, maxWidth, minWidth } from "../media-query";
2
+ import { getWindowDimensions } from "../dimensions";
3
+
4
+ jest.mock("../dimensions", () => ({
5
+ getWindowDimensions: jest.fn(),
6
+ }));
7
+
8
+ const mockWindowWidth = (width: number) => {
9
+ const mockGetWindowDimensions = getWindowDimensions as jest.Mock;
10
+ mockGetWindowDimensions.mockReturnValue({ width });
11
+ };
12
+
13
+ /*
14
+ * To debug use analog on CSS: https://codepen.io/retyui/pen/dyOzKzV
15
+ */
16
+ describe("createBreakpointsMatcher", () => {
17
+ const config = {
18
+ xxs: 100,
19
+ xs: 200,
20
+ s: 300,
21
+ m: 400,
22
+ l: 500,
23
+ };
24
+ const breakpointsMaxWidth = createBreakpointsMatcher(config, maxWidth);
25
+ const breakpointsMinWidth = createBreakpointsMatcher(config);
26
+
27
+ const values = {
28
+ xxs: "xxs: 100",
29
+ xs: "xs: 200",
30
+ s: "s: 300",
31
+ m: "m: 400",
32
+ l: "l: 500",
33
+ default: "default",
34
+ };
35
+
36
+ it("should return boundary values", () => {
37
+ mockWindowWidth(600);
38
+
39
+ expect({
40
+ maxWidth: breakpointsMaxWidth(values),
41
+ minWidth: breakpointsMinWidth(values),
42
+ }).toEqual({
43
+ maxWidth: "default",
44
+ minWidth: "l: 500",
45
+ });
46
+
47
+ mockWindowWidth(50);
48
+
49
+ expect({
50
+ maxWidth: breakpointsMaxWidth(values),
51
+ minWidth: breakpointsMinWidth(values),
52
+ }).toEqual({
53
+ maxWidth: "xxs: 100",
54
+ minWidth: "default",
55
+ });
56
+ });
57
+
58
+ it("should work properly", () => {
59
+ mockWindowWidth(450);
60
+
61
+ expect({
62
+ maxWidth: breakpointsMaxWidth(values),
63
+ minWidth: breakpointsMinWidth(values),
64
+ }).toEqual({
65
+ maxWidth: "l: 500",
66
+ minWidth: "m: 400",
67
+ });
68
+
69
+ mockWindowWidth(401);
70
+
71
+ expect({
72
+ maxWidth: breakpointsMaxWidth(values),
73
+ minWidth: breakpointsMinWidth(values),
74
+ }).toEqual({
75
+ maxWidth: "l: 500",
76
+ minWidth: "m: 400",
77
+ });
78
+
79
+ mockWindowWidth(400);
80
+
81
+ expect({
82
+ maxWidth: breakpointsMaxWidth(values),
83
+ minWidth: breakpointsMinWidth(values),
84
+ }).toEqual({
85
+ maxWidth: "m: 400",
86
+ minWidth: "m: 400",
87
+ });
88
+
89
+ mockWindowWidth(399);
90
+
91
+ expect({
92
+ maxWidth: breakpointsMaxWidth(values),
93
+ minWidth: breakpointsMinWidth(values),
94
+ }).toEqual({
95
+ maxWidth: "m: 400",
96
+ minWidth: "s: 300",
97
+ });
98
+ });
99
+
100
+ it("should return null when no default and it pass boundary values", () => {
101
+ const { default: _, ...valuesWithoutDefault } = values;
102
+ mockWindowWidth(600);
103
+
104
+ expect({
105
+ maxWidth: breakpointsMaxWidth(valuesWithoutDefault),
106
+ minWidth: breakpointsMinWidth(valuesWithoutDefault),
107
+ }).toEqual({
108
+ maxWidth: null,
109
+ minWidth: "l: 500",
110
+ });
111
+
112
+ mockWindowWidth(50);
113
+
114
+ expect({
115
+ maxWidth: breakpointsMaxWidth(valuesWithoutDefault),
116
+ minWidth: breakpointsMinWidth(valuesWithoutDefault),
117
+ }).toEqual({
118
+ maxWidth: "xxs: 100",
119
+ minWidth: null,
120
+ });
121
+ });
122
+ });
123
+
124
+ describe("docs examples", () => {
125
+ const config = {
126
+ xxs: 320,
127
+ xs: 480,
128
+ s: 640,
129
+ m: 768,
130
+ l: 1024,
131
+ xl: 1200,
132
+ xxl: 1920,
133
+ };
134
+ describe("maxWidth", () => {
135
+ const applyBreakpoints = createBreakpointsMatcher(config, maxWidth);
136
+
137
+ it("should work properly", () => {
138
+ const values = { xxs: 20, xs: 18, default: 16 };
139
+
140
+ mockWindowWidth(0);
141
+ expect(applyBreakpoints(values)).toBe(20);
142
+
143
+ mockWindowWidth(320);
144
+ expect(applyBreakpoints(values)).toBe(20);
145
+
146
+ mockWindowWidth(321);
147
+ expect(applyBreakpoints(values)).toBe(18);
148
+
149
+ mockWindowWidth(480);
150
+ expect(applyBreakpoints(values)).toBe(18);
151
+
152
+ mockWindowWidth(481);
153
+ expect(applyBreakpoints(values)).toBe(16);
154
+
155
+ mockWindowWidth(999);
156
+ expect(applyBreakpoints(values)).toBe(16);
157
+ });
158
+ });
159
+
160
+ describe("minWidth", () => {
161
+ const applyBreakpoints = createBreakpointsMatcher(config, minWidth);
162
+
163
+ it("should work properly", () => {
164
+ const values = { xxs: 18, xs: 16, default: 20 };
165
+
166
+ mockWindowWidth(0);
167
+ expect(applyBreakpoints(values)).toBe(20);
168
+
169
+ mockWindowWidth(319);
170
+ expect(applyBreakpoints(values)).toBe(20);
171
+
172
+ mockWindowWidth(320);
173
+ expect(applyBreakpoints(values)).toBe(18);
174
+
175
+ mockWindowWidth(479);
176
+ expect(applyBreakpoints(values)).toBe(18);
177
+
178
+ mockWindowWidth(480);
179
+ expect(applyBreakpoints(values)).toBe(16);
180
+
181
+ mockWindowWidth(481);
182
+ expect(applyBreakpoints(values)).toBe(16);
183
+
184
+ mockWindowWidth(999);
185
+ expect(applyBreakpoints(values)).toBe(16);
186
+ });
187
+ });
188
+ });
@@ -0,0 +1,81 @@
1
+ import { makeUseStyles } from "../index";
2
+ import { createBreakpointsMatcher } from "../media-query";
3
+
4
+ {
5
+ const breakpoints = createBreakpointsMatcher({
6
+ s: 100,
7
+ m: 200,
8
+ l: 300,
9
+ });
10
+
11
+ makeUseStyles(() => ({
12
+ root: {
13
+ position: breakpoints({
14
+ l: "absolute",
15
+ default: "relative",
16
+ }),
17
+
18
+ // @ts-expect-error - 'invalid value' is wrong value
19
+ alignItems: breakpoints({
20
+ l: "invalid value",
21
+ }),
22
+ },
23
+ }));
24
+ }
25
+
26
+ {
27
+ const breakpoints = createBreakpointsMatcher({
28
+ s: 100,
29
+ m: 200,
30
+ l: 300,
31
+ });
32
+
33
+ const a1: string | undefined = breakpoints({ s: "1" });
34
+ const a2: string | undefined = breakpoints({ s: "1", m: "2" });
35
+ const a3: string | undefined = breakpoints({ s: "1", m: "2", l: "3" });
36
+ const a4: string = breakpoints({
37
+ s: "1",
38
+ m: "2",
39
+ l: "3",
40
+ default: "0",
41
+ });
42
+ }
43
+
44
+ {
45
+ const breakpoints = createBreakpointsMatcher({
46
+ s: 100,
47
+ m: 200,
48
+ l: 300,
49
+ });
50
+
51
+ // @ts-expect-error - 'number' is not 'string'
52
+ const a1: string | undefined = breakpoints({ s: 1 });
53
+ const a2 = breakpoints({
54
+ s: 1,
55
+ // @ts-expect-error - 'string' is not 'number'
56
+ m: "2",
57
+ });
58
+ }
59
+
60
+ {
61
+ const breakpoints = createBreakpointsMatcher({
62
+ s: 100,
63
+ m: 200,
64
+ l: 300,
65
+ });
66
+
67
+ // @ts-expect-error - can be 'undefined'
68
+ const a1: string = breakpoints({ s: "1" });
69
+ // @ts-expect-error - can be 'undefined'
70
+ const a2: string = breakpoints({ s: "1", m: "2" });
71
+ // @ts-expect-error - can be 'undefined'
72
+ const a3: string = breakpoints({ s: "1", m: "2", l: "3" });
73
+
74
+ // @ts-expect-error - 'undefined' is not 'string'
75
+ const a4: undefined = breakpoints({
76
+ s: "1",
77
+ m: "2",
78
+ l: "3",
79
+ default: "0",
80
+ });
81
+ }
@@ -0,0 +1,37 @@
1
+ import { createEventEmitter } from "../createEventEmitter";
2
+
3
+ it("should call handler when invoke emit", () => {
4
+ const a = createEventEmitter("event");
5
+ const handler = jest.fn();
6
+
7
+ const unsub = a.on(handler);
8
+
9
+ expect(handler).toHaveBeenCalledTimes(0);
10
+
11
+ a.emit();
12
+
13
+ expect(handler).toHaveBeenCalledTimes(1);
14
+ });
15
+
16
+ it("should not call handler when unsubscribe", () => {
17
+ const a = createEventEmitter("event");
18
+ const handler = jest.fn();
19
+
20
+ const unsub = a.on(handler);
21
+
22
+ a.emit();
23
+
24
+ expect(handler).toHaveBeenCalledTimes(1);
25
+
26
+ unsub();
27
+
28
+ a.emit();
29
+
30
+ expect(handler).toHaveBeenCalledTimes(1);
31
+ });
32
+
33
+ it("should throw error when no subscribed functions", () => {
34
+ const a = createEventEmitter("test");
35
+
36
+ a.emit();
37
+ });
@@ -0,0 +1,56 @@
1
+ import type { Mode } from "react-native-dark-mode";
2
+
3
+ import { darkUiMode, lightUiMode } from "../dark-mode";
4
+ import { state } from "../dark-mode/state";
5
+
6
+ jest.mock("react-native-dark-mode", () => ({
7
+ initialMode: "light",
8
+ eventEmitter: { on: jest.fn() },
9
+ }));
10
+
11
+ const mockStyles = { color: "red" };
12
+
13
+ const mutateUiMode = (mode: Mode | null) => {
14
+ // @ts-expect-error: for test only add null
15
+ state.mode = mode;
16
+ };
17
+
18
+ describe("darkUiMode", () => {
19
+ it("should return style when dark mode", () => {
20
+ mutateUiMode("dark");
21
+
22
+ expect(darkUiMode(mockStyles)).toEqual(mockStyles);
23
+ });
24
+
25
+ it("should return 'undefined' when light mode", () => {
26
+ mutateUiMode("light");
27
+
28
+ expect(darkUiMode(mockStyles)).toBeUndefined();
29
+ });
30
+
31
+ it("should return 'undefined' when unknown mode", () => {
32
+ mutateUiMode(null);
33
+
34
+ expect(darkUiMode(mockStyles)).toBeUndefined();
35
+ });
36
+ });
37
+
38
+ describe("lightUiMode", () => {
39
+ it("should return style when light mode", () => {
40
+ mutateUiMode("light");
41
+
42
+ expect(lightUiMode(mockStyles)).toEqual(mockStyles);
43
+ });
44
+
45
+ it("should return 'undefined' when dark mode", () => {
46
+ mutateUiMode("dark");
47
+
48
+ expect(lightUiMode(mockStyles)).toBeUndefined();
49
+ });
50
+
51
+ it("should return 'undefined' when unknown mode", () => {
52
+ mutateUiMode(null);
53
+
54
+ expect(lightUiMode(mockStyles)).toBeUndefined();
55
+ });
56
+ });
@@ -0,0 +1,16 @@
1
+ import { addDependency, getDependency } from "../dependencyRegistry";
2
+
3
+ it("should overwrite handler", () => {
4
+ const name = "dark-mode";
5
+ const handler = () => () => {};
6
+
7
+ addDependency(name, handler);
8
+
9
+ expect(getDependency(name)).toBe(handler);
10
+
11
+ const newHandler = () => () => {};
12
+
13
+ addDependency(name, newHandler);
14
+
15
+ expect(getDependency(name)).not.toBe(newHandler);
16
+ });
@@ -0,0 +1,13 @@
1
+ import { onUse, resetUsing, getUsing } from "../dependencyUsage";
2
+
3
+ it("should clear usage map", () => {
4
+ onUse("a");
5
+ onUse("a");
6
+ onUse("b");
7
+
8
+ expect(getUsing()).toEqual({ a: true, b: true });
9
+
10
+ resetUsing();
11
+
12
+ expect(getUsing()).toEqual({});
13
+ });
@@ -0,0 +1,36 @@
1
+ import {
2
+ WINDOW_DEPENDENCY_KEY,
3
+ SCREEN_DEPENDENCY_KEY,
4
+ } from "../dimensions/consts";
5
+ import { optimizeDependencies } from "../dimensions/utils";
6
+
7
+ describe("optimizeDependencies", () => {
8
+ it("should remove screen dependency when window dependency exist", () => {
9
+ expect(
10
+ optimizeDependencies({
11
+ [WINDOW_DEPENDENCY_KEY]: true,
12
+ [SCREEN_DEPENDENCY_KEY]: true,
13
+ })
14
+ ).toEqual({
15
+ [WINDOW_DEPENDENCY_KEY]: true,
16
+ });
17
+ });
18
+
19
+ it("should skip removing", () => {
20
+ expect(
21
+ optimizeDependencies({
22
+ [WINDOW_DEPENDENCY_KEY]: true,
23
+ })
24
+ ).toEqual({
25
+ [WINDOW_DEPENDENCY_KEY]: true,
26
+ });
27
+
28
+ expect(
29
+ optimizeDependencies({
30
+ [SCREEN_DEPENDENCY_KEY]: true,
31
+ })
32
+ ).toEqual({
33
+ [SCREEN_DEPENDENCY_KEY]: true,
34
+ });
35
+ });
36
+ });