@tamagui/web 1.90.15 → 1.91.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 (100) hide show
  1. package/dist/cjs/config.js +4 -1
  2. package/dist/cjs/config.js.map +1 -1
  3. package/dist/cjs/config.native.js +2 -1
  4. package/dist/cjs/config.native.js.map +1 -1
  5. package/dist/cjs/createComponent.js +29 -16
  6. package/dist/cjs/createComponent.js.map +1 -1
  7. package/dist/cjs/createComponent.native.js +61 -45
  8. package/dist/cjs/createComponent.native.js.map +2 -2
  9. package/dist/cjs/defaultComponentState.js +3 -1
  10. package/dist/cjs/defaultComponentState.js.map +1 -1
  11. package/dist/cjs/defaultComponentState.native.js +3 -1
  12. package/dist/cjs/defaultComponentState.native.js.map +2 -2
  13. package/dist/cjs/helpers/createShallowSetState.js +8 -4
  14. package/dist/cjs/helpers/createShallowSetState.js.map +1 -1
  15. package/dist/cjs/helpers/createShallowSetState.native.js +9 -5
  16. package/dist/cjs/helpers/createShallowSetState.native.js.map +2 -2
  17. package/dist/cjs/helpers/getSplitStyles.js +22 -7
  18. package/dist/cjs/helpers/getSplitStyles.js.map +1 -1
  19. package/dist/cjs/helpers/getSplitStyles.native.js +24 -31
  20. package/dist/cjs/helpers/getSplitStyles.native.js.map +2 -2
  21. package/dist/cjs/helpers/getStylesAtomic.js +2 -2
  22. package/dist/cjs/helpers/getStylesAtomic.js.map +1 -1
  23. package/dist/cjs/helpers/propMapper.js +1 -1
  24. package/dist/cjs/helpers/propMapper.js.map +1 -1
  25. package/dist/cjs/helpers/propMapper.native.js +2 -2
  26. package/dist/cjs/helpers/propMapper.native.js.map +2 -2
  27. package/dist/cjs/helpers/pseudoDescriptors.js +13 -1
  28. package/dist/cjs/helpers/pseudoDescriptors.js.map +1 -1
  29. package/dist/cjs/helpers/pseudoDescriptors.native.js +13 -1
  30. package/dist/cjs/helpers/pseudoDescriptors.native.js.map +2 -2
  31. package/dist/cjs/styled.js.map +1 -1
  32. package/dist/cjs/styled.native.js.map +1 -1
  33. package/dist/esm/config.js +4 -1
  34. package/dist/esm/config.js.map +1 -1
  35. package/dist/esm/config.mjs +3 -1
  36. package/dist/esm/config.native.js +2 -1
  37. package/dist/esm/config.native.js.map +1 -1
  38. package/dist/esm/createComponent.js +29 -16
  39. package/dist/esm/createComponent.js.map +1 -1
  40. package/dist/esm/createComponent.mjs +33 -20
  41. package/dist/esm/createComponent.native.js +61 -45
  42. package/dist/esm/createComponent.native.js.map +2 -2
  43. package/dist/esm/defaultComponentState.js +3 -1
  44. package/dist/esm/defaultComponentState.js.map +1 -1
  45. package/dist/esm/defaultComponentState.mjs +3 -1
  46. package/dist/esm/defaultComponentState.native.js +3 -1
  47. package/dist/esm/defaultComponentState.native.js.map +2 -2
  48. package/dist/esm/helpers/createShallowSetState.js +8 -4
  49. package/dist/esm/helpers/createShallowSetState.js.map +1 -1
  50. package/dist/esm/helpers/createShallowSetState.mjs +8 -6
  51. package/dist/esm/helpers/createShallowSetState.native.js +9 -5
  52. package/dist/esm/helpers/createShallowSetState.native.js.map +2 -2
  53. package/dist/esm/helpers/getSplitStyles.js +22 -7
  54. package/dist/esm/helpers/getSplitStyles.js.map +1 -1
  55. package/dist/esm/helpers/getSplitStyles.mjs +17 -4
  56. package/dist/esm/helpers/getSplitStyles.native.js +24 -31
  57. package/dist/esm/helpers/getSplitStyles.native.js.map +2 -2
  58. package/dist/esm/helpers/getStylesAtomic.js +2 -2
  59. package/dist/esm/helpers/getStylesAtomic.js.map +1 -1
  60. package/dist/esm/helpers/getStylesAtomic.mjs +3 -2
  61. package/dist/esm/helpers/propMapper.js +1 -1
  62. package/dist/esm/helpers/propMapper.js.map +1 -1
  63. package/dist/esm/helpers/propMapper.mjs +1 -1
  64. package/dist/esm/helpers/propMapper.native.js +2 -2
  65. package/dist/esm/helpers/propMapper.native.js.map +2 -2
  66. package/dist/esm/helpers/pseudoDescriptors.js +13 -1
  67. package/dist/esm/helpers/pseudoDescriptors.js.map +1 -1
  68. package/dist/esm/helpers/pseudoDescriptors.mjs +13 -1
  69. package/dist/esm/helpers/pseudoDescriptors.native.js +13 -1
  70. package/dist/esm/helpers/pseudoDescriptors.native.js.map +2 -2
  71. package/dist/esm/styled.js.map +1 -1
  72. package/dist/esm/styled.native.js.map +1 -1
  73. package/package.json +11 -11
  74. package/src/config.ts +2 -1
  75. package/src/createComponent.tsx +137 -101
  76. package/src/defaultComponentState.tsx +2 -0
  77. package/src/helpers/createShallowSetState.tsx +14 -8
  78. package/src/helpers/getSplitStyles.tsx +27 -7
  79. package/src/helpers/getStylesAtomic.ts +9 -4
  80. package/src/helpers/propMapper.ts +1 -1
  81. package/src/helpers/pseudoDescriptors.ts +18 -1
  82. package/src/interfaces/TamaguiComponentState.tsx +2 -0
  83. package/src/styled.tsx +15 -4
  84. package/src/types.tsx +11 -10
  85. package/types/config.d.ts +1 -1
  86. package/types/config.d.ts.map +1 -1
  87. package/types/createComponent.d.ts.map +1 -1
  88. package/types/defaultComponentState.d.ts.map +1 -1
  89. package/types/helpers/createShallowSetState.d.ts +2 -2
  90. package/types/helpers/createShallowSetState.d.ts.map +1 -1
  91. package/types/helpers/getSplitStyles.d.ts.map +1 -1
  92. package/types/helpers/getStylesAtomic.d.ts.map +1 -1
  93. package/types/helpers/pseudoDescriptors.d.ts +13 -1
  94. package/types/helpers/pseudoDescriptors.d.ts.map +1 -1
  95. package/types/interfaces/TamaguiComponentState.d.ts +2 -0
  96. package/types/interfaces/TamaguiComponentState.d.ts.map +1 -1
  97. package/types/styled.d.ts +2 -2
  98. package/types/styled.d.ts.map +1 -1
  99. package/types/types.d.ts +11 -6
  100. package/types/types.d.ts.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/web",
