@tamagui/web 1.39.7 → 1.39.9

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 (77) hide show
  1. package/dist/cjs/createComponent.js +42 -108
  2. package/dist/cjs/createComponent.js.map +2 -2
  3. package/dist/cjs/helpers/getSplitStyles.js +28 -25
  4. package/dist/cjs/helpers/getSplitStyles.js.map +1 -1
  5. package/dist/cjs/helpers/getThemeCSSRules.js +1 -1
  6. package/dist/cjs/helpers/getThemeCSSRules.js.map +1 -1
  7. package/dist/cjs/helpers/mergeVariants.js +69 -0
  8. package/dist/cjs/helpers/mergeVariants.js.map +6 -0
  9. package/dist/cjs/helpers/parseStaticConfig.js +40 -0
  10. package/dist/cjs/helpers/parseStaticConfig.js.map +6 -0
  11. package/dist/cjs/helpers/styledToStaticConfig.js +2 -0
  12. package/dist/cjs/helpers/styledToStaticConfig.js.map +6 -0
  13. package/dist/cjs/index.js +0 -2
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/styled.js +13 -4
  16. package/dist/cjs/styled.js.map +1 -1
  17. package/dist/cjs/views/Stack.js +3 -1
  18. package/dist/cjs/views/Stack.js.map +1 -1
  19. package/dist/cjs/views/Text.js.map +1 -1
  20. package/dist/cjs/views/Theme.js +3 -2
  21. package/dist/cjs/views/Theme.js.map +1 -1
  22. package/dist/cjs/views/View.js +3 -1
  23. package/dist/cjs/views/View.js.map +1 -1
  24. package/dist/esm/createComponent.js +43 -109
  25. package/dist/esm/createComponent.js.map +2 -2
  26. package/dist/esm/helpers/getSplitStyles.js +28 -25
  27. package/dist/esm/helpers/getSplitStyles.js.map +1 -1
  28. package/dist/esm/helpers/getThemeCSSRules.js +1 -1
  29. package/dist/esm/helpers/getThemeCSSRules.js.map +1 -1
  30. package/dist/esm/helpers/mergeVariants.js +45 -0
  31. package/dist/esm/helpers/mergeVariants.js.map +6 -0
  32. package/dist/esm/helpers/parseStaticConfig.js +16 -0
  33. package/dist/esm/helpers/parseStaticConfig.js.map +6 -0
  34. package/dist/esm/helpers/styledToStaticConfig.js +1 -0
  35. package/dist/esm/helpers/styledToStaticConfig.js.map +6 -0
  36. package/dist/esm/index.js +0 -2
  37. package/dist/esm/index.js.map +1 -1
  38. package/dist/esm/styled.js +13 -4
  39. package/dist/esm/styled.js.map +1 -1
  40. package/dist/esm/views/Stack.js +3 -1
  41. package/dist/esm/views/Stack.js.map +1 -1
  42. package/dist/esm/views/Text.js.map +1 -1
  43. package/dist/esm/views/Theme.js +4 -3
  44. package/dist/esm/views/Theme.js.map +1 -1
  45. package/dist/esm/views/View.js +3 -1
  46. package/dist/esm/views/View.js.map +1 -1
  47. package/package.json +9 -9
  48. package/src/createComponent.tsx +42 -141
  49. package/src/helpers/getSplitStyles.tsx +36 -60
  50. package/src/helpers/getThemeCSSRules.ts +1 -1
  51. package/src/helpers/mergeVariants.ts +59 -0
  52. package/src/helpers/parseStaticConfig.ts +14 -0
  53. package/src/index.ts +0 -1
  54. package/src/styled.tsx +16 -7
  55. package/src/types.tsx +5 -5
  56. package/src/views/Stack.tsx +3 -0
  57. package/src/views/Text.tsx +1 -1
  58. package/src/views/Theme.tsx +6 -3
  59. package/src/views/View.tsx +3 -0
  60. package/types/createComponent.d.ts +2 -2
  61. package/types/createComponent.d.ts.map +1 -1
  62. package/types/helpers/getSplitStyles.d.ts.map +1 -1
  63. package/types/helpers/mergeVariants.d.ts +3 -0
  64. package/types/helpers/mergeVariants.d.ts.map +1 -0
  65. package/types/helpers/parseStaticConfig.d.ts +3 -0
  66. package/types/helpers/parseStaticConfig.d.ts.map +1 -0
  67. package/types/helpers/styledToStaticConfig.d.ts +1 -0
  68. package/types/helpers/styledToStaticConfig.d.ts.map +1 -0
  69. package/types/index.d.ts +1 -1
  70. package/types/index.d.ts.map +1 -1
  71. package/types/styled.d.ts.map +1 -1
  72. package/types/types.d.ts +4 -4
  73. package/types/types.d.ts.map +1 -1
  74. package/types/views/Stack.d.ts.map +1 -1
  75. package/types/views/Theme.d.ts.map +1 -1
  76. package/types/views/View.d.ts.map +1 -1
  77. package/src/helpers/extendStaticConfig.ts +0 -93
