@tamagui/core 1.0.1-beta.218 → 1.0.1-beta.219

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.
@@ -35,19 +35,14 @@ function themeable(component, opts) {
35
35
  const withThemeComponent = (0, import_react.forwardRef)(function WithTheme(props, ref) {
36
36
  const { themeInverse, theme, ...rest } = props;
37
37
  const element = import_react.default.createElement(component, { ...rest, ref });
38
- if (themeInverse) {
39
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ThemeInverse.ThemeInverse, {
40
- children: element
41
- });
42
- }
43
- if (theme || opts) {
44
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Theme.Theme, {
38
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ThemeInverse.ThemeInverse, {
39
+ disable: !themeInverse,
40
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Theme.Theme, {
45
41
  componentName: opts == null ? void 0 : opts.componentName,
46
42
  name: theme || null,
47
43
  children: element
48
- });
49
- }
50
- return element;
44
+ })
45
+ });
51
46
  });
52
47
  const withTheme = withThemeComponent;
53
48
  withTheme.displayName = `Themed(${(component == null ? void 0 : component.displayName) || (component == null ? void 0 : component.name) || "Anonymous"})`;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/themeable.tsx"],
4
- "sourcesContent": ["import React, { forwardRef } from 'react'\n\nimport { ThemeName } from '../types'\nimport { Theme } from '../views/Theme'\nimport { ThemeInverse } from '../views/ThemeInverse'\n\nexport interface ThemeableProps {\n theme?: ThemeName | null\n themeInverse?: boolean\n}\n\nexport function themeable<Component extends (props: any) => any>(\n component: Component,\n opts?: { componentName?: string }\n) {\n const withThemeComponent = forwardRef(function WithTheme(props: any, ref) {\n const { themeInverse, theme, ...rest } = props\n const element = React.createElement(component, { ...rest, ref } as any)\n if (themeInverse) {\n return <ThemeInverse>{element}</ThemeInverse>\n }\n if (theme || opts) {\n return (\n <Theme componentName={opts?.componentName} name={(theme as any) || null}>\n {element}\n </Theme>\n )\n }\n return element\n })\n\n const withTheme: any = withThemeComponent\n withTheme.displayName = `Themed(${\n (component as any)?.displayName || (component as any)?.name || 'Anonymous'\n })`\n\n return withTheme as Component extends (props: infer P) => infer R\n ? (props: Omit<P, 'theme' | 'themeInverse'> & ThemeableProps) => R\n : unknown\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBa;AAnBb,mBAAkC;AAGlC,mBAAsB;AACtB,0BAA6B;AAOtB,SAAS,UACd,WACA,MACA;AACA,QAAM,yBAAqB,yBAAW,SAAS,UAAU,OAAY,KAAK;AACxE,UAAM,EAAE,cAAc,UAAU,KAAK,IAAI;AACzC,UAAM,UAAU,aAAAA,QAAM,cAAc,WAAW,EAAE,GAAG,MAAM,IAAI,CAAQ;AACtE,QAAI,cAAc;AAChB,aAAO,4CAAC;AAAA,QAAc;AAAA,OAAQ;AAAA,IAChC;AACA,QAAI,SAAS,MAAM;AACjB,aACE,4CAAC;AAAA,QAAM,eAAe,6BAAM;AAAA,QAAe,MAAO,SAAiB;AAAA,QAChE;AAAA,OACH;AAAA,IAEJ;AACA,WAAO;AAAA,EACT,CAAC;AAED,QAAM,YAAiB;AACvB,YAAU,cAAc,WACrB,uCAAmB,iBAAgB,uCAAmB,SAAQ;AAGjE,SAAO;AAGT;",
4
+ "sourcesContent": ["import React, { forwardRef } from 'react'\n\nimport { ThemeName } from '../types'\nimport { Theme } from '../views/Theme'\nimport { ThemeInverse } from '../views/ThemeInverse'\n\nexport interface ThemeableProps {\n theme?: ThemeName | null\n themeInverse?: boolean\n}\n\nexport function themeable<Component extends (props: any) => any>(\n component: Component,\n opts?: { componentName?: string }\n) {\n const withThemeComponent = forwardRef(function WithTheme(props: any, ref) {\n const { themeInverse, theme, ...rest } = props\n const element = React.createElement(component, { ...rest, ref } as any)\n return (\n <ThemeInverse disable={!themeInverse}>\n <Theme componentName={opts?.componentName} name={(theme as any) || null}>\n {element}\n </Theme>\n </ThemeInverse>\n )\n })\n\n const withTheme: any = withThemeComponent\n withTheme.displayName = `Themed(${\n (component as any)?.displayName || (component as any)?.name || 'Anonymous'\n })`\n\n return withTheme as Component extends (props: infer P) => infer R\n ? (props: Omit<P, 'theme' | 'themeInverse'> & ThemeableProps) => R\n : unknown\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBQ;AApBR,mBAAkC;AAGlC,mBAAsB;AACtB,0BAA6B;AAOtB,SAAS,UACd,WACA,MACA;AACA,QAAM,yBAAqB,yBAAW,SAAS,UAAU,OAAY,KAAK;AACxE,UAAM,EAAE,cAAc,UAAU,KAAK,IAAI;AACzC,UAAM,UAAU,aAAAA,QAAM,cAAc,WAAW,EAAE,GAAG,MAAM,IAAI,CAAQ;AACtE,WACE,4CAAC;AAAA,MAAa,SAAS,CAAC;AAAA,MACtB,sDAAC;AAAA,QAAM,eAAe,6BAAM;AAAA,QAAe,MAAO,SAAiB;AAAA,QAChE;AAAA,OACH;AAAA,KACF;AAAA,EAEJ,CAAC;AAED,QAAM,YAAiB;AACvB,YAAU,cAAc,WACrB,uCAAmB,iBAAgB,uCAAmB,SAAQ;AAGjE,SAAO;AAGT;",
6
6
  "names": ["React"]
7
7
  }
@@ -18,7 +18,8 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var ThemeInverse_exports = {};
20
20
  __export(ThemeInverse_exports, {
21
- ThemeInverse: () => ThemeInverse
21
+ ThemeInverse: () => ThemeInverse,
22
+ useThemeInverse: () => useThemeInverse
22
23
  });
23
24
  module.exports = __toCommonJS(ThemeInverse_exports);
24
25
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -26,30 +27,35 @@ var import_constants = require("@tamagui/constants");
26
27
  var import_react = require("react");
27
28
  var import_useTheme = require("../hooks/useTheme");
28
29
  var import_Theme = require("./Theme");
29
- const ThemeInverse = ({
30
- children,
31
- disable
32
- }) => {
30
+ const toggleTheme = (themeName) => {
31
+ return themeName.startsWith("light") ? "dark" : "light";
32
+ };
33
+ const useThemeInverse = (props = {}) => {
33
34
  const themeName = (0, import_useTheme.useThemeName)();
34
35
  const defaultTheme = (0, import_useTheme.useDefaultThemeName)();
35
36
  const [name, setName] = (0, import_react.useState)(null);
36
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
37
- if (themeName.startsWith("dark")) {
38
- setName("light");
39
- } else if (themeName.startsWith("light")) {
40
- setName("dark");
41
- }
42
- }, [defaultTheme, themeName]);
43
- if (disable) {
44
- return children;
37
+ if (import_constants.isWeb) {
38
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
39
+ setName(toggleTheme(themeName || defaultTheme || ""));
40
+ }, [defaultTheme, themeName]);
45
41
  }
