@tamagui/web 1.27.2 → 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.
Files changed (98) hide show
  1. package/dist/cjs/config.js +13 -26
  2. package/dist/cjs/config.js.map +1 -1
  3. package/dist/cjs/createComponent.js +27 -3
  4. package/dist/cjs/createComponent.js.map +1 -1
  5. package/dist/cjs/createTamagui.js +11 -3
  6. package/dist/cjs/createTamagui.js.map +1 -1
  7. package/dist/cjs/createVariable.js.map +1 -1
  8. package/dist/cjs/createVariables.js +2 -8
  9. package/dist/cjs/createVariables.js.map +1 -1
  10. package/dist/cjs/helpers/createPropMapper.js +13 -17
  11. package/dist/cjs/helpers/createPropMapper.js.map +1 -1
  12. package/dist/cjs/helpers/createStyledContext.js +44 -0
  13. package/dist/cjs/helpers/createStyledContext.js.map +6 -0
  14. package/dist/cjs/helpers/createVariantContext.js +42 -0
  15. package/dist/cjs/helpers/createVariantContext.js.map +6 -0
  16. package/dist/cjs/helpers/createVariantProvider.js +42 -0
  17. package/dist/cjs/helpers/createVariantProvider.js.map +6 -0
  18. package/dist/cjs/helpers/getSplitStyles.js +1 -0
  19. package/dist/cjs/helpers/getSplitStyles.js.map +1 -1
  20. package/dist/cjs/helpers/getVariantExtras.js +7 -0
  21. package/dist/cjs/helpers/getVariantExtras.js.map +1 -1
  22. package/dist/cjs/hooks/useTheme.js +3 -0
  23. package/dist/cjs/hooks/useTheme.js.map +1 -1
  24. package/dist/cjs/index.js +20 -18
  25. package/dist/cjs/index.js.map +1 -1
  26. package/dist/cjs/styled.js +2 -0
  27. package/dist/cjs/styled.js.map +1 -1
  28. package/dist/cjs/views/Text.js +12 -15
  29. package/dist/cjs/views/Text.js.map +1 -1
  30. package/dist/esm/config.js +13 -26
  31. package/dist/esm/config.js.map +1 -1
  32. package/dist/esm/createComponent.js +28 -4
  33. package/dist/esm/createComponent.js.map +1 -1
  34. package/dist/esm/createTamagui.js +12 -4
  35. package/dist/esm/createTamagui.js.map +1 -1
  36. package/dist/esm/createVariable.js.map +1 -1
  37. package/dist/esm/createVariables.js +1 -6
  38. package/dist/esm/createVariables.js.map +1 -1
  39. package/dist/esm/helpers/createPropMapper.js +13 -17
  40. package/dist/esm/helpers/createPropMapper.js.map +1 -1
  41. package/dist/esm/helpers/createStyledContext.js +20 -0
  42. package/dist/esm/helpers/createStyledContext.js.map +6 -0
  43. package/dist/esm/helpers/createVariantContext.js +18 -0
  44. package/dist/esm/helpers/createVariantContext.js.map +6 -0
  45. package/dist/esm/helpers/createVariantProvider.js +18 -0
  46. package/dist/esm/helpers/createVariantProvider.js.map +6 -0
  47. package/dist/esm/helpers/getSplitStyles.js +1 -0
  48. package/dist/esm/helpers/getSplitStyles.js.map +1 -1
  49. package/dist/esm/helpers/getVariantExtras.js +7 -0
  50. package/dist/esm/helpers/getVariantExtras.js.map +1 -1
  51. package/dist/esm/hooks/useTheme.js +3 -0
  52. package/dist/esm/hooks/useTheme.js.map +1 -1
  53. package/dist/esm/index.js +11 -16
  54. package/dist/esm/index.js.map +1 -1
  55. package/dist/esm/styled.js +2 -0
  56. package/dist/esm/styled.js.map +1 -1
  57. package/dist/esm/views/Text.js +12 -15
  58. package/dist/esm/views/Text.js.map +1 -1
  59. package/package.json +9 -9
  60. package/src/config.ts +11 -25
  61. package/src/createComponent.tsx +33 -5
  62. package/src/createTamagui.ts +14 -3
  63. package/src/createVariable.ts +1 -1
  64. package/src/createVariables.ts +0 -7
  65. package/src/helpers/createPropMapper.ts +18 -20
  66. package/src/helpers/createStyledContext.tsx +38 -0
  67. package/src/helpers/getSplitStyles.tsx +4 -0
  68. package/src/helpers/getVariantExtras.tsx +10 -0
  69. package/src/hooks/useTheme.tsx +12 -3
  70. package/src/index.ts +11 -16
  71. package/src/styled.tsx +4 -0
  72. package/src/types.tsx +48 -9
  73. package/src/views/Text.tsx +15 -16
  74. package/types/config.d.ts.map +1 -1
  75. package/types/createComponent.d.ts +1 -1
  76. package/types/createComponent.d.ts.map +1 -1
  77. package/types/createTamagui.d.ts.map +1 -1
  78. package/types/createVariable.d.ts +1 -1
  79. package/types/createVariable.d.ts.map +1 -1
  80. package/types/createVariables.d.ts +0 -1
  81. package/types/createVariables.d.ts.map +1 -1
  82. package/types/helpers/createStyledContext.d.ts +9 -0
  83. package/types/helpers/createStyledContext.d.ts.map +1 -0
  84. package/types/helpers/createVariantContext.d.ts +9 -0
  85. package/types/helpers/createVariantContext.d.ts.map +1 -0
  86. package/types/helpers/createVariantProvider.d.ts +9 -0
  87. package/types/helpers/createVariantProvider.d.ts.map +1 -0
  88. package/types/helpers/getSplitStyles.d.ts.map +1 -1
  89. package/types/helpers/getVariantExtras.d.ts.map +1 -1
  90. package/types/hooks/useTheme.d.ts +9 -3
  91. package/types/hooks/useTheme.d.ts.map +1 -1
  92. package/types/index.d.ts +11 -10
  93. package/types/index.d.ts.map +1 -1
  94. package/types/styled.d.ts +3 -1
  95. package/types/styled.d.ts.map +1 -1
  96. package/types/types.d.ts +35 -6
  97. package/types/types.d.ts.map +1 -1
  98. package/types/views/Text.d.ts.map +1 -1