@@ -6,7 +6,7 @@ import {
6
6
  isWeb,
7
7
  useIsomorphicLayoutEffect,
8
8
  } from '@tamagui/constants'
9
- import { stylePropsView, validStyles } from '@tamagui/helpers'
9
+ import { validStyles } from '@tamagui/helpers'
10
10
  import React, {
11
11
  Children,
12
12
  Fragment,
@@ -25,9 +25,9 @@ import { stackDefaultStyles } from './constants/constants'
25
25
  import { FontLanguageContext } from './contexts/FontLanguageContext'
26
26
  import { TextAncestorContext } from './contexts/TextAncestorContext'
27
27
  import { didGetVariableValue, setDidGetVariableValue } from './createVariable'
28
- import { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'
29
28
  import { useSplitStyles } from './helpers/getSplitStyles'
30
29
  import { mergeProps } from './helpers/mergeProps'
30
+ import { parseStaticConfig } from './helpers/parseStaticConfig'
31
31
  import { proxyThemeVariables } from './helpers/proxyThemeVariables'
32
32
  import { themeable } from './helpers/themeable'
33
33
  import { useShallowSetState } from './helpers/useShallowSetState'
@@ -43,7 +43,6 @@ import {
43
43
  SpacerProps,
44
44
  StaticConfig,
45
45
  StaticConfigParsed,
46
- StylableComponent,
47
46
  TamaguiComponent,
48
47
  TamaguiComponentEvents,
49
48
  TamaguiComponentState,
@@ -121,19 +120,26 @@ export function createComponent<
121
120
  ComponentPropTypes extends Object = {},
122
121
  Ref = TamaguiElement,
123
122
  BaseProps = never
124
- >(
125
- staticConfigIn: Partial<StaticConfig> | StaticConfigParsed,
126
- ParentComponent?: StylableComponent
127
- ) {
128
- const staticConfig = (() => {
129
- const next = extendStaticConfig(staticConfigIn, ParentComponent)
130
-
131
- if ('parsed' in next) {
132
- return next
133
- } else {
134
- return parseStaticConfig(next)
123
+ >(staticConfigIn: Partial<StaticConfig> | StaticConfigParsed) {
124
+ const staticConfig = parseStaticConfig(staticConfigIn)
125
+
126
+ onConfiguredOnce((conf) => {
127
+ // one time only setup
128
+ if (!tamaguiConfig) {
129
+ tamaguiConfig = conf
130
+
131
+ if (!initialTheme) {
132
+ const next = conf.themes[Object.keys(conf.themes)[0]]
133
+ initialTheme = proxyThemeVariables(next)
134
+ if (process.env.NODE_ENV === 'development') {
135
+ if (!initialTheme) {
136
+ // rome-ignore lint/nursery/noConsoleLog: <explanation>
137
+ console.log('Warning: Missing theme')
138
+ }
139
+ }
140
+ }
135
141
  }
136
- })()
142
+ })
137
143
 
138
144
  const {
139
145
  Component,
@@ -145,10 +151,19 @@ export function createComponent<
145
151
  } = staticConfig
146
152
 
147
153
  const defaultComponentClassName = `is_${staticConfig.componentName}`
148
- let defaultProps: any
149
- let defaultTag: string | undefined
154
+ const defaultProps = staticConfig.defaultProps
155
+
156
+ if (process.env.NODE_ENV === 'development' && staticConfigIn.defaultProps?.['debug']) {
157
+ if (process.env.IS_STATIC !== 'is_static') {
158
+ // rome-ignore lint/nursery/noConsoleLog: <explanation>
159
+ console.log(`🐛 [${staticConfig.componentName || 'Component'}]`, {
160
+ staticConfig,
161
+ defaultProps,
162
+ defaultPropsKeyOrder: Object.keys(defaultProps),
163
+ })
164
+ }
165
+ }
150
166
 
151
- // see onConfiguredOnce below which attaches a name then to this component
152
167
  const component = forwardRef<Ref, ComponentPropTypes>((propsIn: any, forwardedRef) => {
153
168
  if (process.env.TAMAGUI_TARGET === 'native') {
154
169
  // todo this could be moved to a cleaner location
@@ -302,11 +317,7 @@ export function createComponent<
302
317
 
303
318
  const isTaggable = !Component || typeof Component === 'string'
304
319
  // default to tag, fallback to component (when both strings)
305
- const element = isWeb
306
- ? isTaggable
307
- ? props.tag || defaultTag || Component
308
- : Component
309
- : Component
320
+ const element = isWeb ? (isTaggable ? props.tag || Component : Component) : Component
310
321
 
311
322
  const BaseTextComponent = BaseText || element || 'span'
312
323
  const BaseViewComponent = BaseView || element || (hasTextAncestor ? 'span' : 'div')
@@ -368,10 +379,8 @@ export function createComponent<
368
379
  const type = isAnimatedReactNative ? '(animated)' : isReactNative ? '(rnw)' : ''
369
380
  const dataIs = propsIn['data-is'] || ''
370
381
  const banner = `${name}${dataIs ? ` ${dataIs}` : ''} ${type} id ${id}`
371
- const parentsLog = (conf: StaticConfig) =>
372
- conf.parentNames ? ` (${conf.parentNames?.join(' > ')})` : ''
373
382
  console.group(
374
- `%c ${banner}${parentsLog(staticConfig)} (unmounted: ${state.unmounted})`,
383
+ `%c ${banner} (unmounted: ${state.unmounted})`,
375
384
  'background: yellow;'
376
385
  )
377
386
  if (!isServer) {
@@ -927,93 +936,22 @@ export function createComponent<
927
936
  component.displayName = staticConfig.componentName
928
937
  }
929
938
 
930
- onConfiguredOnce((conf) => {
931
- // one time only setup
932
- if (!tamaguiConfig) {
933
- tamaguiConfig = conf
934
-
935
- if (!initialTheme) {
936
- const next = conf.themes[Object.keys(conf.themes)[0]]
937
- initialTheme = proxyThemeVariables(next)
938
- if (process.env.NODE_ENV === 'development') {
939
- if (!initialTheme) {
940
- // rome-ignore lint/nursery/noConsoleLog: <explanation>
941
- console.log('Warning: Missing theme')
942
- }
943
- }
944
- }
945
- }
946
-
947
- // HOC doesn't use defaultProps those already come in below
948
- let defaultPropsIn = staticConfig.defaultProps || {}
949
-
950
- // because we run createTamagui after styled() defs, have to do some work here
951
- // gather defaults props one time and merge downwards
952
- // find last unprocessed and process
953
- const parentNames = [...(staticConfig.parentNames || []), staticConfig.componentName]
954
-
955
- if (tamaguiConfig.defaultProps && parentNames && staticConfig.componentName) {
956
- defaultPropsIn = mergeConfigDefaultProps(
957
- staticConfig.componentName,
958
- defaultPropsIn,
959
- tamaguiConfig.defaultProps,
960
- parentNames,
961
- tamaguiConfig
962
- )
963
- }
964
-
965
- const debug = defaultPropsIn['debug']
966
-
967
- if (defaultPropsIn.tag) {
968
- defaultTag = defaultPropsIn.tag
969
- }
970
-
971
- const { name, variants, defaultVariants, ...restProps } = defaultPropsIn
972
-
973
- defaultProps = restProps
974
-
975
- if (staticConfig.isText && !defaultProps.fontFamily && conf.defaultFont) {
976
- defaultProps.fontFamily = `$${conf.defaultFont}`
977
- }
978
-
979
- // add debug logs
980
- if (process.env.NODE_ENV === 'development' && debug) {
981
- if (process.env.IS_STATIC !== 'is_static') {
982
- // rome-ignore lint/nursery/noConsoleLog: <explanation>
983
- console.log(`🐛 [${staticConfig.componentName || 'Component'}]`, {
984
- staticConfig,
985
- defaultPropsIn,
986
- defaultProps,
987
- defaultPropsKeyOrder: Object.keys(defaultProps),
988
- defaultTag,
989
- })
990
- }
991
- }
992
- })
993
-
994
939
  type ComponentType = TamaguiComponent<ComponentPropTypes, Ref, BaseProps, {}>
995
940
 
996
941
  let res: ComponentType = component as any
997
942
 
998
- if (staticConfigIn.memo) {
943
+ if (staticConfig.memo) {
999
944
  res = memo(res) as any
1000
945
  }
1001
946
 
1002
- // is this necessary?
1003
- res.staticConfig = {
1004
- validStyles: staticConfig.validStyles || stylePropsView,
1005
- ...staticConfig,
1006
- }
947
+ res.staticConfig = staticConfig
1007
948
 
1008
949
  function extendStyledConfig() {
1009
- return extendStaticConfig(
1010
- {
1011
- ...staticConfig,
1012
- neverFlatten: true,
1013
- isHOC: true,
1014
- },
1015
- res
1016
- )
950
+ return {
951
+ ...staticConfig,
952
+ neverFlatten: true,
953
+ isHOC: true,
954
+ }
1017
955
  }
1018
956
 
1019
957
  function extractable(Component: any) {
@@ -1228,43 +1166,6 @@ function isUnspaced(child: React.ReactNode) {
1228
1166
 
1229
1167
  const DefaultProps = new Map()
1230
1168
 
1231
- function mergeConfigDefaultProps(
1232
- name: string,
1233
- props: Record<string, any>,
1234
- configDefaults: Record<string, Object>,
1235
- parentNames: (string | undefined)[],
1236
- conf: TamaguiInternalConfig
1237
- ) {
1238
- const len = parentNames.length
1239
- let prev
1240
-
1241
- for (let i = 0; i < len; i++) {
1242
- const n = parentNames[i]
1243
- if (!n) continue
1244
- if (DefaultProps.has(n)) {
1245
- prev = DefaultProps.get(n)
1246
- continue
1247
- }
1248
- const props = configDefaults[n]
1249
- if (!props) {
1250
- if (prev) {
1251
- DefaultProps.set(n, prev)
1252
- }
1253
- continue
1254
- }
1255
- prev = mergeProps(prev || {}, props, false, conf.inverseShorthands)[0]
1256
- DefaultProps.set(n, prev)
1257
- }
1258
-
1259
- // overwrite the user defined defaults on top of internal defined defaults
1260
- const ourDefaultsMerged = DefaultProps.get(name)
1261
- if (ourDefaultsMerged) {
1262
- return mergeProps(props, ourDefaultsMerged, false, conf.inverseShorthands)[0]
1263
- }
1264
-
1265
- return props
1266
- }
1267
-
1268
1169
  const AbsoluteFill: any = createComponent({
1269
1170
  defaultProps: {
1270
1171
  ...stackDefaultStyles,
@@ -214,6 +214,7 @@ export const getSplitStyles: StyleSplitter = (
214
214
 
215
215
  if (keyInit === 'className') continue // handled above
216
216
  if (keyInit in usedKeys) continue
217
+ if (keyInit in skipProps && !staticConfig.isHOC) continue
217
218
 
218
219
  // TODO this is duplicated! but seems to be fixing some bugs so leaving got now
219
220
  if (process.env.TAMAGUI_TARGET === 'web') {
@@ -290,12 +291,6 @@ export const getSplitStyles: StyleSplitter = (
290
291
  }
291
292
  }
292
293
 
293
- if (!staticConfig.isHOC) {
294
- if (keyInit in skipProps) {
295
- continue
296
- }
297
- }
298
-
299
294
  if (keyInit === 'dataSet') {
300
295
  for (const keyInit in valInit) {
301
296
  viewProps[`data-${hyphenate(keyInit)}`] = valInit[keyInit]
@@ -625,6 +620,20 @@ export const getSplitStyles: StyleSplitter = (
625
620
  const isEnter = descriptor.name === 'enter'
626
621
  const isExit = descriptor.name === 'exit'
627
622
 
623
+ // dev-time warning that helps clear confusion around need for animation when using enter/exit style
624
+ if (
625
+ process.env.NODE_ENV === 'development' &&
626
+ !state.isAnimated &&
627
+ !state.unmounted &&
628
+ (isEnter || isExit)
629
+ ) {
630
+ console.warn(
631
+ `No animation prop given to component ${
632
+ staticConfig.componentName || ''
633
+ } with enterStyle / exitStyle, these styles will be ignore.`
634
+ )
635
+ }
636
+
628
637
  // don't continue here on isEnter && !state.unmounted because we need to merge defaults
629
638
  if (!descriptor || (isExit && !state.isExiting)) {
630
639
  if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
@@ -1053,40 +1062,6 @@ export const getSplitStyles: StyleSplitter = (
1053
1062
  return result
1054
1063
  }
1055
1064
 
1056
- // not ever hitting cache?
1057
- // const cache = createChainedWeakCache()
1058
- // export const getSplitStyles: StyleSplitter = (
1059
- // props,
1060
- // staticConfig,
1061
- // theme,
1062
- // state,
1063
- // parentSplitStyles,
1064
- // languageContext,
1065
- // elementType,
1066
- // debug
1067
- // ) => {
1068
- // const cacheProps = [props, theme, state]
1069
- // const cached = cache.get(cacheProps)
1070
- // if (cached) {
1071
- // return cached as any
1072
- // }
1073
-
1074
- // const res = getSplitStylesWithoutMemo(
1075
- // props,
1076
- // staticConfig,
1077
- // theme,
1078
- // state,
1079
- // parentSplitStyles,
1080
- // languageContext,
1081
- // elementType,
1082
- // debug
1083
- // )
1084
-
1085
- // cache.set(cacheProps, res)
1086
-
1087
- // return res
1088
- // }
1089
-
1090
1065
  function mergeClassName(
1091
1066
  transforms: Record<string, any[]>,
1092
1067
  classNames: Record<string, string>,
@@ -1296,16 +1271,17 @@ const mapTransformKeys = {
1296
1271
  }
1297
1272
 
1298
1273
  const skipProps = {
1299
- animation: true,
1300
- space: true,
1301
- animateOnly: true,
1302
- debug: true,
1303
- componentName: true,
1304
- tag: true,
1274
+ animation: 1,
1275
+ space: 1,
1276
+ animateOnly: 1,
1277
+ debug: 1,
1278
+ componentName: 1,
1279
+ disableOptimization: 1,
1280
+ tag: 1,
1305
1281
  }
1306
1282
 
1307
1283
  if (process.env.NODE_ENV === 'test') {
1308
- skipProps['data-test-renders'] = true
1284
+ skipProps['data-test-renders'] = 1
1309
1285
  }
1310
1286
 
1311
1287
  const IS_STATIC = process.env.IS_STATIC === 'is_static'
@@ -1313,22 +1289,22 @@ const IS_STATIC = process.env.IS_STATIC === 'is_static'
1313
1289
  // native only skips
1314
1290
  if (process.env.TAMAGUI_TARGET === 'native') {
1315
1291
  Object.assign(skipProps, {
1316
- whiteSpace: true,
1317
- wordWrap: true,
1318
- textOverflow: true,
1319
- textDecorationDistance: true,
1320
- cursor: true,
1321
- contain: true,
1322
- boxSizing: true,
1323
- boxShadow: true,
1324
- outlineStyle: true,
1325
- outlineOffset: true,
1326
- outlineWidth: true,
1327
- outlineColor: true,
1292
+ whiteSpace: 1,
1293
+ wordWrap: 1,
1294
+ textOverflow: 1,
1295
+ textDecorationDistance: 1,
1296
+ cursor: 1,
1297
+ contain: 1,
1298
+ boxSizing: 1,
1299
+ boxShadow: 1,
1300
+ outlineStyle: 1,
1301
+ outlineOffset: 1,
1302
+ outlineWidth: 1,
1303
+ outlineColor: 1,
1328
1304
  })
1329
1305
  } else {
1330
1306
  Object.assign(skipProps, {
1331
- elevationAndroid: true,
1307
+ elevationAndroid: 1,
1332
1308
  })
1333
1309
  }
1334
1310
 
@@ -104,7 +104,7 @@ export function getThemeCSSRules({
104
104
  }
105
105
  }
106
106
 
107
- const selectors = [...selectorsSet]
107
+ const selectors = [...selectorsSet].sort((a, b) => a.localeCompare(b))
108
108
 
109
109
  // only do our :root attach if it's not light/dark - not support sub themes on root saves a lot of effort/size
110
110
  // this isBaseTheme logic could probably be done more efficiently above
@@ -0,0 +1,59 @@
1
+ import type { GenericVariantDefinitions } from '../types'
2
+
3
+ // deep merge variants
4
+ // except for functions which override any parents
5
+
6
+ export const mergeVariants = (
7
+ parentVariants: GenericVariantDefinitions,
8
+ ourVariants: GenericVariantDefinitions
9
+ ) => {
10
+ const variants = {}
11
+
12
+ for (const key in ourVariants) {
13
+ const parentVariant = parentVariants?.[key]
14
+ const ourVariant = ourVariants[key]
15
+
16
+ // do some early checks to avoid bad merges
17
+ if (!parentVariant || typeof ourVariant === 'function') {
18
+ variants[key] = ourVariant
19
+ continue
20
+ }
21
+
22
+ // do some early checks to avoid bad merges
23
+ if (parentVariant && !ourVariant) {
24
+ variants[key] = parentVariant[key]
25
+ continue
26
+ }
27
+
28
+ variants[key] = {}
29
+
30
+ for (const subKey in ourVariant) {
31
+ const val = ourVariant[subKey]
32
+ const parentVal = parentVariant?.[subKey]
33
+ if (typeof val === 'function') {
34
+ variants[key][subKey] = val
35
+ } else if (!parentVal || typeof parentVal === 'function') {
36
+ variants[key][subKey] = val
37
+ } else {
38
+ variants[key][subKey] = {
39
+ // keep order
40
+ ...parentVal,
41
+ ...val,
42
+ }
43
+ }
44
+ }
45
+
46
+ // merge parent variant keys that are superset
47
+ if (parentVariant) {
48
+ variants[key] = {
49
+ ...parentVariant,
50
+ ...variants[key],
51
+ }
52
+ }
53
+ }
54
+
55
+ return {
56
+ ...parentVariants,
57
+ ...variants,
58
+ }
59
+ }
@@ -0,0 +1,14 @@
1
+ import type { StaticConfig, StaticConfigParsed } from '../types'
2
+ import { createPropMapper } from './createPropMapper'
3
+
4
+ export const parseStaticConfig = (config: Partial<StaticConfig>): StaticConfigParsed => {
5
+ const parsed = {
6
+ defaultProps: {},
7
+ ...config,
8
+ parsed: true,
9
+ } as const
10
+ return {
11
+ ...parsed,
12
+ propMapper: createPropMapper(parsed as StaticConfigParsed),
13
+ }
14
+ }
package/src/index.ts CHANGED
@@ -16,7 +16,6 @@ export {
16
16
  getConfig,
17
17
  getThemes,
18
18
  getTokens,
19
- onConfiguredOnce,
20
19
  updateConfig,
21
20
  getToken,
22
21
  getTokenValue,
package/src/styled.tsx CHANGED
@@ -2,7 +2,7 @@ import { stylePropsAll } from '@tamagui/helpers'
2
2
 
3
3
  import { createComponent } from './createComponent'
4
4
  import { StyledContext } from './helpers/createStyledContext'
5
- import { mergeVariants } from './helpers/extendStaticConfig'
5
+ import { mergeVariants } from './helpers/mergeVariants'
6
6
  import { getReactNativeConfig } from './setupReactNative'
7
7
  import type {
8
8
  GetProps,
@@ -13,7 +13,6 @@ import type {
13
13
  StaticConfig,
14
14
  StylableComponent,
15
15
  TamaguiComponent,
16
- TamaguiElement,
17
16
  VariantDefinitions,
18
17
  VariantSpreadFunction,
19
18
  } from './types'
@@ -74,8 +73,7 @@ export function styled<
74
73
  }
75
74
  }
76
75
 
77
- const parentStaticConfig =
78
- 'staticConfig' in ComponentIn ? (ComponentIn.staticConfig as StaticConfig) : null
76
+ const parentStaticConfig = ComponentIn['staticConfig'] as StaticConfig | undefined
79
77
 
80
78
  const isPlainStyledComponent =
81
79
  !!parentStaticConfig &&
@@ -113,6 +111,10 @@ export function styled<
113
111
  ...defaultVariants,
114
112
  }
115
113
  }
114
+
115
+ if (parentStaticConfig.variants) {
116
+ variants = mergeVariants(parentStaticConfig.variants, variants)
117
+ }
116
118
  }
117
119
 
118
120
  if (defaultVariants) {
@@ -123,8 +125,6 @@ export function styled<
123
125
  }
124
126
 
125
127
  if (parentStaticConfig?.isHOC) {
126
- variants = mergeVariants(parentStaticConfig.variants, variants)
127
-
128
128
  // if HOC we map name => componentName as we have a difference in how we name prop vs styled() there
129
129
  if (name) {
130
130
  // @ts-ignore
@@ -135,13 +135,22 @@ export function styled<
135
135
  const isText = Boolean(
136
136
  staticExtractionOptions?.isText || parentStaticConfig?.isText
137
137
  )
138
+
138
139
  const acceptsClassName =
139
140
  acceptsClassNameProp ??
140
141
  (isPlainStyledComponent ||
141
142
  isReactNative ||
142
143
  (parentStaticConfig?.isHOC && parentStaticConfig?.acceptsClassName))
143
144
 
145
+ if (process.env.NODE_ENV === 'development') {
146
+ // dont inherit the debug prop so we can debug specific styled() more accurately
147
+ if (parentStaticConfig?.defaultProps?.debug && !options.debug) {
148
+ delete defaultProps.debug
149
+ }
150
+ }
151
+
144
152
  const conf: Partial<StaticConfig> = {
153
+ ...parentStaticConfig,
145
154
  ...staticExtractionOptions,
146
155
  ...(!isPlainStyledComponent && {
147
156
  Component,
@@ -169,7 +178,7 @@ export function styled<
169
178
  }
170
179
  })()
171
180
 
172
- const component = createComponent(staticConfigProps || {}, Component)
181
+ const component = createComponent(staticConfigProps || {})
173
182
 
174
183
  // get parent props without pseudos and medias so we can rebuild both with new variants
175
184
  // get parent props without pseudos and medias so we can rebuild both with new variants
package/src/types.tsx CHANGED
@@ -157,6 +157,11 @@ export type TamaguiComponentPropsBase = {
157
157
  tabIndex?: string | number
158
158
  role?: Role
159
159
 
160
+ /**
161
+ * Disable all compiler optimization
162
+ */
163
+ disableOptimization?: boolean
164
+
160
165
  /**
161
166
  * Forces the pseudo style state to be on
162
167
  */
@@ -1388,11 +1393,6 @@ type StaticConfigBase = StaticConfigPublic & {
1388
1393
  */
1389
1394
  memo?: boolean
1390
1395
 
1391
- /**
1392
- * Used insternally to attach default props to names
1393
- */
1394
- parentNames?: string[]
1395
-
1396
1396
  /**
1397
1397
  * By default if styled() doesn't recognize a parent Tamagui compoent or specific react-native views,
1398
1398
  * it will assume the passed in component only accepts style={} for react-native compatibility.
@@ -1,3 +1,5 @@
1
+ import { validStyles } from '@tamagui/helpers'
2
+
1
3
  import { stackDefaultStyles } from '../constants/constants'
2
4
  import { createComponent } from '../createComponent'
3
5
  import type { StackProps, StackPropsBase, TamaguiElement } from '../types'
@@ -8,6 +10,7 @@ export const Stack = createComponent<StackProps, TamaguiElement, StackPropsBase>
8
10
  ...stackDefaultStyles,
9
11
  flexDirection: 'column',
10
12
  },
13
+ validStyles,
11
14
  })
12
15
 
13
16
  // test types
@@ -1,4 +1,4 @@
1
- import { stylePropsTextOnly, validStyles } from '@tamagui/helpers'
1
+ import { stylePropsText, stylePropsTextOnly, validStyles } from '@tamagui/helpers'
2
2
 
3
3
  import { createComponent } from '../createComponent'
4
4
  import { TamaguiTextElement, TextProps, TextPropsBase } from '../types'
@@ -1,8 +1,9 @@
1
1
  import { isWeb } from '@tamagui/constants'
2
- import React, { Children, cloneElement, isValidElement } from 'react'
2
+ import React, { Children, cloneElement, isValidElement, useMemo } from 'react'
3
3
 
4
4
  import { variableToString } from '../createVariable'
5
5
  import { ThemeManagerContext } from '../helpers/ThemeManagerContext'
6
+ import { useMemoDebug } from '../hooks/useMemoDebug'
6
7
  import { useServerRef } from '../hooks/useServerHooks'
7
8
  import { ChangedThemeResponse, useChangeThemeEffect } from '../hooks/useTheme'
8
9
  import type { DebugProp, ThemeProps } from '../types'
@@ -57,8 +58,10 @@ export function useThemedChildren(
57
58
  const shouldRenderChildrenWithTheme =
58
59
  isNewTheme || hasEverThemed.current || forceClassName || isRoot
59
60
 
61
+ const childrenMemo = useMemo(() => children, [children])
62
+
60
63
  if (!shouldRenderChildrenWithTheme) {
61
- return children
64
+ return childrenMemo
62
65
  }
63
66
 
64
67
  // be sure to memoize shouldReset to avoid reparenting
@@ -81,7 +84,7 @@ export function useThemedChildren(
81
84
 
82
85
  const elementsWithContext = (
83
86
  <ThemeManagerContext.Provider value={themeManager}>
84
- {children}
87
+ {childrenMemo}
85
88
  </ThemeManagerContext.Provider>
86
89
  )
87
90
 
@@ -1,6 +1,9 @@
1
+ import { validStyles } from '@tamagui/helpers'
2
+
1
3
  import { createComponent } from '../createComponent'
2
4
  import type { StackProps, StackPropsBase, TamaguiElement } from '../types'
3
5
 
4
6
  export const View = createComponent<StackProps, TamaguiElement, StackPropsBase>({
5
7
  acceptsClassName: true,
8
+ validStyles,
6
9
  })
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
- import { DebugProp, SpaceDirection, SpaceValue, SpacerProps, StaticConfig, StaticConfigParsed, StylableComponent, TamaguiComponent, TamaguiComponentState, TamaguiElement } from './types';
2
+ import { DebugProp, SpaceDirection, SpaceValue, SpacerProps, StaticConfig, StaticConfigParsed, TamaguiComponent, TamaguiComponentState, TamaguiElement } from './types';
3
3
  export declare const defaultComponentState: TamaguiComponentState;
4
4
  export declare const mouseUps: Set<Function>;
5
- export declare function createComponent<ComponentPropTypes extends Object = {}, Ref = TamaguiElement, BaseProps = never>(staticConfigIn: Partial<StaticConfig> | StaticConfigParsed, ParentComponent?: StylableComponent): TamaguiComponent<ComponentPropTypes, Ref, BaseProps, {}>;
5
+ export declare function createComponent<ComponentPropTypes extends Object = {}, Ref = TamaguiElement, BaseProps = never>(staticConfigIn: Partial<StaticConfig> | StaticConfigParsed): TamaguiComponent<ComponentPropTypes, Ref, BaseProps, {}>;
6
6
  export declare const Unspaced: {
7
7
  (props: {
8
8
  children?: any;
@@ -1 +1 @@
1
- {"version":3,"file":"createComponent.d.ts","sourceRoot":"","sources":["../src/createComponent.tsx"],"names":[],"mappings":"AASA,OAAO,KAWN,MAAM,OAAO,CAAA;AAkBd,OAAO,EACL,SAAS,EACT,cAAc,EACd,UAAU,EACV,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAEhB,qBAAqB,EACrB,cAAc,EAIf,MAAM,SAAS,CAAA;AAoBhB,eAAO,MAAM,qBAAqB,EAAE,qBAMnC,CAAA;AAmBD,eAAO,MAAM,QAAQ,eAAsB,CAAA;AAqB3C,wBAAgB,eAAe,CAC7B,kBAAkB,SAAS,MAAM,GAAG,EAAE,EACtC,GAAG,GAAG,cAAc,EACpB,SAAS,GAAG,KAAK,EAEjB,cAAc,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,kBAAkB,EAC1D,eAAe,CAAC,EAAE,iBAAiB,4DAo5BpC;AAGD,eAAO,MAAM,QAAQ;YAAW;QAAE,QAAQ,CAAC,EAAE,GAAG,CAAA;KAAE;;CAAmB,CAAA;AAMrE,eAAO,MAAM,MAAM,0DA8CjB,CAAA;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC5B,SAAS,CAAC,EAAE,cAAc,CAAA;IAC1B,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAA;CAClB,CAAA;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,mBAkGxD"}
1
+ {"version":3,"file":"createComponent.d.ts","sourceRoot":"","sources":["../src/createComponent.tsx"],"names":[],"mappings":"AASA,OAAO,KAWN,MAAM,OAAO,CAAA;AAkBd,OAAO,EACL,SAAS,EACT,cAAc,EACd,UAAU,EACV,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAEhB,qBAAqB,EACrB,cAAc,EAIf,MAAM,SAAS,CAAA;AAoBhB,eAAO,MAAM,qBAAqB,EAAE,qBAMnC,CAAA;AAmBD,eAAO,MAAM,QAAQ,eAAsB,CAAA;AAqB3C,wBAAgB,eAAe,CAC7B,kBAAkB,SAAS,MAAM,GAAG,EAAE,EACtC,GAAG,GAAG,cAAc,EACpB,SAAS,GAAG,KAAK,EACjB,cAAc,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,kBAAkB,4DAy1B3D;AAGD,eAAO,MAAM,QAAQ;YAAW;QAAE,QAAQ,CAAC,EAAE,GAAG,CAAA;KAAE;;CAAmB,CAAA;AAMrE,eAAO,MAAM,MAAM,0DA8CjB,CAAA;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC5B,SAAS,CAAC,EAAE,cAAc,CAAA;IAC1B,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAA;CAClB,CAAA;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,mBAkGxD"}