@tamagui/theme 1.15.25 → 1.15.27
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/_mutateTheme.js +90 -0
- package/dist/cjs/_mutateTheme.js.map +6 -0
- package/dist/cjs/addTheme.js +2 -46
- package/dist/cjs/addTheme.js.map +2 -2
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/replaceTheme.js +47 -0
- package/dist/cjs/replaceTheme.js.map +6 -0
- package/dist/cjs/updateTheme.js +3 -3
- package/dist/cjs/updateTheme.js.map +1 -1
- package/dist/esm/_mutateTheme.js +72 -0
- package/dist/esm/_mutateTheme.js.map +6 -0
- package/dist/esm/_mutateTheme.mjs +72 -0
- package/dist/esm/_mutateTheme.mjs.map +6 -0
- package/dist/esm/addTheme.js +2 -52
- package/dist/esm/addTheme.js.map +2 -2
- package/dist/esm/addTheme.mjs +2 -52
- package/dist/esm/addTheme.mjs.map +2 -2
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/replaceTheme.js +23 -0
- package/dist/esm/replaceTheme.js.map +6 -0
- package/dist/esm/replaceTheme.mjs +23 -0
- package/dist/esm/replaceTheme.mjs.map +6 -0
- package/dist/esm/updateTheme.js +3 -3
- package/dist/esm/updateTheme.js.map +1 -1
- package/dist/esm/updateTheme.mjs +3 -3
- package/dist/esm/updateTheme.mjs.map +1 -1
- package/dist/jsx/_mutateTheme.js +71 -0
- package/dist/jsx/_mutateTheme.js.map +6 -0
- package/dist/jsx/_mutateTheme.mjs +71 -0
- package/dist/jsx/_mutateTheme.mjs.map +6 -0
- package/dist/jsx/addTheme.js +2 -51
- package/dist/jsx/addTheme.js.map +2 -2
- package/dist/jsx/addTheme.mjs +2 -51
- package/dist/jsx/addTheme.mjs.map +2 -2
- package/dist/jsx/index.js +1 -0
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -0
- package/dist/jsx/index.mjs.map +1 -1
- package/dist/jsx/replaceTheme.js +23 -0
- package/dist/jsx/replaceTheme.js.map +6 -0
- package/dist/jsx/replaceTheme.mjs +23 -0
- package/dist/jsx/replaceTheme.mjs.map +6 -0
- package/dist/jsx/updateTheme.js +3 -3
- package/dist/jsx/updateTheme.js.map +1 -1
- package/dist/jsx/updateTheme.mjs +3 -3
- package/dist/jsx/updateTheme.mjs.map +1 -1
- package/package.json +4 -4
- package/src/_mutateTheme.ts +84 -0
- package/src/addTheme.ts +3 -60
- package/src/index.ts +1 -0
- package/src/replaceTheme.ts +27 -0
- package/src/updateTheme.ts +3 -3
- package/types/_mutateTheme.d.ts +32 -0
- package/types/_mutateTheme.d.ts.map +1 -0
- package/types/addTheme.d.ts +1 -2
- package/types/addTheme.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/replaceTheme.d.ts +30 -0
- package/types/replaceTheme.d.ts.map +1 -0
- package/types/updateTheme.d.ts +1 -1
- package/types/updateTheme.d.ts.map +1 -1
package/src/addTheme.ts
CHANGED
|
@@ -1,68 +1,11 @@
|
|
|
1
|
-
import { isWeb } from '@tamagui/constants'
|
|
2
|
-
import {
|
|
3
|
-
ensureThemeVariable,
|
|
4
|
-
getConfig,
|
|
5
|
-
getThemeCSSRules,
|
|
6
|
-
proxyThemeToParents,
|
|
7
|
-
updateConfig,
|
|
8
|
-
} from '@tamagui/web'
|
|
9
1
|
import type { ThemeDefinition, ThemeParsed } from '@tamagui/web'
|
|
10
2
|
|
|
3
|
+
import { _mutateTheme } from './_mutateTheme'
|
|
4
|
+
|
|
11
5
|
export function addTheme(props: {
|
|
12
6
|
name: string
|
|
13
7
|
theme: Partial<Record<keyof ThemeDefinition, any>>
|
|
14
8
|
insertCSS?: boolean
|
|
15
|
-
update?: boolean
|
|
16
9
|
}) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (process.env.NODE_ENV === 'development') {
|
|
20
|
-
if (!config) {
|
|
21
|
-
throw new Error('No config')
|
|
22
|
-
}
|
|
23
|
-
const theme = config.themes[props.name]
|
|
24
|
-
if (!props.update && theme) {
|
|
25
|
-
return { theme }
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const { name: themeName, theme: themeIn, insertCSS } = props
|
|
30
|
-
const theme = { ...themeIn } as ThemeParsed
|
|
31
|
-
for (const key in theme) {
|
|
32
|
-
ensureThemeVariable(theme, key)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const themeProxied = proxyThemeToParents(themeName, theme, config.themes)
|
|
36
|
-
config.themes[themeName] = themeProxied
|
|
37
|
-
|
|
38
|
-
let cssRules: string[] = []
|
|
39
|
-
|
|
40
|
-
if (isWeb) {
|
|
41
|
-
if (insertCSS) {
|
|
42
|
-
cssRules = getThemeCSSRules({
|
|
43
|
-
// @ts-ignore this works but should be fixed types
|
|
44
|
-
config,
|
|
45
|
-
themeName,
|
|
46
|
-
names: [themeName],
|
|
47
|
-
theme,
|
|
48
|
-
})
|
|
49
|
-
const id = `t_theme_style_${themeName}`
|
|
50
|
-
const existing = document.querySelector(`#${id}`)
|
|
51
|
-
const style = document.createElement('style')
|
|
52
|
-
style.id = id
|
|
53
|
-
style.appendChild(document.createTextNode(cssRules.join('\n')))
|
|
54
|
-
document.head.appendChild(style)
|
|
55
|
-
if (existing) {
|
|
56
|
-
existing.parentElement?.removeChild(existing)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
updateConfig('themes', { ...config.themes, [themeName]: themeProxied })
|
|
62
|
-
|
|
63
|
-
// trigger updates in components
|
|
64
|
-
return {
|
|
65
|
-
theme: themeProxied,
|
|
66
|
-
cssRules,
|
|
67
|
-
}
|
|
10
|
+
return _mutateTheme({ ...props })
|
|
68
11
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { activeThemeManagers } from '@tamagui/web'
|
|
2
|
+
import type { ThemeDefinition } from '@tamagui/web'
|
|
3
|
+
|
|
4
|
+
import { _mutateTheme } from './_mutateTheme.js'
|
|
5
|
+
|
|
6
|
+
export function replaceTheme({
|
|
7
|
+
name,
|
|
8
|
+
theme,
|
|
9
|
+
}: {
|
|
10
|
+
name: string
|
|
11
|
+
theme: Partial<Record<keyof ThemeDefinition, any>>
|
|
12
|
+
}) {
|
|
13
|
+
const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: 'replace' })
|
|
14
|
+
|
|
15
|
+
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
16
|
+
activeThemeManagers.forEach((manager) => {
|
|
17
|
+
if (manager.state.name === name) {
|
|
18
|
+
manager.updateState({
|
|
19
|
+
name,
|
|
20
|
+
forceTheme: next?.theme,
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return next
|
|
27
|
+
}
|
package/src/updateTheme.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { activeThemeManagers } from '@tamagui/web'
|
|
2
2
|
import type { ThemeDefinition } from '@tamagui/web'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { _mutateTheme } from './_mutateTheme.js'
|
|
5
5
|
|
|
6
6
|
export function updateTheme({
|
|
7
7
|
name,
|
|
@@ -10,14 +10,14 @@ export function updateTheme({
|
|
|
10
10
|
name: string
|
|
11
11
|
theme: Partial<Record<keyof ThemeDefinition, any>>
|
|
12
12
|
}) {
|
|
13
|
-
const next =
|
|
13
|
+
const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: 'update' })
|
|
14
14
|
|
|
15
15
|
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
16
16
|
activeThemeManagers.forEach((manager) => {
|
|
17
17
|
if (manager.state.name === name) {
|
|
18
18
|
manager.updateState({
|
|
19
19
|
name,
|
|
20
|
-
forceTheme: next
|
|
20
|
+
forceTheme: next?.theme,
|
|
21
21
|
})
|
|
22
22
|
}
|
|
23
23
|
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ThemeDefinition } from '@tamagui/web';
|
|
2
|
+
export declare function _mutateTheme(props: {
|
|
3
|
+
name: string;
|
|
4
|
+
theme: Partial<Record<keyof ThemeDefinition, any>>;
|
|
5
|
+
insertCSS?: boolean;
|
|
6
|
+
mutationType?: 'replace' | 'update';
|
|
7
|
+
}): {
|
|
8
|
+
theme: {
|
|
9
|
+
[x: string]: import("@tamagui/web").Variable<any>;
|
|
10
|
+
background?: import("@tamagui/web").Variable<any> | undefined;
|
|
11
|
+
backgroundHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
12
|
+
backgroundPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
13
|
+
backgroundFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
14
|
+
color?: import("@tamagui/web").Variable<any> | undefined;
|
|
15
|
+
colorHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
16
|
+
colorPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
17
|
+
colorFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
18
|
+
borderColor?: import("@tamagui/web").Variable<any> | undefined;
|
|
19
|
+
borderColorHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
20
|
+
borderColorPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
21
|
+
borderColorFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
22
|
+
shadowColor?: import("@tamagui/web").Variable<any> | undefined;
|
|
23
|
+
shadowColorHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
24
|
+
shadowColorPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
25
|
+
shadowColorFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
26
|
+
};
|
|
27
|
+
cssRules?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
theme: any;
|
|
30
|
+
cssRules: string[];
|
|
31
|
+
} | undefined;
|
|
32
|
+
//# sourceMappingURL=_mutateTheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_mutateTheme.d.ts","sourceRoot":"","sources":["../src/_mutateTheme.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,cAAc,CAAA;AAEhE,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;IAClD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;CACpC;;;;;;;;;;;;;;;;;;;;;;;;cAoEA"}
|
package/types/addTheme.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export declare function addTheme(props: {
|
|
|
3
3
|
name: string;
|
|
4
4
|
theme: Partial<Record<keyof ThemeDefinition, any>>;
|
|
5
5
|
insertCSS?: boolean;
|
|
6
|
-
update?: boolean;
|
|
7
6
|
}): {
|
|
8
7
|
theme: {
|
|
9
8
|
[x: string]: import("@tamagui/web").Variable<any>;
|
|
@@ -28,5 +27,5 @@ export declare function addTheme(props: {
|
|
|
28
27
|
} | {
|
|
29
28
|
theme: any;
|
|
30
29
|
cssRules: string[];
|
|
31
|
-
};
|
|
30
|
+
} | undefined;
|
|
32
31
|
//# sourceMappingURL=addTheme.d.ts.map
|
package/types/addTheme.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addTheme.d.ts","sourceRoot":"","sources":["../src/addTheme.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"addTheme.d.ts","sourceRoot":"","sources":["../src/addTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,cAAc,CAAA;AAIhE,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;IAClD,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;;;;;;;;;;;;;;;;;;;;;;;;cAEA"}
|
package/types/index.d.ts
CHANGED
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ThemeDefinition } from '@tamagui/web';
|
|
2
|
+
export declare function replaceTheme({ name, theme, }: {
|
|
3
|
+
name: string;
|
|
4
|
+
theme: Partial<Record<keyof ThemeDefinition, any>>;
|
|
5
|
+
}): {
|
|
6
|
+
theme: {
|
|
7
|
+
[x: string]: import("@tamagui/web").Variable<any>;
|
|
8
|
+
background?: import("@tamagui/web").Variable<any> | undefined;
|
|
9
|
+
backgroundHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
10
|
+
backgroundPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
11
|
+
backgroundFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
12
|
+
color?: import("@tamagui/web").Variable<any> | undefined;
|
|
13
|
+
colorHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
14
|
+
colorPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
15
|
+
colorFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
16
|
+
borderColor?: import("@tamagui/web").Variable<any> | undefined;
|
|
17
|
+
borderColorHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
18
|
+
borderColorPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
19
|
+
borderColorFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
20
|
+
shadowColor?: import("@tamagui/web").Variable<any> | undefined;
|
|
21
|
+
shadowColorHover?: import("@tamagui/web").Variable<any> | undefined;
|
|
22
|
+
shadowColorPress?: import("@tamagui/web").Variable<any> | undefined;
|
|
23
|
+
shadowColorFocus?: import("@tamagui/web").Variable<any> | undefined;
|
|
24
|
+
};
|
|
25
|
+
cssRules?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
theme: any;
|
|
28
|
+
cssRules: string[];
|
|
29
|
+
} | undefined;
|
|
30
|
+
//# sourceMappingURL=replaceTheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replaceTheme.d.ts","sourceRoot":"","sources":["../src/replaceTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAInD,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;CACnD;;;;;;;;;;;;;;;;;;;;;;;;cAeA"}
|
package/types/updateTheme.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateTheme.d.ts","sourceRoot":"","sources":["../src/updateTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAInD,wBAAgB,WAAW,CAAC,EAC1B,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;CACnD;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"updateTheme.d.ts","sourceRoot":"","sources":["../src/updateTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAInD,wBAAgB,WAAW,CAAC,EAC1B,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;CACnD;;;;;;;;;;;;;;;;;;;;;;;;cAeA"}
|