@tamagui/core 1.0.1-beta.141 → 1.0.1-beta.142
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/Tamagui.js +2 -2
- package/dist/cjs/Tamagui.js.map +2 -2
- package/dist/cjs/addTheme.js +28 -22
- package/dist/cjs/addTheme.js.map +2 -2
- package/dist/cjs/config.js +75 -0
- package/dist/cjs/config.js.map +7 -0
- package/dist/cjs/constants/platform.js +7 -1
- package/dist/cjs/constants/platform.js.map +2 -2
- package/dist/cjs/constants/platform.native.js +62 -0
- package/dist/cjs/constants/platform.native.js.map +7 -0
- package/dist/cjs/createComponent.js +71 -58
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createComponent.server.js +431 -0
- package/dist/cjs/createComponent.server.js.map +7 -0
- package/dist/cjs/createTamagui.js +10 -8
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/createVariable.js +6 -12
- package/dist/cjs/createVariable.js.map +2 -2
- package/dist/cjs/createVariables.js +5 -2
- package/dist/cjs/createVariables.js.map +2 -2
- package/dist/cjs/helpers/RNComponents.js +11 -11
- package/dist/cjs/helpers/RNComponents.js.map +2 -2
- package/dist/cjs/helpers/ThemeManager.js +7 -9
- package/dist/cjs/helpers/ThemeManager.js.map +2 -2
- package/dist/cjs/helpers/assignNativePropsToWeb.js +0 -1
- package/dist/cjs/helpers/assignNativePropsToWeb.js.map +2 -2
- package/dist/cjs/helpers/createPropMapper.js +3 -3
- package/dist/cjs/helpers/createPropMapper.js.map +2 -2
- package/dist/cjs/helpers/expandStyles.js +4 -4
- package/dist/cjs/helpers/expandStyles.js.map +2 -2
- package/dist/cjs/helpers/getAnimationDriver.js +32 -0
- package/dist/cjs/helpers/getAnimationDriver.js.map +7 -0
- package/dist/cjs/helpers/getExpandedShorthands.js +3 -3
- package/dist/cjs/helpers/getExpandedShorthands.js.map +2 -2
- package/dist/cjs/helpers/getFont.js +1 -1
- package/dist/cjs/helpers/getFont.js.map +2 -2
- package/dist/cjs/helpers/getSize.js +2 -2
- package/dist/cjs/helpers/getSize.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +12 -13
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.js +6 -4
- package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
- package/dist/cjs/helpers/getVariantExtras.js +2 -2
- package/dist/cjs/helpers/getVariantExtras.js.map +2 -2
- package/dist/cjs/helpers/normalizeColor.js +2 -2
- package/dist/cjs/helpers/normalizeColor.js.map +2 -2
- package/dist/cjs/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/cjs/helpers/useAnimationDriver.js +2 -0
- package/dist/cjs/helpers/useAnimationDriver.js.map +7 -0
- package/dist/cjs/hooks/getThemeUnwrapped.js +2 -0
- package/dist/cjs/hooks/getThemeUnwrapped.js.map +2 -2
- package/dist/cjs/hooks/useAnimationDriver.js +2 -0
- package/dist/cjs/hooks/useAnimationDriver.js.map +7 -0
- package/dist/cjs/hooks/useFeatures.js +2 -2
- package/dist/cjs/hooks/useFeatures.js.map +2 -2
- package/dist/cjs/hooks/useServerContext.js +21 -0
- package/dist/cjs/hooks/useServerContext.js.map +7 -0
- package/dist/cjs/hooks/useServerHooks.js +36 -0
- package/dist/cjs/hooks/useServerHooks.js.map +7 -0
- package/dist/cjs/hooks/useTheme.js +71 -41
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/index.js +7 -6
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/injectStyles.js +40 -0
- package/dist/cjs/injectStyles.js.map +7 -0
- package/dist/cjs/insertFont.js +2 -2
- package/dist/cjs/insertFont.js.map +2 -2
- package/dist/cjs/styled.js +11 -1
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/views/TamaguiProvider.js +6 -1
- package/dist/cjs/views/TamaguiProvider.js.map +2 -2
- package/dist/cjs/views/ThemeProvider.js +9 -5
- package/dist/cjs/views/ThemeProvider.js.map +2 -2
- package/dist/esm/Tamagui.js +1 -1
- package/dist/esm/Tamagui.js.map +1 -1
- package/dist/esm/addTheme.js +27 -21
- package/dist/esm/addTheme.js.map +2 -2
- package/dist/esm/config.js +43 -0
- package/dist/esm/config.js.map +7 -0
- package/dist/esm/constants/platform.js +5 -1
- package/dist/esm/constants/platform.js.map +2 -2
- package/dist/esm/constants/platform.native.js +28 -0
- package/dist/esm/constants/platform.native.js.map +7 -0
- package/dist/esm/createComponent.js +71 -60
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createComponent.server.js +408 -0
- package/dist/esm/createComponent.server.js.map +7 -0
- package/dist/esm/createTamagui.js +7 -5
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/createVariable.js +6 -12
- package/dist/esm/createVariable.js.map +2 -2
- package/dist/esm/createVariables.js +5 -2
- package/dist/esm/createVariables.js.map +2 -2
- package/dist/esm/helpers/RNComponents.js +11 -8
- package/dist/esm/helpers/RNComponents.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.js +6 -8
- package/dist/esm/helpers/ThemeManager.js.map +2 -2
- package/dist/esm/helpers/assignNativePropsToWeb.js +0 -1
- package/dist/esm/helpers/assignNativePropsToWeb.js.map +2 -2
- package/dist/esm/helpers/createPropMapper.js +2 -2
- package/dist/esm/helpers/createPropMapper.js.map +2 -2
- package/dist/esm/helpers/expandStyles.js +3 -3
- package/dist/esm/helpers/expandStyles.js.map +2 -2
- package/dist/esm/helpers/getAnimationDriver.js +8 -0
- package/dist/esm/helpers/getAnimationDriver.js.map +7 -0
- package/dist/esm/helpers/getExpandedShorthands.js +2 -2
- package/dist/esm/helpers/getExpandedShorthands.js.map +2 -2
- package/dist/esm/helpers/getFont.js +1 -1
- package/dist/esm/helpers/getFont.js.map +2 -2
- package/dist/esm/helpers/getSize.js +1 -1
- package/dist/esm/helpers/getSize.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.js +12 -13
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.js +5 -3
- package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
- package/dist/esm/helpers/getVariantExtras.js +1 -1
- package/dist/esm/helpers/getVariantExtras.js.map +1 -1
- package/dist/esm/helpers/normalizeColor.js +1 -1
- package/dist/esm/helpers/normalizeColor.js.map +1 -1
- package/dist/esm/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/esm/helpers/useAnimationDriver.js +1 -0
- package/dist/esm/helpers/useAnimationDriver.js.map +7 -0
- package/dist/esm/hooks/getThemeUnwrapped.js +2 -0
- package/dist/esm/hooks/getThemeUnwrapped.js.map +2 -2
- package/dist/esm/hooks/useAnimationDriver.js +1 -0
- package/dist/esm/hooks/useAnimationDriver.js.map +7 -0
- package/dist/esm/hooks/useFeatures.js +1 -1
- package/dist/esm/hooks/useFeatures.js.map +2 -2
- package/dist/esm/hooks/useServerContext.js +4 -0
- package/dist/esm/hooks/useServerContext.js.map +7 -0
- package/dist/esm/hooks/useServerHooks.js +11 -0
- package/dist/esm/hooks/useServerHooks.js.map +7 -0
- package/dist/esm/hooks/useTheme.js +72 -42
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/injectStyles.js +16 -0
- package/dist/esm/injectStyles.js.map +7 -0
- package/dist/esm/insertFont.js +1 -1
- package/dist/esm/insertFont.js.map +1 -1
- package/dist/esm/styled.js +11 -1
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/views/TamaguiProvider.js +7 -2
- package/dist/esm/views/TamaguiProvider.js.map +2 -2
- package/dist/esm/views/ThemeProvider.js +9 -5
- package/dist/esm/views/ThemeProvider.js.map +2 -2
- package/package.json +35 -14
- package/src/Tamagui.ts +1 -1
- package/src/addTheme.ts +33 -21
- package/src/{conf.ts → config.ts} +4 -0
- package/src/constants/platform.native.ts +14 -0
- package/src/constants/platform.ts +12 -1
- package/src/createComponent.tsx +164 -148
- package/src/createTamagui.ts +11 -5
- package/src/createVariable.ts +8 -25
- package/src/createVariables.ts +5 -2
- package/src/helpers/RNComponents.tsx +13 -13
- package/src/helpers/ThemeManager.tsx +15 -12
- package/src/helpers/assignNativePropsToWeb.tsx +0 -1
- package/src/helpers/createPropMapper.ts +2 -2
- package/src/helpers/expandStyles.ts +4 -3
- package/src/helpers/getAnimationDriver.tsx +5 -0
- package/src/helpers/getExpandedShorthands.ts +2 -2
- package/src/helpers/getFont.tsx +1 -1
- package/src/helpers/getSize.ts +1 -1
- package/src/helpers/getSplitStyles.tsx +12 -13
- package/src/helpers/getStylesAtomic.ts +6 -3
- package/src/helpers/getVariantExtras.tsx +2 -2
- package/src/helpers/normalizeColor.ts +1 -1
- package/src/helpers/normalizeValueWithProperty.ts +2 -0
- package/src/hooks/getThemeUnwrapped.tsx +1 -0
- package/src/hooks/useFeatures.tsx +2 -1
- package/src/hooks/useServerHooks.tsx +13 -0
- package/src/hooks/useTheme.tsx +94 -48
- package/src/index.ts +2 -1
- package/src/injectStyles.ts +20 -0
- package/src/insertFont.ts +1 -1
- package/src/styled.tsx +15 -1
- package/src/types.tsx +33 -0
- package/src/views/TamaguiProvider.tsx +11 -4
- package/src/views/ThemeProvider.tsx +9 -6
- package/types/config.d.ts +27 -0
- package/types/constants/platform.d.ts +1 -0
- package/types/constants/platform.native.d.ts +13 -0
- package/types/createComponent.server.d.ts +36 -0
- package/types/createVariable.d.ts +1 -2
- package/types/helpers/RNComponents.d.ts +1 -1
- package/types/helpers/ThemeManager.d.ts +2 -8
- package/types/helpers/getAnimationDriver.d.ts +6 -0
- package/types/helpers/useAnimationDriver.d.ts +1 -0
- package/types/hooks/useAnimationDriver.d.ts +1 -0
- package/types/hooks/useServerContext.d.ts +2 -0
- package/types/hooks/useServerHooks.d.ts +4 -0
- package/types/hooks/useTheme.d.ts +5 -21
- package/types/index.d.ts +2 -1
- package/types/injectStyles.d.ts +7 -0
- package/types/types.d.ts +23 -0
- package/types/views/TamaguiProvider.d.ts +1 -1
- package/types/views/ThemeProvider.d.ts +0 -1
package/src/createVariable.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { isValidCSSCharCode, simpleHash } from '@tamagui/helpers'
|
|
2
|
+
|
|
1
3
|
import { isWeb } from './constants/platform'
|
|
2
|
-
import { VariableColorVal } from './types'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Should rename this to Token
|
|
@@ -35,10 +36,12 @@ export const createVariable = <A extends string | number = any>(props: VariableI
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// on the client maybe we can change the prototype of variable object toString to keep backwards compat
|
|
38
|
-
export function variableToString(vrble?:
|
|
39
|
+
export function variableToString(vrble?: any) {
|
|
39
40
|
if (!vrble) return ''
|
|
40
|
-
if (
|
|
41
|
-
|
|
41
|
+
if (isVariable(vrble)) {
|
|
42
|
+
return `${isWeb ? vrble.variable : vrble.val}`
|
|
43
|
+
}
|
|
44
|
+
return `${vrble}`
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
export function isVariable(v: Variable | any): v is Variable {
|
|
@@ -69,26 +72,6 @@ export const createCSSVariable = (nameProp: string, includeVar = true) => {
|
|
|
69
72
|
return ``
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
|
-
|
|
73
|
-
for (let i = 0; i < nameProp.length; i++) {
|
|
74
|
-
const code = nameProp.charCodeAt(i)
|
|
75
|
-
if (
|
|
76
|
-
// A-Z
|
|
77
|
-
(code >= 65 && code <= 90) ||
|
|
78
|
-
// a-z
|
|
79
|
-
(code >= 97 && code <= 122) ||
|
|
80
|
-
// _
|
|
81
|
-
code == 95 ||
|
|
82
|
-
// -
|
|
83
|
-
code === 45 ||
|
|
84
|
-
// 0-9
|
|
85
|
-
(code >= 48 && code <= 57)
|
|
86
|
-
) {
|
|
87
|
-
name += nameProp[i]
|
|
88
|
-
} else {
|
|
89
|
-
// allow any name but turn it into a stringified num
|
|
90
|
-
name += `-c${code}-`
|
|
91
|
-
}
|
|
92
|
-
}
|
|
75
|
+
const name = simpleHash(nameProp, 60)
|
|
93
76
|
return includeVar ? `var(--${name})` : name
|
|
94
77
|
}
|
package/src/createVariables.ts
CHANGED
|
@@ -18,19 +18,22 @@ export const createVariables = <A extends DeepTokenObject>(
|
|
|
18
18
|
isFont = false
|
|
19
19
|
): DeepVariableObject<A> => {
|
|
20
20
|
const res: any = {}
|
|
21
|
+
let i = 0
|
|
21
22
|
for (const key in tokens) {
|
|
23
|
+
i++
|
|
24
|
+
const variableName = isFont ? key.slice(0, 2) : i
|
|
22
25
|
const val = tokens[key]
|
|
23
26
|
if (isVariable(val)) {
|
|
24
27
|
res[key] = val
|
|
25
28
|
continue
|
|
26
29
|
}
|
|
27
|
-
let name = parentPath ? `${parentPath}-${
|
|
30
|
+
let name = parentPath ? `${parentPath}-${variableName}` : key
|
|
28
31
|
if (isFont && name.includes('_')) {
|
|
29
32
|
name = name.replace(/_[a-z0-9]+/i, '')
|
|
30
33
|
}
|
|
31
34
|
if (val && typeof val === 'object') {
|
|
32
35
|
// recurse
|
|
33
|
-
res[key] = createVariables(tokens[key] as any,
|
|
36
|
+
res[key] = createVariables(tokens[key] as any, `${name}`)
|
|
34
37
|
continue
|
|
35
38
|
}
|
|
36
39
|
res[key] = isVariable(val) ? val : createVariable({ val, name, key })
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Image, Text, TextInput, View } from 'react-native'
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
// limited support
|
|
4
|
+
export const RNComponents = new Set<any>([
|
|
5
|
+
Image,
|
|
6
|
+
TextInput,
|
|
7
|
+
Text,
|
|
8
|
+
View,
|
|
9
|
+
// see fake-react-native + styled() check
|
|
10
|
+
'Image',
|
|
11
|
+
'TextInput',
|
|
12
|
+
'Text',
|
|
13
|
+
'View',
|
|
14
|
+
])
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext } from 'react'
|
|
2
2
|
|
|
3
|
-
import { getThemes } from '../
|
|
3
|
+
import { getThemes } from '../config'
|
|
4
4
|
import { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from '../constants/constants'
|
|
5
5
|
import { getThemeUnwrapped } from '../hooks/getThemeUnwrapped'
|
|
6
6
|
import { ThemeObject, Themes } from '../types'
|
|
@@ -100,7 +100,14 @@ export class ThemeManager {
|
|
|
100
100
|
return true
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
getNextTheme(
|
|
103
|
+
getNextTheme(
|
|
104
|
+
props: GetNextThemeProps = {},
|
|
105
|
+
debug?: any
|
|
106
|
+
): {
|
|
107
|
+
name: string
|
|
108
|
+
theme: ThemeObject | null
|
|
109
|
+
className: string | undefined
|
|
110
|
+
} {
|
|
104
111
|
const { themes = getThemes(), name, componentName } = props
|
|
105
112
|
|
|
106
113
|
if (props.reset && name) {
|
|
@@ -130,6 +137,7 @@ export class ThemeManager {
|
|
|
130
137
|
return {
|
|
131
138
|
name: this.name,
|
|
132
139
|
theme: this.theme,
|
|
140
|
+
className: undefined,
|
|
133
141
|
}
|
|
134
142
|
}
|
|
135
143
|
|
|
@@ -137,17 +145,11 @@ export class ThemeManager {
|
|
|
137
145
|
let parentName = parentIsReset ? this.parentName || this.fullName : this.fullName
|
|
138
146
|
|
|
139
147
|
while (true) {
|
|
140
|
-
if (nextName in themes)
|
|
141
|
-
break
|
|
142
|
-
}
|
|
148
|
+
if (nextName in themes) break
|
|
143
149
|
nextName = `${parentName}_${name}`
|
|
144
|
-
if (nextName in themes)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (!parentName.includes(THEME_NAME_SEPARATOR)) {
|
|
148
|
-
// this is fine - some themes can not have parents
|
|
149
|
-
break
|
|
150
|
-
}
|
|
150
|
+
if (nextName in themes) break
|
|
151
|
+
// this is fine - some themes can not have parents
|
|
152
|
+
if (!parentName.includes(THEME_NAME_SEPARATOR)) break
|
|
151
153
|
// go up one
|
|
152
154
|
parentName = parentName.slice(0, parentName.lastIndexOf(THEME_NAME_SEPARATOR))
|
|
153
155
|
}
|
|
@@ -172,6 +174,7 @@ export class ThemeManager {
|
|
|
172
174
|
|
|
173
175
|
if (process.env.NODE_ENV === 'development') {
|
|
174
176
|
if (debug) {
|
|
177
|
+
// eslint-disable-next-line no-console
|
|
175
178
|
console.log('getNextTheme', this.getClassName(nextName), { props, nextName, parentName })
|
|
176
179
|
}
|
|
177
180
|
}
|
|
@@ -39,7 +39,6 @@ export function assignNativePropsToWeb(elementType: string, viewProps: any, nati
|
|
|
39
39
|
viewProps['aria-colspan'] = nativeProps.accessibilityColumnSpan
|
|
40
40
|
}
|
|
41
41
|
if (nativeProps.accessibilityControls != null) {
|
|
42
|
-
console.log('wtf', nativeProps.accessibilityControls)
|
|
43
42
|
viewProps['aria-controls'] = processIDRefList(nativeProps.accessibilityControls)
|
|
44
43
|
}
|
|
45
44
|
if (nativeProps.accessibilityCurrent != null) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getConfig } from '../
|
|
1
|
+
import { getConfig } from '../config'
|
|
2
2
|
import { isWeb } from '../constants/platform'
|
|
3
3
|
import { Variable, isVariable } from '../createVariable'
|
|
4
4
|
import {
|
|
@@ -31,7 +31,7 @@ export const createPropMapper = (staticConfig: StaticConfigParsed) => {
|
|
|
31
31
|
const variants = staticConfig.variants || {}
|
|
32
32
|
|
|
33
33
|
// temp remove classnames
|
|
34
|
-
const defaultProps = mergeProps(staticConfig.defaultProps || {}, {},
|
|
34
|
+
const defaultProps = mergeProps(staticConfig.defaultProps || {}, {}, false)[0]
|
|
35
35
|
|
|
36
36
|
const mapper: PropMapper = (
|
|
37
37
|
key,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { getConfig } from '../
|
|
1
|
+
import { getConfig } from '../config'
|
|
2
2
|
import { isWeb } from '../constants/platform'
|
|
3
3
|
import { expandStyle } from './expandStyle'
|
|
4
4
|
import { colorToRGBA, normalizeColor } from './normalizeColor'
|
|
5
|
-
import { normalizeValueWithProperty } from './normalizeValueWithProperty'
|
|
5
|
+
import { normalizeValueWithProperty } from './normalizeValueWithProperty.js'
|
|
6
6
|
import { pseudoDescriptors } from './pseudoDescriptors'
|
|
7
7
|
|
|
8
8
|
let shorthands: Record<string, string> | null = null
|
|
@@ -81,12 +81,13 @@ function normalizeShadow({
|
|
|
81
81
|
...(isWeb && {
|
|
82
82
|
shadowColor: normalizeColor(colorStr, shadowOpacity),
|
|
83
83
|
}),
|
|
84
|
-
...(
|
|
84
|
+
...(process.env.TAMAGUI_TARGET === 'native' &&
|
|
85
85
|
(() => {
|
|
86
86
|
// on native fix bug - shadows behave better if turned into non-alpha rgb() + shadowOpacity
|
|
87
87
|
const rgba = colorToRGBA(colorStr)
|
|
88
88
|
if (!rgba) {
|
|
89
89
|
if (process.env.NODE_ENV === 'development') {
|
|
90
|
+
// eslint-disable-next-line no-console
|
|
90
91
|
console.warn('No rgba form', colorStr)
|
|
91
92
|
}
|
|
92
93
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getConfig } from '../
|
|
1
|
+
import { getConfig } from '../config'
|
|
2
2
|
import { Shorthands } from '../types'
|
|
3
3
|
|
|
4
4
|
export function getExpandedShorthands<A extends Object>(props: A): Omit<A, keyof Shorthands> {
|
|
@@ -6,7 +6,7 @@ export function getExpandedShorthands<A extends Object>(props: A): Omit<A, keyof
|
|
|
6
6
|
if (!shorthands) {
|
|
7
7
|
return props
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
const res: A = {} as any
|
|
10
10
|
for (const key in props) {
|
|
11
11
|
// @ts-ignore
|
|
12
12
|
res[shorthands[key] || key] = props[key]
|
package/src/helpers/getFont.tsx
CHANGED
|
@@ -31,7 +31,7 @@ export const getFont: VariantSpreadFunction<TextProps, FontSizeTokens> = (
|
|
|
31
31
|
}
|
|
32
32
|
if (process.env.NODE_ENV === 'development') {
|
|
33
33
|
if (props['debug']) {
|
|
34
|
-
console.groupCollapsed(' 🔹 getFont', val)
|
|
34
|
+
console.groupCollapsed(' 🔹 getFont', val, props['fontWeight'], props['fow'])
|
|
35
35
|
console.log({ style, props, font })
|
|
36
36
|
console.groupEnd()
|
|
37
37
|
}
|
package/src/helpers/getSize.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { stylePropsText, stylePropsTransform, validPseudoKeys, validStyles } fro
|
|
|
2
2
|
import { useInsertionEffect } from 'react'
|
|
3
3
|
import { ViewStyle } from 'react-native'
|
|
4
4
|
|
|
5
|
-
import { getConfig } from '../
|
|
6
|
-
import { isClient, isWeb, useIsomorphicLayoutEffect } from '../constants/platform'
|
|
5
|
+
import { getConfig } from '../config'
|
|
6
|
+
import { isClient, isRSC, isWeb, useIsomorphicLayoutEffect } from '../constants/platform'
|
|
7
7
|
import { mediaQueryConfig, mediaState } from '../hooks/useMedia'
|
|
8
8
|
import type {
|
|
9
9
|
DebugProp,
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
updateRules,
|
|
31
31
|
} from './insertStyleRule'
|
|
32
32
|
import { mergeTransform } from './mergeTransform'
|
|
33
|
-
import { normalizeValueWithProperty } from './normalizeValueWithProperty'
|
|
33
|
+
import { normalizeValueWithProperty } from './normalizeValueWithProperty.js'
|
|
34
34
|
import { pseudoDescriptors } from './pseudoDescriptors'
|
|
35
35
|
|
|
36
36
|
export type SplitStyles = ReturnType<typeof getSplitStyles>
|
|
@@ -588,7 +588,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
588
588
|
* and to avoid re-creating it over and over, use a WeakMap
|
|
589
589
|
*/
|
|
590
590
|
const propProxies = new WeakMap()
|
|
591
|
-
function getSubStyleProxiedProps(baseProps: Object, specificProps: Object) {
|
|
591
|
+
function getSubStyleProxiedProps(defaultProps: Object, baseProps: Object, specificProps: Object) {
|
|
592
592
|
if (!specificProps) {
|
|
593
593
|
// functional variants may want to eventually do something like:
|
|
594
594
|
// have a hooks-like rule (no conditionals)
|
|
@@ -603,14 +603,11 @@ function getSubStyleProxiedProps(baseProps: Object, specificProps: Object) {
|
|
|
603
603
|
return propProxies.get(specificProps)
|
|
604
604
|
}
|
|
605
605
|
const next = new Proxy(specificProps, {
|
|
606
|
-
ownKeys() {
|
|
607
|
-
return [...new Set([...Object.keys(baseProps), ...Object.keys(specificProps)])]
|
|
608
|
-
},
|
|
609
606
|
has(_, key) {
|
|
610
|
-
return key in specificProps || key in baseProps
|
|
607
|
+
return key in defaultProps || key in specificProps || key in baseProps
|
|
611
608
|
},
|
|
612
609
|
get(_, key) {
|
|
613
|
-
return specificProps[key] ?? baseProps[key]
|
|
610
|
+
return defaultProps[key] ?? specificProps[key] ?? baseProps[key]
|
|
614
611
|
},
|
|
615
612
|
})
|
|
616
613
|
propProxies.set(specificProps, next)
|
|
@@ -636,7 +633,7 @@ export const getSubStyle = (
|
|
|
636
633
|
key,
|
|
637
634
|
val,
|
|
638
635
|
theme,
|
|
639
|
-
getSubStyleProxiedProps(props, props[subKey]),
|
|
636
|
+
getSubStyleProxiedProps(staticConfig.defaultProps, props, props[subKey]),
|
|
640
637
|
state,
|
|
641
638
|
languageContext,
|
|
642
639
|
avoidDefaultProps
|
|
@@ -668,9 +665,11 @@ const useInsertEffectCompat = isWeb ? useInsertionEffect || useIsomorphicLayoutE
|
|
|
668
665
|
export const useSplitStyles: StyleSplitter = (...args) => {
|
|
669
666
|
const res = getSplitStyles(...args)
|
|
670
667
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
668
|
+
if (!isRSC) {
|
|
669
|
+
useInsertEffectCompat(() => {
|
|
670
|
+
insertStyleRules(res.rulesToInsert)
|
|
671
|
+
}, [res.rulesToInsert])
|
|
672
|
+
}
|
|
674
673
|
|
|
675
674
|
return res
|
|
676
675
|
}
|
|
@@ -7,10 +7,10 @@ import { StyleObject, simpleHash } from '@tamagui/helpers'
|
|
|
7
7
|
import hyphenateStyleName from 'hyphenate-style-name'
|
|
8
8
|
import { TextStyle, ViewStyle } from 'react-native'
|
|
9
9
|
|
|
10
|
-
import { getConfig } from '../
|
|
10
|
+
import { getConfig } from '../config'
|
|
11
11
|
import { TamaguiInternalConfig } from '../types'
|
|
12
12
|
import { defaultOffset } from './expandStyles'
|
|
13
|
-
import { normalizeValueWithProperty } from './normalizeValueWithProperty'
|
|
13
|
+
import { normalizeValueWithProperty } from './normalizeValueWithProperty.js'
|
|
14
14
|
import { PseudoDescriptor, pseudoDescriptors } from './pseudoDescriptors'
|
|
15
15
|
|
|
16
16
|
// refactor this file away next...
|
|
@@ -50,7 +50,10 @@ export function getAtomicStyle(style: ViewOrTextStyle, pseudo?: PseudoDescriptor
|
|
|
50
50
|
}
|
|
51
51
|
} else {
|
|
52
52
|
if (!style) {
|
|
53
|
-
|
|
53
|
+
if (process.env.NODE_ENV === 'development') {
|
|
54
|
+
// eslint-disable-next-line no-console
|
|
55
|
+
console.warn(`Invalid style`)
|
|
56
|
+
}
|
|
54
57
|
return []
|
|
55
58
|
}
|
|
56
59
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getConfig } from '../
|
|
2
|
-
import { GenericFonts } from '../types'
|
|
1
|
+
import { getConfig } from '../config'
|
|
2
|
+
import { GenericFonts, StaticConfig } from '../types'
|
|
3
3
|
import { LanguageContextType } from '../views/FontLanguage.types'
|
|
4
4
|
|
|
5
5
|
const extrasCache = new WeakMap()
|
|
@@ -2,7 +2,7 @@ import React from 'react'
|
|
|
2
2
|
import { RefObject } from 'react'
|
|
3
3
|
import { View, ViewStyle } from 'react-native'
|
|
4
4
|
|
|
5
|
-
import { getConfig } from '../
|
|
5
|
+
import { getConfig } from '../config'
|
|
6
6
|
import { useIsomorphicLayoutEffect } from '../constants/platform'
|
|
7
7
|
import { getSubStyle } from '../helpers/getSplitStyles'
|
|
8
8
|
import {
|
|
@@ -97,6 +97,7 @@ function loadAnimationFeature() {
|
|
|
97
97
|
} = _utils
|
|
98
98
|
|
|
99
99
|
if (!useAnimations) {
|
|
100
|
+
// eslint-disable-next-line no-console
|
|
100
101
|
console.error('no useAnimations hook provided')
|
|
101
102
|
return null
|
|
102
103
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { isRSC } from '../constants/platform'
|
|
4
|
+
|
|
5
|
+
export const useServerState = isRSC
|
|
6
|
+
? (((val: any) => [val, idFn]) as unknown as typeof useState)
|
|
7
|
+
: useState
|
|
8
|
+
|
|
9
|
+
export const useServerRef = isRSC
|
|
10
|
+
? (((val: any) => ({ current: val })) as unknown as typeof useRef)
|
|
11
|
+
: useRef
|
|
12
|
+
|
|
13
|
+
const idFn = () => {}
|
package/src/hooks/useTheme.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useForceUpdate } from '@tamagui/use-force-update'
|
|
2
2
|
import React, { useContext, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
3
3
|
|
|
4
|
-
import { getConfig } from '../
|
|
5
|
-
import {
|
|
4
|
+
import { getConfig } from '../config'
|
|
5
|
+
import { isRSC, isSSR, useIsomorphicLayoutEffect } from '../constants/platform'
|
|
6
6
|
import { ThemeContext } from '../contexts/ThemeContext'
|
|
7
7
|
import { areEqualSets } from '../helpers/areEqualSets'
|
|
8
8
|
import {
|
|
@@ -14,8 +14,9 @@ import {
|
|
|
14
14
|
import { ThemeName, ThemeObject } from '../types'
|
|
15
15
|
import { GetThemeUnwrapped } from './getThemeUnwrapped'
|
|
16
16
|
import { useConstant } from './useConstant'
|
|
17
|
+
import { useServerRef } from './useServerHooks'
|
|
17
18
|
|
|
18
|
-
export
|
|
19
|
+
export interface ThemeProps {
|
|
19
20
|
className?: string
|
|
20
21
|
disableThemeClass?: boolean
|
|
21
22
|
name: Exclude<ThemeName, number> | null
|
|
@@ -25,7 +26,7 @@ export type ThemeProps = {
|
|
|
25
26
|
debug?: boolean | 'verbose'
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
interface UseThemeState {
|
|
29
30
|
uuid: Object
|
|
30
31
|
keys: Set<string>
|
|
31
32
|
isRendering: boolean
|
|
@@ -37,6 +38,13 @@ export const useTheme = (
|
|
|
37
38
|
props?: ThemeProps,
|
|
38
39
|
forceUpdate?: any
|
|
39
40
|
): ThemeObject => {
|
|
41
|
+
// TODO this can use useChangeThemeEffect almost ready
|
|
42
|
+
if (isRSC) {
|
|
43
|
+
const config = getConfig()
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
return getThemeProxied(config.themes[config.defaultTheme], config.defaultTheme)
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
const { name, theme, themes, themeManager, className } = useChangeThemeEffect(
|
|
41
49
|
themeName,
|
|
42
50
|
componentName,
|
|
@@ -51,7 +59,7 @@ export const useTheme = (
|
|
|
51
59
|
}
|
|
52
60
|
}
|
|
53
61
|
|
|
54
|
-
const state =
|
|
62
|
+
const state = useServerRef() as React.MutableRefObject<UseThemeState>
|
|
55
63
|
if (!state.current) {
|
|
56
64
|
state.current = {
|
|
57
65
|
uuid: {},
|
|
@@ -82,49 +90,60 @@ export const useTheme = (
|
|
|
82
90
|
}
|
|
83
91
|
|
|
84
92
|
return useMemo(() => {
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
93
|
+
return getThemeProxied(theme, name, className, themeManager, state, debugProp)
|
|
94
|
+
}, [theme, name, themeManager, className, debugProp])
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function getThemeProxied(
|
|
98
|
+
theme: any,
|
|
99
|
+
name: string,
|
|
100
|
+
className?: string,
|
|
101
|
+
themeManager?: ThemeManager | null,
|
|
102
|
+
state?: React.MutableRefObject<UseThemeState>,
|
|
103
|
+
debugProp?: boolean | 'verbose'
|
|
104
|
+
) {
|
|
105
|
+
return new Proxy(theme, {
|
|
106
|
+
has(_, key) {
|
|
107
|
+
if (typeof key === 'string' && key[0] === '$') {
|
|
108
|
+
key = key.slice(1)
|
|
109
|
+
}
|
|
110
|
+
return Reflect.has(theme, key)
|
|
111
|
+
},
|
|
112
|
+
get(_, key) {
|
|
113
|
+
if (key === GetThemeUnwrapped) {
|
|
114
|
+
return theme
|
|
115
|
+
}
|
|
116
|
+
if (key === GetThemeManager) {
|
|
117
|
+
return themeManager
|
|
118
|
+
}
|
|
119
|
+
if (key === 'name') {
|
|
120
|
+
return name
|
|
121
|
+
}
|
|
122
|
+
if (key === 'className') {
|
|
123
|
+
return className
|
|
124
|
+
}
|
|
125
|
+
if (!name || key === '__proto__' || typeof key === 'symbol' || key === '$typeof') {
|
|
126
|
+
return Reflect.get(_, key)
|
|
127
|
+
}
|
|
128
|
+
// auto convert variables to plain
|
|
129
|
+
if (key[0] === '$') {
|
|
130
|
+
key = key.slice(1)
|
|
131
|
+
}
|
|
132
|
+
if (!themeManager) {
|
|
133
|
+
return theme[key]
|
|
134
|
+
}
|
|
135
|
+
if (state) {
|
|
118
136
|
if (state.current.isRendering && !state.current.keys.has(key)) {
|
|
119
137
|
state.current.keys.add(key)
|
|
120
138
|
if (process.env.NODE_ENV === 'development' && debugProp === 'verbose') {
|
|
139
|
+
// eslint-disable-next-line no-console
|
|
121
140
|
console.log(' 🔸 tracking theme', key)
|
|
122
141
|
}
|
|
123
142
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
}
|
|
143
|
+
}
|
|
144
|
+
return themeManager.getValue(key)
|
|
145
|
+
},
|
|
146
|
+
})
|
|
128
147
|
}
|
|
129
148
|
|
|
130
149
|
const GetThemeManager = Symbol()
|
|
@@ -135,6 +154,10 @@ export const getThemeManager = (theme: any): ThemeManager | undefined => {
|
|
|
135
154
|
}
|
|
136
155
|
|
|
137
156
|
export const useThemeName = (opts?: { parent?: true }) => {
|
|
157
|
+
if (isRSC) {
|
|
158
|
+
const config = getConfig()
|
|
159
|
+
return config.defaultTheme || 'light'
|
|
160
|
+
}
|
|
138
161
|
const parent = useContext(ThemeManagerContext)
|
|
139
162
|
const [name, setName] = useState(parent?.name || '')
|
|
140
163
|
|
|
@@ -161,20 +184,43 @@ export const useChangeThemeEffect = (
|
|
|
161
184
|
componentName?: string,
|
|
162
185
|
props?: ThemeProps,
|
|
163
186
|
forceUpdateProp?: any
|
|
164
|
-
)
|
|
187
|
+
): {
|
|
188
|
+
themes: Record<string, ThemeObject>
|
|
189
|
+
themeManager: ThemeManager | null
|
|
190
|
+
name: string
|
|
191
|
+
theme: ThemeObject | null
|
|
192
|
+
className?: string
|
|
193
|
+
} => {
|
|
194
|
+
const { themes } = getConfig()
|
|
195
|
+
if (isRSC) {
|
|
196
|
+
// we need context working for this to work well
|
|
197
|
+
const parentManager = new ThemeManager('light', themes.light)
|
|
198
|
+
const next = parentManager.getNextTheme({
|
|
199
|
+
name,
|
|
200
|
+
componentName,
|
|
201
|
+
themes,
|
|
202
|
+
reset: props?.reset,
|
|
203
|
+
})
|
|
204
|
+
return {
|
|
205
|
+
...next,
|
|
206
|
+
themes,
|
|
207
|
+
themeManager: null,
|
|
208
|
+
}
|
|
209
|
+
}
|
|
165
210
|
const debug = props && props['debug']
|
|
166
211
|
const parentManager = useContext(ThemeManagerContext) || emptyManager
|
|
167
|
-
const { themes } = useContext(ThemeContext)!
|
|
168
212
|
const reset = props?.reset || false
|
|
169
|
-
const getThemeProps: GetNextThemeProps = {
|
|
213
|
+
const getThemeProps: GetNextThemeProps = {
|
|
214
|
+
name,
|
|
215
|
+
componentName,
|
|
216
|
+
themes,
|
|
217
|
+
reset,
|
|
218
|
+
}
|
|
170
219
|
const next = parentManager.getNextTheme(getThemeProps, debug)
|
|
171
220
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
172
221
|
const forceUpdate = forceUpdateProp || useForceUpdate()
|
|
173
222
|
|
|
174
223
|
const themeManager = useConstant<ThemeManager | null>(() => {
|
|
175
|
-
// if (!next) return null
|
|
176
|
-
// RSC test
|
|
177
|
-
// if (typeof document === 'undefined') return null
|
|
178
224
|
return new ThemeManager(next.name, next.theme, parentManager, reset)
|
|
179
225
|
})
|
|
180
226
|
|
package/src/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ export * from './types'
|
|
|
15
15
|
|
|
16
16
|
// for type portability
|
|
17
17
|
export type { RNWTextProps, RNWViewProps } from './types-rnw'
|
|
18
|
-
export { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from './
|
|
18
|
+
export { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from './config'
|
|
19
19
|
|
|
20
20
|
export * from './constants/constants'
|
|
21
21
|
export * from './constants/platform'
|
|
@@ -25,6 +25,7 @@ export * from './helpers/calc'
|
|
|
25
25
|
export * from './helpers/createShallowUpdate'
|
|
26
26
|
export * from './helpers/getStackSize'
|
|
27
27
|
export * from './helpers/getVariantExtras'
|
|
28
|
+
export * from './helpers/getAnimationDriver'
|
|
28
29
|
export * from './helpers/getExpandedShorthands'
|
|
29
30
|
export * from './helpers/getSize'
|
|
30
31
|
export * from './helpers/getSplitStyles'
|