@@ -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
- // @ts-ignore
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
- fontFamily: "System",
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
- ...isWeb && {
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: isWeb ? ellipseStyle : {
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(isWeb ? [] : ["ellipse"]),
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,aAAa;AACtB,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,cAAc;AAAA;AAAA,MAEZ,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,GAAI,QACA;AAAA,QACE,SAAS;AAAA,QACT,WAAW;AAAA,QACX,UAAU;AAAA,QACV,QAAQ;AAAA,MACV,IACA;AAAA,QACE,sBAAsB;AAAA,MACxB;AAAA,IACN;AAAA,IAEA,uBAAuB,oBAAI,IAAI,CAAC,YAAY,CAAC;AAAA,IAE7C,UAAU;AAAA,MACR,GAAI,SAAS;AAAA,QACX,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,MAAM,QACF,eACA;AAAA,UACE,eAAe;AAAA,UACf,eAAe;AAAA,QACjB;AAAA,MACN;AAAA,IACF;AAAA,IAEA,YAAY,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;AAAA,IAE5C,aAAa;AAAA,MACX,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,EACF;AACF;",
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.27.2",
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.27.2",
31
- "@tamagui/constants": "1.27.2",
32
- "@tamagui/helpers": "1.27.2",
33
- "@tamagui/normalize-css-color": "1.27.2",
34
- "@tamagui/use-did-finish-ssr": "1.27.2",
35
- "@tamagui/use-event": "1.27.2",
36
- "@tamagui/use-force-update": "1.27.2"
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.27.2",
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 (!conf) throw new Error(`never called createTamagui`)
39
- if (prefixed === false) return conf.tokens
40
- if (prefixed === true) return conf.tokensParsed
41
- return (cached ??= Object.freeze({
42
- size: {
43
- ...conf.tokens['size'],
44
- ...conf.tokensParsed['size'],
45
- },
46
- space: {
47
- ...conf.tokens['space'],
48
- ...conf.tokensParsed['space'],
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
  /**
@@ -6,7 +6,7 @@ import {
6
6
  isWeb,
7
7
  useIsomorphicLayoutEffect,
8
8
  } from '@tamagui/constants'
9
- import { stylePropsView, validPseudoKeys, validStyles } from '@tamagui/helpers'
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
- configIn: Partial<StaticConfig> | StaticConfigParsed,
124
+ staticConfigIn: Partial<StaticConfig> | StaticConfigParsed,
125
125
  ParentComponent?: StylableComponent
126
126
  ) {
127
127
  const staticConfig = (() => {
128
- const next = extendStaticConfig(configIn, ParentComponent)
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 (configIn.memo) {
946
+ if (staticConfigIn.memo) {
919
947
  res = memo(res) as any
920
948
  }
921
949
 
@@ -1,7 +1,7 @@
1
1
  import { isRSC, isWeb } from '@tamagui/constants'
2
2
 
3
3
  import { configListeners, setConfig } from './config'
4
- import { createVariables, tokensKeysOrdered } from './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
- res[`$${familyName}`] = parseFont(fontTokens[familyName])
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
  }
@@ -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)
@@ -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
- const fontFamily =
59
+ let fontFamily =
60
60
  props[conf.inverseShorthands.fontFamily] ||
61
61
  props.fontFamily ||
62
62
  defaultProps.fontFamily ||
63
63
  propsIn.fontFamily ||
64
- '$body'
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?.[key]) return
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 (variant[spreadName] && value in tokensParsed[name]) {
414
+ if (spreadName in variant && value in tokensParsed[name]) {
415
415
  return variant[spreadName]
416
416
  }
417
417
  }
418
- let fn: any
419
- const type = typeof value
420
- if (type === 'number') {
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 or size
428
- return fn || variant['...'] || variant['...size']
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 = '$body',
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
- const fontsParsed = languageContext
471
- ? getFontsForLanguage(conf.fontsParsed, languageContext)
472
- : conf.fontsParsed
473
- valOrVar = fontsParsed[fontFamily]?.[fontShorthand[key] || key]?.[value] || value
474
- hasSet = true
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
@@ -41,7 +41,13 @@ function getDefaultThemeProxied() {
41
41
  })
42
42
  }
43
43
 
44
- export const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {
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/useShallowSetState'
26
- export * from './helpers/getVariantExtras'
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/pseudoDescriptors'
32
- export * from './helpers/mergeProps'
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/themes'
38
- export * from './helpers/getThemeCSSRules'
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