@multiplatform.one/theme 7.16.0 → 7.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/theme",
3
- "version": "7.16.0",
3
+ "version": "7.18.0",
4
4
  "description": "Tamagui theme system for multiplatform.one",
5
5
  "keywords": [
6
6
  "multiplatform",
@@ -44,8 +44,8 @@
44
44
  "access": "public"
45
45
  },
46
46
  "dependencies": {
47
- "@multiplatform.one/platform": "7.16.0",
48
- "@multiplatform.one/store": "7.16.0",
47
+ "@multiplatform.one/platform": "7.18.0",
48
+ "@multiplatform.one/store": "7.18.0",
49
49
  "@tamagui/colors": "2.7.6",
50
50
  "@tamagui/config": "2.7.6",
51
51
  "@tamagui/get-token": "2.7.6",
@@ -57,8 +57,8 @@
57
57
  "react-cookie": "^8.1.2"
58
58
  },
59
59
  "devDependencies": {
60
- "@multiplatform.one/config": "7.16.0",
61
- "@multiplatform.one/test-utils": "7.16.0",
60
+ "@multiplatform.one/config": "7.18.0",
61
+ "@multiplatform.one/test-utils": "7.18.0",
62
62
  "@tamagui/animations-css": "2.7.6",
63
63
  "@tamagui/animations-reanimated": "2.7.6",
64
64
  "@tamagui/font-inter": "2.7.6",
@@ -0,0 +1,53 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { getConfig } from "@tamagui/web";
3
+ import { TamaguiProvider, Theme, useThemeName } from "tamagui";
4
+ import { afterEach, describe, expect, it } from "vitest";
5
+ import { activateThemeConfig } from "./activateThemeConfig";
6
+ import { createDefaultThemeConfig } from "./createDefaultThemeConfig";
7
+ import type { ThemeConfig } from "./shared";
8
+
9
+ const full = createDefaultThemeConfig({});
10
+ const subset = createDefaultThemeConfig({
11
+ subset: { components: ["Button"], tints: ["accent", "error", "success", "warning"] },
12
+ });
13
+
14
+ function Name() {
15
+ return <span data-testid="red">{useThemeName()}</span>;
16
+ }
17
+
18
+ function ResolvedRed({ themeConfig }: { themeConfig: ThemeConfig }) {
19
+ return (
20
+ <TamaguiProvider config={themeConfig.tamagui} defaultTheme="light" disableInjectCSS>
21
+ <Theme name="red">
22
+ <Name />
23
+ </Theme>
24
+ </TamaguiProvider>
25
+ );
26
+ }
27
+
28
+ afterEach(cleanup);
29
+
30
+ describe("activateThemeConfig", () => {
31
+ it("makes the given config the one Tamagui resolves against, once", () => {
32
+ expect(getConfig()).toBe(subset.tamagui);
33
+ expect(activateThemeConfig(full)).toBe(true);
34
+ expect(getConfig()).toBe(full.tamagui);
35
+ expect(activateThemeConfig(full)).toBe(false);
36
+ });
37
+
38
+ it("drops the resolved-name cache, so a theme the new config lacks stops resolving", () => {
39
+ activateThemeConfig(full);
40
+ const first = render(<ResolvedRed themeConfig={full} />);
41
+ expect(screen.getByTestId("red").textContent).toBe("light_red");
42
+ first.unmount();
43
+
44
+ activateThemeConfig(subset);
45
+ const second = render(<ResolvedRed themeConfig={subset} />);
46
+ expect(screen.getByTestId("red").textContent).toBe("light");
47
+ second.unmount();
48
+
49
+ activateThemeConfig(full);
50
+ render(<ResolvedRed themeConfig={full} />);
51
+ expect(screen.getByTestId("red").textContent).toBe("light_red");
52
+ });
53
+ });
@@ -0,0 +1,20 @@
1
+ import { forceUpdateThemes, getConfig, setConfig } from "@tamagui/web";
2
+ import type { ThemeConfig } from "./shared";
3
+
4
+ /**
5
+ * Make `themeConfig` the config Tamagui resolves theme names against.
6
+ *
7
+ * `createTamagui` installs every config it builds as the global one, and
8
+ * `TamaguiProvider` never replaces it, so once two configs are loaded (the
9
+ * full house config and its subset) the one created last wins whichever
10
+ * config the provider is handed. Tamagui also caches resolved theme names,
11
+ * so the cache is dropped here too: without that a name the new config lacks
12
+ * keeps resolving to the old config's theme. Returns false when `themeConfig`
13
+ * is already the active one.
14
+ */
15
+ export function activateThemeConfig(themeConfig: ThemeConfig): boolean {
16
+ if (getConfig() === themeConfig.tamagui) return false;
17
+ setConfig(themeConfig.tamagui);
18
+ forceUpdateThemes();
19
+ return true;
20
+ }
@@ -1,3 +1,4 @@
1
+ export * from "./activateThemeConfig";
1
2
  export * from "./animations/index";
2
3
  export * from "./chartPalette";
3
4
  export * from "./colorRules";
@@ -0,0 +1,14 @@
1
+ import type { ThemeConfig } from "./shared";
2
+ /**
3
+ * Make `themeConfig` the config Tamagui resolves theme names against.
4
+ *
5
+ * `createTamagui` installs every config it builds as the global one, and
6
+ * `TamaguiProvider` never replaces it, so once two configs are loaded (the
7
+ * full house config and its subset) the one created last wins whichever
8
+ * config the provider is handed. Tamagui also caches resolved theme names,
9
+ * so the cache is dropped here too: without that a name the new config lacks
10
+ * keeps resolving to the old config's theme. Returns false when `themeConfig`
11
+ * is already the active one.
12
+ */
13
+ export declare function activateThemeConfig(themeConfig: ThemeConfig): boolean;
14
+ //# sourceMappingURL=activateThemeConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activateThemeConfig.d.ts","sourceRoot":"","sources":["../../src/theme/activateThemeConfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAKrE"}
@@ -1,3 +1,4 @@
1
+ export * from "./activateThemeConfig";
1
2
  export * from "./animations/index";
2
3
  export * from "./chartPalette";
3
4
  export * from "./colorRules";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cA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