42
+ return props.disable ? null : name;
43
+ };
44
+ const ThemeInverse = ({
45
+ children,
46
+ disable
47
+ }) => {
48
+ const inverseTheme = useThemeInverse({
49
+ disable
50
+ });
46
51
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Theme.Theme, {
47
- name,
52
+ name: inverseTheme,
48
53
  children
49
54
  });
50
55
  };
51
56
  // Annotate the CommonJS export names for ESM import in node:
52
57
  0 && (module.exports = {
53
- ThemeInverse
58
+ ThemeInverse,
59
+ useThemeInverse
54
60
  });
55
61
  //# sourceMappingURL=ThemeInverse.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/ThemeInverse.tsx"],
4
- "sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport React, { useState } from 'react'\n\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\nexport const ThemeInverse = ({\n children,\n disable,\n}: {\n children: React.ReactNode\n disable?: boolean\n}) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const [name, setName] = useState<null | string>(null)\n\n // ssr\n useIsomorphicLayoutEffect(() => {\n if (themeName.startsWith('dark')) {\n setName('light')\n } else if (themeName.startsWith('light')) {\n setName('dark')\n }\n }, [defaultTheme, themeName])\n\n if (disable) {\n return children as JSX.Element\n }\n\n return <Theme name={name}>{children}</Theme>\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BS;AA9BT,uBAA0C;AAC1C,mBAAgC;AAEhC,sBAAkD;AAClD,mBAAsB;AAEf,MAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AACF,MAGM;AACJ,QAAM,gBAAY,8BAAa;AAC/B,QAAM,mBAAe,qCAAoB;AACzC,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAwB,IAAI;AAGpD,kDAA0B,MAAM;AAC9B,QAAI,UAAU,WAAW,MAAM,GAAG;AAChC,cAAQ,OAAO;AAAA,IACjB,WAAW,UAAU,WAAW,OAAO,GAAG;AACxC,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,cAAc,SAAS,CAAC;AAE5B,MAAI,SAAS;AACX,WAAO;AAAA,EACT;AAEA,SAAO,4CAAC;AAAA,IAAM;AAAA,IAAa;AAAA,GAAS;AACtC;",
4
+ "sourcesContent": ["import { isWeb, useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport React, { useState } from 'react'\n\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\nexport type ThemeInverseProps = {\n disable?: boolean\n}\n\nconst toggleTheme = (themeName: string) => {\n return themeName.startsWith('light') ? 'dark' : 'light'\n}\n\nexport const useThemeInverse = (props: ThemeInverseProps = {}) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const [name, setName] = useState<null | string>(null)\n\n if (isWeb) {\n // for SSR must be in effect\n useIsomorphicLayoutEffect(() => {\n setName(toggleTheme(themeName || defaultTheme || ''))\n }, [defaultTheme, themeName])\n }\n\n return props.disable ? null : name\n}\n\nexport const ThemeInverse = ({\n children,\n disable,\n}: ThemeInverseProps & {\n children: React.ReactNode\n}) => {\n const inverseTheme = useThemeInverse({\n disable,\n })\n return <Theme name={inverseTheme}>{children}</Theme>\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsCS;AAtCT,uBAAiD;AACjD,mBAAgC;AAEhC,sBAAkD;AAClD,mBAAsB;AAMtB,MAAM,cAAc,CAAC,cAAsB;AACzC,SAAO,UAAU,WAAW,OAAO,IAAI,SAAS;AAClD;AAEO,MAAM,kBAAkB,CAAC,QAA2B,CAAC,MAAM;AAChE,QAAM,gBAAY,8BAAa;AAC/B,QAAM,mBAAe,qCAAoB;AACzC,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAwB,IAAI;AAEpD,MAAI,wBAAO;AAET,oDAA0B,MAAM;AAC9B,cAAQ,YAAY,aAAa,gBAAgB,EAAE,CAAC;AAAA,IACtD,GAAG,CAAC,cAAc,SAAS,CAAC;AAAA,EAC9B;AAEA,SAAO,MAAM,UAAU,OAAO;AAChC;AAEO,MAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AACF,MAEM;AACJ,QAAM,eAAe,gBAAgB;AAAA,IACnC;AAAA,EACF,CAAC;AACD,SAAO,4CAAC;AAAA,IAAM,MAAM;AAAA,IAAe;AAAA,GAAS;AAC9C;",
6
6
  "names": []
7
7
  }
