@tamagui/core 1.0.0-alpha.2 → 1.0.0-alpha.7
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/createComponent.js +43 -29
- package/dist/createComponent.js.map +2 -2
- package/dist/createFont.js +4 -0
- package/dist/createFont.js.map +2 -2
- package/dist/createTamagui.js +7 -0
- package/dist/createTamagui.js.map +2 -2
- package/dist/createTokens.js +4 -0
- package/dist/createTokens.js.map +2 -2
- package/dist/createVariable.js +3 -0
- package/dist/createVariable.js.map +2 -2
- package/dist/helpers/getSplitStyles.js +1 -13
- package/dist/helpers/getSplitStyles.js.map +2 -2
- package/dist/helpers/isComponent.js +10 -0
- package/dist/helpers/isComponent.js.map +7 -0
- package/dist/helpers/isTamaguiComponent.js +10 -0
- package/dist/helpers/isTamaguiComponent.js.map +7 -0
- package/dist/helpers/isTamaguiElement.js +10 -0
- package/dist/helpers/isTamaguiElement.js.map +7 -0
- package/dist/helpers/validate.js +60 -0
- package/dist/helpers/validate.js.map +7 -0
- package/dist/helpers/validateConfig.js +46 -0
- package/dist/helpers/validateConfig.js.map +7 -0
- package/dist/helpers/validateTokens.js +29 -0
- package/dist/helpers/validateTokens.js.map +7 -0
- package/dist/hooks/useMedia.js +1 -1
- package/dist/hooks/useMedia.js.map +2 -2
- package/dist/hooks/useTheme.js +1 -1
- package/dist/hooks/useTheme.js.map +2 -2
- package/dist/index.cjs +223 -137
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +1 -2
- package/dist/index.js.map +2 -2
- package/dist/views/Theme.js +16 -7
- package/dist/views/Theme.js.map +2 -2
- package/dist/views/ThemeInverse.js +0 -1
- package/dist/views/ThemeInverse.js.map +2 -2
- package/dist/views/ThemeManagerContext.js +7 -1
- package/dist/views/ThemeManagerContext.js.map +2 -2
- package/package.json +12 -5
- package/src/createComponent.tsx +49 -38
- package/src/createFont.ts +5 -0
- package/src/createTamagui.ts +8 -0
- package/src/createTokens.ts +6 -1
- package/src/createVariable.ts +4 -0
- package/src/helpers/getSplitStyles.tsx +3 -16
- package/src/helpers/isTamaguiElement.tsx +5 -0
- package/src/helpers/validate.ts +59 -0
- package/src/hooks/useMedia.tsx +1 -1
- package/src/hooks/useTheme.tsx +1 -1
- package/src/index.ts +1 -2
- package/src/types.tsx +1 -0
- package/src/views/Theme.tsx +26 -9
- package/src/views/ThemeInverse.tsx +0 -1
- package/src/views/ThemeManagerContext.tsx +11 -1
- package/types.d.ts +3 -5
- package/.ultra.cache.json +0 -1
- package/_/constants/constants.js +0 -14
- package/_/constants/constants.js.map +0 -7
- package/_/constants/platform.js +0 -20
- package/_/constants/platform.js.map +0 -7
- package/_/constants/pseudos.js +0 -18
- package/_/constants/pseudos.js.map +0 -7
- package/_/constants/rnw.js +0 -22
- package/_/constants/rnw.js.map +0 -7
- package/_/createComponent.js +0 -427
- package/_/createComponent.js.map +0 -7
- package/_/createShorthands.js +0 -10
- package/_/createShorthands.js.map +0 -7
- package/_/createTamagui.js +0 -122
- package/_/createTamagui.js.map +0 -7
- package/_/createTheme.js +0 -20
- package/_/createTheme.js.map +0 -7
- package/_/createTokens.js +0 -29
- package/_/createTokens.js.map +0 -7
- package/_/createVariable.js +0 -22
- package/_/createVariable.js.map +0 -7
- package/_/helpers/addStylesUsingClassname.js +0 -32
- package/_/helpers/addStylesUsingClassname.js.map +0 -7
- package/_/helpers/createMediaStyle.js +0 -34
- package/_/helpers/createMediaStyle.js.map +0 -7
- package/_/helpers/createTamaguiProvider.js +0 -42
- package/_/helpers/createTamaguiProvider.js.map +0 -7
- package/_/helpers/extendStaticConfig.js +0 -176
- package/_/helpers/extendStaticConfig.js.map +0 -7
- package/_/helpers/fixNativeShadow.js +0 -8
- package/_/helpers/fixNativeShadow.js.map +0 -7
- package/_/helpers/fixNativeShadow.native.js +0 -30
- package/_/helpers/fixNativeShadow.native.js.map +0 -7
- package/_/helpers/getSplitStyles.js +0 -160
- package/_/helpers/getSplitStyles.js.map +0 -7
- package/_/helpers/getStylesAtomic.js +0 -84
- package/_/helpers/getStylesAtomic.js.map +0 -7
- package/_/helpers/getStylesAtomic.native.js +0 -10
- package/_/helpers/getStylesAtomic.native.js.map +0 -7
- package/_/helpers/insertStyleRule.js +0 -24
- package/_/helpers/insertStyleRule.js.map +0 -7
- package/_/helpers/matchMedia.js +0 -15
- package/_/helpers/matchMedia.js.map +0 -7
- package/_/helpers/matchMedia.native.js +0 -8
- package/_/helpers/matchMedia.native.js.map +0 -7
- package/_/helpers/themeable.js +0 -26
- package/_/helpers/themeable.js.map +0 -7
- package/_/hooks/useConstant.js +0 -15
- package/_/hooks/useConstant.js.map +0 -7
- package/_/hooks/useFeatures.js +0 -75
- package/_/hooks/useFeatures.js.map +0 -7
- package/_/hooks/useForceUpdate.js +0 -28
- package/_/hooks/useForceUpdate.js.map +0 -7
- package/_/hooks/useMedia.js +0 -173
- package/_/hooks/useMedia.js.map +0 -7
- package/_/hooks/usePressable.js +0 -14
- package/_/hooks/usePressable.js.map +0 -7
- package/_/hooks/useTheme.js +0 -94
- package/_/hooks/useTheme.js.map +0 -7
- package/_/index.js +0 -30
- package/_/index.js.map +0 -7
- package/_/static/postProcessStyles.js +0 -18
- package/_/static/postProcessStyles.js.map +0 -7
- package/_/static.js +0 -12
- package/_/static.js.map +0 -7
- package/_/styled.js +0 -21
- package/_/styled.js.map +0 -7
- package/_/types.js +0 -1
- package/_/types.js.map +0 -7
- package/_/views/Animated.js +0 -79
- package/_/views/Animated.js.map +0 -7
- package/_/views/Stack.js +0 -12
- package/_/views/Stack.js.map +0 -7
- package/_/views/Text.js +0 -60
- package/_/views/Text.js.map +0 -7
- package/_/views/TextAncestorContext.js +0 -19
- package/_/views/TextAncestorContext.js.map +0 -7
- package/_/views/Theme.js +0 -57
- package/_/views/Theme.js.map +0 -7
- package/_/views/ThemeContext.js +0 -6
- package/_/views/ThemeContext.js.map +0 -7
- package/_/views/ThemeInverse.js +0 -27
- package/_/views/ThemeInverse.js.map +0 -7
- package/_/views/ThemeManagerContext.js +0 -56
- package/_/views/ThemeManagerContext.js.map +0 -7
- package/_/views/ThemeProvider.js +0 -45
- package/_/views/ThemeProvider.js.map +0 -7
- package/src/hooks/useForceUpdate.tsx +0 -26
- package/src/views/SafeAreaProvider.tsx +0 -33
- package/tsconfig.json +0 -8
package/dist/index.js
CHANGED
|
@@ -15,8 +15,8 @@ export * from "./helpers/isObj";
|
|
|
15
15
|
export * from "./helpers/getStylesAtomic";
|
|
16
16
|
export * from "./helpers/matchMedia";
|
|
17
17
|
export * from "./helpers/themeable";
|
|
18
|
+
export * from "./helpers/isTamaguiElement";
|
|
18
19
|
export * from "./hooks/useConstant";
|
|
19
|
-
export * from "./hooks/useForceUpdate";
|
|
20
20
|
export * from "./hooks/useMedia";
|
|
21
21
|
export * from "./hooks/useTheme";
|
|
22
22
|
export * from "./views/Animated";
|
|
@@ -26,7 +26,6 @@ export * from "./views/Theme";
|
|
|
26
26
|
export * from "./views/ThemeInverse";
|
|
27
27
|
export * from "./views/ThemeProvider";
|
|
28
28
|
export * from "./views/TextAncestorContext";
|
|
29
|
-
export * from "./views/SafeAreaProvider";
|
|
30
29
|
export {
|
|
31
30
|
createTokens
|
|
32
31
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport { createTokens } from './createTokens'\nexport * from './createVariable'\nexport * from './styled'\nexport * from './types'\n\nexport * from './constants/pseudos'\nexport * from './constants/constants'\nexport * from './constants/platform'\nexport * from './constants/rnw'\n\nexport * from './helpers/isObj'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/matchMedia'\nexport * from './helpers/themeable'\
|
|
5
|
-
"mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;
|
|
4
|
+
"sourcesContent": ["export * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport { createTokens } from './createTokens'\nexport * from './createVariable'\nexport * from './styled'\nexport * from './types'\n\nexport * from './constants/pseudos'\nexport * from './constants/constants'\nexport * from './constants/platform'\nexport * from './constants/rnw'\n\nexport * from './helpers/isObj'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/matchMedia'\nexport * from './helpers/themeable'\nexport * from './helpers/isTamaguiElement'\n\nexport * from './hooks/useConstant'\nexport * from './hooks/useMedia'\nexport * from './hooks/useTheme'\n\nexport * from './views/Animated'\nexport * from './views/Stack'\nexport * from './views/Text'\nexport * from './views/Theme'\nexport * from './views/ThemeInverse'\nexport * from './views/ThemeProvider'\nexport * from './views/TextAncestorContext'\n"],
|
|
5
|
+
"mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/views/Theme.js
CHANGED
|
@@ -11,28 +11,37 @@ const Theme = /* @__PURE__ */ __name((props) => {
|
|
|
11
11
|
const themes = useContext(ThemeContext);
|
|
12
12
|
const [parentName, setParentName] = useState(parent.name || "light");
|
|
13
13
|
if (!themes) {
|
|
14
|
-
console.warn("no themes
|
|
14
|
+
console.warn("Error, no themes in context", props);
|
|
15
15
|
return props.children;
|
|
16
16
|
}
|
|
17
17
|
const name = props.name;
|
|
18
|
-
const
|
|
18
|
+
const nextNameParent = `${name}-${parentName}`;
|
|
19
|
+
const nextNameParentParent = `${name}-${parent.parentName}`;
|
|
20
|
+
const activeName = !name ? null : name in themes ? name : nextNameParent in themes ? nextNameParent : nextNameParentParent in themes ? nextNameParentParent : null;
|
|
21
|
+
const theme = activeName ? themes[activeName] : null;
|
|
19
22
|
const themeManager = useConstant(() => {
|
|
23
|
+
if (!theme) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
20
26
|
const manager = new ThemeManager();
|
|
21
27
|
if (name) {
|
|
22
|
-
manager.setActiveTheme(name, themes[name]);
|
|
28
|
+
manager.setActiveTheme({ name, theme: themes[name], parentName });
|
|
23
29
|
}
|
|
24
30
|
return manager;
|
|
25
31
|
});
|
|
26
32
|
useIsomorphicLayoutEffect(() => {
|
|
27
|
-
themeManager
|
|
33
|
+
if (!themeManager) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
themeManager.setActiveTheme({ name: activeName, theme, parentName });
|
|
28
37
|
return parent.onChangeTheme((next) => {
|
|
29
38
|
if (next) {
|
|
30
|
-
themeManager.setActiveTheme(next, themes[next]);
|
|
39
|
+
themeManager.setActiveTheme({ name: next, theme: themes[next], parentName });
|
|
31
40
|
setParentName(next);
|
|
32
41
|
}
|
|
33
42
|
});
|
|
34
|
-
}, [themes,
|
|
35
|
-
if (!name) {
|
|
43
|
+
}, [themes, activeName, parentName]);
|
|
44
|
+
if (!name || !theme) {
|
|
36
45
|
return props.children;
|
|
37
46
|
}
|
|
38
47
|
const contents = themeManager ? /* @__PURE__ */ React.createElement(ThemeManagerContext.Provider, {
|
package/dist/views/Theme.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/views/Theme.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useContext, useState } from 'react'\n\nimport { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'\nimport { getThemeParentClassName } from '../createTamagui'\nimport { useConstant } from '../hooks/useConstant'\nimport { ThemeName
|
|
5
|
-
"mappings": ";;AAAA;AAEA;AACA;AACA;AAEA;AACA;AAQO,MAAM,QAAQ,wBAAC,UAAsB;AAC1C,QAAM,SAAS,WAAW;AAC1B,QAAM,SAAS,WAAW;AAC1B,QAAM,CAAC,YAAY,iBAAiB,SAAS,OAAO,QAAQ;AAC5D,MAAI,CAAC,QAAQ;AACX,YAAQ,KAAK
|
|
4
|
+
"sourcesContent": ["import React, { useContext, useState } from 'react'\n\nimport { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'\nimport { getThemeParentClassName } from '../createTamagui'\nimport { useConstant } from '../hooks/useConstant'\nimport { ThemeName } from '../types'\nimport { ThemeContext } from './ThemeContext'\nimport { ThemeManager, ThemeManagerContext } from './ThemeManagerContext'\n\nexport type ThemeProps = {\n disableThemeClass?: boolean\n name: ThemeName | null\n children?: any\n}\n\nexport const Theme = (props: ThemeProps) => {\n const parent = useContext(ThemeManagerContext)\n const themes = useContext(ThemeContext)\n const [parentName, setParentName] = useState(parent.name || 'light')\n if (!themes) {\n console.warn('Error, no themes in context', props)\n return props.children\n }\n const name = props.name as string\n const nextNameParent = `${name}-${parentName}`\n const nextNameParentParent = `${name}-${parent.parentName}`\n const activeName = !name\n ? null\n : name in themes\n ? name\n : nextNameParent in themes\n ? nextNameParent\n : nextNameParentParent in themes\n ? nextNameParentParent\n : null\n const theme = activeName ? themes[activeName] : null\n const themeManager = useConstant<ThemeManager | null>(() => {\n if (!theme) {\n return null\n }\n const manager = new ThemeManager()\n if (name) {\n manager.setActiveTheme({ name, theme: themes[name], parentName })\n }\n return manager\n })\n\n useIsomorphicLayoutEffect(() => {\n if (!themeManager) {\n return\n }\n themeManager.setActiveTheme({ name: activeName, theme, parentName })\n return parent.onChangeTheme((next) => {\n if (next) {\n themeManager.setActiveTheme({ name: next, theme: themes[next], parentName })\n setParentName(next)\n }\n })\n }, [themes, activeName, parentName])\n\n if (!name || !theme) {\n return props.children\n }\n\n const contents = themeManager ? (\n <ThemeManagerContext.Provider value={themeManager}>\n {props.children}\n </ThemeManagerContext.Provider>\n ) : (\n props.children\n )\n\n if (isWeb) {\n if (props.disableThemeClass) {\n return contents\n }\n const color = themes[name]?.['color']?.['variable']\n return (\n <div\n className={getThemeParentClassName(name)}\n // in order to provide currentColor, set color by default\n style={{ display: 'contents', color }}\n >\n {contents}\n </div>\n )\n }\n\n return contents\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAEA;AACA;AACA;AAEA;AACA;AAQO,MAAM,QAAQ,wBAAC,UAAsB;AAC1C,QAAM,SAAS,WAAW;AAC1B,QAAM,SAAS,WAAW;AAC1B,QAAM,CAAC,YAAY,iBAAiB,SAAS,OAAO,QAAQ;AAC5D,MAAI,CAAC,QAAQ;AACX,YAAQ,KAAK,+BAA+B;AAC5C,WAAO,MAAM;AAAA;AAEf,QAAM,OAAO,MAAM;AACnB,QAAM,iBAAiB,GAAG,QAAQ;AAClC,QAAM,uBAAuB,GAAG,QAAQ,OAAO;AAC/C,QAAM,aAAa,CAAC,OAChB,OACA,QAAQ,SACR,OACA,kBAAkB,SAClB,iBACA,wBAAwB,SACxB,uBACA;AACJ,QAAM,QAAQ,aAAa,OAAO,cAAc;AAChD,QAAM,eAAe,YAAiC,MAAM;AAC1D,QAAI,CAAC,OAAO;AACV,aAAO;AAAA;AAET,UAAM,UAAU,IAAI;AACpB,QAAI,MAAM;AACR,cAAQ,eAAe,EAAE,MAAM,OAAO,OAAO,OAAO;AAAA;AAEtD,WAAO;AAAA;AAGT,4BAA0B,MAAM;AAC9B,QAAI,CAAC,cAAc;AACjB;AAAA;AAEF,iBAAa,eAAe,EAAE,MAAM,YAAY,OAAO;AACvD,WAAO,OAAO,cAAc,CAAC,SAAS;AACpC,UAAI,MAAM;AACR,qBAAa,eAAe,EAAE,MAAM,MAAM,OAAO,OAAO,OAAO;AAC/D,sBAAc;AAAA;AAAA;AAAA,KAGjB,CAAC,QAAQ,YAAY;AAExB,MAAI,CAAC,QAAQ,CAAC,OAAO;AACnB,WAAO,MAAM;AAAA;AAGf,QAAM,WAAW,eACf,oCAAC,oBAAoB,UAArB;AAAA,IAA8B,OAAO;AAAA,KAClC,MAAM,YAGT,MAAM;AAGR,MAAI,OAAO;AACT,QAAI,MAAM,mBAAmB;AAC3B,aAAO;AAAA;AAET,UAAM,QAAQ,OAAO,QAAQ,WAAW;AACxC,WACE,oCAAC,OAAD;AAAA,MACE,WAAW,wBAAwB;AAAA,MAEnC,OAAO,EAAE,SAAS,YAAY;AAAA,OAE7B;AAAA;AAKP,SAAO;AAAA,GAzEY;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -15,7 +15,6 @@ const ThemeInverse = /* @__PURE__ */ __name((props) => {
|
|
|
15
15
|
const themeName = useThemeName();
|
|
16
16
|
const defaultTheme = useDefaultThemeName();
|
|
17
17
|
const name = inversions[themeName] || inversions[defaultTheme] || null;
|
|
18
|
-
console.log("todo fixme invert", { themeName, defaultTheme, next: name });
|
|
19
18
|
return /* @__PURE__ */ React.createElement(Theme, {
|
|
20
19
|
name
|
|
21
20
|
}, props.children);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/views/ThemeInverse.tsx"],
|
|
4
|
-
"sourcesContent": ["import React from 'react'\n\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\ntype StringRecord = { [key: string]: string }\n\nlet inversions: StringRecord = {\n light: 'dark',\n dark: 'light',\n}\n\nexport function setThemeInversions(next: StringRecord) {\n inversions = next\n}\n\nexport const ThemeInverse = (props: { children: any }) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const name = inversions[themeName] || inversions[defaultTheme] || null\n
|
|
5
|
-
"mappings": ";;AAAA;AAEA;AACA;AAIA,IAAI,aAA2B;AAAA,EAC7B,OAAO;AAAA,EACP,MAAM;AAAA;AAGD,4BAA4B,MAAoB;AACrD,eAAa;AAAA;AADC;AAIT,MAAM,eAAe,wBAAC,UAA6B;AACxD,QAAM,YAAY;AAClB,QAAM,eAAe;AACrB,QAAM,OAAO,WAAW,cAAc,WAAW,iBAAiB;AAClE,
|
|
4
|
+
"sourcesContent": ["import React from 'react'\n\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\ntype StringRecord = { [key: string]: string }\n\nlet inversions: StringRecord = {\n light: 'dark',\n dark: 'light',\n}\n\nexport function setThemeInversions(next: StringRecord) {\n inversions = next\n}\n\nexport const ThemeInverse = (props: { children: any }) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const name = inversions[themeName] || inversions[defaultTheme] || null\n return <Theme name={name}>{props.children}</Theme>\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAEA;AACA;AAIA,IAAI,aAA2B;AAAA,EAC7B,OAAO;AAAA,EACP,MAAM;AAAA;AAGD,4BAA4B,MAAoB;AACrD,eAAa;AAAA;AADC;AAIT,MAAM,eAAe,wBAAC,UAA6B;AACxD,QAAM,YAAY;AAClB,QAAM,eAAe;AACrB,QAAM,OAAO,WAAW,cAAc,WAAW,iBAAiB;AAClE,SAAO,oCAAC,OAAD;AAAA,IAAO;AAAA,KAAa,MAAM;AAAA,GAJP;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,16 +4,22 @@ import { createContext } from "react";
|
|
|
4
4
|
class ThemeManager {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.name = "light";
|
|
7
|
+
this.parentName = null;
|
|
7
8
|
this.keys = new Map();
|
|
8
9
|
this.listeners = new Map();
|
|
9
10
|
this.callbacks = new Set();
|
|
10
11
|
this.theme = null;
|
|
11
12
|
}
|
|
12
|
-
setActiveTheme(
|
|
13
|
+
setActiveTheme({
|
|
14
|
+
name,
|
|
15
|
+
theme,
|
|
16
|
+
parentName
|
|
17
|
+
}) {
|
|
13
18
|
if (name === this.name)
|
|
14
19
|
return;
|
|
15
20
|
this.name = name;
|
|
16
21
|
this.theme = theme;
|
|
22
|
+
this.parentName = parentName || null;
|
|
17
23
|
this.update();
|
|
18
24
|
}
|
|
19
25
|
track(uuid, keys) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/views/ThemeManagerContext.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createContext } from 'react'\n\nexport class ThemeManager {\n name: string | null = 'light'\n keys = new Map<any, Set<string>>()\n listeners = new Map<any, Function>()\n callbacks = new Set<Function>()\n theme = null\n\n setActiveTheme(name: string | null
|
|
5
|
-
"mappings": ";;AAAA;AAEO,mBAAmB;AAAA,EAAnB,cAFP;AAGE,gBAAsB;AACtB,gBAAO,IAAI;AACX,qBAAY,IAAI;AAChB,qBAAY,IAAI;AAChB,iBAAQ;AAAA;AAAA,EAER,eAAe,
|
|
4
|
+
"sourcesContent": ["import { createContext } from 'react'\n\nexport class ThemeManager {\n name: string | null = 'light'\n parentName: string | null = null\n keys = new Map<any, Set<string>>()\n listeners = new Map<any, Function>()\n callbacks = new Set<Function>()\n theme = null\n\n setActiveTheme({\n name,\n theme,\n parentName,\n }: {\n parentName?: string | null\n name: string | null\n theme?: any\n }) {\n if (name === this.name) return\n this.name = name\n this.theme = theme\n this.parentName = parentName || null\n this.update()\n }\n\n track(uuid: any, keys: Set<string>) {\n if (!this.name) return\n this.keys.set(uuid, keys)\n }\n\n update() {\n if (!this.name) {\n this.keys.clear()\n }\n for (const [uuid, keys] of this.keys.entries()) {\n if (keys.size) {\n this.listeners.get(uuid)?.()\n }\n }\n this.callbacks.forEach((cb) => cb(this.name))\n }\n\n onChangeTheme(cb: (name: string | null) => void) {\n this.callbacks.add(cb)\n return () => {\n this.callbacks.delete(cb)\n }\n }\n\n onUpdate(uuid: any, cb: Function) {\n this.listeners.set(uuid, cb)\n return () => {\n this.listeners.delete(uuid)\n this.keys.delete(uuid)\n }\n }\n}\n\nexport const ThemeManagerContext = createContext<ThemeManager>(new ThemeManager())\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAEO,mBAAmB;AAAA,EAAnB,cAFP;AAGE,gBAAsB;AACtB,sBAA4B;AAC5B,gBAAO,IAAI;AACX,qBAAY,IAAI;AAChB,qBAAY,IAAI;AAChB,iBAAQ;AAAA;AAAA,EAER,eAAe;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,KAKC;AACD,QAAI,SAAS,KAAK;AAAM;AACxB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,aAAa,cAAc;AAChC,SAAK;AAAA;AAAA,EAGP,MAAM,MAAW,MAAmB;AAClC,QAAI,CAAC,KAAK;AAAM;AAChB,SAAK,KAAK,IAAI,MAAM;AAAA;AAAA,EAGtB,SAAS;AACP,QAAI,CAAC,KAAK,MAAM;AACd,WAAK,KAAK;AAAA;AAEZ,eAAW,CAAC,MAAM,SAAS,KAAK,KAAK,WAAW;AAC9C,UAAI,KAAK,MAAM;AACb,aAAK,UAAU,IAAI;AAAA;AAAA;AAGvB,SAAK,UAAU,QAAQ,CAAC,OAAO,GAAG,KAAK;AAAA;AAAA,EAGzC,cAAc,IAAmC;AAC/C,SAAK,UAAU,IAAI;AACnB,WAAO,MAAM;AACX,WAAK,UAAU,OAAO;AAAA;AAAA;AAAA,EAI1B,SAAS,MAAW,IAAc;AAChC,SAAK,UAAU,IAAI,MAAM;AACzB,WAAO,MAAM;AACX,WAAK,UAAU,OAAO;AACtB,WAAK,KAAK,OAAO;AAAA;AAAA;AAAA;AApDhB;AAyDA,MAAM,sBAAsB,cAA4B,IAAI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/core",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.7",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -9,17 +9,24 @@
|
|
|
9
9
|
"build": "tamagui-build",
|
|
10
10
|
"watch": "tamagui-build --watch"
|
|
11
11
|
},
|
|
12
|
+
"files": [
|
|
13
|
+
"types.d.ts",
|
|
14
|
+
"dist",
|
|
15
|
+
"src"
|
|
16
|
+
],
|
|
12
17
|
"dependencies": {
|
|
13
|
-
"@tamagui/helpers": "^1.0.0-alpha.
|
|
18
|
+
"@tamagui/helpers": "^1.0.0-alpha.5",
|
|
19
|
+
"@tamagui/use-debounce": "^1.0.0-alpha.6",
|
|
20
|
+
"@tamagui/use-force-update": "^1.0.0-alpha.5",
|
|
14
21
|
"react": "*",
|
|
15
|
-
"react-dom": "*"
|
|
16
|
-
"react-native-safe-area-context": "^3.3.0"
|
|
22
|
+
"react-dom": "*"
|
|
17
23
|
},
|
|
18
24
|
"peerDependencies": {
|
|
19
25
|
"react-native-web": "*"
|
|
20
26
|
},
|
|
21
27
|
"devDependencies": {
|
|
22
28
|
"@tamagui/build": "^1.0.0-alpha.2",
|
|
29
|
+
"@tamagui/ow": "^0.28.1",
|
|
23
30
|
"@types/react": "^17.0.35",
|
|
24
31
|
"esbuild": "^0.11.20",
|
|
25
32
|
"typescript": "^4.4.4"
|
|
@@ -30,5 +37,5 @@
|
|
|
30
37
|
"engines": {
|
|
31
38
|
"node": ">=16"
|
|
32
39
|
},
|
|
33
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "13694a98d31535846699004532630788177537e9"
|
|
34
41
|
}
|
package/src/createComponent.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { concatClassName, stylePropsView } from '@tamagui/helpers'
|
|
2
|
+
import { useForceUpdate } from '@tamagui/use-force-update'
|
|
2
3
|
import React, {
|
|
3
4
|
Children,
|
|
4
5
|
Fragment,
|
|
@@ -20,7 +21,6 @@ import { addStylesUsingClassname, useStylesAsClassname } from './helpers/addStyl
|
|
|
20
21
|
import { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'
|
|
21
22
|
import { getSplitStyles } from './helpers/getSplitStyles'
|
|
22
23
|
import { useFeatures } from './hooks/useFeatures'
|
|
23
|
-
import { useForceUpdate } from './hooks/useForceUpdate'
|
|
24
24
|
import { usePressable } from './hooks/usePressable'
|
|
25
25
|
import {
|
|
26
26
|
SpaceTokens,
|
|
@@ -68,6 +68,44 @@ export function createComponent<A extends Object = DefaultProps>(
|
|
|
68
68
|
// see onConfiguredOnce below which attaches a name then to this component
|
|
69
69
|
|
|
70
70
|
const component = forwardRef<View, A>((props: any, forwardedRef) => {
|
|
71
|
+
const forceUpdate = useForceUpdate()
|
|
72
|
+
const features = useFeatures(props, { forceUpdate })
|
|
73
|
+
const manager = useContext(ThemeManagerContext)
|
|
74
|
+
const [state, set_] = useState(() => ({
|
|
75
|
+
hover: false,
|
|
76
|
+
press: false,
|
|
77
|
+
pressIn: false,
|
|
78
|
+
theme: manager.name,
|
|
79
|
+
}))
|
|
80
|
+
const set = (next: Partial<typeof state>) =>
|
|
81
|
+
set_((prev) => {
|
|
82
|
+
for (const key in next) {
|
|
83
|
+
if (prev[key] !== next[key]) {
|
|
84
|
+
return { ...prev, ...next }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return prev
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
// from react-native-web
|
|
91
|
+
if (process.env.NODE_ENV === 'development' && !isText && isWeb) {
|
|
92
|
+
Children.toArray(props.children).forEach((item) => {
|
|
93
|
+
if (typeof item === 'string') {
|
|
94
|
+
console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const hasTextAncestor = isWeb ? useContext(TextAncestorContext) : false
|
|
100
|
+
const hostRef = useRef(null)
|
|
101
|
+
|
|
102
|
+
const {
|
|
103
|
+
viewProps: viewPropsIn,
|
|
104
|
+
pseudos,
|
|
105
|
+
style,
|
|
106
|
+
classNames,
|
|
107
|
+
} = getSplitStyles(props, staticConfig, (manager.theme as any) || initialTheme)
|
|
108
|
+
|
|
71
109
|
const {
|
|
72
110
|
tag,
|
|
73
111
|
hitSlop,
|
|
@@ -101,40 +139,19 @@ export function createComponent<A extends Object = DefaultProps>(
|
|
|
101
139
|
onStartShouldSetResponderCapture,
|
|
102
140
|
onMouseDown,
|
|
103
141
|
onClick,
|
|
104
|
-
// TODO feature load layou hook
|
|
105
|
-
onLayout,
|
|
106
|
-
} = props
|
|
107
142
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const manager = useContext(ThemeManagerContext)
|
|
111
|
-
const [state, set_] = useState(() => ({
|
|
112
|
-
hover: false,
|
|
113
|
-
press: false,
|
|
114
|
-
pressIn: false,
|
|
115
|
-
theme: manager.name,
|
|
116
|
-
}))
|
|
117
|
-
const set = (next: Partial<typeof state>) =>
|
|
118
|
-
set_((prev) => {
|
|
119
|
-
for (const key in next) {
|
|
120
|
-
if (prev[key] !== next[key]) {
|
|
121
|
-
return { ...prev, ...next }
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return prev
|
|
125
|
-
})
|
|
143
|
+
accessible,
|
|
144
|
+
accessibilityRole,
|
|
126
145
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)
|
|
132
|
-
}
|
|
133
|
-
})
|
|
134
|
-
}
|
|
146
|
+
// TODO feature load layout hook
|
|
147
|
+
onLayout,
|
|
148
|
+
...viewProps
|
|
149
|
+
} = viewPropsIn
|
|
135
150
|
|
|
136
|
-
|
|
137
|
-
|
|
151
|
+
if (!isWeb) {
|
|
152
|
+
if (accessible) viewProps.accessible = accessible
|
|
153
|
+
if (accessibilityRole) viewProps.accessibilityRole = accessibilityRole
|
|
154
|
+
}
|
|
138
155
|
|
|
139
156
|
if (isWeb) {
|
|
140
157
|
// from react-native-web
|
|
@@ -160,12 +177,6 @@ export function createComponent<A extends Object = DefaultProps>(
|
|
|
160
177
|
|
|
161
178
|
const isTracking = useRef(false)
|
|
162
179
|
|
|
163
|
-
const { viewProps, pseudos, style, classNames } = getSplitStyles(
|
|
164
|
-
props,
|
|
165
|
-
staticConfig,
|
|
166
|
-
(manager.theme as any) || initialTheme
|
|
167
|
-
)
|
|
168
|
-
|
|
169
180
|
// hasEverHadEvents prevents repareting if you remove onPress or similar...
|
|
170
181
|
const internal = useRef<{ isMounted: boolean; hasEverHadEvents?: boolean }>()
|
|
171
182
|
if (!internal.current) {
|
package/src/createFont.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { validateFont } from './helpers/validate'
|
|
1
2
|
import { GenericFont } from './types'
|
|
2
3
|
|
|
3
4
|
export const createFont = <A extends GenericFont>(font: A): A => {
|
|
5
|
+
if (process.env.NODE_ENV === 'development') {
|
|
6
|
+
validateFont(font)
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
// fills in any missing values based on size keys being standard
|
|
5
10
|
const sizeKeys = Object.keys(font.size)
|
|
6
11
|
|
package/src/createTamagui.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { getStyleRules } from '@tamagui/helpers'
|
|
|
2
2
|
|
|
3
3
|
import { Variable, createVariable, isVariable } from './createVariable'
|
|
4
4
|
import { createTamaguiProvider } from './helpers/createTamaguiProvider'
|
|
5
|
+
import { validateConfig } from './helpers/validate'
|
|
5
6
|
import { configureMedia } from './hooks/useMedia'
|
|
6
7
|
import {
|
|
7
8
|
CreateTamaguiConfig,
|
|
@@ -46,6 +47,12 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
46
47
|
): Conf extends CreateTamaguiConfig<infer A, infer B, infer C, infer D>
|
|
47
48
|
? TamaguiInternalConfig<A, B, C, D>
|
|
48
49
|
: unknown {
|
|
50
|
+
if (process.env.NODE_ENV === 'development') {
|
|
51
|
+
// config is re-run by the @tamagui/static, dont double validate
|
|
52
|
+
if (!config['parsed']) {
|
|
53
|
+
validateConfig(config)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
49
56
|
// test env loads a few times as it runs diff tests
|
|
50
57
|
if (conf) {
|
|
51
58
|
console.warn('Called createTamagui twice! Should never do so')
|
|
@@ -157,6 +164,7 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
157
164
|
themeConfig,
|
|
158
165
|
themeParsed,
|
|
159
166
|
tokensParsed,
|
|
167
|
+
parsed: true,
|
|
160
168
|
getCSS() {
|
|
161
169
|
return `${themeConfig.css}\n${[...getStyleRules()].join('\n')}`
|
|
162
170
|
},
|
package/src/createTokens.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { Variable, createVariable } from './createVariable'
|
|
2
|
+
import { validateTokens } from './helpers/validate'
|
|
2
3
|
import { CreateTokens } from './types'
|
|
3
4
|
|
|
4
|
-
// tokens.color.dark.red ===>{ var: `color-dark-red`, val: '' }
|
|
5
|
+
// tokens.color.dark.red ===> { var: `color-dark-red`, val: '' }
|
|
5
6
|
|
|
6
7
|
export function createTokens<T extends CreateTokens>(tokens: T): MakeTokens<T> {
|
|
8
|
+
if (process.env.NODE_ENV === 'development') {
|
|
9
|
+
validateTokens(tokens)
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
return setupTokens(tokens) as any
|
|
8
13
|
}
|
|
9
14
|
|
package/src/createVariable.ts
CHANGED
|
@@ -28,7 +28,6 @@ export const getSplitStyles = (
|
|
|
28
28
|
const validStyleProps = staticConfig.isText ? stylePropsText : validStyles
|
|
29
29
|
const viewProps: Record<string, any> = {}
|
|
30
30
|
const style: any[] = []
|
|
31
|
-
const blacklistProps = isSplittingDefaultProps ? blacklistDefaultProps : blacklistFinalProps
|
|
32
31
|
|
|
33
32
|
let pseudos: { hoverStyle?: ViewStyle; pressStyle?: ViewStyle } | null = null
|
|
34
33
|
let cur: ViewStyle | null = null
|
|
@@ -130,8 +129,9 @@ export const getSplitStyles = (
|
|
|
130
129
|
cur[key] = val
|
|
131
130
|
continue
|
|
132
131
|
}
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
|
|
133
|
+
// pass to view props
|
|
134
|
+
if (!staticConfig.variants || !(key in staticConfig.variants)) {
|
|
135
135
|
viewProps[key] = val
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -181,19 +181,6 @@ const getSubStyle = (
|
|
|
181
181
|
return styleOut
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
const blacklistDefaultProps = {
|
|
185
|
-
...validStyles,
|
|
186
|
-
...stylePropsText,
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const blacklistFinalProps = {
|
|
190
|
-
...blacklistDefaultProps,
|
|
191
|
-
tag: true,
|
|
192
|
-
debug: true,
|
|
193
|
-
space: true,
|
|
194
|
-
hitSlop: true,
|
|
195
|
-
}
|
|
196
|
-
|
|
197
184
|
const mapTransformKeys = {
|
|
198
185
|
x: 'translateX',
|
|
199
186
|
y: 'translateY',
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// published a patched version that works on native
|
|
2
|
+
import ow from '@tamagui/ow'
|
|
3
|
+
|
|
4
|
+
export const validateConfig = (conf: any) => {
|
|
5
|
+
if (!conf) {
|
|
6
|
+
console.warn('no conf?')
|
|
7
|
+
return
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
ow(conf, validConfig)
|
|
11
|
+
} catch (err: any) {
|
|
12
|
+
console.log('Given config:\n', JSON.stringify(conf, null, 2))
|
|
13
|
+
throw err
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const validConfig = ow.object.exactShape({
|
|
18
|
+
defaultTheme: ow.optional.string,
|
|
19
|
+
disableRootThemeClass: ow.optional.boolean,
|
|
20
|
+
shorthands: ow.optional.object.valuesOfType(ow.string),
|
|
21
|
+
themes: ow.object.valuesOfType(ow.object),
|
|
22
|
+
tokens: ow.object.valuesOfType(ow.object),
|
|
23
|
+
media: ow.object.valuesOfType(ow.object),
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const validFont = ow.object.exactShape({
|
|
27
|
+
family: ow.string,
|
|
28
|
+
size: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
29
|
+
lineHeight: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
30
|
+
weight: ow.object.nonEmpty.valuesOfType(ow.string),
|
|
31
|
+
letterSpacing: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const validTokens = ow.object.exactShape({
|
|
35
|
+
font: ow.object.valuesOfType(validFont),
|
|
36
|
+
size: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
37
|
+
space: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
38
|
+
zIndex: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
39
|
+
radius: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
40
|
+
color: ow.object.nonEmpty.valuesOfType(ow.string),
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
export const validateTokens = (tokens: any) => {
|
|
44
|
+
try {
|
|
45
|
+
ow(tokens, validTokens)
|
|
46
|
+
} catch (err: any) {
|
|
47
|
+
console.log('Given tokens:\n', JSON.stringify(tokens, null, 2))
|
|
48
|
+
throw err
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const validateFont = (font: any) => {
|
|
53
|
+
try {
|
|
54
|
+
ow(font, validFont)
|
|
55
|
+
} catch (err: any) {
|
|
56
|
+
console.log('Given font:\n', JSON.stringify(font, null, 2))
|
|
57
|
+
throw err
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/hooks/useMedia.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useForceUpdate } from '@tamagui/use-force-update'
|
|
1
2
|
import { useRef } from 'react'
|
|
2
3
|
|
|
3
4
|
import { useIsomorphicLayoutEffect } from '../constants/platform'
|
|
@@ -9,7 +10,6 @@ import {
|
|
|
9
10
|
MediaQueryState,
|
|
10
11
|
} from '../types'
|
|
11
12
|
import { useConstant } from './useConstant'
|
|
12
|
-
import { useForceUpdate } from './useForceUpdate'
|
|
13
13
|
|
|
14
14
|
export const mediaState: { [key in keyof MediaQueryState]: boolean } = {} as any
|
|
15
15
|
const mediaQueryListeners: { [key: string]: Set<Function> } = {}
|
package/src/hooks/useTheme.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useForceUpdate } from '@tamagui/use-force-update'
|
|
1
2
|
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react'
|
|
2
3
|
|
|
3
4
|
import { useIsomorphicLayoutEffect } from '../constants/platform'
|
|
@@ -6,7 +7,6 @@ import { ThemeName } from '../types'
|
|
|
6
7
|
import { ThemeContext } from '../views/ThemeContext'
|
|
7
8
|
import { ThemeManagerContext } from '../views/ThemeManagerContext'
|
|
8
9
|
import { GET_DEFAULT_THEME } from '../views/ThemeProvider'
|
|
9
|
-
import { useForceUpdate } from './useForceUpdate'
|
|
10
10
|
|
|
11
11
|
type UseThemeState = {
|
|
12
12
|
uuid: Object
|
package/src/index.ts
CHANGED
|
@@ -17,9 +17,9 @@ export * from './helpers/isObj'
|
|
|
17
17
|
export * from './helpers/getStylesAtomic'
|
|
18
18
|
export * from './helpers/matchMedia'
|
|
19
19
|
export * from './helpers/themeable'
|
|
20
|
+
export * from './helpers/isTamaguiElement'
|
|
20
21
|
|
|
21
22
|
export * from './hooks/useConstant'
|
|
22
|
-
export * from './hooks/useForceUpdate'
|
|
23
23
|
export * from './hooks/useMedia'
|
|
24
24
|
export * from './hooks/useTheme'
|
|
25
25
|
|
|
@@ -30,4 +30,3 @@ export * from './views/Theme'
|
|
|
30
30
|
export * from './views/ThemeInverse'
|
|
31
31
|
export * from './views/ThemeProvider'
|
|
32
32
|
export * from './views/TextAncestorContext'
|
|
33
|
-
export * from './views/SafeAreaProvider'
|
package/src/types.tsx
CHANGED
package/src/views/Theme.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import React, { useContext, useState } from 'react'
|
|
|
3
3
|
import { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'
|
|
4
4
|
import { getThemeParentClassName } from '../createTamagui'
|
|
5
5
|
import { useConstant } from '../hooks/useConstant'
|
|
6
|
-
import { ThemeName
|
|
6
|
+
import { ThemeName } from '../types'
|
|
7
7
|
import { ThemeContext } from './ThemeContext'
|
|
8
8
|
import { ThemeManager, ThemeManagerContext } from './ThemeManagerContext'
|
|
9
9
|
|
|
@@ -18,30 +18,47 @@ export const Theme = (props: ThemeProps) => {
|
|
|
18
18
|
const themes = useContext(ThemeContext)
|
|
19
19
|
const [parentName, setParentName] = useState(parent.name || 'light')
|
|
20
20
|
if (!themes) {
|
|
21
|
-
console.warn('no themes
|
|
21
|
+
console.warn('Error, no themes in context', props)
|
|
22
22
|
return props.children
|
|
23
23
|
}
|
|
24
24
|
const name = props.name as string
|
|
25
|
-
const
|
|
26
|
-
const
|
|
25
|
+
const nextNameParent = `${name}-${parentName}`
|
|
26
|
+
const nextNameParentParent = `${name}-${parent.parentName}`
|
|
27
|
+
const activeName = !name
|
|
28
|
+
? null
|
|
29
|
+
: name in themes
|
|
30
|
+
? name
|
|
31
|
+
: nextNameParent in themes
|
|
32
|
+
? nextNameParent
|
|
33
|
+
: nextNameParentParent in themes
|
|
34
|
+
? nextNameParentParent
|
|
35
|
+
: null
|
|
36
|
+
const theme = activeName ? themes[activeName] : null
|
|
37
|
+
const themeManager = useConstant<ThemeManager | null>(() => {
|
|
38
|
+
if (!theme) {
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
27
41
|
const manager = new ThemeManager()
|
|
28
42
|
if (name) {
|
|
29
|
-
manager.setActiveTheme(name, themes[name])
|
|
43
|
+
manager.setActiveTheme({ name, theme: themes[name], parentName })
|
|
30
44
|
}
|
|
31
45
|
return manager
|
|
32
46
|
})
|
|
33
47
|
|
|
34
48
|
useIsomorphicLayoutEffect(() => {
|
|
35
|
-
themeManager
|
|
49
|
+
if (!themeManager) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
themeManager.setActiveTheme({ name: activeName, theme, parentName })
|
|
36
53
|
return parent.onChangeTheme((next) => {
|
|
37
54
|
if (next) {
|
|
38
|
-
themeManager.setActiveTheme(next, themes[next])
|
|
55
|
+
themeManager.setActiveTheme({ name: next, theme: themes[next], parentName })
|
|
39
56
|
setParentName(next)
|
|
40
57
|
}
|
|
41
58
|
})
|
|
42
|
-
}, [themes,
|
|
59
|
+
}, [themes, activeName, parentName])
|
|
43
60
|
|
|
44
|
-
if (!name) {
|
|
61
|
+
if (!name || !theme) {
|
|
45
62
|
return props.children
|
|
46
63
|
}
|
|
47
64
|
|
|
@@ -18,6 +18,5 @@ export const ThemeInverse = (props: { children: any }) => {
|
|
|
18
18
|
const themeName = useThemeName()
|
|
19
19
|
const defaultTheme = useDefaultThemeName()
|
|
20
20
|
const name = inversions[themeName] || inversions[defaultTheme] || null
|
|
21
|
-
console.log('todo fixme invert', { themeName, defaultTheme, next: name })
|
|
22
21
|
return <Theme name={name}>{props.children}</Theme>
|
|
23
22
|
}
|