@draftbit/theme 50.6.2-8430ca.2 → 50.6.2-98b4e5.2
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/DefaultTheme.js +1 -1
- package/lib/commonjs/Provider.js +1 -1
- package/lib/commonjs/createTheme.js +1 -1
- package/lib/commonjs/createThemeValuesProxy.js +1 -1
- package/lib/commonjs/types.js +1 -0
- package/lib/commonjs/validators.js +1 -1
- package/lib/typescript/src/DefaultTheme.js +38 -38
- package/lib/typescript/src/DefaultTheme.js.map +1 -1
- package/lib/typescript/src/Provider.js +10 -1
- package/lib/typescript/src/Provider.js.map +1 -1
- package/lib/typescript/src/createTheme.d.ts +13 -1
- package/lib/typescript/src/createTheme.js +17 -6
- package/lib/typescript/src/createTheme.js.map +1 -1
- package/lib/typescript/src/createThemeValuesProxy.js +34 -22
- package/lib/typescript/src/createThemeValuesProxy.js.map +1 -1
- package/lib/typescript/src/types.d.ts +30 -2
- package/lib/typescript/src/validators.d.ts +3 -1
- package/lib/typescript/src/validators.js +10 -45
- package/lib/typescript/src/validators.js.map +1 -1
- package/lib/typescript/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/src/DefaultTheme.js +38 -38
- package/src/DefaultTheme.js.map +1 -1
- package/src/DefaultTheme.ts +38 -38
- package/src/Provider.js +10 -1
- package/src/Provider.js.map +1 -1
- package/src/Provider.tsx +10 -1
- package/src/createTheme.js +17 -6
- package/src/createTheme.js.map +1 -1
- package/src/createTheme.ts +19 -12
- package/src/createThemeValuesProxy.js +34 -22
- package/src/createThemeValuesProxy.js.map +1 -1
- package/src/createThemeValuesProxy.ts +49 -31
- package/src/types.ts +33 -2
- package/src/validators.js +10 -45
- package/src/validators.js.map +1 -1
- package/src/validators.ts +12 -49
package/src/DefaultTheme.ts
CHANGED
|
@@ -64,84 +64,84 @@ const DraftbitTheme = createTheme({
|
|
|
64
64
|
},
|
|
65
65
|
},
|
|
66
66
|
typography: {
|
|
67
|
-
|
|
67
|
+
body1: {
|
|
68
68
|
...systemWeights.regular,
|
|
69
|
+
fontSize: 16,
|
|
70
|
+
letterSpacing: 0,
|
|
71
|
+
lineHeight: 26,
|
|
72
|
+
},
|
|
73
|
+
body2: {
|
|
74
|
+
...systemWeights.regular,
|
|
75
|
+
fontSize: 14,
|
|
76
|
+
letterSpacing: 0,
|
|
77
|
+
lineHeight: 22,
|
|
78
|
+
},
|
|
79
|
+
button: {
|
|
80
|
+
...systemWeights.bold,
|
|
81
|
+
fontSize: 14,
|
|
82
|
+
letterSpacing: 0,
|
|
83
|
+
lineHeight: 16,
|
|
84
|
+
},
|
|
85
|
+
caption: {
|
|
86
|
+
...systemWeights.regular,
|
|
87
|
+
fontSize: 12,
|
|
88
|
+
letterSpacing: 0,
|
|
89
|
+
lineHeight: 16,
|
|
90
|
+
},
|
|
91
|
+
headline1: {
|
|
92
|
+
...systemWeights.bold,
|
|
69
93
|
fontSize: 60,
|
|
70
94
|
letterSpacing: 0,
|
|
71
95
|
lineHeight: 71,
|
|
72
96
|
},
|
|
73
97
|
headline2: {
|
|
74
|
-
...systemWeights.
|
|
98
|
+
...systemWeights.bold,
|
|
75
99
|
fontSize: 48,
|
|
76
100
|
letterSpacing: 0,
|
|
77
101
|
lineHeight: 58,
|
|
78
102
|
},
|
|
79
103
|
headline3: {
|
|
80
|
-
...systemWeights.
|
|
104
|
+
...systemWeights.bold,
|
|
81
105
|
fontSize: 34,
|
|
82
106
|
letterSpacing: 0,
|
|
83
107
|
lineHeight: 40,
|
|
84
108
|
},
|
|
85
109
|
headline4: {
|
|
86
|
-
...systemWeights.
|
|
110
|
+
...systemWeights.bold,
|
|
87
111
|
fontSize: 24,
|
|
88
112
|
letterSpacing: 0,
|
|
89
113
|
lineHeight: 34,
|
|
90
114
|
},
|
|
91
115
|
headline5: {
|
|
92
|
-
...systemWeights.
|
|
116
|
+
...systemWeights.bold,
|
|
93
117
|
fontSize: 20,
|
|
94
118
|
letterSpacing: 0,
|
|
95
119
|
lineHeight: 26,
|
|
96
120
|
},
|
|
97
|
-
|
|
98
|
-
...systemWeights.
|
|
121
|
+
headline6: {
|
|
122
|
+
...systemWeights.bold,
|
|
99
123
|
fontSize: 16,
|
|
100
124
|
letterSpacing: 0,
|
|
101
|
-
lineHeight:
|
|
125
|
+
lineHeight: 24,
|
|
102
126
|
},
|
|
103
|
-
|
|
127
|
+
overline: {
|
|
104
128
|
...systemWeights.regular,
|
|
105
|
-
fontSize:
|
|
106
|
-
letterSpacing:
|
|
107
|
-
lineHeight:
|
|
129
|
+
fontSize: 12,
|
|
130
|
+
letterSpacing: 2,
|
|
131
|
+
lineHeight: 16,
|
|
108
132
|
},
|
|
109
|
-
|
|
133
|
+
subtitle1: {
|
|
110
134
|
...systemWeights.regular,
|
|
111
135
|
fontSize: 16,
|
|
112
136
|
letterSpacing: 0,
|
|
113
137
|
lineHeight: 26,
|
|
114
138
|
},
|
|
115
|
-
|
|
139
|
+
subtitle2: {
|
|
116
140
|
...systemWeights.regular,
|
|
117
141
|
fontSize: 14,
|
|
118
142
|
letterSpacing: 0,
|
|
119
143
|
lineHeight: 22,
|
|
120
144
|
},
|
|
121
|
-
button: {
|
|
122
|
-
...systemWeights.regular,
|
|
123
|
-
fontSize: 14,
|
|
124
|
-
letterSpacing: 0,
|
|
125
|
-
lineHeight: 16,
|
|
126
|
-
},
|
|
127
|
-
caption: {
|
|
128
|
-
...systemWeights.regular,
|
|
129
|
-
fontSize: 12,
|
|
130
|
-
letterSpacing: 0,
|
|
131
|
-
lineHeight: 16,
|
|
132
|
-
},
|
|
133
|
-
overline: {
|
|
134
|
-
...systemWeights.regular,
|
|
135
|
-
fontSize: 12,
|
|
136
|
-
letterSpacing: 2,
|
|
137
|
-
lineHeight: 16,
|
|
138
|
-
},
|
|
139
|
-
headline6: {
|
|
140
|
-
...systemWeights.regular,
|
|
141
|
-
fontSize: 16,
|
|
142
|
-
letterSpacing: 0,
|
|
143
|
-
lineHeight: 24,
|
|
144
|
-
},
|
|
145
145
|
},
|
|
146
146
|
},
|
|
147
147
|
});
|
package/src/Provider.js
CHANGED
|
@@ -37,6 +37,7 @@ const Provider = ({ themes, breakpoints, initialThemeName, children, }) => {
|
|
|
37
37
|
foreground: createThemeValuesProxy(currentTheme.colors.foreground, breakpoints, deviceWidth, Platform.OS, lightDarkSelection),
|
|
38
38
|
border: createThemeValuesProxy(currentTheme.colors.border, breakpoints, deviceWidth, Platform.OS, lightDarkSelection),
|
|
39
39
|
},
|
|
40
|
+
typography: currentTheme.typography,
|
|
40
41
|
}), [currentTheme, deviceWidth, breakpoints, lightDarkSelection]);
|
|
41
42
|
React.useEffect(() => {
|
|
42
43
|
const listener = Dimensions.addEventListener("change", ({ window }) => setDeviceWidth(window.width));
|
|
@@ -47,8 +48,16 @@ const Provider = ({ themes, breakpoints, initialThemeName, children, }) => {
|
|
|
47
48
|
React.useEffect(() => {
|
|
48
49
|
const run = async () => {
|
|
49
50
|
const savedSelectedThemeName = await AsyncStorage.getItem(SAVED_SELECTED_THEME_KEY);
|
|
51
|
+
const themeExists = themes.some((t) => t.name === savedSelectedThemeName);
|
|
50
52
|
if (savedSelectedThemeName) {
|
|
51
|
-
|
|
53
|
+
if (themeExists) {
|
|
54
|
+
changeTheme(savedSelectedThemeName);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
AsyncStorage.removeItem(SAVED_SELECTED_THEME_KEY).catch((e) => {
|
|
58
|
+
console.warn("Failed to reset persisted selected theme", e);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
52
61
|
}
|
|
53
62
|
};
|
|
54
63
|
run();
|
package/src/Provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["Provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACpE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AE,KAAK,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACjD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,GAGZ,EAAE;IACX,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACvD,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAChB,SAAqC,EACrC,EAAE;IACF,OAAO,KAAK,CAAC,UAAU,CACrB,CAAC,KAA2B,EAAE,GAAmB,EAAE,EAAE;QACnD,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;QACjD,OAAO,oBAAC,SAAS,OAAM,KAAe,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;IACrE,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC"}
|
package/src/Provider.tsx
CHANGED
|
@@ -106,6 +106,7 @@ const Provider: React.FC<React.PropsWithChildren<ProviderProps>> = ({
|
|
|
106
106
|
lightDarkSelection
|
|
107
107
|
),
|
|
108
108
|
},
|
|
109
|
+
typography: currentTheme.typography,
|
|
109
110
|
}),
|
|
110
111
|
[currentTheme, deviceWidth, breakpoints, lightDarkSelection]
|
|
111
112
|
);
|
|
@@ -124,8 +125,16 @@ const Provider: React.FC<React.PropsWithChildren<ProviderProps>> = ({
|
|
|
124
125
|
const savedSelectedThemeName = await AsyncStorage.getItem(
|
|
125
126
|
SAVED_SELECTED_THEME_KEY
|
|
126
127
|
);
|
|
128
|
+
const themeExists = themes.some((t) => t.name === savedSelectedThemeName);
|
|
129
|
+
|
|
127
130
|
if (savedSelectedThemeName) {
|
|
128
|
-
|
|
131
|
+
if (themeExists) {
|
|
132
|
+
changeTheme(savedSelectedThemeName);
|
|
133
|
+
} else {
|
|
134
|
+
AsyncStorage.removeItem(SAVED_SELECTED_THEME_KEY).catch((e) => {
|
|
135
|
+
console.warn("Failed to reset persisted selected theme", e);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
129
138
|
}
|
|
130
139
|
};
|
|
131
140
|
run();
|
package/src/createTheme.js
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import merge from "deepmerge";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Custom deepmerge function to skip merging of typography/text style objects.
|
|
4
|
+
*
|
|
5
|
+
* The theme object allows for special keys that trigger variability depending
|
|
6
|
+
* on platform, breakpoint, color mode, etc.
|
|
7
|
+
*
|
|
8
|
+
* Text style objects can break this logic when merged with other objects.
|
|
9
|
+
* For example, if you merge a standard text style object with another object that
|
|
10
|
+
* has variability through the special keys, you get an object with both special
|
|
11
|
+
* keys and the keys of the style object which breaks how the proxy is able to
|
|
12
|
+
* return the correct value.
|
|
13
|
+
*/
|
|
14
|
+
export default function createTheme({ theme, baseTheme, }) {
|
|
15
|
+
// validateBreakpoints(breakpoints);
|
|
16
|
+
// validatePalettes(palettes);
|
|
17
|
+
// validateTheme(theme);
|
|
7
18
|
let resultTheme = theme;
|
|
8
19
|
if (baseTheme) {
|
|
9
|
-
validateTheme(baseTheme);
|
|
20
|
+
//validateTheme(baseTheme);
|
|
10
21
|
resultTheme = merge(baseTheme, theme);
|
|
11
22
|
}
|
|
12
23
|
return {
|
package/src/createTheme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTheme.js","sourceRoot":"","sources":["createTheme.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createTheme.js","sourceRoot":"","sources":["createTheme.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,WAAW,CAAC;AAE9B;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,KAAK,EACL,SAAS,GAMV;IACC,oCAAoC;IACpC,8BAA8B;IAC9B,wBAAwB;IAExB,IAAI,WAAW,GAAG,KAAK,CAAC;IAExB,IAAI,SAAS,EAAE;QACb,2BAA2B;QAC3B,WAAW,GAAG,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;KACvC;IAED,OAAO;QACL,GAAG,WAAW;QACd,SAAS,EAAE,IAAI;KAChB,CAAC;AACJ,CAAC"}
|
package/src/createTheme.ts
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
import merge from "deepmerge";
|
|
2
1
|
import type {
|
|
3
2
|
Breakpoints,
|
|
4
3
|
Theme,
|
|
5
4
|
ValidatedTheme,
|
|
6
5
|
ColorPalettes,
|
|
7
6
|
} from "./types";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
|
|
8
|
+
import merge from "deepmerge";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Custom deepmerge function to skip merging of typography/text style objects.
|
|
12
|
+
*
|
|
13
|
+
* The theme object allows for special keys that trigger variability depending
|
|
14
|
+
* on platform, breakpoint, color mode, etc.
|
|
15
|
+
*
|
|
16
|
+
* Text style objects can break this logic when merged with other objects.
|
|
17
|
+
* For example, if you merge a standard text style object with another object that
|
|
18
|
+
* has variability through the special keys, you get an object with both special
|
|
19
|
+
* keys and the keys of the style object which breaks how the proxy is able to
|
|
20
|
+
* return the correct value.
|
|
21
|
+
*/
|
|
13
22
|
|
|
14
23
|
export default function createTheme({
|
|
15
|
-
breakpoints,
|
|
16
|
-
palettes,
|
|
17
24
|
theme,
|
|
18
25
|
baseTheme,
|
|
19
26
|
}: {
|
|
@@ -22,14 +29,14 @@ export default function createTheme({
|
|
|
22
29
|
theme: Theme;
|
|
23
30
|
baseTheme?: Theme;
|
|
24
31
|
}): ValidatedTheme {
|
|
25
|
-
validateBreakpoints(breakpoints);
|
|
26
|
-
validatePalettes(palettes);
|
|
27
|
-
validateTheme(theme);
|
|
32
|
+
// validateBreakpoints(breakpoints);
|
|
33
|
+
// validatePalettes(palettes);
|
|
34
|
+
// validateTheme(theme);
|
|
28
35
|
|
|
29
36
|
let resultTheme = theme;
|
|
30
37
|
|
|
31
38
|
if (baseTheme) {
|
|
32
|
-
validateTheme(baseTheme);
|
|
39
|
+
//validateTheme(baseTheme);
|
|
33
40
|
resultTheme = merge(baseTheme, theme);
|
|
34
41
|
}
|
|
35
42
|
|
|
@@ -13,30 +13,33 @@ export default function createThemeValuesProxy(value, breakpoints, deviceWidth,
|
|
|
13
13
|
return new Proxy(value, {
|
|
14
14
|
get: (target, key) => {
|
|
15
15
|
const currentValue = target[key];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const valueAsThemeValues = isObject(currentValue)
|
|
17
|
+
? currentValue
|
|
18
|
+
: undefined;
|
|
19
|
+
if (valueAsThemeValues) {
|
|
20
20
|
const platformKeys = ["ios", "android", "web", "macos", "windows"];
|
|
21
21
|
const breakpointKeys = Object.keys(breakpoints);
|
|
22
22
|
const lightDarkKeys = ["light", "dark"];
|
|
23
|
-
const keysType = getKeysType(
|
|
23
|
+
const keysType = getKeysType(valueAsThemeValues, platformKeys, breakpointKeys, lightDarkKeys);
|
|
24
24
|
if (keysType === "default") {
|
|
25
|
-
return createThemeValuesProxy(
|
|
25
|
+
return createThemeValuesProxy(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
|
|
26
26
|
}
|
|
27
27
|
else if (keysType === "platform") {
|
|
28
|
-
return getPlatformValue(
|
|
28
|
+
return getPlatformValue(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
|
|
29
29
|
}
|
|
30
30
|
else if (keysType === "breakpoint") {
|
|
31
|
-
return getBreakpointValue(
|
|
31
|
+
return getBreakpointValue(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
|
|
32
32
|
}
|
|
33
33
|
else if (keysType === "lightDark") {
|
|
34
|
-
return getLightDarkValue(
|
|
34
|
+
return getLightDarkValue(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
37
|
return undefined;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
else {
|
|
41
|
+
return currentValue;
|
|
42
|
+
}
|
|
40
43
|
},
|
|
41
44
|
set: () => {
|
|
42
45
|
throw new Error("Theme is read only, cannot be modified at runtime");
|
|
@@ -77,17 +80,20 @@ function allFalse(a, b, c, d) {
|
|
|
77
80
|
}
|
|
78
81
|
function getPlatformValue(value, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection) {
|
|
79
82
|
var _a;
|
|
80
|
-
const currentPlatformValue = (_a = value[devicePlatform]) !== null && _a !== void 0 ? _a : value.default;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
const currentPlatformValue = (_a = value === null || value === void 0 ? void 0 : value[devicePlatform]) !== null && _a !== void 0 ? _a : value === null || value === void 0 ? void 0 : value.default;
|
|
84
|
+
const valueAsThemeValues = isObject(currentPlatformValue)
|
|
85
|
+
? currentPlatformValue
|
|
86
|
+
: undefined;
|
|
87
|
+
if (valueAsThemeValues) {
|
|
88
|
+
return createThemeValuesProxy(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
|
|
83
89
|
}
|
|
84
90
|
else {
|
|
85
|
-
return
|
|
91
|
+
return currentPlatformValue;
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
function getBreakpointValue(value, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection) {
|
|
89
95
|
var _a;
|
|
90
|
-
const keysToBreakpointValue = Object.keys(value).map((key) => [key, breakpoints[key]]);
|
|
96
|
+
const keysToBreakpointValue = Object.keys(value !== null && value !== void 0 ? value : {}).map((key) => [key, breakpoints[key]]);
|
|
91
97
|
const orderedBreakpoints = keysToBreakpointValue.sort(([_, val]) => val);
|
|
92
98
|
let currentBreakpointKey = "";
|
|
93
99
|
for (const [breakpointKey, breakpointValue] of orderedBreakpoints) {
|
|
@@ -95,22 +101,28 @@ function getBreakpointValue(value, breakpoints, deviceWidth, devicePlatform, cur
|
|
|
95
101
|
currentBreakpointKey = breakpointKey;
|
|
96
102
|
}
|
|
97
103
|
}
|
|
98
|
-
const currentBreakpointValue = (_a = value[currentBreakpointKey]) !== null && _a !== void 0 ? _a : value.default;
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
const currentBreakpointValue = (_a = value === null || value === void 0 ? void 0 : value[currentBreakpointKey]) !== null && _a !== void 0 ? _a : value === null || value === void 0 ? void 0 : value.default;
|
|
105
|
+
const valueAsThemeValues = isObject(currentBreakpointKey)
|
|
106
|
+
? currentBreakpointKey
|
|
107
|
+
: undefined;
|
|
108
|
+
if (valueAsThemeValues) {
|
|
109
|
+
return createThemeValuesProxy(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
|
|
101
110
|
}
|
|
102
111
|
else {
|
|
103
|
-
return
|
|
112
|
+
return currentBreakpointValue;
|
|
104
113
|
}
|
|
105
114
|
}
|
|
106
115
|
function getLightDarkValue(value, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection) {
|
|
107
116
|
var _a;
|
|
108
|
-
const currentLightDarkValue = (_a = value[currentLightDarkSelection]) !== null && _a !== void 0 ? _a : value.default;
|
|
109
|
-
|
|
110
|
-
|
|
117
|
+
const currentLightDarkValue = (_a = value === null || value === void 0 ? void 0 : value[currentLightDarkSelection]) !== null && _a !== void 0 ? _a : value === null || value === void 0 ? void 0 : value.default;
|
|
118
|
+
const valueAsThemeValues = isObject(currentLightDarkSelection)
|
|
119
|
+
? currentLightDarkSelection
|
|
120
|
+
: undefined;
|
|
121
|
+
if (valueAsThemeValues) {
|
|
122
|
+
return createThemeValuesProxy(valueAsThemeValues, breakpoints, deviceWidth, devicePlatform, currentLightDarkSelection);
|
|
111
123
|
}
|
|
112
124
|
else {
|
|
113
|
-
return
|
|
125
|
+
return currentLightDarkValue;
|
|
114
126
|
}
|
|
115
127
|
}
|
|
116
128
|
//# sourceMappingURL=createThemeValuesProxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThemeValuesProxy.js","sourceRoot":"","sources":["createThemeValuesProxy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,KAA8B,EAC9B,WAAwB,EACxB,WAAmB,EACnB,cAAkC,EAClC,yBAA2C;IAE3C,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE;QACzC,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE;QACtB,GAAG,EAAE,CACH,MAAmB,EACnB,GAAW,
|
|
1
|
+
{"version":3,"file":"createThemeValuesProxy.js","sourceRoot":"","sources":["createThemeValuesProxy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,KAA8B,EAC9B,WAAwB,EACxB,WAAmB,EACnB,cAAkC,EAClC,yBAA2C;IAE3C,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE;QACzC,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE;QACtB,GAAG,EAAE,CACH,MAAmB,EACnB,GAAW,EAC4C,EAAE;YACzD,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAEjC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,YAAY,CAAC;gBAC/C,CAAC,CAAE,YAA4B;gBAC/B,CAAC,CAAC,SAAS,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;AACH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ThemeValues, Breakpoints } from "./types";
|
|
2
|
-
import { Platform } from "react-native";
|
|
2
|
+
import { Platform, TextStyle } from "react-native";
|
|
3
3
|
import { isObject } from "lodash";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -23,16 +23,20 @@ export default function createThemeValuesProxy(
|
|
|
23
23
|
get: (
|
|
24
24
|
target: ThemeValues,
|
|
25
25
|
key: string
|
|
26
|
-
): string | number | ThemeValues | undefined => {
|
|
26
|
+
): string | number | ThemeValues | TextStyle | undefined => {
|
|
27
27
|
const currentValue = target[key];
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
|
|
29
|
+
const valueAsThemeValues = isObject(currentValue)
|
|
30
|
+
? (currentValue as ThemeValues)
|
|
31
|
+
: undefined;
|
|
32
|
+
|
|
33
|
+
if (valueAsThemeValues) {
|
|
31
34
|
const platformKeys = ["ios", "android", "web", "macos", "windows"];
|
|
32
35
|
const breakpointKeys = Object.keys(breakpoints);
|
|
33
36
|
const lightDarkKeys = ["light", "dark"];
|
|
37
|
+
|
|
34
38
|
const keysType = getKeysType(
|
|
35
|
-
|
|
39
|
+
valueAsThemeValues,
|
|
36
40
|
platformKeys,
|
|
37
41
|
breakpointKeys,
|
|
38
42
|
lightDarkKeys
|
|
@@ -40,7 +44,7 @@ export default function createThemeValuesProxy(
|
|
|
40
44
|
|
|
41
45
|
if (keysType === "default") {
|
|
42
46
|
return createThemeValuesProxy(
|
|
43
|
-
|
|
47
|
+
valueAsThemeValues,
|
|
44
48
|
breakpoints,
|
|
45
49
|
deviceWidth,
|
|
46
50
|
devicePlatform,
|
|
@@ -48,7 +52,7 @@ export default function createThemeValuesProxy(
|
|
|
48
52
|
);
|
|
49
53
|
} else if (keysType === "platform") {
|
|
50
54
|
return getPlatformValue(
|
|
51
|
-
|
|
55
|
+
valueAsThemeValues,
|
|
52
56
|
breakpoints,
|
|
53
57
|
deviceWidth,
|
|
54
58
|
devicePlatform,
|
|
@@ -56,7 +60,7 @@ export default function createThemeValuesProxy(
|
|
|
56
60
|
);
|
|
57
61
|
} else if (keysType === "breakpoint") {
|
|
58
62
|
return getBreakpointValue(
|
|
59
|
-
|
|
63
|
+
valueAsThemeValues,
|
|
60
64
|
breakpoints,
|
|
61
65
|
deviceWidth,
|
|
62
66
|
devicePlatform,
|
|
@@ -64,7 +68,7 @@ export default function createThemeValuesProxy(
|
|
|
64
68
|
);
|
|
65
69
|
} else if (keysType === "lightDark") {
|
|
66
70
|
return getLightDarkValue(
|
|
67
|
-
|
|
71
|
+
valueAsThemeValues,
|
|
68
72
|
breakpoints,
|
|
69
73
|
deviceWidth,
|
|
70
74
|
devicePlatform,
|
|
@@ -73,6 +77,8 @@ export default function createThemeValuesProxy(
|
|
|
73
77
|
} else {
|
|
74
78
|
return undefined;
|
|
75
79
|
}
|
|
80
|
+
} else {
|
|
81
|
+
return currentValue;
|
|
76
82
|
}
|
|
77
83
|
},
|
|
78
84
|
set: () => {
|
|
@@ -140,36 +146,40 @@ function allFalse(a: boolean, b: boolean, c: boolean, d: boolean) {
|
|
|
140
146
|
}
|
|
141
147
|
|
|
142
148
|
function getPlatformValue(
|
|
143
|
-
value: ThemeValues,
|
|
149
|
+
value: ThemeValues | undefined,
|
|
144
150
|
breakpoints: Breakpoints,
|
|
145
151
|
deviceWidth: number,
|
|
146
152
|
devicePlatform: typeof Platform.OS,
|
|
147
153
|
currentLightDarkSelection: "light" | "dark"
|
|
148
154
|
) {
|
|
149
|
-
const currentPlatformValue = value[devicePlatform] ?? value
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
155
|
+
const currentPlatformValue = value?.[devicePlatform] ?? value?.default;
|
|
156
|
+
const valueAsThemeValues = isObject(currentPlatformValue)
|
|
157
|
+
? (currentPlatformValue as ThemeValues)
|
|
158
|
+
: undefined;
|
|
159
|
+
|
|
160
|
+
if (valueAsThemeValues) {
|
|
153
161
|
return createThemeValuesProxy(
|
|
154
|
-
|
|
162
|
+
valueAsThemeValues,
|
|
155
163
|
breakpoints,
|
|
156
164
|
deviceWidth,
|
|
157
165
|
devicePlatform,
|
|
158
166
|
currentLightDarkSelection
|
|
159
167
|
);
|
|
168
|
+
} else {
|
|
169
|
+
return currentPlatformValue;
|
|
160
170
|
}
|
|
161
171
|
}
|
|
162
172
|
|
|
163
173
|
function getBreakpointValue(
|
|
164
|
-
value: ThemeValues,
|
|
174
|
+
value: ThemeValues | undefined,
|
|
165
175
|
breakpoints: Breakpoints,
|
|
166
176
|
deviceWidth: number,
|
|
167
177
|
devicePlatform: typeof Platform.OS,
|
|
168
178
|
currentLightDarkSelection: "light" | "dark"
|
|
169
179
|
) {
|
|
170
|
-
const keysToBreakpointValue: [string, number][] = Object.keys(
|
|
171
|
-
|
|
172
|
-
);
|
|
180
|
+
const keysToBreakpointValue: [string, number][] = Object.keys(
|
|
181
|
+
value ?? {}
|
|
182
|
+
).map((key) => [key, breakpoints[key]]);
|
|
173
183
|
const orderedBreakpoints = keysToBreakpointValue.sort(([_, val]) => val);
|
|
174
184
|
let currentBreakpointKey = "";
|
|
175
185
|
for (const [breakpointKey, breakpointValue] of orderedBreakpoints) {
|
|
@@ -177,39 +187,47 @@ function getBreakpointValue(
|
|
|
177
187
|
currentBreakpointKey = breakpointKey;
|
|
178
188
|
}
|
|
179
189
|
}
|
|
180
|
-
const currentBreakpointValue =
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
190
|
+
const currentBreakpointValue =
|
|
191
|
+
value?.[currentBreakpointKey] ?? value?.default;
|
|
192
|
+
const valueAsThemeValues = isObject(currentBreakpointKey)
|
|
193
|
+
? (currentBreakpointKey as ThemeValues)
|
|
194
|
+
: undefined;
|
|
195
|
+
|
|
196
|
+
if (valueAsThemeValues) {
|
|
184
197
|
return createThemeValuesProxy(
|
|
185
|
-
|
|
198
|
+
valueAsThemeValues,
|
|
186
199
|
breakpoints,
|
|
187
200
|
deviceWidth,
|
|
188
201
|
devicePlatform,
|
|
189
202
|
currentLightDarkSelection
|
|
190
203
|
);
|
|
204
|
+
} else {
|
|
205
|
+
return currentBreakpointValue;
|
|
191
206
|
}
|
|
192
207
|
}
|
|
193
208
|
|
|
194
209
|
function getLightDarkValue(
|
|
195
|
-
value: ThemeValues,
|
|
210
|
+
value: ThemeValues | undefined,
|
|
196
211
|
breakpoints: Breakpoints,
|
|
197
212
|
deviceWidth: number,
|
|
198
213
|
devicePlatform: typeof Platform.OS,
|
|
199
214
|
currentLightDarkSelection: "light" | "dark"
|
|
200
215
|
) {
|
|
201
216
|
const currentLightDarkValue =
|
|
202
|
-
value[currentLightDarkSelection] ?? value
|
|
217
|
+
value?.[currentLightDarkSelection] ?? value?.default;
|
|
218
|
+
const valueAsThemeValues = isObject(currentLightDarkSelection)
|
|
219
|
+
? (currentLightDarkSelection as ThemeValues)
|
|
220
|
+
: undefined;
|
|
203
221
|
|
|
204
|
-
if (
|
|
205
|
-
return currentLightDarkValue;
|
|
206
|
-
} else {
|
|
222
|
+
if (valueAsThemeValues) {
|
|
207
223
|
return createThemeValuesProxy(
|
|
208
|
-
|
|
224
|
+
valueAsThemeValues,
|
|
209
225
|
breakpoints,
|
|
210
226
|
deviceWidth,
|
|
211
227
|
devicePlatform,
|
|
212
228
|
currentLightDarkSelection
|
|
213
229
|
);
|
|
230
|
+
} else {
|
|
231
|
+
return currentLightDarkValue;
|
|
214
232
|
}
|
|
215
233
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { TextStyle } from "react-native";
|
|
2
|
+
|
|
1
3
|
export type ThemeValues = {
|
|
2
|
-
[key: string]: string | number | ThemeValues;
|
|
4
|
+
[key: string]: string | number | TextStyle | ThemeValues;
|
|
3
5
|
};
|
|
4
6
|
|
|
5
7
|
export type Theme = {
|
|
@@ -11,7 +13,21 @@ export type Theme = {
|
|
|
11
13
|
foreground?: ThemeValues;
|
|
12
14
|
border?: ThemeValues;
|
|
13
15
|
};
|
|
14
|
-
typography: {
|
|
16
|
+
typography: {
|
|
17
|
+
body1?: ThemeValues | TextStyle;
|
|
18
|
+
body2?: ThemeValues | TextStyle;
|
|
19
|
+
button?: ThemeValues | TextStyle;
|
|
20
|
+
caption?: ThemeValues | TextStyle;
|
|
21
|
+
headline1?: ThemeValues | TextStyle;
|
|
22
|
+
headline2?: ThemeValues | TextStyle;
|
|
23
|
+
headline3?: ThemeValues | TextStyle;
|
|
24
|
+
headline4?: ThemeValues | TextStyle;
|
|
25
|
+
headline5?: ThemeValues | TextStyle;
|
|
26
|
+
headline6?: ThemeValues | TextStyle;
|
|
27
|
+
overline?: ThemeValues | TextStyle;
|
|
28
|
+
subtitle1?: ThemeValues | TextStyle;
|
|
29
|
+
subtitle2?: ThemeValues | TextStyle;
|
|
30
|
+
};
|
|
15
31
|
};
|
|
16
32
|
|
|
17
33
|
export type ValidatedTheme = Theme & {
|
|
@@ -26,6 +42,21 @@ export type ReadTheme = Theme & {
|
|
|
26
42
|
foreground?: any;
|
|
27
43
|
border?: any;
|
|
28
44
|
};
|
|
45
|
+
typography: {
|
|
46
|
+
body1?: any;
|
|
47
|
+
body2?: any;
|
|
48
|
+
button?: any;
|
|
49
|
+
caption?: any;
|
|
50
|
+
headline1?: any;
|
|
51
|
+
headline2?: any;
|
|
52
|
+
headline3?: any;
|
|
53
|
+
headline4?: any;
|
|
54
|
+
headline5?: any;
|
|
55
|
+
headline6?: any;
|
|
56
|
+
overline?: any;
|
|
57
|
+
subtitle1?: any;
|
|
58
|
+
subtitle2?: any;
|
|
59
|
+
};
|
|
29
60
|
};
|
|
30
61
|
|
|
31
62
|
export type ColorPaletteValues = {
|