@@ -6,19 +6,14 @@ function themeable(component, opts) {
6
6
  const withThemeComponent = forwardRef(function WithTheme(props, ref) {
7
7
  const { themeInverse, theme, ...rest } = props;
8
8
  const element = React.createElement(component, { ...rest, ref });
9
- if (themeInverse) {
10
- return /* @__PURE__ */ jsx(ThemeInverse, {
11
- children: element
12
- });
13
- }
14
- if (theme || opts) {
15
- return /* @__PURE__ */ jsx(Theme, {
9
+ return /* @__PURE__ */ jsx(ThemeInverse, {
10
+ disable: !themeInverse,
11
+ children: /* @__PURE__ */ jsx(Theme, {
16
12
  componentName: opts == null ? void 0 : opts.componentName,
17
13
  name: theme || null,
18
14
  children: element
19
- });
20
- }
21
- return element;
15
+ })
16
+ });
22
17
  });
23
18
  const withTheme = withThemeComponent;
24
19
  withTheme.displayName = `Themed(${(component == null ? void 0 : component.displayName) || (component == null ? void 0 : component.name) || "Anonymous"})`;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/themeable.tsx"],
4
- "sourcesContent": ["import React, { forwardRef } from 'react'\n\nimport { ThemeName } from '../types'\nimport { Theme } from '../views/Theme'\nimport { ThemeInverse } from '../views/ThemeInverse'\n\nexport interface ThemeableProps {\n theme?: ThemeName | null\n themeInverse?: boolean\n}\n\nexport function themeable<Component extends (props: any) => any>(\n component: Component,\n opts?: { componentName?: string }\n) {\n const withThemeComponent = forwardRef(function WithTheme(props: any, ref) {\n const { themeInverse, theme, ...rest } = props\n const element = React.createElement(component, { ...rest, ref } as any)\n if (themeInverse) {\n return <ThemeInverse>{element}</ThemeInverse>\n }\n if (theme || opts) {\n return (\n <Theme componentName={opts?.componentName} name={(theme as any) || null}>\n {element}\n </Theme>\n )\n }\n return element\n })\n\n const withTheme: any = withThemeComponent\n withTheme.displayName = `Themed(${\n (component as any)?.displayName || (component as any)?.name || 'Anonymous'\n })`\n\n return withTheme as Component extends (props: infer P) => infer R\n ? (props: Omit<P, 'theme' | 'themeInverse'> & ThemeableProps) => R\n : unknown\n}\n"],
5
- "mappings": "AAmBa;AAnBb,OAAO,SAAS,kBAAkB;AAGlC,SAAS,aAAa;AACtB,SAAS,oBAAoB;AAOtB,SAAS,UACd,WACA,MACA;AACA,QAAM,qBAAqB,WAAW,SAAS,UAAU,OAAY,KAAK;AACxE,UAAM,EAAE,cAAc,UAAU,KAAK,IAAI;AACzC,UAAM,UAAU,MAAM,cAAc,WAAW,EAAE,GAAG,MAAM,IAAI,CAAQ;AACtE,QAAI,cAAc;AAChB,aAAO,oBAAC;AAAA,QAAc;AAAA,OAAQ;AAAA,IAChC;AACA,QAAI,SAAS,MAAM;AACjB,aACE,oBAAC;AAAA,QAAM,eAAe,6BAAM;AAAA,QAAe,MAAO,SAAiB;AAAA,QAChE;AAAA,OACH;AAAA,IAEJ;AACA,WAAO;AAAA,EACT,CAAC;AAED,QAAM,YAAiB;AACvB,YAAU,cAAc,WACrB,uCAAmB,iBAAgB,uCAAmB,SAAQ;AAGjE,SAAO;AAGT;",
4
+ "sourcesContent": ["import React, { forwardRef } from 'react'\n\nimport { ThemeName } from '../types'\nimport { Theme } from '../views/Theme'\nimport { ThemeInverse } from '../views/ThemeInverse'\n\nexport interface ThemeableProps {\n theme?: ThemeName | null\n themeInverse?: boolean\n}\n\nexport function themeable<Component extends (props: any) => any>(\n component: Component,\n opts?: { componentName?: string }\n) {\n const withThemeComponent = forwardRef(function WithTheme(props: any, ref) {\n const { themeInverse, theme, ...rest } = props\n const element = React.createElement(component, { ...rest, ref } as any)\n return (\n <ThemeInverse disable={!themeInverse}>\n <Theme componentName={opts?.componentName} name={(theme as any) || null}>\n {element}\n </Theme>\n </ThemeInverse>\n )\n })\n\n const withTheme: any = withThemeComponent\n withTheme.displayName = `Themed(${\n (component as any)?.displayName || (component as any)?.name || 'Anonymous'\n })`\n\n return withTheme as Component extends (props: infer P) => infer R\n ? (props: Omit<P, 'theme' | 'themeInverse'> & ThemeableProps) => R\n : unknown\n}\n"],
5
+ "mappings": "AAoBQ;AApBR,OAAO,SAAS,kBAAkB;AAGlC,SAAS,aAAa;AACtB,SAAS,oBAAoB;AAOtB,SAAS,UACd,WACA,MACA;AACA,QAAM,qBAAqB,WAAW,SAAS,UAAU,OAAY,KAAK;AACxE,UAAM,EAAE,cAAc,UAAU,KAAK,IAAI;AACzC,UAAM,UAAU,MAAM,cAAc,WAAW,EAAE,GAAG,MAAM,IAAI,CAAQ;AACtE,WACE,oBAAC;AAAA,MAAa,SAAS,CAAC;AAAA,MACtB,8BAAC;AAAA,QAAM,eAAe,6BAAM;AAAA,QAAe,MAAO,SAAiB;AAAA,QAChE;AAAA,OACH;AAAA,KACF;AAAA,EAEJ,CAAC;AAED,QAAM,YAAiB;AACvB,YAAU,cAAc,WACrB,uCAAmB,iBAAgB,uCAAmB,SAAQ;AAGjE,SAAO;AAGT;",
6
6
  "names": []
7
7
  }