3
- "version": "1.90.15",
3
+ "version": "1.91.0",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -27,20 +27,20 @@
27
27
  "reset.css"
28
28
  ],
29
29
  "dependencies": {
30
- "@tamagui/compose-refs": "1.90.15",
31
- "@tamagui/constants": "1.90.15",
32
- "@tamagui/helpers": "1.90.15",
33
- "@tamagui/normalize-css-color": "1.90.15",
34
- "@tamagui/timer": "1.90.15",
35
- "@tamagui/types": "1.90.15",
36
- "@tamagui/use-did-finish-ssr": "1.90.15",
37
- "@tamagui/use-event": "1.90.15",
38
- "@tamagui/use-force-update": "1.90.15",
30
+ "@tamagui/compose-refs": "1.91.0",
31
+ "@tamagui/constants": "1.91.0",
32
+ "@tamagui/helpers": "1.91.0",
33
+ "@tamagui/normalize-css-color": "1.91.0",
34
+ "@tamagui/timer": "1.91.0",
35
+ "@tamagui/types": "1.91.0",
36
+ "@tamagui/use-did-finish-ssr": "1.91.0",
37
+ "@tamagui/use-event": "1.91.0",
38
+ "@tamagui/use-force-update": "1.91.0",
39
39
  "react": "^18.2.0",
40
40
  "react-dom": "^18.2.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@tamagui/build": "1.90.15",
43
+ "@tamagui/build": "1.91.0",
44
44
  "@testing-library/react": "^14.0.0",
45
45
  "csstype": "^3.0.10",
46
46
  "typescript": "^5.3.3",
package/src/config.ts CHANGED
@@ -71,7 +71,8 @@ export const getToken = (value: Token, group?: keyof Tokens, useVariable = isWeb
71
71
  return useVariable ? token?.variable : token?.val
72
72
  }
73
73
 
74
- export const getTokenValue = (value: Token, group?: keyof Tokens) => {
74
+ export const getTokenValue = (value: Token | 'unset' | 'auto', group?: keyof Tokens) => {
75
+ if (value === 'unset' || value === 'auto') return
75
76
  return getToken(value, group, false)
76
77
  }
77
78
 
@@ -333,7 +333,9 @@ export function createComponent<
333
333
  // conditional but if ever true stays true
334
334
  // [animated, inversed]
335
335
  // HOOK
336
- const stateRef = useRef<TamaguiComponentStateRef>({})
336
+ const stateRef = useRef<TamaguiComponentStateRef>({
337
+ handleFocusVisible: true,
338
+ })
337
339
  if (process.env.NODE_ENV === 'development' && time) time`stateref`
338
340
 
339
341
  /**
@@ -400,15 +402,33 @@ export function createComponent<
400
402
  : defaultComponentState
401
403
  : defaultComponentStateMounted
402
404
 
405
+ // will be nice to deprecate half of these:
406
+ const disabled =
407
+ props.disabled ||
408
+ props.accessibilityState?.disabled ||
409
+ props['aria-disabled'] ||
410
+ // @ts-expect-error (comes from core)
411
+ props.accessibilityDisabled ||
412
+ false
413
+
414
+ if (disabled != null) {
415
+ initialState.disabled = disabled
416
+ }
417
+
403
418
  // HOOK
404
419
  const states = useState<TamaguiComponentState>(initialState)
405
420
 
406
421
  const state = props.forceStyle
407
422
  ? { ...states[0], [props.forceStyle]: true }
408
423
  : states[0]
409
-
410
424
  const setState = states[1]
411
- let setStateShallow = createShallowSetState(setState, debugProp)
425
+
426
+ // immediately update disabled state
427
+ if (disabled !== state.disabled) {
428
+ setState({ ...state, disabled })
429
+ }
430
+
431
+ let setStateShallow = createShallowSetState(setState, disabled, debugProp)
412
432
 
413
433
  if (isHydrated && state.unmounted === 'should-enter') {
414
434
  state.unmounted = true
@@ -491,7 +511,6 @@ export function createComponent<
491
511
  if (process.env.NODE_ENV === 'development' && time) time`use-state`
492
512
 
493
513
  const hasTextAncestor = !!(isWeb && isText ? componentContext.inText : false)
494
- const isDisabled = props.disabled ?? props.accessibilityState?.disabled
495
514
 
496
515
  if (process.env.NODE_ENV === 'development' && time) time`use-context`
497
516
 
@@ -748,11 +767,6 @@ export function createComponent<
748
767
 
749
768
  if (process.env.NODE_ENV === 'development' && time) time`destructure`
750
769
 
751
- const disabled =
752
- props.accessibilityState?.disabled ||
753
- // @ts-expect-error (comes from core)
754
- props.accessibilityDisabled
755
-
756
770
  if (groupName) {
757
771
  nonTamaguiProps.onLayout = composeEventHandlers(
758
772
  nonTamaguiProps.onLayout,
@@ -820,6 +834,10 @@ export function createComponent<
820
834
  const shouldEnter = state.unmounted
821
835
 
822
836
  useEffect(() => {
837
+ if (disabled) {
838
+ return
839
+ }
840
+
823
841
  if (shouldEnter) {
824
842
  setStateShallow({ unmounted: false })
825
843
  return
@@ -866,6 +884,7 @@ export function createComponent<
866
884
  mouseUps.delete(unPress)
867
885
  }
868
886
  }, [
887
+ disabled,
869
888
  shouldEnter,
870
889
  pseudoGroups ? Object.keys([...pseudoGroups]).join('') : 0,
871
890
  mediaGroups ? Object.keys([...mediaGroups]).join('') : 0,
@@ -887,7 +906,8 @@ export function createComponent<
887
906
  onMouseDown ||
888
907
  onMouseUp ||
889
908
  onLongPress ||
890
- onClick
909
+ onClick ||
910
+ pseudos?.focusVisibleStyle
891
911
  )
892
912
  const runtimeHoverStyle = !disabled && noClassNames && pseudos?.hoverStyle
893
913
  const needsHoverState = Boolean(
@@ -898,116 +918,132 @@ export function createComponent<
898
918
 
899
919
  // check presence rather than value to prevent reparenting bugs
900
920
  // allows for onPress={x ? function : undefined} without re-ordering dom
901
- const shouldAttach = Boolean(
902
- attachFocus ||
903
- attachPress ||
904
- attachHover ||
905
- runtimePressStyle ||
906
- runtimeHoverStyle ||
907
- runtimeFocusStyle
908
- )
921
+ const shouldAttach =
922
+ !disabled &&
923
+ !props.asChild &&
924
+ Boolean(
925
+ attachFocus ||
926
+ attachPress ||
927
+ attachHover ||
928
+ runtimePressStyle ||
929
+ runtimeHoverStyle ||
930
+ runtimeFocusStyle
931
+ )
909
932
  const needsPressState = Boolean(groupName || runtimeHoverStyle)
910
933
 
911
934
  if (process.env.NODE_ENV === 'development' && time) time`events-setup`
912
935
 
913
- const events: TamaguiComponentEvents | null =
914
- shouldAttach && !isDisabled && !props.asChild
915
- ? {
916
- onPressOut: attachPress
917
- ? (e) => {
918
- unPress()
919
- onPressOut?.(e)
920
- onMouseUp?.(e)
936
+ const events: TamaguiComponentEvents | null = shouldAttach
937
+ ? {
938
+ onPressOut: attachPress
939
+ ? (e) => {
940
+ stateRef.current.handleFocusVisible = true
941
+ unPress()
942
+ onPressOut?.(e)
943
+ onMouseUp?.(e)
944
+ }
945
+ : undefined,
946
+ ...((attachHover || attachPress) && {
947
+ onMouseEnter: (e) => {
948
+ const next: Partial<typeof state> = {}
949
+ if (needsHoverState) {
950
+ next.hover = true
951
+ }
952
+ if (needsPressState) {
953
+ if (state.pressIn) {
954
+ next.press = true
921
955
  }
922
- : undefined,
923
- ...((attachHover || attachPress) && {
924
- onMouseEnter: (e) => {
925
- const next: Partial<typeof state> = {}
926
- if (needsHoverState) {
927
- next.hover = true
956
+ }
957
+ setStateShallow(next)
958
+ onHoverIn?.(e)
959
+ onMouseEnter?.(e)
960
+ },
961
+ onMouseLeave: (e) => {
962
+ const next: Partial<typeof state> = {}
963
+ mouseUps.add(unPress)
964
+ if (needsHoverState) {
965
+ next.hover = false
966
+ }
967
+ if (needsPressState) {
968
+ if (state.pressIn) {
969
+ next.press = false
970
+ next.pressIn = false
928
971
  }
929
- if (needsPressState) {
930
- if (state.pressIn) {
931
- next.press = true
932
- }
972
+ }
973
+ setStateShallow(next)
974
+ onHoverOut?.(e)
975
+ onMouseLeave?.(e)
976
+ },
977
+ }),
978
+ onPressIn: attachPress
979
+ ? (e) => {
980
+ stateRef.current.handleFocusVisible = false
981
+ if (runtimePressStyle) {
982
+ setStateShallow({
983
+ press: true,
984
+ pressIn: true,
985
+ })
933
986
  }
934
- setStateShallow(next)
935
- onHoverIn?.(e)
936
- onMouseEnter?.(e)
937
- },
938
- onMouseLeave: (e) => {
939
- const next: Partial<typeof state> = {}
940
- mouseUps.add(unPress)
941
- if (needsHoverState) {
942
- next.hover = false
987
+ onPressIn?.(e)
988
+ onMouseDown?.(e)
989
+ if (isWeb) {
990
+ mouseUps.add(unPress)
943
991
  }
944
- if (needsPressState) {
945
- if (state.pressIn) {
946
- next.press = false
947
- next.pressIn = false
948
- }
992
+ }
993
+ : undefined,
994
+ onPress: attachPress
995
+ ? (e) => {
996
+ unPress()
997
+ // @ts-ignore
998
+ isWeb && onClick?.(e)
999
+ onPress?.(e)
1000
+ if (process.env.TAMAGUI_TARGET === 'web') {
1001
+ onLongPress?.(e)
949
1002
  }
950
- setStateShallow(next)
951
- onHoverOut?.(e)
952
- onMouseLeave?.(e)
1003
+ }
1004
+ : undefined,
1005
+ ...(process.env.TAMAGUI_TARGET === 'native' &&
1006
+ attachPress &&
1007
+ onLongPress && {
1008
+ onLongPress: (e) => {
1009
+ unPress()
1010
+ onLongPress?.(e)
953
1011
  },
954
1012
  }),
955
- onPressIn: attachPress
956
- ? (e) => {
957
- if (runtimePressStyle) {
958
- setStateShallow({
959
- press: true,
960
- pressIn: true,
961
- })
962
- }
963
- onPressIn?.(e)
964
- onMouseDown?.(e)
965
- if (isWeb) {
966
- mouseUps.add(unPress)
967
- }
968
- }
969
- : undefined,
970
- onPress: attachPress
971
- ? (e) => {
972
- unPress()
973
- // @ts-ignore
974
- isWeb && onClick?.(e)
975
- onPress?.(e)
976
- if (process.env.TAMAGUI_TARGET === 'web') {
977
- onLongPress?.(e)
978
- }
979
- }
980
- : undefined,
981
- ...(process.env.TAMAGUI_TARGET === 'native' &&
982
- attachPress &&
983
- onLongPress && {
984
- onLongPress: (e) => {
985
- unPress()
986
- onLongPress?.(e)
987
- },
988
- }),
989
- ...(attachFocus && {
990
- onFocus: (e) => {
1013
+ ...(attachFocus && {
1014
+ onFocus: (e) => {
1015
+ if (pseudos?.focusVisibleStyle) {
1016
+ setTimeout(() => {
1017
+ setStateShallow({
1018
+ focus: true,
1019
+ focusVisible: !!stateRef.current.handleFocusVisible,
1020
+ })
1021
+ }, 0)
1022
+ } else {
991
1023
  setStateShallow({
992
1024
  focus: true,
1025
+ focusVisible: false,
993
1026
  })
994
- onFocus?.(e)
995
- },
996
- onBlur: (e) => {
997
- setStateShallow({
998
- focus: false,
999
- })
1000
- onBlur?.(e)
1001
- },
1002
- }),
1003
- }
1004
- : null
1027
+ }
1028
+ onFocus?.(e)
1029
+ },
1030
+ onBlur: (e) => {
1031
+ stateRef.current.handleFocusVisible = true
1032
+ setStateShallow({
1033
+ focus: false,
1034
+ focusVisible: false,
1035
+ })
1036
+ onBlur?.(e)
1037
+ },
1038
+ }),
1039
+ }
1040
+ : null
1005
1041
 
1006
1042
  if (process.env.TAMAGUI_TARGET === 'native' && events && !asChild) {
1007
1043
  // replicating TouchableWithoutFeedback
1008
1044
  Object.assign(events, {
1009
1045
  cancelable: !viewProps.rejectResponderTermination,
1010
- disabled: isDisabled,
1046
+ disabled: disabled,
1011
1047
  hitSlop: viewProps.hitSlop,
1012
1048
  delayLongPress: viewProps.delayLongPress,
1013
1049
  delayPressIn: viewProps.delayPressIn,
@@ -5,7 +5,9 @@ export const defaultComponentState: TamaguiComponentState = {
5
5
  press: false,
6
6
  pressIn: false,
7
7
  focus: false,
8
+ focusVisible: false,
8
9
  unmounted: true,
10
+ disabled: false,
9
11
  }
10
12
 
11
13
  export const defaultComponentStateMounted: TamaguiComponentState = {
@@ -3,23 +3,29 @@ import type { DebugProp } from '../types'
3
3
 
4
4
  export function createShallowSetState<State extends Object>(
5
5
  setter: React.Dispatch<React.SetStateAction<State>>,
6
+ isDisabled?: boolean,
6
7
  debug?: DebugProp
7
8
  ) {
8
- return (next: Partial<State>) =>
9
- setter((prev) => mergeIfNotShallowEqual(prev, next, debug))
9
+ return (next?: Partial<State>) =>
10
+ setter((prev) => mergeIfNotShallowEqual(prev, next, isDisabled, debug))
10
11
  }
11
12
 
12
- export function mergeIfNotShallowEqual(prev: any, next: any, debug?: DebugProp) {
13
- if (isEqualShallow(prev, next)) {
13
+ export function mergeIfNotShallowEqual(
14
+ prev: any,
15
+ next: any,
16
+ isDisabled?: boolean,
17
+ debug?: DebugProp
18
+ ) {
19
+ if (isDisabled || !prev || !next || isEqualShallow(prev, next)) {
14
20
  return prev
15
21
  }
16
22
  if (process.env.NODE_ENV === 'development') {
17
23
  if (debug) {
18
24
  console.warn(`setStateShallow CHANGE`, { prev, next })
19
- // if (debug === 'break') {
20
- // // biome-ignore lint/suspicious/noDebugger: <explanation>
21
- // debugger
22
- // }
25
+ if (debug === 'break') {
26
+ // biome-ignore lint/suspicious/noDebugger: <explanation>
27
+ debugger
28
+ }
23
29
  }
24
30
  }
25
31
  return { ...prev, ...next }
@@ -127,7 +127,7 @@ function isValidStyleKey(key: string, staticConfig: StaticConfig) {
127
127
  const validStyleProps =
128
128
  staticConfig.validStyles ||
129
129
  (staticConfig.isText || staticConfig.isInput ? stylePropsText : validStyles)
130
- return validStyleProps[key] || staticConfig.acceptTokens?.[key]
130
+ return validStyleProps[key] || staticConfig.accept?.[key]
131
131
  }
132
132
 
133
133
  export const getSplitStyles: StyleSplitter = (
@@ -229,6 +229,22 @@ export const getSplitStyles: StyleSplitter = (
229
229
  let keyInit = keyOg
230
230
  let valInit = props[keyOg]
231
231
 
232
+ if (
233
+ staticConfig.accept &&
234
+ (staticConfig.accept[keyInit] === 'style' ||
235
+ staticConfig.accept[keyInit] === 'textStyle') &&
236
+ typeof valInit === 'object'
237
+ ) {
238
+ const styleObject = getSubStyle(
239
+ styleState,
240
+ keyInit,
241
+ valInit,
242
+ styleProps.noClassNames
243
+ )
244
+ viewProps[keyInit] = styleObject
245
+ continue
246
+ }
247
+
232
248
  if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
233
249
  // otherwise things just keep nesting - careful don't leave these around
234
250
  // they cause big performance dips in Chrome, only use them when debug prop set
@@ -1224,11 +1240,15 @@ export const getSplitStyles: StyleSplitter = (
1224
1240
  }
1225
1241
 
1226
1242
  // merge after the prop loop - and always keep it on style dont turn into className except if RN gives us
1227
- if (props.style) {
1243
+ const styleProp = props.style
1244
+ if (styleProp) {
1228
1245
  if (isHOC) {
1229
- viewProps.style = normalizeStyle(props.style)
1246
+ viewProps.style = normalizeStyle(styleProp)
1230
1247
  } else {
1231
- for (const style of [].concat(props.style)) {
1248
+ const isArray = Array.isArray(styleProp)
1249
+ const len = isArray ? props.length : 1
1250
+ for (let i = 0; i < len; i++) {
1251
+ const style = isArray ? styleProp[i] : styleProp
1232
1252
  if (style) {
1233
1253
  if (style['$$css']) {
1234
1254
  Object.assign(styleState.classNames, style)
@@ -1420,9 +1440,9 @@ function mergeStyle(
1420
1440
  const shouldNormalize = isWeb && !disableNormalize && !styleProps.noNormalize
1421
1441
  const out = shouldNormalize ? normalizeValueWithProperty(val, key) : val
1422
1442
  if (
1423
- // acceptTokens are for props not styles
1424
- staticConfig.acceptTokens &&
1425
- key in staticConfig.acceptTokens
1443
+ // accept is for props not styles
1444
+ staticConfig.accept &&
1445
+ key in staticConfig.accept
1426
1446
  ) {
1427
1447
  viewProps[key] = out
1428
1448
  } else {
@@ -7,12 +7,12 @@ import type { StyleObject } from '@tamagui/helpers'
7
7
  import { simpleHash } from '@tamagui/helpers'
8
8
 
9
9
  import { getConfig } from '../config'
10
- import type { DebugProp, TamaguiInternalConfig, ViewStyleWithPseudos } from '../types'
10
+ import type { TamaguiInternalConfig, ViewStyleWithPseudos } from '../types'
11
11
  import { defaultOffset } from './defaultOffset'
12
+ import { normalizeColor } from './normalizeColor'
12
13
  import { normalizeValueWithProperty } from './normalizeValueWithProperty'
13
14
  import type { PseudoDescriptor } from './pseudoDescriptors'
14
- import { pseudoDescriptors, pseudoDescriptorsBase } from './pseudoDescriptors'
15
- import { normalizeColor } from './normalizeColor'
15
+ import { pseudoDescriptors } from './pseudoDescriptors'
16
16
  import { transformsToString } from './transformsToString'
17
17
 
18
18
  // refactor this file away next...
@@ -148,10 +148,15 @@ function createAtomicRules(
148
148
  value: any,
149
149
  pseudo?: PseudoDescriptor
150
150
  ): string[] {
151
+ const pseudoSelector = pseudo
152
+ ? pseudo.name === 'disabled'
153
+ ? `[aria-disabled]`
154
+ : `:${pseudo.name}`
155
+ : ''
151
156
  const selector = pseudo
152
157
  ? pseudo?.selector
153
158
  ? `${pseudo?.selector} .${identifier}`
154
- : `${selectorPriority[pseudo.name]} .${identifier}:${pseudo.name}`
159
+ : `${selectorPriority[pseudo.name]} .${identifier}${pseudoSelector}`
155
160
  : `:root .${identifier}`
156
161
  const important = !!pseudo
157
162
 
@@ -387,7 +387,7 @@ export const getTokenForKey = (
387
387
  let valOrVar: any
388
388
  let hasSet = false
389
389
 
390
- const customTokenAccept = staticConfig?.acceptTokens?.[key]
390
+ const customTokenAccept = staticConfig?.accept?.[key]
391
391
  if (customTokenAccept) {
392
392
  const val = theme?.[value] ?? tokensParsed[customTokenAccept][value]
393
393
  if (val != null) {
@@ -11,20 +11,37 @@ export const pseudoDescriptorsBase = {
11
11
  stateKey: 'press',
12
12
  priority: 2,
13
13
  },
14
+ focusVisibleStyle: {
15
+ name: 'focus-visible',
16
+ priority: 3,
17
+ stateKey: 'focusVisible',
18
+ },
14
19
  focusStyle: {
15
20
  name: 'focus',
16
21
  priority: 3,
17
22
  },
23
+ disabledStyle: {
24
+ name: 'disabled',
25
+ priority: 4,
26
+ stateKey: 'disabled',
27
+ },
18
28
  } as const
19
29
 
20
30
  export const pseudoPriorities = {
21
31
  hover: 1,
22
32
  press: 2,
23
33
  focus: 3,
34
+ focusVisible: 3,
35
+ disabled: 4,
24
36
  }
25
37
 
26
38
  export const pseudoDescriptors: Record<
27
- 'hoverStyle' | 'pressStyle' | 'focusStyle' | 'enterStyle' | 'exitStyle',
39
+ | 'hoverStyle'
40
+ | 'pressStyle'
41
+ | 'focusStyle'
42
+ | 'focusVisibleStyle'
43
+ | 'enterStyle'
44
+ | 'exitStyle',
28
45
  PseudoDescriptor
29
46
  > = {
30
47
  ...pseudoDescriptorsBase,
@@ -1,10 +1,12 @@
1
1
  import type { GroupState } from '../types'
2
2
 
3
3
  export type TamaguiComponentState = {
4
+ disabled: boolean
4
5
  hover: boolean
5
6
  press: boolean
6
7
  pressIn: boolean
7
8
  focus: boolean
9
+ focusVisible: boolean
8
10
  unmounted: boolean | 'should-enter'
9
11
  animation?: null | {
10
12
  style?: any
package/src/styled.tsx CHANGED
@@ -8,7 +8,6 @@ import type {
8
8
  GetNonStyledProps,
9
9
  GetStaticConfig,
10
10
  GetStyledVariants,
11
- GetTokenPropsFromAcceptedTokens,
12
11
  GetVariantValues,
13
12
  InferStyledProps,
14
13
  StaticConfig,
@@ -16,9 +15,11 @@ import type {
16
15
  StylableComponent,
17
16
  TamaDefer,
18
17
  TamaguiComponent,
18
+ ThemeValueGet,
19
19
  VariantDefinitions,
20
20
  VariantSpreadFunction,
21
21
  } from './types'
22
+ import type { Text } from './views/Text'
22
23
 
23
24
  type AreVariantsUndefined<Variants> =
24
25
  // because we pass in the Generic variants which for some reason has this :)
@@ -70,8 +71,18 @@ export function styled<
70
71
  | (Key extends keyof OurVariantProps ? OurVariantProps[Key] : undefined)
71
72
  }
72
73
 
73
- type AcceptedTokens = StyledStaticConfig['acceptTokens']
74
- type CustomTokenProps = GetTokenPropsFromAcceptedTokens<AcceptedTokens>
74
+ type Accepted = StyledStaticConfig['accept']
75
+ type CustomTokenProps = Accepted extends Record<string, any>
76
+ ? {
77
+ [Key in keyof Accepted]?:
78
+ | (Key extends keyof ParentStylesBase ? ParentStylesBase[Key] : never)
79
+ | (Accepted[Key] extends 'style'
80
+ ? Partial<InferStyledProps<ParentComponent, StyledStaticConfig>>
81
+ : Accepted[Key] extends 'textStyle'
82
+ ? Partial<InferStyledProps<typeof Text, StyledStaticConfig>>
83
+ : Omit<ThemeValueGet<Accepted[Key]>, 'unset'>)
84
+ }
85
+ : {}
75
86
 
76
87
  /**
77
88
  * de-opting a bit of type niceness because were hitting depth issues too soon
@@ -87,7 +98,7 @@ export function styled<
87
98
  TamaDefer,
88
99
  GetRef<ParentComponent>,
89
100
  ParentNonStyledProps,
90
- AcceptedTokens extends Record<string, any>
101
+ Accepted extends Record<string, any>
91
102
  ? ParentStylesBase & CustomTokenProps
92
103
  : ParentStylesBase,
93
104
  MergedVariants,