@tamagui/web 1.82.0 → 1.82.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/dist/cjs/createComponent.js +2 -2
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/createComponent.native.js +2 -2
- package/dist/cjs/createComponent.native.js.map +1 -1
- package/dist/cjs/helpers/ThemeManager.js +12 -8
- package/dist/cjs/helpers/ThemeManager.js.map +1 -1
- package/dist/cjs/helpers/ThemeManager.native.js +12 -8
- package/dist/cjs/helpers/ThemeManager.native.js.map +1 -1
- package/dist/cjs/helpers/expandStyles.js +1 -1
- package/dist/cjs/helpers/expandStyles.js.map +1 -1
- package/dist/cjs/helpers/expandStyles.native.js +1 -1
- package/dist/cjs/helpers/expandStyles.native.js.map +1 -1
- package/dist/cjs/helpers/expandStylesAndRemoveNullishValues.js.map +1 -1
- package/dist/cjs/helpers/expandStylesAndRemoveNullishValues.native.js.map +1 -1
- package/dist/cjs/helpers/getExpandedShorthands.js.map +1 -1
- package/dist/cjs/helpers/getExpandedShorthands.native.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.js +1 -1
- package/dist/cjs/helpers/getSplitStyles.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.native.js +1 -1
- package/dist/cjs/helpers/getSplitStyles.native.js.map +1 -1
- package/dist/cjs/helpers/getVariantExtras.js +2 -2
- package/dist/cjs/helpers/getVariantExtras.js.map +1 -1
- package/dist/cjs/helpers/getVariantExtras.native.js +2 -2
- package/dist/cjs/helpers/getVariantExtras.native.js.map +1 -1
- package/dist/cjs/helpers/mergeVariants.js +8 -21
- package/dist/cjs/helpers/mergeVariants.js.map +1 -1
- package/dist/cjs/helpers/mergeVariants.native.js +8 -21
- package/dist/cjs/helpers/mergeVariants.native.js.map +1 -1
- package/dist/cjs/helpers/normalizeColor.js +2 -2
- package/dist/cjs/helpers/normalizeColor.js.map +1 -1
- package/dist/cjs/helpers/normalizeColor.native.js +2 -2
- package/dist/cjs/helpers/normalizeColor.native.js.map +1 -1
- package/dist/cjs/helpers/propMapper.js +2 -2
- package/dist/cjs/helpers/propMapper.js.map +1 -1
- package/dist/cjs/helpers/propMapper.native.js +2 -2
- package/dist/cjs/helpers/propMapper.native.js.map +1 -1
- package/dist/cjs/helpers/proxyThemeToParents.js +5 -9
- package/dist/cjs/helpers/proxyThemeToParents.js.map +1 -1
- package/dist/cjs/helpers/proxyThemeToParents.native.js +5 -9
- package/dist/cjs/helpers/proxyThemeToParents.native.js.map +1 -1
- package/dist/cjs/helpers/proxyThemeVariables.js +1 -2
- package/dist/cjs/helpers/proxyThemeVariables.js.map +1 -1
- package/dist/cjs/helpers/proxyThemeVariables.native.js +1 -2
- package/dist/cjs/helpers/proxyThemeVariables.native.js.map +1 -1
- package/dist/cjs/helpers/themeable.js +4 -1
- package/dist/cjs/helpers/themeable.js.map +1 -1
- package/dist/cjs/helpers/themeable.native.js +4 -1
- package/dist/cjs/helpers/themeable.native.js.map +1 -1
- package/dist/cjs/helpers/themes.js +5 -5
- package/dist/cjs/helpers/themes.js.map +1 -1
- package/dist/cjs/helpers/themes.native.js +5 -5
- package/dist/cjs/helpers/themes.native.js.map +1 -1
- package/dist/cjs/hooks/useDisableSSR.js +4 -10
- package/dist/cjs/hooks/useDisableSSR.js.map +1 -1
- package/dist/cjs/hooks/useDisableSSR.native.js +4 -10
- package/dist/cjs/hooks/useDisableSSR.native.js.map +1 -1
- package/dist/cjs/hooks/useMedia.js +3 -3
- package/dist/cjs/hooks/useMedia.js.map +1 -1
- package/dist/cjs/hooks/useMedia.native.js +3 -3
- package/dist/cjs/hooks/useMedia.native.js.map +1 -1
- package/dist/cjs/hooks/useTheme.js +3 -5
- package/dist/cjs/hooks/useTheme.js.map +1 -1
- package/dist/cjs/hooks/useTheme.native.js +3 -5
- package/dist/cjs/hooks/useTheme.native.js.map +1 -1
- package/dist/cjs/views/Theme.js +28 -27
- package/dist/cjs/views/Theme.js.map +2 -2
- package/dist/cjs/views/Theme.native.js +28 -27
- package/dist/cjs/views/Theme.native.js.map +2 -2
- package/dist/cjs/views/ThemeDebug.js +3 -5
- package/dist/cjs/views/ThemeDebug.js.map +1 -1
- package/dist/esm/createComponent.js +3 -3
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createComponent.native.js +3 -3
- package/dist/esm/createComponent.native.js.map +1 -1
- package/dist/esm/helpers/ThemeManager.js +12 -8
- package/dist/esm/helpers/ThemeManager.js.map +1 -1
- package/dist/esm/helpers/ThemeManager.native.js +12 -8
- package/dist/esm/helpers/ThemeManager.native.js.map +1 -1
- package/dist/esm/helpers/expandStyles.js +1 -1
- package/dist/esm/helpers/expandStyles.js.map +1 -1
- package/dist/esm/helpers/expandStyles.native.js +1 -1
- package/dist/esm/helpers/expandStyles.native.js.map +1 -1
- package/dist/esm/helpers/expandStylesAndRemoveNullishValues.js.map +1 -1
- package/dist/esm/helpers/expandStylesAndRemoveNullishValues.native.js.map +1 -1
- package/dist/esm/helpers/getExpandedShorthands.js.map +1 -1
- package/dist/esm/helpers/getExpandedShorthands.native.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.js +1 -1
- package/dist/esm/helpers/getSplitStyles.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.native.js +1 -1
- package/dist/esm/helpers/getSplitStyles.native.js.map +1 -1
- package/dist/esm/helpers/getVariantExtras.js +1 -2
- package/dist/esm/helpers/getVariantExtras.js.map +1 -1
- package/dist/esm/helpers/getVariantExtras.native.js +1 -2
- package/dist/esm/helpers/getVariantExtras.native.js.map +1 -1
- package/dist/esm/helpers/mergeVariants.js +8 -21
- package/dist/esm/helpers/mergeVariants.js.map +1 -1
- package/dist/esm/helpers/mergeVariants.native.js +8 -21
- package/dist/esm/helpers/mergeVariants.native.js.map +1 -1
- package/dist/esm/helpers/normalizeColor.js +1 -2
- package/dist/esm/helpers/normalizeColor.js.map +1 -1
- package/dist/esm/helpers/normalizeColor.native.js +1 -2
- package/dist/esm/helpers/normalizeColor.native.js.map +1 -1
- package/dist/esm/helpers/propMapper.js +2 -2
- package/dist/esm/helpers/propMapper.js.map +1 -1
- package/dist/esm/helpers/propMapper.native.js +2 -2
- package/dist/esm/helpers/propMapper.native.js.map +1 -1
- package/dist/esm/helpers/proxyThemeToParents.js +3 -7
- package/dist/esm/helpers/proxyThemeToParents.js.map +1 -1
- package/dist/esm/helpers/proxyThemeToParents.native.js +3 -7
- package/dist/esm/helpers/proxyThemeToParents.native.js.map +1 -1
- package/dist/esm/helpers/proxyThemeVariables.js +1 -2
- package/dist/esm/helpers/proxyThemeVariables.js.map +1 -1
- package/dist/esm/helpers/proxyThemeVariables.native.js +1 -2
- package/dist/esm/helpers/proxyThemeVariables.native.js.map +1 -1
- package/dist/esm/helpers/themeable.js +4 -1
- package/dist/esm/helpers/themeable.js.map +1 -1
- package/dist/esm/helpers/themeable.native.js +4 -1
- package/dist/esm/helpers/themeable.native.js.map +1 -1
- package/dist/esm/helpers/themes.js +5 -5
- package/dist/esm/helpers/themes.js.map +1 -1
- package/dist/esm/helpers/themes.native.js +5 -5
- package/dist/esm/helpers/themes.native.js.map +1 -1
- package/dist/esm/hooks/useDisableSSR.js +2 -9
- package/dist/esm/hooks/useDisableSSR.js.map +1 -1
- package/dist/esm/hooks/useDisableSSR.native.js +2 -9
- package/dist/esm/hooks/useDisableSSR.native.js.map +1 -1
- package/dist/esm/hooks/useMedia.js +3 -4
- package/dist/esm/hooks/useMedia.js.map +1 -1
- package/dist/esm/hooks/useMedia.native.js +3 -4
- package/dist/esm/hooks/useMedia.native.js.map +1 -1
- package/dist/esm/hooks/useTheme.js +2 -6
- package/dist/esm/hooks/useTheme.js.map +1 -1
- package/dist/esm/hooks/useTheme.native.js +2 -6
- package/dist/esm/hooks/useTheme.native.js.map +1 -1
- package/dist/esm/views/Theme.js +28 -34
- package/dist/esm/views/Theme.js.map +2 -2
- package/dist/esm/views/Theme.native.js +28 -34
- package/dist/esm/views/Theme.native.js.map +2 -2
- package/dist/esm/views/ThemeDebug.js +3 -4
- package/dist/esm/views/ThemeDebug.js.map +1 -1
- package/package.json +10 -10
- package/src/createComponent.tsx +3 -3
- package/src/helpers/ThemeManager.tsx +12 -8
- package/src/helpers/expandStyles.ts +2 -2
- package/src/helpers/expandStylesAndRemoveNullishValues.ts +0 -1
- package/src/helpers/getExpandedShorthands.ts +3 -0
- package/src/helpers/getSplitStyles.tsx +1 -1
- package/src/helpers/getVariantExtras.tsx +1 -2
- package/src/helpers/mergeVariants.ts +13 -32
- package/src/helpers/normalizeColor.ts +1 -5
- package/src/helpers/propMapper.ts +3 -1
- package/src/helpers/proxyThemeToParents.ts +5 -8
- package/src/helpers/proxyThemeVariables.tsx +1 -3
- package/src/helpers/themeable.tsx +5 -3
- package/src/helpers/themes.ts +4 -5
- package/src/hooks/useDisableSSR.tsx +2 -10
- package/src/hooks/useMedia.tsx +4 -5
- package/src/hooks/useTheme.tsx +2 -8
- package/src/views/Theme.tsx +44 -52
- package/src/views/ThemeDebug.tsx +7 -5
- package/types/helpers/ThemeManager.d.ts +1 -1
- package/types/helpers/ThemeManager.d.ts.map +1 -1
- package/types/helpers/expandStylesAndRemoveNullishValues.d.ts.map +1 -1
- package/types/helpers/getExpandedShorthands.d.ts +3 -0
- package/types/helpers/getExpandedShorthands.d.ts.map +1 -1
- package/types/helpers/getVariantExtras.d.ts.map +1 -1
- package/types/helpers/mergeVariants.d.ts +1 -1
- package/types/helpers/mergeVariants.d.ts.map +1 -1
- package/types/helpers/normalizeColor.d.ts.map +1 -1
- package/types/helpers/propMapper.d.ts.map +1 -1
- package/types/helpers/proxyThemeToParents.d.ts +0 -1
- package/types/helpers/proxyThemeToParents.d.ts.map +1 -1
- package/types/helpers/proxyThemeVariables.d.ts.map +1 -1
- package/types/helpers/themeable.d.ts.map +1 -1
- package/types/helpers/themes.d.ts.map +1 -1
- package/types/hooks/useDisableSSR.d.ts +1 -2
- package/types/hooks/useDisableSSR.d.ts.map +1 -1
- package/types/hooks/useMedia.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/views/Theme.d.ts +1 -1
- package/types/views/Theme.d.ts.map +1 -1
- package/types/views/ThemeDebug.d.ts.map +1 -1
- package/src/helpers/createChainedWeakCache.tsx +0 -39
- package/src/helpers/createProxy.ts +0 -15
- package/src/hooks/getThemeUnwrapped.tsx +0 -5
- package/src/hooks/useId.tsx +0 -1
- package/src/hooks/useMemoDebug.tsx +0 -18
package/dist/esm/views/Theme.js
CHANGED
|
@@ -1,48 +1,42 @@
|
|
|
1
1
|
import { isWeb } from "@tamagui/constants";
|
|
2
|
-
import React, {
|
|
3
|
-
Children,
|
|
4
|
-
cloneElement,
|
|
5
|
-
forwardRef,
|
|
6
|
-
isValidElement,
|
|
7
|
-
useMemo,
|
|
8
|
-
useRef
|
|
9
|
-
} from "react";
|
|
2
|
+
import React, { Children, cloneElement, forwardRef, isValidElement, useRef } from "react";
|
|
10
3
|
import { variableToString } from "../createVariable";
|
|
11
4
|
import { ThemeManagerContext } from "../helpers/ThemeManagerContext";
|
|
12
5
|
import { useChangeThemeEffect } from "../hooks/useTheme";
|
|
13
6
|
import { ThemeDebug } from "./ThemeDebug";
|
|
14
7
|
import { jsx } from "react/jsx-runtime";
|
|
15
|
-
const Theme = forwardRef(function(props, ref) {
|
|
8
|
+
const Theme = forwardRef(function({ children, ...props }, ref) {
|
|
16
9
|
if (props.disable)
|
|
17
|
-
return
|
|
18
|
-
const isRoot = !!props._isRoot,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}, [props.children, disableDirectChildTheme]);
|
|
30
|
-
return useThemedChildren(themeState, children, props, isRoot);
|
|
10
|
+
return children;
|
|
11
|
+
const isRoot = !!props._isRoot, themeState = useChangeThemeEffect(props, isRoot);
|
|
12
|
+
let finalChildren = props["disable-child-theme"] ? Children.map(
|
|
13
|
+
children,
|
|
14
|
+
(child) => cloneElement(child, { "data-disable-theme": !0 })
|
|
15
|
+
) : children;
|
|
16
|
+
if (ref)
|
|
17
|
+
try {
|
|
18
|
+
React.Children.only(finalChildren), finalChildren = cloneElement(finalChildren, { ref });
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
return process.env.NODE_ENV === "development" && props.debug === "visualize" && (finalChildren = /* @__PURE__ */ jsx(ThemeDebug, { themeState, themeProps: props, children: finalChildren })), getThemedChildren(themeState, finalChildren, props, isRoot);
|
|
31
22
|
});
|
|
32
23
|
Theme.displayName = "Theme";
|
|
33
24
|
Theme.avoidForwardRef = !0;
|
|
34
|
-
function
|
|
35
|
-
const { themeManager, isNewTheme } = themeState
|
|
36
|
-
if (
|
|
25
|
+
function getThemedChildren(themeState, children, props, isRoot = !1) {
|
|
26
|
+
const { themeManager, isNewTheme } = themeState;
|
|
27
|
+
if (!themeManager)
|
|
28
|
+
throw "\u274C";
|
|
29
|
+
const { shallow, forceClassName } = props, hasEverThemed = useRef(!1), shouldRenderChildrenWithTheme = isNewTheme || props.inverse || hasEverThemed.current || forceClassName || isRoot;
|
|
30
|
+
if (shouldRenderChildrenWithTheme && (hasEverThemed.current = !0), !shouldRenderChildrenWithTheme)
|
|
37
31
|
return children;
|
|
38
32
|
let next = children;
|
|
39
|
-
shallow &&
|
|
33
|
+
shallow && (next = Children.toArray(children).map((child) => isValidElement(child) ? cloneElement(
|
|
40
34
|
child,
|
|
41
35
|
void 0,
|
|
42
36
|
/* @__PURE__ */ jsx(Theme, { name: themeManager.state.parentName, children: child.props.children })
|
|
43
37
|
) : child));
|
|
44
|
-
const elementsWithContext =
|
|
45
|
-
return forceClassName === !1 ? elementsWithContext : isWeb
|
|
38
|
+
const elementsWithContext = /* @__PURE__ */ jsx(ThemeManagerContext.Provider, { value: themeManager, children: next });
|
|
39
|
+
return forceClassName === !1 ? elementsWithContext : isWeb ? wrapThemeElements({
|
|
46
40
|
children: elementsWithContext,
|
|
47
41
|
themeState,
|
|
48
42
|
forceClassName,
|
|
@@ -57,10 +51,7 @@ function wrapThemeElements({
|
|
|
57
51
|
}) {
|
|
58
52
|
if (isRoot && forceClassName === !1)
|
|
59
53
|
return children;
|
|
60
|
-
const inverse = themeState.inversed, requiresExtraWrapper = inverse != null || forceClassName;
|
|
61
|
-
if (!themeState.isNewTheme && !requiresExtraWrapper)
|
|
62
|
-
return /* @__PURE__ */ jsx("span", { className: "_dsp_contents is_Theme", children });
|
|
63
|
-
const { className, style } = getThemeClassNameAndStyle(themeState, isRoot);
|
|
54
|
+
const inverse = themeState.inversed, requiresExtraWrapper = inverse != null || forceClassName, { className, style } = getThemeClassNameAndStyle(themeState, isRoot);
|
|
64
55
|
let themedChildren = /* @__PURE__ */ jsx("span", { className: `${className} _dsp_contents is_Theme`, style, children });
|
|
65
56
|
if (requiresExtraWrapper) {
|
|
66
57
|
const name = themeState.state?.name || "", inverseClassName = name.startsWith("light") ? "t_light is_inversed" : name.startsWith("dark") ? "t_dark is_inversed" : "";
|
|
@@ -68,7 +59,10 @@ function wrapThemeElements({
|
|
|
68
59
|
}
|
|
69
60
|
return themedChildren;
|
|
70
61
|
}
|
|
62
|
+
const emptyObj = {};
|
|
71
63
|
function getThemeClassNameAndStyle(themeState, isRoot = !1) {
|
|
64
|
+
if (!themeState.isNewTheme)
|
|
65
|
+
return { className: "", style: emptyObj };
|
|
72
66
|
const themeColor = themeState.state?.theme && themeState.isNewTheme ? variableToString(themeState.state.theme.color) : "", style = themeColor ? {
|
|
73
67
|
color: themeColor
|
|
74
68
|
} : void 0;
|
|
@@ -77,6 +71,6 @@ function getThemeClassNameAndStyle(themeState, isRoot = !1) {
|
|
|
77
71
|
}
|
|
78
72
|
export {
|
|
79
73
|
Theme,
|
|
80
|
-
|
|
74
|
+
getThemedChildren
|
|
81
75
|
};
|
|
82
76
|
//# sourceMappingURL=Theme.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"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,UAAU,QAAQ,eAAe,EAAE,IAE1C,EAAE,OAAO,UAAU;AAC5B;",
|
|
5
|
+
"names": []
|
|
6
6
|
}
|
|
@@ -1,48 +1,42 @@
|
|
|
1
1
|
import { isWeb } from "@tamagui/constants";
|
|
2
|
-
import React, {
|
|
3
|
-
Children,
|
|
4
|
-
cloneElement,
|
|
5
|
-
forwardRef,
|
|
6
|
-
isValidElement,
|
|
7
|
-
useMemo,
|
|
8
|
-
useRef
|
|
9
|
-
} from "react";
|
|
2
|
+
import React, { Children, cloneElement, forwardRef, isValidElement, useRef } from "react";
|
|
10
3
|
import { variableToString } from "../createVariable";
|
|
11
4
|
import { ThemeManagerContext } from "../helpers/ThemeManagerContext";
|
|
12
5
|
import { useChangeThemeEffect } from "../hooks/useTheme";
|
|
13
6
|
import { ThemeDebug } from "./ThemeDebug";
|
|
14
7
|
import { jsx } from "react/jsx-runtime";
|
|
15
|
-
const Theme = forwardRef(function(props, ref) {
|
|
8
|
+
const Theme = forwardRef(function({ children, ...props }, ref) {
|
|
16
9
|
if (props.disable)
|
|
17
|
-
return
|
|
18
|
-
const isRoot = !!props._isRoot,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}, [props.children, disableDirectChildTheme]);
|
|
30
|
-
return useThemedChildren(themeState, children, props, isRoot);
|
|
10
|
+
return children;
|
|
11
|
+
const isRoot = !!props._isRoot, themeState = useChangeThemeEffect(props, isRoot);
|
|
12
|
+
let finalChildren = props["disable-child-theme"] ? Children.map(
|
|
13
|
+
children,
|
|
14
|
+
(child) => cloneElement(child, { "data-disable-theme": !0 })
|
|
15
|
+
) : children;
|
|
16
|
+
if (ref)
|
|
17
|
+
try {
|
|
18
|
+
React.Children.only(finalChildren), finalChildren = cloneElement(finalChildren, { ref });
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
return process.env.NODE_ENV === "development" && props.debug === "visualize" && (finalChildren = /* @__PURE__ */ jsx(ThemeDebug, { themeState, themeProps: props, children: finalChildren })), getThemedChildren(themeState, finalChildren, props, isRoot);
|
|
31
22
|
});
|
|
32
23
|
Theme.displayName = "Theme";
|
|
33
24
|
Theme.avoidForwardRef = !0;
|
|
34
|
-
function
|
|
35
|
-
const { themeManager, isNewTheme } = themeState
|
|
36
|
-
if (
|
|
25
|
+
function getThemedChildren(themeState, children, props, isRoot = !1) {
|
|
26
|
+
const { themeManager, isNewTheme } = themeState;
|
|
27
|
+
if (!themeManager)
|
|
28
|
+
throw "\u274C";
|
|
29
|
+
const { shallow, forceClassName } = props, hasEverThemed = useRef(!1), shouldRenderChildrenWithTheme = isNewTheme || props.inverse || hasEverThemed.current || forceClassName || isRoot;
|
|
30
|
+
if (shouldRenderChildrenWithTheme && (hasEverThemed.current = !0), !shouldRenderChildrenWithTheme)
|
|
37
31
|
return children;
|
|
38
32
|
let next = children;
|
|
39
|
-
shallow &&
|
|
33
|
+
shallow && (next = Children.toArray(children).map((child) => isValidElement(child) ? cloneElement(
|
|
40
34
|
child,
|
|
41
35
|
void 0,
|
|
42
36
|
/* @__PURE__ */ jsx(Theme, { name: themeManager.state.parentName, children: child.props.children })
|
|
43
37
|
) : child));
|
|
44
|
-
const elementsWithContext =
|
|
45
|
-
return forceClassName === !1 ? elementsWithContext : isWeb
|
|
38
|
+
const elementsWithContext = /* @__PURE__ */ jsx(ThemeManagerContext.Provider, { value: themeManager, children: next });
|
|
39
|
+
return forceClassName === !1 ? elementsWithContext : isWeb ? wrapThemeElements({
|
|
46
40
|
children: elementsWithContext,
|
|
47
41
|
themeState,
|
|
48
42
|
forceClassName,
|
|
@@ -57,10 +51,7 @@ function wrapThemeElements({
|
|
|
57
51
|
}) {
|
|
58
52
|
if (isRoot && forceClassName === !1)
|
|
59
53
|
return children;
|
|
60
|
-
const inverse = themeState.inversed, requiresExtraWrapper = inverse != null || forceClassName;
|
|
61
|
-
if (!themeState.isNewTheme && !requiresExtraWrapper)
|
|
62
|
-
return /* @__PURE__ */ jsx("span", { className: "_dsp_contents is_Theme", children });
|
|
63
|
-
const { className, style } = getThemeClassNameAndStyle(themeState, isRoot);
|
|
54
|
+
const inverse = themeState.inversed, requiresExtraWrapper = inverse != null || forceClassName, { className, style } = getThemeClassNameAndStyle(themeState, isRoot);
|
|
64
55
|
let themedChildren = /* @__PURE__ */ jsx("span", { className: `${className} _dsp_contents is_Theme`, style, children });
|
|
65
56
|
if (requiresExtraWrapper) {
|
|
66
57
|
const name = themeState.state?.name || "", inverseClassName = name.startsWith("light") ? "t_light is_inversed" : name.startsWith("dark") ? "t_dark is_inversed" : "";
|
|
@@ -68,7 +59,10 @@ function wrapThemeElements({
|
|
|
68
59
|
}
|
|
69
60
|
return themedChildren;
|
|
70
61
|
}
|
|
62
|
+
const emptyObj = {};
|
|
71
63
|
function getThemeClassNameAndStyle(themeState, isRoot = !1) {
|
|
64
|
+
if (!themeState.isNewTheme)
|
|
65
|
+
return { className: "", style: emptyObj };
|
|
72
66
|
const themeColor = themeState.state?.theme && themeState.isNewTheme ? variableToString(themeState.state.theme.color) : "", style = themeColor ? {
|
|
73
67
|
color: themeColor
|
|
74
68
|
} : void 0;
|
|
@@ -77,6 +71,6 @@ function getThemeClassNameAndStyle(themeState, isRoot = !1) {
|
|
|
77
71
|
}
|
|
78
72
|
export {
|
|
79
73
|
Theme,
|
|
80
|
-
|
|
74
|
+
getThemedChildren
|
|
81
75
|
};
|
|
82
76
|
//# sourceMappingURL=Theme.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/Theme.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAAS,aAAa;AACtB,OAAO
|
|
5
|
-
"names": [
|
|
4
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB,OAAO,SAAS,UAAU,cAAc,YAAY,gBAAgB,cAAc;AAElF,SAA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AAC,oBAAoB,UAApB,EAA6B,OAAO,cAClC,gBACH;AAGF,SAAI,mBAAmB,KACd,sBAGL,QACK,kBAAkB;AAAA,IACvB,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC,IAGI;AACT;AAEA,SAAS,kBAAkB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKG;AACD,MAAI,UAAU,mBAAmB;AAC/B,WAAO;AAGT,QAAM,UAAU,WAAW,UACrB,uBAAuB,WAAW,QAAQ,gBAE1C,EAAE,WAAW,MAAM,IAAI,0BAA0B,YAAY,MAAM;AAEzE,MAAI,iBACF,oBAAC,UAAK,WAAW,GAAG,SAAS,2BAA2B,OACrD,UACH;AAIF,MAAI,sBAAsB;AACxB,UAAM,OAAO,WAAW,OAAO,QAAQ,IACjC,mBAAmB,KAAK,WAAW,OAAO,IAC5C,wBACA,KAAK,WAAW,MAAM,IACtB,uBACA;AACJ,qBACE,oBAAC,UAAK,WAAW,GAAG,UAAU,mBAAmB,EAAE,kBAChD,0BACH;AAAA,EAEJ;AAEA,SAAO;AACT;AAEA,MAAM,WAAW,CAAC;AAElB,SAAS,0BAA0B,YAAkC,SAAS,IAAO;AACnF,MAAI,CAAC,WAAW;AACd,WAAO,EAAE,WAAW,IAAI,OAAO,SAAS;AAI1C,QAAM,aACJ,WAAW,OAAO,SAAS,WAAW,aAClC,iBAAiB,WAAW,MAAM,MAAM,KAAK,IAC7C,IAEA,QAAQ,aACV;AAAA,IACE,OAAO;AAAA,EACT,IACA;AAEJ,MAAI,YAAY,WAAW,OAAO,aAAa;AAC/C,SAAI,WACF,YAAY,UAAU,QAAQ,eAAe,EAAE,IAE1C,EAAE,OAAO,UAAU;AAC5B;",
|
|
5
|
+
"names": []
|
|
6
6
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useDidFinishSSR } from "@tamagui/use-did-finish-ssr";
|
|
1
2
|
import { useForceUpdate } from "@tamagui/use-force-update";
|
|
2
3
|
import { useEffect, useId, useState } from "react";
|
|
3
4
|
import { createPortal } from "react-dom";
|
|
@@ -8,10 +9,8 @@ function ThemeDebug({
|
|
|
8
9
|
themeProps,
|
|
9
10
|
children
|
|
10
11
|
}) {
|
|
11
|
-
if (themeProps["disable-child-theme"])
|
|
12
|
-
return children;
|
|
13
12
|
if (process.env.NODE_ENV === "development") {
|
|
14
|
-
const [onChangeCount, setOnChangeCount] = useState(0), rerender = useForceUpdate(), id = useId();
|
|
13
|
+
const isHydrated = useDidFinishSSR(), [onChangeCount, setOnChangeCount] = useState(0), rerender = useForceUpdate(), id = useId();
|
|
15
14
|
return process.env.NODE_ENV === "development" && typeof document < "u" && (node || (node = document.createElement("div"), node.style.height = "200px", node.style.overflowY = "scroll", node.style.position = "fixed", node.style.zIndex = 1e7, node.style.bottom = "30px", node.style.left = "30px", node.style.right = "30px", node.style.display = "flex", node.style.border = "1px solid #888", node.style.flexDirection = "row", node.style.background = "var(--background)", document.body.appendChild(node))), useEffect(() => {
|
|
16
15
|
themeState.themeManager?.parentManager?.onChangeTheme((name, manager) => {
|
|
17
16
|
setOnChangeCount((p) => ++p), console.warn(
|
|
@@ -22,7 +21,7 @@ function ThemeDebug({
|
|
|
22
21
|
}, [themeState.themeManager]), useEffect(() => {
|
|
23
22
|
const tm = setInterval(rerender, 1e3);
|
|
24
23
|
return () => clearTimeout(tm);
|
|
25
|
-
}, []), /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
24
|
+
}, []), themeProps["disable-child-theme"] || !isHydrated ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
26
25
|
createPortal(
|
|
27
26
|
/* @__PURE__ */ jsxs(
|
|
28
27
|
"code",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/ThemeDebug.tsx"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "AACA,SAAS,uBAAuB;AAChC,SAAS,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A,YACD;AAAA;AAAA,cACY;AAAA,cAAG;AAAA,cACb,KAAK;AAAA,gBACJ;AAAA,kBACE,MAAM,YAAY,OAAO;AAAA,kBACzB,WAAW,YAAY,OAAO;AAAA,kBAC9B,SAAS,WAAW;AAAA,kBACpB,gBAAgB,WAAW;AAAA,kBAC3B,QAAQ,WAAW,cAAc,MAAM;AAAA,kBACvC,IAAI,WAAW,cAAc;AAAA,kBAC7B,UAAU,WAAW,cAAc,eAAe;AAAA,kBAClD,OAAO,WAAW;AAAA,kBAClB;AAAA,kBACA,WAAW,CAAC,GAAI,WAAW,cAAe,iBAAoB,CAAC,CAAE,EAAE;AAAA,oBACjE;AAAA,kBACF;AAAA,kBACA,sBAAsB,WAAW,cAAe;AAAA,gBAClD;AAAA,gBACA;AAAA,gBACA;AAAA,cACF;AAAA;AAAA;AAAA,QACF;AAAA,QACA;AAAA,MACF;AAAA,MAEA,oBAAC,SAAI,OAAO,EAAE,OAAO,MAAM,GAAI,cAAG;AAAA,MAEjC;AAAA,OACH;AAAA,EAEJ;AACA,SAAO;AACT;AAEA,WAAW,cAAiB;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/web",
|
|
3
|
-
"version": "1.82.
|
|
3
|
+
"version": "1.82.2",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -27,20 +27,20 @@
|
|
|
27
27
|
"reset.css"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@tamagui/compose-refs": "1.82.
|
|
31
|
-
"@tamagui/constants": "1.82.
|
|
32
|
-
"@tamagui/helpers": "1.82.
|
|
33
|
-
"@tamagui/normalize-css-color": "1.82.
|
|
34
|
-
"@tamagui/timer": "1.82.
|
|
35
|
-
"@tamagui/use-did-finish-ssr": "1.82.
|
|
36
|
-
"@tamagui/use-event": "1.82.
|
|
37
|
-
"@tamagui/use-force-update": "1.82.
|
|
30
|
+
"@tamagui/compose-refs": "1.82.2",
|
|
31
|
+
"@tamagui/constants": "1.82.2",
|
|
32
|
+
"@tamagui/helpers": "1.82.2",
|
|
33
|
+
"@tamagui/normalize-css-color": "1.82.2",
|
|
34
|
+
"@tamagui/timer": "1.82.2",
|
|
35
|
+
"@tamagui/use-did-finish-ssr": "1.82.2",
|
|
36
|
+
"@tamagui/use-event": "1.82.2",
|
|
37
|
+
"@tamagui/use-force-update": "1.82.2"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"react": "*"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@tamagui/build": "1.82.
|
|
43
|
+
"@tamagui/build": "1.82.2",
|
|
44
44
|
"@testing-library/react": "^14.0.0",
|
|
45
45
|
"csstype": "^3.0.10",
|
|
46
46
|
"react": "^18.2.0",
|
package/src/createComponent.tsx
CHANGED
|
@@ -65,7 +65,7 @@ import {
|
|
|
65
65
|
WebOnlyPressEvents,
|
|
66
66
|
} from './types'
|
|
67
67
|
import { Slot } from './views/Slot'
|
|
68
|
-
import {
|
|
68
|
+
import { getThemedChildren } from './views/Theme'
|
|
69
69
|
import { ThemeDebug } from './views/ThemeDebug'
|
|
70
70
|
|
|
71
71
|
// this appears to fix expo / babel not picking this up sometimes? really odd
|
|
@@ -1205,9 +1205,9 @@ export function createComponent<
|
|
|
1205
1205
|
if (process.env.NODE_ENV === 'development' && time) time`group-context`
|
|
1206
1206
|
|
|
1207
1207
|
// disable theme prop is deterministic so conditional hook ok here
|
|
1208
|
-
content =
|
|
1208
|
+
content = disableTheme
|
|
1209
1209
|
? content
|
|
1210
|
-
:
|
|
1210
|
+
: getThemedChildren(themeState, content, themeStateProps, false)
|
|
1211
1211
|
|
|
1212
1212
|
if (process.env.NODE_ENV === 'development' && time) time`themed-children`
|
|
1213
1213
|
|
|
@@ -30,7 +30,7 @@ export type ThemeManagerState = {
|
|
|
30
30
|
const emptyState: ThemeManagerState = { name: '' }
|
|
31
31
|
|
|
32
32
|
export function getHasThemeUpdatingProps(props: ThemeProps) {
|
|
33
|
-
return props.name || props.componentName || props.inverse || props.reset
|
|
33
|
+
return Boolean(props.name || props.componentName || props.inverse || props.reset)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
let uid = 0
|
|
@@ -228,7 +228,7 @@ function getState(
|
|
|
228
228
|
|
|
229
229
|
if (
|
|
230
230
|
process.env.NODE_ENV !== 'production' &&
|
|
231
|
-
|
|
231
|
+
props.debug &&
|
|
232
232
|
typeof window !== 'undefined'
|
|
233
233
|
) {
|
|
234
234
|
console.groupCollapsed('ThemeManager.getState()')
|
|
@@ -257,19 +257,22 @@ function getState(
|
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
if (componentName && !props.reset) {
|
|
260
|
+
const baseLen = base.length
|
|
260
261
|
let componentPotentials: string[] = []
|
|
261
262
|
// components only look for component themes
|
|
262
|
-
if (nextName) {
|
|
263
|
-
const beforeSeparator =
|
|
263
|
+
if (nextName && baseLen > 1) {
|
|
264
|
+
const beforeSeparator = base[0]
|
|
264
265
|
componentPotentials.push(`${beforeSeparator}_${nextName}_${componentName}`)
|
|
265
266
|
}
|
|
266
267
|
componentPotentials.push(`${prefix}_${componentName}`)
|
|
267
268
|
if (nextName) {
|
|
268
269
|
// do this one and one level up
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
270
|
+
if (i > baseLen) {
|
|
271
|
+
const prefixLessOne = base.slice(0, i - 1).join(THEME_NAME_SEPARATOR)
|
|
272
|
+
if (prefixLessOne) {
|
|
273
|
+
const lessSpecific = `${prefixLessOne}_${nextName}_${componentName}`
|
|
274
|
+
componentPotentials.unshift(lessSpecific)
|
|
275
|
+
}
|
|
273
276
|
}
|
|
274
277
|
const moreSpecific = `${prefix}_${nextName}_${componentName}`
|
|
275
278
|
componentPotentials.unshift(moreSpecific)
|
|
@@ -282,6 +285,7 @@ function getState(
|
|
|
282
285
|
|
|
283
286
|
if (process.env.NODE_ENV !== 'production' && typeof props.debug === 'string') {
|
|
284
287
|
console.info(' getState ', {
|
|
288
|
+
props,
|
|
285
289
|
found,
|
|
286
290
|
potentials,
|
|
287
291
|
baseManager,
|
|
@@ -24,8 +24,8 @@ export function fixStyles(style: Record<string, any>) {
|
|
|
24
24
|
// TODO could be native-only
|
|
25
25
|
// ensure border style set by default to solid
|
|
26
26
|
for (const key in borderDefaults) {
|
|
27
|
-
if (key in style
|
|
28
|
-
style[borderDefaults[key]]
|
|
27
|
+
if (key in style) {
|
|
28
|
+
style[borderDefaults[key]] ||= 'solid'
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -284,7 +284,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
// keyInit === 'style' is handled in skipProps
|
|
287
|
-
if (keyInit in skipProps && !isHOC) {
|
|
287
|
+
if (keyInit in skipProps && !styleProps.noSkip && !isHOC) {
|
|
288
288
|
if (keyInit === 'group') {
|
|
289
289
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
290
290
|
// add container style
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getVariableValue } from '../createVariable'
|
|
2
2
|
import { GenericFonts, GetStyleState } from '../types'
|
|
3
3
|
import { LanguageContextType } from '../views/FontLanguage.types'
|
|
4
|
-
import { createProxy } from './createProxy'
|
|
5
4
|
|
|
6
5
|
export function getVariantExtras(styleState: GetStyleState) {
|
|
7
6
|
const { curProps, conf, context, theme } = styleState
|
|
@@ -23,7 +22,7 @@ export function getVariantExtras(styleState: GetStyleState) {
|
|
|
23
22
|
font: fonts[fontFamily] || fonts[styleState.conf.defaultFont!],
|
|
24
23
|
// TODO do this in splitstlye
|
|
25
24
|
// we avoid passing in default props for media queries because that would confuse things like SizableText.size:
|
|
26
|
-
props:
|
|
25
|
+
props: new Proxy(curProps, {
|
|
27
26
|
// handles shorthands
|
|
28
27
|
get(target, key) {
|
|
29
28
|
const shorthand = conf.inverseShorthands[key as any]
|
|
@@ -5,51 +5,32 @@ import type { GenericVariantDefinitions } from '../types'
|
|
|
5
5
|
|
|
6
6
|
export const mergeVariants = (
|
|
7
7
|
parentVariants: GenericVariantDefinitions,
|
|
8
|
-
ourVariants: GenericVariantDefinitions
|
|
8
|
+
ourVariants: GenericVariantDefinitions,
|
|
9
|
+
level = 0
|
|
9
10
|
) => {
|
|
10
11
|
const variants = {}
|
|
11
12
|
|
|
12
13
|
for (const key in ourVariants) {
|
|
13
14
|
const parentVariant = parentVariants?.[key]
|
|
14
15
|
const ourVariant = ourVariants[key]
|
|
15
|
-
|
|
16
|
-
// do some early checks to avoid bad merges
|
|
17
16
|
if (!parentVariant || typeof ourVariant === 'function') {
|
|
18
17
|
variants[key] = ourVariant
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// do some early checks to avoid bad merges
|
|
23
|
-
if (parentVariant && !ourVariant) {
|
|
18
|
+
} else if (parentVariant && !ourVariant) {
|
|
24
19
|
variants[key] = parentVariant[key]
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const parentVal = parentVariant?.[subKey]
|
|
33
|
-
if (typeof val === 'function') {
|
|
34
|
-
variants[key][subKey] = val
|
|
35
|
-
} else if (!parentVal || typeof parentVal === 'function') {
|
|
36
|
-
variants[key][subKey] = val
|
|
20
|
+
} else {
|
|
21
|
+
if (level === 0) {
|
|
22
|
+
variants[key] = mergeVariants(
|
|
23
|
+
parentVariant as Record<string, any>,
|
|
24
|
+
ourVariant as Record<string, any>,
|
|
25
|
+
level + 1
|
|
26
|
+
)
|
|
37
27
|
} else {
|
|
38
|
-
variants[key]
|
|
39
|
-
|
|
40
|
-
...
|
|
41
|
-
...val,
|
|
28
|
+
variants[key] = {
|
|
29
|
+
...parentVariant,
|
|
30
|
+
...ourVariant,
|
|
42
31
|
}
|
|
43
32
|
}
|
|
44
33
|
}
|
|
45
|
-
|
|
46
|
-
// merge parent variant keys that are superset
|
|
47
|
-
if (parentVariant) {
|
|
48
|
-
variants[key] = {
|
|
49
|
-
...parentVariant,
|
|
50
|
-
...variants[key],
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
34
|
}
|
|
54
35
|
|
|
55
36
|
return {
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { isWeb } from '@tamagui/constants'
|
|
2
1
|
import { normalizeCSSColor, rgba } from '@tamagui/normalize-css-color'
|
|
3
2
|
|
|
4
3
|
export { rgba } from '@tamagui/normalize-css-color'
|
|
5
4
|
|
|
6
5
|
export const normalizeColor = (color?: string | null, opacity?: number) => {
|
|
7
6
|
if (!color) return
|
|
8
|
-
if (color[0] === '$' ||
|
|
9
|
-
return color
|
|
10
|
-
}
|
|
11
|
-
if (isWeb && opacity === 1) {
|
|
7
|
+
if (color[0] === '$' || color.startsWith('var(')) {
|
|
12
8
|
return color
|
|
13
9
|
}
|
|
14
10
|
const colorProcessed = normalizeCSSColor(color)
|
|
@@ -19,6 +19,8 @@ import { isObj } from './isObj'
|
|
|
19
19
|
import { pseudoDescriptors } from './pseudoDescriptors'
|
|
20
20
|
|
|
21
21
|
export const propMapper: PropMapper = (key, value, styleStateIn, subPropsIn) => {
|
|
22
|
+
lastFontFamilyToken = null
|
|
23
|
+
|
|
22
24
|
if (!(process.env.TAMAGUI_TARGET === 'native' && isAndroid)) {
|
|
23
25
|
// this shouldnt be necessary and handled in the outer loop
|
|
24
26
|
if (key === 'elevationAndroid') return
|
|
@@ -99,7 +101,7 @@ export const propMapper: PropMapper = (key, value, styleStateIn, subPropsIn) =>
|
|
|
99
101
|
[key, value],
|
|
100
102
|
]
|
|
101
103
|
|
|
102
|
-
if (key === 'fontFamily') {
|
|
104
|
+
if (key === 'fontFamily' && lastFontFamilyToken) {
|
|
103
105
|
fontFamilyCache.set(result, lastFontFamilyToken)
|
|
104
106
|
}
|
|
105
107
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GetThemeUnwrapped } from '../hooks/getThemeUnwrapped'
|
|
1
|
+
import { getTokenObject } from '../config'
|
|
3
2
|
import { DedupedThemes, ThemeParsed } from '../types'
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
const themesRaw: Record<string, ThemeParsed> = {}
|
|
6
5
|
|
|
7
6
|
// this seems expensive but its necessary to do two loops unless we want to refactor a variety of things again
|
|
8
7
|
// not *too* much work but not a big cost doing the two loops
|
|
@@ -50,9 +49,8 @@ export function proxyThemeToParents(themeName: string, theme: ThemeParsed) {
|
|
|
50
49
|
// proxy fallback values to parent theme values
|
|
51
50
|
return new Proxy(theme, {
|
|
52
51
|
get(target, key) {
|
|
53
|
-
if (key === GetThemeUnwrapped) return theme
|
|
54
52
|
if (
|
|
55
|
-
key
|
|
53
|
+
!key ||
|
|
56
54
|
// dont ask me, idk why but on hermes you can see that useTheme()[undefined] passes in STRING undefined to proxy
|
|
57
55
|
// if someone is crazy enough to use "undefined" as a theme key then this not working is on them
|
|
58
56
|
key == 'undefined' ||
|
|
@@ -63,12 +61,11 @@ export function proxyThemeToParents(themeName: string, theme: ThemeParsed) {
|
|
|
63
61
|
// check parents
|
|
64
62
|
for (let i = numParents - 1; i >= 0; i--) {
|
|
65
63
|
const parent = themesRaw[parents[i]]
|
|
66
|
-
if (
|
|
67
|
-
if (Reflect.has(parent, key)) {
|
|
64
|
+
if (parent && Reflect.has(parent, key)) {
|
|
68
65
|
return Reflect.get(parent, key)
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
|
-
return getTokenObject(key as any)
|
|
68
|
+
return getTokenObject(key as any)
|
|
72
69
|
},
|
|
73
70
|
})
|
|
74
71
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { forwardRef } from 'react'
|
|
2
2
|
|
|
3
3
|
import { StaticConfig, ThemeableProps } from '../types'
|
|
4
4
|
import { Theme } from '../views/Theme'
|
|
@@ -10,8 +10,10 @@ export function themeable<ComponentType extends (props: any) => any>(
|
|
|
10
10
|
const withThemeComponent = forwardRef(function WithTheme(props: ThemeableProps, ref) {
|
|
11
11
|
const { themeInverse, theme, componentName, themeReset, ...rest } = props
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const element = (
|
|
14
|
+
// @ts-expect-error its ok
|
|
15
|
+
<Component ref={ref} {...rest} data-disable-theme />
|
|
16
|
+
)
|
|
15
17
|
|
|
16
18
|
let contents = (
|
|
17
19
|
<Theme
|