@tamagui/web 1.27.3 → 1.28.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/dist/cjs/config.js +13 -26
- package/dist/cjs/config.js.map +1 -1
- package/dist/cjs/createComponent.js +27 -3
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/createTamagui.js +11 -3
- package/dist/cjs/createTamagui.js.map +1 -1
- package/dist/cjs/createVariable.js.map +1 -1
- package/dist/cjs/createVariables.js +2 -8
- package/dist/cjs/createVariables.js.map +1 -1
- package/dist/cjs/helpers/createPropMapper.js +13 -17
- package/dist/cjs/helpers/createPropMapper.js.map +1 -1
- package/dist/cjs/helpers/createStyledContext.js +44 -0
- package/dist/cjs/helpers/createStyledContext.js.map +6 -0
- package/dist/cjs/helpers/createVariantContext.js +42 -0
- package/dist/cjs/helpers/createVariantContext.js.map +6 -0
- package/dist/cjs/helpers/createVariantProvider.js +42 -0
- package/dist/cjs/helpers/createVariantProvider.js.map +6 -0
- package/dist/cjs/helpers/getSplitStyles.js +1 -0
- package/dist/cjs/helpers/getSplitStyles.js.map +1 -1
- package/dist/cjs/helpers/getVariantExtras.js +7 -0
- package/dist/cjs/helpers/getVariantExtras.js.map +1 -1
- package/dist/cjs/hooks/useTheme.js +3 -0
- package/dist/cjs/hooks/useTheme.js.map +1 -1
- package/dist/cjs/index.js +20 -18
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/styled.js +2 -0
- package/dist/cjs/styled.js.map +1 -1
- package/dist/cjs/views/Text.js +12 -15
- package/dist/cjs/views/Text.js.map +1 -1
- package/dist/esm/config.js +13 -26
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/createComponent.js +28 -4
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createTamagui.js +12 -4
- package/dist/esm/createTamagui.js.map +1 -1
- package/dist/esm/createVariable.js.map +1 -1
- package/dist/esm/createVariables.js +1 -6
- package/dist/esm/createVariables.js.map +1 -1
- package/dist/esm/helpers/createPropMapper.js +13 -17
- package/dist/esm/helpers/createPropMapper.js.map +1 -1
- package/dist/esm/helpers/createStyledContext.js +20 -0
- package/dist/esm/helpers/createStyledContext.js.map +6 -0
- package/dist/esm/helpers/createVariantContext.js +18 -0
- package/dist/esm/helpers/createVariantContext.js.map +6 -0
- package/dist/esm/helpers/createVariantProvider.js +18 -0
- package/dist/esm/helpers/createVariantProvider.js.map +6 -0
- package/dist/esm/helpers/getSplitStyles.js +1 -0
- package/dist/esm/helpers/getSplitStyles.js.map +1 -1
- package/dist/esm/helpers/getVariantExtras.js +7 -0
- package/dist/esm/helpers/getVariantExtras.js.map +1 -1
- package/dist/esm/hooks/useTheme.js +3 -0
- package/dist/esm/hooks/useTheme.js.map +1 -1
- package/dist/esm/index.js +11 -16
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/styled.js +2 -0
- package/dist/esm/styled.js.map +1 -1
- package/dist/esm/views/Text.js +12 -15
- package/dist/esm/views/Text.js.map +1 -1
- package/package.json +9 -9
- package/src/config.ts +11 -25
- package/src/createComponent.tsx +33 -5
- package/src/createTamagui.ts +14 -3
- package/src/createVariable.ts +1 -1
- package/src/createVariables.ts +0 -7
- package/src/helpers/createPropMapper.ts +18 -20
- package/src/helpers/createStyledContext.tsx +38 -0
- package/src/helpers/getSplitStyles.tsx +4 -0
- package/src/helpers/getVariantExtras.tsx +10 -0
- package/src/hooks/useTheme.tsx +12 -3
- package/src/index.ts +11 -16
- package/src/styled.tsx +4 -0
- package/src/types.tsx +48 -9
- package/src/views/Text.tsx +15 -16
- package/types/config.d.ts.map +1 -1
- package/types/createComponent.d.ts +1 -1
- package/types/createComponent.d.ts.map +1 -1
- package/types/createTamagui.d.ts.map +1 -1
- package/types/createVariable.d.ts +1 -1
- package/types/createVariable.d.ts.map +1 -1
- package/types/createVariables.d.ts +0 -1
- package/types/createVariables.d.ts.map +1 -1
- package/types/helpers/createStyledContext.d.ts +9 -0
- package/types/helpers/createStyledContext.d.ts.map +1 -0
- package/types/helpers/createVariantContext.d.ts +9 -0
- package/types/helpers/createVariantContext.d.ts.map +1 -0
- package/types/helpers/createVariantProvider.d.ts +9 -0
- package/types/helpers/createVariantProvider.d.ts.map +1 -0
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
- package/types/helpers/getVariantExtras.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts +9 -3
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/index.d.ts +11 -10
- package/types/index.d.ts.map +1 -1
- package/types/styled.d.ts +3 -1
- package/types/styled.d.ts.map +1 -1
- package/types/types.d.ts +35 -6
- package/types/types.d.ts.map +1 -1
- package/types/views/Text.d.ts.map +1 -1
package/dist/esm/views/Text.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isWeb } from "@tamagui/constants";
|
|
2
1
|
import { stylePropsTextOnly, validStyles } from "@tamagui/helpers";
|
|
3
2
|
import { createComponent } from "../createComponent";
|
|
4
3
|
const ellipseStyle = {
|
|
@@ -11,22 +10,20 @@ const Text = createComponent(
|
|
|
11
10
|
{
|
|
12
11
|
acceptsClassName: true,
|
|
13
12
|
isText: true,
|
|
14
|
-
defaultProps: {
|
|
15
|
-
|
|
13
|
+
defaultProps: process.env.TAMAGUI_TARGET === "web" ? {
|
|
14
|
+
color: "$color",
|
|
15
|
+
display: "inline",
|
|
16
|
+
boxSizing: "border-box",
|
|
17
|
+
wordWrap: "break-word",
|
|
18
|
+
margin: 0
|
|
19
|
+
} : {
|
|
20
|
+
color: "$color",
|
|
16
21
|
display: "flex",
|
|
17
|
-
|
|
18
|
-
...isWeb ? {
|
|
19
|
-
display: "inline",
|
|
20
|
-
boxSizing: "border-box",
|
|
21
|
-
wordWrap: "break-word",
|
|
22
|
-
margin: 0
|
|
23
|
-
} : {
|
|
24
|
-
suppressHighlighting: true
|
|
25
|
-
}
|
|
22
|
+
suppressHighlighting: true
|
|
26
23
|
},
|
|
27
24
|
inlineWhenUnflattened: /* @__PURE__ */ new Set(["fontFamily"]),
|
|
28
25
|
variants: {
|
|
29
|
-
...
|
|
26
|
+
...process.env.TAMAGUI_TARGET === "web" && {
|
|
30
27
|
numberOfLines: {
|
|
31
28
|
1: ellipseStyle,
|
|
32
29
|
":number": (numberOfLines) => numberOfLines >= 1 ? {
|
|
@@ -52,13 +49,13 @@ const Text = createComponent(
|
|
|
52
49
|
}
|
|
53
50
|
},
|
|
54
51
|
ellipse: {
|
|
55
|
-
true:
|
|
52
|
+
true: process.env.TAMAGUI_TARGET === "web" ? ellipseStyle : {
|
|
56
53
|
numberOfLines: 1,
|
|
57
54
|
lineBreakMode: "clip"
|
|
58
55
|
}
|
|
59
56
|
}
|
|
60
57
|
},
|
|
61
|
-
deoptProps: new Set(
|
|
58
|
+
deoptProps: new Set(process.env.TAMAGUI_TARGET === "web" ? [] : ["ellipse"]),
|
|
62
59
|
validStyles: {
|
|
63
60
|
...validStyles,
|
|
64
61
|
...stylePropsTextOnly
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/Text.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAAS,
|
|
4
|
+
"mappings": "AAAA,SAAS,oBAAoB,mBAAmB;AAEhD,SAAS,uBAAuB;AAGhC,MAAM,eAAe;AAAA,EACnB,UAAU;AAAA,EACV,UAAU;AAAA,EACV,cAAc;AAAA,EACd,YAAY;AACd;AAEO,MAAM,OAAO;AAAA,EAClB;AAAA,IACE,kBAAkB;AAAA,IAClB,QAAQ;AAAA,IAER,cACE,QAAQ,IAAI,mBAAmB,QAC3B;AAAA,MACE,OAAO;AAAA,MACP,SAAS;AAAA,MACT,WAAW;AAAA,MACX,UAAU;AAAA,MACV,QAAQ;AAAA,IACV,IACA;AAAA,MACE,OAAO;AAAA,MACP,SAAS;AAAA,MACT,sBAAsB;AAAA,IACxB;AAAA,IAEN,uBAAuB,oBAAI,IAAI,CAAC,YAAY,CAAC;AAAA,IAE7C,UAAU;AAAA,MACR,GAAI,QAAQ,IAAI,mBAAmB,SAAS;AAAA,QAC1C,eAAe;AAAA,UACb,GAAG;AAAA,UAEH,WAAW,CAAC,kBACV,iBAAiB,IACb;AAAA,YACE,iBAAiB;AAAA,YACjB,iBAAiB;AAAA,YACjB,SAAS;AAAA,YACT,UAAU;AAAA,UACZ,IACA;AAAA,QACR;AAAA,MACF;AAAA;AAAA,MAGA,eAAe;AAAA,QACb,OAAO,MAAM;AAAA,MACf;AAAA,MAEA,YAAY;AAAA,QACV,MAAM;AAAA,UACJ,YAAY;AAAA,UACZ,QAAQ;AAAA,QACV;AAAA,QACA,OAAO;AAAA,UACL,YAAY;AAAA,UACZ,QAAQ;AAAA,QACV;AAAA,MACF;AAAA,MAEA,SAAS;AAAA,QACP,MACE,QAAQ,IAAI,mBAAmB,QAC3B,eACA;AAAA,UACE,eAAe;AAAA,UACf,eAAe;AAAA,QACjB;AAAA,MACR;AAAA,IACF;AAAA,IAEA,YAAY,IAAI,IAAI,QAAQ,IAAI,mBAAmB,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;AAAA,IAE3E,aAAa;AAAA,MACX,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,EACF;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -27,19 +27,19 @@
|
|
|
27
27
|
"reset.css"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@tamagui/compose-refs": "1.
|
|
31
|
-
"@tamagui/constants": "1.
|
|
32
|
-
"@tamagui/helpers": "1.
|
|
33
|
-
"@tamagui/normalize-css-color": "1.
|
|
34
|
-
"@tamagui/use-did-finish-ssr": "1.
|
|
35
|
-
"@tamagui/use-event": "1.
|
|
36
|
-
"@tamagui/use-force-update": "1.
|
|
30
|
+
"@tamagui/compose-refs": "1.28.0",
|
|
31
|
+
"@tamagui/constants": "1.28.0",
|
|
32
|
+
"@tamagui/helpers": "1.28.0",
|
|
33
|
+
"@tamagui/normalize-css-color": "1.28.0",
|
|
34
|
+
"@tamagui/use-did-finish-ssr": "1.28.0",
|
|
35
|
+
"@tamagui/use-event": "1.28.0",
|
|
36
|
+
"@tamagui/use-force-update": "1.28.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": "*"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@tamagui/build": "1.
|
|
42
|
+
"@tamagui/build": "1.28.0",
|
|
43
43
|
"@testing-library/react": "^13.4.0",
|
|
44
44
|
"csstype": "^3.0.10",
|
|
45
45
|
"react": "^18.2.0",
|
package/src/config.ts
CHANGED
|
@@ -35,31 +35,17 @@ export const getTokens = ({
|
|
|
35
35
|
*/
|
|
36
36
|
prefixed?: boolean
|
|
37
37
|
} = {}): TokensMerged => {
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
radius: {
|
|
51
|
-
...conf.tokens['radius'],
|
|
52
|
-
...conf.tokensParsed['radius'],
|
|
53
|
-
},
|
|
54
|
-
zIndex: {
|
|
55
|
-
...conf.tokens['zIndex'],
|
|
56
|
-
...conf.tokensParsed['zIndex'],
|
|
57
|
-
},
|
|
58
|
-
color: {
|
|
59
|
-
...conf.tokens['color'],
|
|
60
|
-
...conf.tokensParsed['color'],
|
|
61
|
-
},
|
|
62
|
-
}) as any)
|
|
38
|
+
if (process.env.NODE_ENV === 'development') {
|
|
39
|
+
if (!conf) throw new Error(`Haven't called createTamagui yet`)
|
|
40
|
+
}
|
|
41
|
+
const { tokens, tokensParsed } = conf!
|
|
42
|
+
if (prefixed === false) return tokens
|
|
43
|
+
if (prefixed === true) return tokensParsed
|
|
44
|
+
if (cached) return cached
|
|
45
|
+
cached = Object.fromEntries(
|
|
46
|
+
Object.entries(tokens).map(([k, v]) => [k, { ...v, ...tokensParsed[k] }])
|
|
47
|
+
) as any
|
|
48
|
+
return cached
|
|
63
49
|
}
|
|
64
50
|
|
|
65
51
|
/**
|
package/src/createComponent.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
isWeb,
|
|
7
7
|
useIsomorphicLayoutEffect,
|
|
8
8
|
} from '@tamagui/constants'
|
|
9
|
-
import { stylePropsView,
|
|
9
|
+
import { stylePropsView, validStyles } from '@tamagui/helpers'
|
|
10
10
|
import React, {
|
|
11
11
|
Children,
|
|
12
12
|
Fragment,
|
|
@@ -19,7 +19,7 @@ import React, {
|
|
|
19
19
|
useRef,
|
|
20
20
|
} from 'react'
|
|
21
21
|
|
|
22
|
-
import { onConfiguredOnce } from './config'
|
|
22
|
+
import { getConfig, onConfiguredOnce } from './config'
|
|
23
23
|
import { stackDefaultStyles } from './constants/constants'
|
|
24
24
|
import { FontLanguageContext } from './contexts/FontLanguageContext'
|
|
25
25
|
import { TextAncestorContext } from './contexts/TextAncestorContext'
|
|
@@ -121,11 +121,11 @@ export function createComponent<
|
|
|
121
121
|
Ref = TamaguiElement,
|
|
122
122
|
BaseProps = never
|
|
123
123
|
>(
|
|
124
|
-
|
|
124
|
+
staticConfigIn: Partial<StaticConfig> | StaticConfigParsed,
|
|
125
125
|
ParentComponent?: StylableComponent
|
|
126
126
|
) {
|
|
127
127
|
const staticConfig = (() => {
|
|
128
|
-
const next = extendStaticConfig(
|
|
128
|
+
const next = extendStaticConfig(staticConfigIn, ParentComponent)
|
|
129
129
|
|
|
130
130
|
if ('parsed' in next) {
|
|
131
131
|
return next
|
|
@@ -172,6 +172,25 @@ export function createComponent<
|
|
|
172
172
|
props = propsIn
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
// set variants through context
|
|
176
|
+
let provided: Object | undefined
|
|
177
|
+
const { context } = staticConfig
|
|
178
|
+
if (context) {
|
|
179
|
+
const contextValue = useContext(context)
|
|
180
|
+
const { inverseShorthands } = getConfig()
|
|
181
|
+
for (const key in context.props) {
|
|
182
|
+
const propVal = props[key] || props[inverseShorthands[key]]
|
|
183
|
+
if (propVal == null) {
|
|
184
|
+
if (contextValue) {
|
|
185
|
+
props[key] = contextValue[key]
|
|
186
|
+
}
|
|
187
|
+
} else {
|
|
188
|
+
provided ||= {}
|
|
189
|
+
provided[key] = propVal
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
175
194
|
const debugProp = props['debug'] as DebugProp
|
|
176
195
|
const { Component, isText, isZStack } = staticConfig
|
|
177
196
|
const componentName = props.componentName || staticConfig.componentName
|
|
@@ -823,6 +842,11 @@ export function createComponent<
|
|
|
823
842
|
}
|
|
824
843
|
}
|
|
825
844
|
|
|
845
|
+
if (provided) {
|
|
846
|
+
const Provider = staticConfig.context!.Provider!
|
|
847
|
+
content = <Provider {...provided}>{content}</Provider>
|
|
848
|
+
}
|
|
849
|
+
|
|
826
850
|
if (process.env.NODE_ENV === 'development') {
|
|
827
851
|
if (debugProp) {
|
|
828
852
|
const element = typeof elementType === 'string' ? elementType : 'Component'
|
|
@@ -895,6 +919,10 @@ export function createComponent<
|
|
|
895
919
|
|
|
896
920
|
defaultProps = restProps
|
|
897
921
|
|
|
922
|
+
if (staticConfig.isText && !defaultProps.fontFamily && conf.defaultFont) {
|
|
923
|
+
defaultProps.fontFamily = `$${conf.defaultFont}`
|
|
924
|
+
}
|
|
925
|
+
|
|
898
926
|
// add debug logs
|
|
899
927
|
if (process.env.NODE_ENV === 'development' && debug) {
|
|
900
928
|
if (process.env.IS_STATIC !== 'is_static') {
|
|
@@ -915,7 +943,7 @@ export function createComponent<
|
|
|
915
943
|
|
|
916
944
|
let res: ComponentType = component as any
|
|
917
945
|
|
|
918
|
-
if (
|
|
946
|
+
if (staticConfigIn.memo) {
|
|
919
947
|
res = memo(res) as any
|
|
920
948
|
}
|
|
921
949
|
|
package/src/createTamagui.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isRSC, isWeb } from '@tamagui/constants'
|
|
2
2
|
|
|
3
3
|
import { configListeners, setConfig } from './config'
|
|
4
|
-
import { createVariables
|
|
4
|
+
import { createVariables } from './createVariables'
|
|
5
5
|
import { getThemeCSSRules } from './helpers/getThemeCSSRules'
|
|
6
6
|
import {
|
|
7
7
|
getAllRules,
|
|
@@ -56,10 +56,17 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
56
56
|
})
|
|
57
57
|
)
|
|
58
58
|
|
|
59
|
+
let fontSizeTokens: Set<string> | null = null
|
|
60
|
+
|
|
59
61
|
const fontsParsed = (() => {
|
|
60
62
|
const res = {} as typeof fontTokens
|
|
61
63
|
for (const familyName in fontTokens) {
|
|
62
|
-
|
|
64
|
+
const font = fontTokens[familyName]
|
|
65
|
+
const fontParsed = parseFont(font)
|
|
66
|
+
res[`$${familyName}`] = fontParsed
|
|
67
|
+
if (!fontSizeTokens && fontParsed.size) {
|
|
68
|
+
fontSizeTokens = new Set(Object.keys(fontParsed.size))
|
|
69
|
+
}
|
|
63
70
|
}
|
|
64
71
|
return res!
|
|
65
72
|
})()
|
|
@@ -196,7 +203,6 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
196
203
|
const tokensParsed: any = Object.fromEntries(
|
|
197
204
|
Object.entries(configIn.tokens).map(([k, v]) => {
|
|
198
205
|
const val = Object.fromEntries(Object.entries(v).map(([k, v]) => [`$${k}`, v]))
|
|
199
|
-
tokensKeysOrdered.set(val, tokensKeysOrdered.get(v))
|
|
200
206
|
return [k, val]
|
|
201
207
|
})
|
|
202
208
|
)
|
|
@@ -228,6 +234,9 @@ ${getAllRules().join(separator)}`
|
|
|
228
234
|
|
|
229
235
|
const getNewCSS: GetCSS = (opts) => getCSS({ ...opts, sinceLastCall: true })
|
|
230
236
|
|
|
237
|
+
// defaults to the first font to make life easier
|
|
238
|
+
const defaultFont = configIn.defaultFont || Object.keys(configIn.fonts)[0]
|
|
239
|
+
|
|
231
240
|
const config: TamaguiInternalConfig = {
|
|
232
241
|
onlyAllowShorthands: false,
|
|
233
242
|
fontLanguages: [],
|
|
@@ -248,6 +257,8 @@ ${getAllRules().join(separator)}`
|
|
|
248
257
|
parsed: true,
|
|
249
258
|
getNewCSS,
|
|
250
259
|
getCSS,
|
|
260
|
+
defaultFont,
|
|
261
|
+
fontSizeTokens: fontSizeTokens || new Set(),
|
|
251
262
|
// const tokens = [...getToken(tokens.size[0])]
|
|
252
263
|
// .spacer-sm + ._dsp_contents._dsp-sm-hidden { margin-left: -var(--${}) }
|
|
253
264
|
}
|
package/src/createVariable.ts
CHANGED
|
@@ -50,7 +50,7 @@ export function isVariable(v: Variable | any): v is Variable {
|
|
|
50
50
|
return v && typeof v === 'object' && IS_VAR in v
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export function getVariable(nameOrVariable: Variable | string) {
|
|
53
|
+
export function getVariable(nameOrVariable: Variable | string | any) {
|
|
54
54
|
setDidGetVariableValue(true)
|
|
55
55
|
if (isVariable(nameOrVariable)) {
|
|
56
56
|
return variableToString(nameOrVariable)
|
package/src/createVariables.ts
CHANGED
|
@@ -14,8 +14,6 @@ export type DeepVariableObject<A extends DeepTokenObject> = {
|
|
|
14
14
|
: never
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const tokensKeysOrdered = new WeakMap()
|
|
18
|
-
|
|
19
17
|
export const createVariables = <A extends DeepTokenObject>(
|
|
20
18
|
tokens: A,
|
|
21
19
|
parentPath = '',
|
|
@@ -46,10 +44,5 @@ export const createVariables = <A extends DeepTokenObject>(
|
|
|
46
44
|
res[key] = isVariable(val) ? val : createVariable({ val, name, key: niceKey })
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
// ordering for relative sizing for now just size/space
|
|
50
|
-
if (parentPath === 'size' || parentPath === 'space') {
|
|
51
|
-
tokensKeysOrdered.set(res, Object.keys(tokens))
|
|
52
|
-
}
|
|
53
|
-
|
|
54
47
|
return res
|
|
55
48
|
}
|
|
@@ -56,12 +56,12 @@ export const createPropMapper = (staticConfig: StaticConfigParsed) => {
|
|
|
56
56
|
const returnVariablesAs = state.resolveVariablesAs === 'value' ? 'value' : 'auto'
|
|
57
57
|
|
|
58
58
|
// handled here because we need to resolve this off tokens, its the only one-off like this
|
|
59
|
-
|
|
59
|
+
let fontFamily =
|
|
60
60
|
props[conf.inverseShorthands.fontFamily] ||
|
|
61
61
|
props.fontFamily ||
|
|
62
62
|
defaultProps.fontFamily ||
|
|
63
63
|
propsIn.fontFamily ||
|
|
64
|
-
|
|
64
|
+
`$${conf.defaultFont}`
|
|
65
65
|
|
|
66
66
|
if (
|
|
67
67
|
process.env.NODE_ENV === 'development' &&
|
|
@@ -173,7 +173,7 @@ const resolveVariants: StyleResolver = (
|
|
|
173
173
|
if (!variantValue) {
|
|
174
174
|
// variant at key exists, but no matching variant value, return nothing
|
|
175
175
|
if (process.env.NODE_ENV === 'development') {
|
|
176
|
-
if (staticConfig.validStyles
|
|
176
|
+
if (staticConfig.validStyles && key in staticConfig.validStyles) return
|
|
177
177
|
// don't warn on missing boolean values, common to only one of true/false
|
|
178
178
|
if (typeof value === 'boolean') return
|
|
179
179
|
const name = staticConfig.componentName || '[UnnamedComponent]'
|
|
@@ -411,21 +411,16 @@ function getVariantDefinition(
|
|
|
411
411
|
}
|
|
412
412
|
const { tokensParsed } = conf
|
|
413
413
|
for (const { name, spreadName } of tokenCats) {
|
|
414
|
-
if (
|
|
414
|
+
if (spreadName in variant && value in tokensParsed[name]) {
|
|
415
415
|
return variant[spreadName]
|
|
416
416
|
}
|
|
417
417
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
fn = variant[':number']
|
|
422
|
-
} else if (type === 'string') {
|
|
423
|
-
fn = variant[':string']
|
|
424
|
-
} else if (value === true || value === false) {
|
|
425
|
-
fn = variant[':boolean']
|
|
418
|
+
const fontSizeVariant = variant['...fontSize']
|
|
419
|
+
if (fontSizeVariant && conf.fontSizeTokens.has(value)) {
|
|
420
|
+
return fontSizeVariant
|
|
426
421
|
}
|
|
427
|
-
// fallback to catch all
|
|
428
|
-
return
|
|
422
|
+
// fallback to catch all | size
|
|
423
|
+
return variant[`:${typeof value}`] || variant['...'] || variant['...size']
|
|
429
424
|
}
|
|
430
425
|
|
|
431
426
|
const fontShorthand = {
|
|
@@ -438,7 +433,7 @@ const getToken = (
|
|
|
438
433
|
value: string,
|
|
439
434
|
conf: TamaguiInternalConfig,
|
|
440
435
|
theme: any,
|
|
441
|
-
fontFamily: string | undefined
|
|
436
|
+
fontFamily: string | undefined,
|
|
442
437
|
languageContext?: LanguageContextType,
|
|
443
438
|
resolveAs?: ResolveVariableTypes,
|
|
444
439
|
debug?: DebugProp
|
|
@@ -467,11 +462,14 @@ const getToken = (
|
|
|
467
462
|
case 'lineHeight':
|
|
468
463
|
case 'letterSpacing':
|
|
469
464
|
case 'fontWeight': {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
465
|
+
if (fontFamily) {
|
|
466
|
+
const fontsParsed = languageContext
|
|
467
|
+
? getFontsForLanguage(conf.fontsParsed, languageContext)
|
|
468
|
+
: conf.fontsParsed
|
|
469
|
+
valOrVar =
|
|
470
|
+
fontsParsed[fontFamily]?.[fontShorthand[key] || key]?.[value] || value
|
|
471
|
+
hasSet = true
|
|
472
|
+
}
|
|
475
473
|
break
|
|
476
474
|
}
|
|
477
475
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { createContext, useContext, useMemo } from 'react'
|
|
2
|
+
|
|
3
|
+
export type StyledContext<Props extends Object = any> = Omit<
|
|
4
|
+
React.Context<Props>,
|
|
5
|
+
'Provider'
|
|
6
|
+
> & {
|
|
7
|
+
props: Object
|
|
8
|
+
Provider: React.ProviderExoticComponent<
|
|
9
|
+
Partial<Props> & {
|
|
10
|
+
children?: React.ReactNode
|
|
11
|
+
}
|
|
12
|
+
>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createStyledContext<VariantProps extends Record<string, any>>(
|
|
16
|
+
props: VariantProps
|
|
17
|
+
): StyledContext<VariantProps> {
|
|
18
|
+
const OGContext = createContext<any>(null)
|
|
19
|
+
const OGProvider = OGContext.Provider
|
|
20
|
+
const Context = OGContext as any as StyledContext<VariantProps>
|
|
21
|
+
|
|
22
|
+
const Provider = ({
|
|
23
|
+
children,
|
|
24
|
+
...values
|
|
25
|
+
}: VariantProps & { children?: React.ReactNode }) => {
|
|
26
|
+
return (
|
|
27
|
+
<OGProvider value={useMemo(() => values, [JSON.stringify(values)])}>
|
|
28
|
+
{children}
|
|
29
|
+
</OGProvider>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
Context.Provider = Provider
|
|
35
|
+
Context.props = props
|
|
36
|
+
|
|
37
|
+
return Context
|
|
38
|
+
}
|
|
@@ -822,6 +822,10 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
822
822
|
const valInit = props[keyInit]
|
|
823
823
|
processProp(keyInit, valInit)
|
|
824
824
|
}
|
|
825
|
+
|
|
826
|
+
// default to default font
|
|
827
|
+
fontFamily ||= conf.defaultFont
|
|
828
|
+
|
|
825
829
|
// loop the special props once again
|
|
826
830
|
// this one doesn't need to be backwards since it was pushed in the backwards loop (is already reversed)
|
|
827
831
|
for (let i = 0; i < specialProps.length; i++) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getConfig } from '../config'
|
|
2
|
+
import { getVariableValue } from '../createVariable'
|
|
2
3
|
import { GenericFonts } from '../types'
|
|
3
4
|
import { LanguageContextType } from '../views/FontLanguage.types'
|
|
4
5
|
import { createProxy } from './createProxy'
|
|
@@ -27,6 +28,15 @@ export function getVariantExtras(
|
|
|
27
28
|
fonts,
|
|
28
29
|
tokens: conf.tokensParsed,
|
|
29
30
|
theme,
|
|
31
|
+
|
|
32
|
+
get fontFamily() {
|
|
33
|
+
return getVariableValue(props.fontFamily)
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
get font() {
|
|
37
|
+
return fonts[this.fontFamily]
|
|
38
|
+
},
|
|
39
|
+
|
|
30
40
|
// TODO do this in splitstlye
|
|
31
41
|
// we avoid passing in default props for media queries because that would confuse things like SizableText.size:
|
|
32
42
|
props: avoidDefaultProps
|
package/src/hooks/useTheme.tsx
CHANGED
|
@@ -41,7 +41,13 @@ function getDefaultThemeProxied() {
|
|
|
41
41
|
})
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
type UseThemeResult = {
|
|
45
|
+
[key in keyof ThemeParsed]: ThemeParsed[key] & {
|
|
46
|
+
get: () => string | ThemeParsed[key]['val']
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const useTheme = (props: ThemeProps = emptyProps): UseThemeResult => {
|
|
45
51
|
return (isRSC ? null : useThemeWithState(props)?.theme) || getDefaultThemeProxied()
|
|
46
52
|
}
|
|
47
53
|
|
|
@@ -96,7 +102,7 @@ export function getThemeProxied(
|
|
|
96
102
|
theme: ThemeParsed
|
|
97
103
|
},
|
|
98
104
|
keys?: string[]
|
|
99
|
-
) {
|
|
105
|
+
): UseThemeResult {
|
|
100
106
|
return createProxy(theme, {
|
|
101
107
|
has(_, key) {
|
|
102
108
|
if (typeof key === 'string') {
|
|
@@ -127,6 +133,9 @@ export function getThemeProxied(
|
|
|
127
133
|
// when they touch the actual value we only track it
|
|
128
134
|
// if its a variable (web), its ignored!
|
|
129
135
|
get(_, subkey) {
|
|
136
|
+
if (subkey === 'get') {
|
|
137
|
+
return () => val
|
|
138
|
+
}
|
|
130
139
|
if (subkey === 'val' && !keys.includes(keyString)) {
|
|
131
140
|
keys.push(keyString)
|
|
132
141
|
}
|
|
@@ -137,7 +146,7 @@ export function getThemeProxied(
|
|
|
137
146
|
|
|
138
147
|
return val
|
|
139
148
|
},
|
|
140
|
-
})
|
|
149
|
+
}) as UseThemeResult
|
|
141
150
|
}
|
|
142
151
|
|
|
143
152
|
export const activeThemeManagers = new Set<ThemeManager>()
|
package/src/index.ts
CHANGED
|
@@ -12,34 +12,29 @@ export * from './styled'
|
|
|
12
12
|
export * from './types'
|
|
13
13
|
export * from './setupReactNative'
|
|
14
14
|
|
|
15
|
-
export {
|
|
16
|
-
getConfig,
|
|
17
|
-
getThemes,
|
|
18
|
-
getTokens,
|
|
19
|
-
onConfiguredOnce,
|
|
20
|
-
updateConfig,
|
|
21
|
-
} from './config'
|
|
15
|
+
export { getConfig, getThemes, getTokens, onConfiguredOnce, updateConfig } from './config'
|
|
22
16
|
|
|
23
17
|
export * from './constants/constants'
|
|
24
18
|
|
|
25
|
-
export * from './helpers/
|
|
26
|
-
export * from './helpers/
|
|
19
|
+
export * from './helpers/createStyledContext'
|
|
20
|
+
export * from './helpers/expandStyles'
|
|
27
21
|
export * from './helpers/getAnimationDriver'
|
|
28
22
|
export * from './helpers/getExpandedShorthands'
|
|
29
23
|
export * from './helpers/getSplitStyles'
|
|
30
24
|
export * from './helpers/getStylesAtomic'
|
|
31
|
-
export * from './helpers/
|
|
32
|
-
export * from './helpers/
|
|
33
|
-
export * from './helpers/expandStyles'
|
|
34
|
-
export * from './helpers/isTamaguiElement'
|
|
25
|
+
export * from './helpers/getThemeCSSRules'
|
|
26
|
+
export * from './helpers/getVariantExtras'
|
|
35
27
|
export * from './helpers/isTamaguiComponent'
|
|
28
|
+
export * from './helpers/isTamaguiElement'
|
|
36
29
|
export * from './helpers/matchMedia'
|
|
37
|
-
export * from './helpers/
|
|
38
|
-
export * from './helpers/
|
|
30
|
+
export * from './helpers/mergeProps'
|
|
31
|
+
export * from './helpers/normalizeColor'
|
|
39
32
|
export * from './helpers/proxyThemeVariables'
|
|
33
|
+
export * from './helpers/pseudoDescriptors'
|
|
40
34
|
export * from './helpers/themeable'
|
|
35
|
+
export * from './helpers/themes'
|
|
36
|
+
export * from './helpers/useShallowSetState'
|
|
41
37
|
export * from './helpers/withStaticProperties'
|
|
42
|
-
export * from './helpers/normalizeColor'
|
|
43
38
|
|
|
44
39
|
export * from './contexts/ButtonNestingContext'
|
|
45
40
|
|
package/src/styled.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { stylePropsAll } from '@tamagui/helpers'
|
|
2
2
|
|
|
3
3
|
import { createComponent } from './createComponent'
|
|
4
|
+
import { StyledContext } from './helpers/createStyledContext'
|
|
4
5
|
import { mergeVariants } from './helpers/extendStaticConfig'
|
|
5
6
|
import { ReactNativeStaticConfigs } from './setupReactNative'
|
|
6
7
|
import type {
|
|
@@ -51,6 +52,7 @@ export function styled<
|
|
|
51
52
|
name?: string
|
|
52
53
|
variants?: Variants | undefined
|
|
53
54
|
defaultVariants?: GetVariantAcceptedValues<Variants>
|
|
55
|
+
context?: StyledContext
|
|
54
56
|
acceptsClassName?: boolean
|
|
55
57
|
},
|
|
56
58
|
staticExtractionOptions?: Partial<StaticConfig>
|
|
@@ -96,6 +98,7 @@ export function styled<
|
|
|
96
98
|
name,
|
|
97
99
|
defaultVariants,
|
|
98
100
|
acceptsClassName: acceptsClassNameProp,
|
|
101
|
+
context,
|
|
99
102
|
...defaultProps
|
|
100
103
|
} = options
|
|
101
104
|
|
|
@@ -144,6 +147,7 @@ export function styled<
|
|
|
144
147
|
isReactNative,
|
|
145
148
|
isText,
|
|
146
149
|
acceptsClassName,
|
|
150
|
+
context,
|
|
147
151
|
...nativeConf,
|
|
148
152
|
}
|
|
149
153
|
|