@@ -1,31 +1,36 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useIsomorphicLayoutEffect } from "@tamagui/constants";
2
+ import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
3
3
  import { useState } from "react";
4
4
  import { useDefaultThemeName, useThemeName } from "../hooks/useTheme";
5
5
  import { Theme } from "./Theme";
6
- const ThemeInverse = ({
7
- children,
8
- disable
9
- }) => {
6
+ const toggleTheme = (themeName) => {
7
+ return themeName.startsWith("light") ? "dark" : "light";
8
+ };
9
+ const useThemeInverse = (props = {}) => {
10
10
  const themeName = useThemeName();
11
11
  const defaultTheme = useDefaultThemeName();
12
12
  const [name, setName] = useState(null);
13
- useIsomorphicLayoutEffect(() => {
14
- if (themeName.startsWith("dark")) {
15
- setName("light");
16
- } else if (themeName.startsWith("light")) {
17
- setName("dark");
18
- }
19
- }, [defaultTheme, themeName]);
20
- if (disable) {
21
- return children;
13
+ if (isWeb) {
14
+ useIsomorphicLayoutEffect(() => {
15
+ setName(toggleTheme(themeName || defaultTheme || ""));
16
+ }, [defaultTheme, themeName]);
22
17
  }
18
+ return props.disable ? null : name;
19
+ };
20
+ const ThemeInverse = ({
21
+ children,
22
+ disable
23
+ }) => {
24
+ const inverseTheme = useThemeInverse({
25
+ disable
26
+ });
23
27
  return /* @__PURE__ */ jsx(Theme, {
24
- name,
28
+ name: inverseTheme,
25
29
  children
26
30
  });
27
31
  };
28
32
  export {
29
- ThemeInverse
33
+ ThemeInverse,
34
+ useThemeInverse
30
35
  };
31
36
  //# sourceMappingURL=ThemeInverse.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/ThemeInverse.tsx"],
4
- "sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport React, { useState } from 'react'\n\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\nexport const ThemeInverse = ({\n children,\n disable,\n}: {\n children: React.ReactNode\n disable?: boolean\n}) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const [name, setName] = useState<null | string>(null)\n\n // ssr\n useIsomorphicLayoutEffect(() => {\n if (themeName.startsWith('dark')) {\n setName('light')\n } else if (themeName.startsWith('light')) {\n setName('dark')\n }\n }, [defaultTheme, themeName])\n\n if (disable) {\n return children as JSX.Element\n }\n\n return <Theme name={name}>{children}</Theme>\n}\n"],
5
- "mappings": "AA8BS;AA9BT,SAAS,iCAAiC;AAC1C,SAAgB,gBAAgB;AAEhC,SAAS,qBAAqB,oBAAoB;AAClD,SAAS,aAAa;AAEf,MAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AACF,MAGM;AACJ,QAAM,YAAY,aAAa;AAC/B,QAAM,eAAe,oBAAoB;AACzC,QAAM,CAAC,MAAM,OAAO,IAAI,SAAwB,IAAI;AAGpD,4BAA0B,MAAM;AAC9B,QAAI,UAAU,WAAW,MAAM,GAAG;AAChC,cAAQ,OAAO;AAAA,IACjB,WAAW,UAAU,WAAW,OAAO,GAAG;AACxC,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,cAAc,SAAS,CAAC;AAE5B,MAAI,SAAS;AACX,WAAO;AAAA,EACT;AAEA,SAAO,oBAAC;AAAA,IAAM;AAAA,IAAa;AAAA,GAAS;AACtC;",
4
+ "sourcesContent": ["import { isWeb, useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport React, { useState } from 'react'\n\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\nexport type ThemeInverseProps = {\n disable?: boolean\n}\n\nconst toggleTheme = (themeName: string) => {\n return themeName.startsWith('light') ? 'dark' : 'light'\n}\n\nexport const useThemeInverse = (props: ThemeInverseProps = {}) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const [name, setName] = useState<null | string>(null)\n\n if (isWeb) {\n // for SSR must be in effect\n useIsomorphicLayoutEffect(() => {\n setName(toggleTheme(themeName || defaultTheme || ''))\n }, [defaultTheme, themeName])\n }\n\n return props.disable ? null : name\n}\n\nexport const ThemeInverse = ({\n children,\n disable,\n}: ThemeInverseProps & {\n children: React.ReactNode\n}) => {\n const inverseTheme = useThemeInverse({\n disable,\n })\n return <Theme name={inverseTheme}>{children}</Theme>\n}\n"],
5
+ "mappings": "AAsCS;AAtCT,SAAS,OAAO,iCAAiC;AACjD,SAAgB,gBAAgB;AAEhC,SAAS,qBAAqB,oBAAoB;AAClD,SAAS,aAAa;AAMtB,MAAM,cAAc,CAAC,cAAsB;AACzC,SAAO,UAAU,WAAW,OAAO,IAAI,SAAS;AAClD;AAEO,MAAM,kBAAkB,CAAC,QAA2B,CAAC,MAAM;AAChE,QAAM,YAAY,aAAa;AAC/B,QAAM,eAAe,oBAAoB;AACzC,QAAM,CAAC,MAAM,OAAO,IAAI,SAAwB,IAAI;AAEpD,MAAI,OAAO;AAET,8BAA0B,MAAM;AAC9B,cAAQ,YAAY,aAAa,gBAAgB,EAAE,CAAC;AAAA,IACtD,GAAG,CAAC,cAAc,SAAS,CAAC;AAAA,EAC9B;AAEA,SAAO,MAAM,UAAU,OAAO;AAChC;AAEO,MAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AACF,MAEM;AACJ,QAAM,eAAe,gBAAgB;AAAA,IACnC;AAAA,EACF,CAAC;AACD,SAAO,oBAAC;AAAA,IAAM,MAAM;AAAA,IAAe;AAAA,GAAS;AAC9C;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/core",
3
- "version": "1.0.1-beta.218",
3
+ "version": "1.0.1-beta.219",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -28,23 +28,23 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "@expo/match-media": "^0.3.0",
31
- "@tamagui/compose-refs": "^1.0.1-beta.218",
32
- "@tamagui/constants": "^1.0.1-beta.218",
33
- "@tamagui/helpers": "^1.0.1-beta.218",
34
- "@tamagui/normalize-css-color-lite": "^1.0.1-beta.218",
35
- "@tamagui/react-native-use-pressable": "^1.0.1-beta.218",
36
- "@tamagui/react-native-use-responder-events": "^1.0.1-beta.218",
37
- "@tamagui/types-react-native": "^1.0.1-beta.218",
38
- "@tamagui/use-did-finish-ssr": "^1.0.1-beta.218",
39
- "@tamagui/use-event": "^1.0.1-beta.218",
40
- "@tamagui/use-force-update": "^1.0.1-beta.218"
31
+ "@tamagui/compose-refs": "^1.0.1-beta.219",
32
+ "@tamagui/constants": "^1.0.1-beta.219",
33
+ "@tamagui/helpers": "^1.0.1-beta.219",
34
+ "@tamagui/normalize-css-color-lite": "^1.0.1-beta.219",
35
+ "@tamagui/react-native-use-pressable": "^1.0.1-beta.219",
36
+ "@tamagui/react-native-use-responder-events": "^1.0.1-beta.219",
37
+ "@tamagui/types-react-native": "^1.0.1-beta.219",
38
+ "@tamagui/use-did-finish-ssr": "^1.0.1-beta.219",
39
+ "@tamagui/use-event": "^1.0.1-beta.219",
40
+ "@tamagui/use-force-update": "^1.0.1-beta.219"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": ">=18",
44
44
  "react-dom": ">=18"
45
45
  },
46
46
  "devDependencies": {
47
- "@tamagui/build": "^1.0.1-beta.218",
47
+ "@tamagui/build": "^1.0.1-beta.219",
48
48
  "@types/node": "^16.11.9",
49
49
  "@types/react": "^18.0.15",
50
50
  "@types/react-native": "^0.69.2",
@@ -16,17 +16,13 @@ export function themeable<Component extends (props: any) => any>(
16
16
  const withThemeComponent = forwardRef(function WithTheme(props: any, ref) {
17
17
  const { themeInverse, theme, ...rest } = props
18
18
  const element = React.createElement(component, { ...rest, ref } as any)
19
- if (themeInverse) {
20
- return <ThemeInverse>{element}</ThemeInverse>
21
- }
22
- if (theme || opts) {
23
- return (
19
+ return (
20
+ <ThemeInverse disable={!themeInverse}>
24
21
  <Theme componentName={opts?.componentName} name={(theme as any) || null}>
25
22
  {element}
26
23
  </Theme>
27
- )
28
- }
29
- return element
24
+ </ThemeInverse>
25
+ )
30
26
  })
31
27
 
32
28
  const withTheme: any = withThemeComponent
@@ -1,32 +1,40 @@
1
- import { useIsomorphicLayoutEffect } from '@tamagui/constants'
1
+ import { isWeb, useIsomorphicLayoutEffect } from '@tamagui/constants'
2
2
  import React, { useState } from 'react'
3
3
 
4
4
  import { useDefaultThemeName, useThemeName } from '../hooks/useTheme'
5
5
  import { Theme } from './Theme'
6
6
 
7
- export const ThemeInverse = ({
8
- children,
9
- disable,
10
- }: {
11
- children: React.ReactNode
7
+ export type ThemeInverseProps = {
12
8
  disable?: boolean
13
- }) => {
9
+ }
10
+
11
+ const toggleTheme = (themeName: string) => {
12
+ return themeName.startsWith('light') ? 'dark' : 'light'
13
+ }
14
+
15
+ export const useThemeInverse = (props: ThemeInverseProps = {}) => {
14
16
  const themeName = useThemeName()
15
17
  const defaultTheme = useDefaultThemeName()
16
18
  const [name, setName] = useState<null | string>(null)
17
19
 
18
- // ssr
19
- useIsomorphicLayoutEffect(() => {
20
- if (themeName.startsWith('dark')) {
21
- setName('light')
22
- } else if (themeName.startsWith('light')) {
23
- setName('dark')
24
- }
25
- }, [defaultTheme, themeName])
26
-
27
- if (disable) {
28
- return children as JSX.Element
20
+ if (isWeb) {
21
+ // for SSR must be in effect
22
+ useIsomorphicLayoutEffect(() => {
23
+ setName(toggleTheme(themeName || defaultTheme || ''))
24
+ }, [defaultTheme, themeName])
29
25
  }
30
26
 
31
- return <Theme name={name}>{children}</Theme>
27
+ return props.disable ? null : name
28
+ }
29
+
30
+ export const ThemeInverse = ({
31
+ children,
32
+ disable,
33
+ }: ThemeInverseProps & {
34
+ children: React.ReactNode
35
+ }) => {
36
+ const inverseTheme = useThemeInverse({
37
+ disable,
38
+ })
39
+ return <Theme name={inverseTheme}>{children}</Theme>
32
40
  }
@@ -1,6 +1,9 @@
1
1
  import React from 'react';
2
- export declare const ThemeInverse: ({ children, disable, }: {
2
+ export declare type ThemeInverseProps = {
3
+ disable?: boolean;
4
+ };
5
+ export declare const useThemeInverse: (props?: ThemeInverseProps) => string | null;
6
+ export declare const ThemeInverse: ({ children, disable, }: ThemeInverseProps & {
3
7
  children: React.ReactNode;
4
- disable?: boolean | undefined;
5
8
  }) => JSX.Element;
6
9
  //# sourceMappingURL=ThemeInverse.d.ts.map