@tamagui/input 2.7.7 → 3.0.0-beta.637.1

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 (168) hide show
  1. package/dist/cjs/Input.cjs +78 -162
  2. package/dist/cjs/Input.native.cjs +209 -0
  3. package/dist/cjs/Input.native.js +186 -282
  4. package/dist/cjs/Input.native.js.map +1 -1
  5. package/dist/cjs/InputNativeProps.cjs +10 -11
  6. package/dist/cjs/InputNativeProps.native.cjs +19 -0
  7. package/dist/cjs/InputNativeProps.native.js +10 -10
  8. package/dist/cjs/InputNativeProps.native.js.map +1 -1
  9. package/dist/cjs/TextArea.cjs +25 -38
  10. package/dist/cjs/TextArea.native.cjs +41 -0
  11. package/dist/cjs/TextArea.native.js +25 -37
  12. package/dist/cjs/TextArea.native.js.map +1 -1
  13. package/dist/cjs/index.cjs +16 -17
  14. package/dist/cjs/index.native.cjs +33 -0
  15. package/dist/cjs/index.native.js +16 -16
  16. package/dist/cjs/index.native.js.map +1 -1
  17. package/dist/cjs/shared.cjs +115 -122
  18. package/dist/cjs/shared.native.cjs +144 -0
  19. package/dist/cjs/shared.native.js +120 -126
  20. package/dist/cjs/shared.native.js.map +1 -1
  21. package/dist/cjs/types.cjs +10 -11
  22. package/dist/cjs/types.native.cjs +19 -0
  23. package/dist/cjs/types.native.js +10 -10
  24. package/dist/cjs/types.native.js.map +1 -1
  25. package/dist/esm/Input.mjs +63 -137
  26. package/dist/esm/Input.mjs.map +1 -1
  27. package/dist/esm/Input.native.js +172 -259
  28. package/dist/esm/Input.native.js.map +1 -1
  29. package/dist/esm/InputNativeProps.mjs +0 -2
  30. package/dist/esm/InputNativeProps.native.js +0 -2
  31. package/dist/esm/TextArea.mjs +12 -20
  32. package/dist/esm/TextArea.mjs.map +1 -1
  33. package/dist/esm/TextArea.native.js +12 -20
  34. package/dist/esm/TextArea.native.js.map +1 -1
  35. package/dist/esm/index.js +6 -4
  36. package/dist/esm/index.mjs +6 -4
  37. package/dist/esm/index.native.js +6 -4
  38. package/dist/esm/shared.mjs +99 -104
  39. package/dist/esm/shared.mjs.map +1 -1
  40. package/dist/esm/shared.native.js +104 -109
  41. package/dist/esm/shared.native.js.map +1 -1
  42. package/dist/esm/types.mjs +0 -2
  43. package/dist/esm/types.native.js +0 -2
  44. package/dist/jsx/Input.mjs +63 -137
  45. package/dist/jsx/Input.mjs.map +1 -1
  46. package/dist/jsx/Input.native.cjs +209 -0
  47. package/dist/jsx/Input.native.js +186 -282
  48. package/dist/jsx/Input.native.js.map +1 -1
  49. package/dist/jsx/InputNativeProps.mjs +0 -2
  50. package/dist/jsx/InputNativeProps.native.cjs +19 -0
  51. package/dist/jsx/InputNativeProps.native.js +10 -10
  52. package/dist/jsx/InputNativeProps.native.js.map +1 -1
  53. package/dist/jsx/TextArea.mjs +12 -20
  54. package/dist/jsx/TextArea.mjs.map +1 -1
  55. package/dist/jsx/TextArea.native.cjs +41 -0
  56. package/dist/jsx/TextArea.native.js +25 -37
  57. package/dist/jsx/TextArea.native.js.map +1 -1
  58. package/dist/jsx/index.js +6 -4
  59. package/dist/jsx/index.mjs +6 -4
  60. package/dist/jsx/index.native.cjs +33 -0
  61. package/dist/jsx/index.native.js +16 -16
  62. package/dist/jsx/index.native.js.map +1 -1
  63. package/dist/jsx/shared.mjs +99 -104
  64. package/dist/jsx/shared.mjs.map +1 -1
  65. package/dist/jsx/shared.native.cjs +144 -0
  66. package/dist/jsx/shared.native.js +120 -126
  67. package/dist/jsx/shared.native.js.map +1 -1
  68. package/dist/jsx/types.mjs +0 -2
  69. package/dist/jsx/types.native.cjs +19 -0
  70. package/dist/jsx/types.native.js +10 -10
  71. package/dist/jsx/types.native.js.map +1 -1
  72. package/package.json +13 -15
  73. package/src/Input.native.tsx +263 -240
  74. package/src/Input.tsx +162 -152
  75. package/src/TextArea.tsx +6 -14
  76. package/src/shared.tsx +65 -70
  77. package/src/types.ts +1 -1
  78. package/types/Input.d.ts +57 -41
  79. package/types/Input.d.ts.map +1 -1
  80. package/types/Input.native.d.ts +57 -41
  81. package/types/Input.native.d.ts.map +1 -1
  82. package/types/TextArea.d.ts +172 -24
  83. package/types/TextArea.d.ts.map +1 -1
  84. package/types/shared.d.ts +14 -99
  85. package/types/shared.d.ts.map +1 -1
  86. package/types/types.d.ts +1 -1
  87. package/dist/cjs/inputTypes.test-d.cjs +0 -128
  88. package/dist/cjs/inputTypes.test-d.native.js +0 -131
  89. package/dist/cjs/inputTypes.test-d.native.js.map +0 -1
  90. package/dist/cjs/v1/Input.cjs +0 -200
  91. package/dist/cjs/v1/Input.native.js +0 -183
  92. package/dist/cjs/v1/Input.native.js.map +0 -1
  93. package/dist/cjs/v1/TextArea.cjs +0 -52
  94. package/dist/cjs/v1/TextArea.native.js +0 -55
  95. package/dist/cjs/v1/TextArea.native.js.map +0 -1
  96. package/dist/cjs/v1/index.cjs +0 -21
  97. package/dist/cjs/v1/index.native.js +0 -24
  98. package/dist/cjs/v1/index.native.js.map +0 -1
  99. package/dist/cjs/v1/types.cjs +0 -18
  100. package/dist/cjs/v1/types.native.js +0 -21
  101. package/dist/cjs/v1/types.native.js.map +0 -1
  102. package/dist/esm/InputNativeProps.mjs.map +0 -1
  103. package/dist/esm/InputNativeProps.native.js.map +0 -1
  104. package/dist/esm/index.js.map +0 -1
  105. package/dist/esm/index.mjs.map +0 -1
  106. package/dist/esm/index.native.js.map +0 -1
  107. package/dist/esm/inputTypes.test-d.mjs +0 -129
  108. package/dist/esm/inputTypes.test-d.mjs.map +0 -1
  109. package/dist/esm/inputTypes.test-d.native.js +0 -129
  110. package/dist/esm/inputTypes.test-d.native.js.map +0 -1
  111. package/dist/esm/types.mjs.map +0 -1
  112. package/dist/esm/types.native.js.map +0 -1
  113. package/dist/esm/v1/Input.mjs +0 -164
  114. package/dist/esm/v1/Input.mjs.map +0 -1
  115. package/dist/esm/v1/Input.native.js +0 -144
  116. package/dist/esm/v1/Input.native.js.map +0 -1
  117. package/dist/esm/v1/TextArea.mjs +0 -27
  118. package/dist/esm/v1/TextArea.mjs.map +0 -1
  119. package/dist/esm/v1/TextArea.native.js +0 -27
  120. package/dist/esm/v1/TextArea.native.js.map +0 -1
  121. package/dist/esm/v1/index.mjs +0 -3
  122. package/dist/esm/v1/index.mjs.map +0 -1
  123. package/dist/esm/v1/index.native.js +0 -3
  124. package/dist/esm/v1/index.native.js.map +0 -1
  125. package/dist/esm/v1/types.mjs +0 -2
  126. package/dist/esm/v1/types.mjs.map +0 -1
  127. package/dist/esm/v1/types.native.js +0 -2
  128. package/dist/esm/v1/types.native.js.map +0 -1
  129. package/dist/jsx/InputNativeProps.mjs.map +0 -1
  130. package/dist/jsx/index.js.map +0 -1
  131. package/dist/jsx/index.mjs.map +0 -1
  132. package/dist/jsx/inputTypes.test-d.mjs +0 -129
  133. package/dist/jsx/inputTypes.test-d.mjs.map +0 -1
  134. package/dist/jsx/inputTypes.test-d.native.js +0 -131
  135. package/dist/jsx/inputTypes.test-d.native.js.map +0 -1
  136. package/dist/jsx/types.mjs.map +0 -1
  137. package/dist/jsx/v1/Input.mjs +0 -164
  138. package/dist/jsx/v1/Input.mjs.map +0 -1
  139. package/dist/jsx/v1/Input.native.js +0 -183
  140. package/dist/jsx/v1/Input.native.js.map +0 -1
  141. package/dist/jsx/v1/TextArea.mjs +0 -27
  142. package/dist/jsx/v1/TextArea.mjs.map +0 -1
  143. package/dist/jsx/v1/TextArea.native.js +0 -55
  144. package/dist/jsx/v1/TextArea.native.js.map +0 -1
  145. package/dist/jsx/v1/index.mjs +0 -3
  146. package/dist/jsx/v1/index.mjs.map +0 -1
  147. package/dist/jsx/v1/index.native.js +0 -24
  148. package/dist/jsx/v1/index.native.js.map +0 -1
  149. package/dist/jsx/v1/types.mjs +0 -2
  150. package/dist/jsx/v1/types.mjs.map +0 -1
  151. package/dist/jsx/v1/types.native.js +0 -21
  152. package/dist/jsx/v1/types.native.js.map +0 -1
  153. package/src/inputTypes.test-d.ts +0 -245
  154. package/src/v1/Input.native.tsx +0 -153
  155. package/src/v1/Input.tsx +0 -190
  156. package/src/v1/TextArea.tsx +0 -35
  157. package/src/v1/index.ts +0 -3
  158. package/src/v1/types.ts +0 -65
  159. package/types/v1/Input.d.ts +0 -64
  160. package/types/v1/Input.d.ts.map +0 -1
  161. package/types/v1/Input.native.d.ts +0 -63
  162. package/types/v1/Input.native.d.ts.map +0 -1
  163. package/types/v1/TextArea.d.ts +0 -41
  164. package/types/v1/TextArea.d.ts.map +0 -1
  165. package/types/v1/index.d.ts +0 -4
  166. package/types/v1/index.d.ts.map +0 -1
  167. package/types/v1/types.d.ts +0 -39
  168. package/types/v1/types.d.ts.map +0 -1
package/src/Input.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { type GetProps, View, styled, useTheme } from '@tamagui/core'
1
+ import { createStyledHOC, type GetProps, View, styled, useTheme } from '@tamagui/core'
2
2
  import { registerFocusable } from '@tamagui/focusable'
3
3
  import { useWebRef } from '@tamagui/element'
4
4
  import React from 'react'
@@ -11,163 +11,173 @@ const StyledInput = styled(View, styledBody[0], styledBody[1])
11
11
  * A web-aligned input component.
12
12
  * @see — Docs https://tamagui.dev/ui/inputs#input
13
13
  */
14
- export const Input = StyledInput.styleable<InputExtraProps>((props, _forwardedRef) => {
15
- const {
16
- disabled,
17
- id,
18
- onChangeText,
19
- onSubmitEditing,
20
- onSelectionChange,
21
- selection,
22
- placeholderTextColor,
23
- selectionColor,
24
- rows,
25
-
26
- // Native-only props (ignored on web)
27
- keyboardAppearance,
28
- returnKeyType,
29
- submitBehavior,
30
- blurOnSubmit,
31
- caretHidden,
32
- contextMenuHidden,
33
- selectTextOnFocus,
34
- secureTextEntry,
35
- maxFontSizeMultiplier,
36
- allowFontScaling,
37
- multiline,
38
- keyboardType,
39
- autoCapitalize: autoCapitalizeProp,
40
- autoCorrect: autoCorrectProp,
41
- autoFocusNative,
42
- textContentType,
43
- onEndEditing,
44
- onContentSizeChange,
45
- onScroll,
46
- onKeyPress,
47
-
48
- // iOS-only props (ignored on web)
49
- clearButtonMode,
50
- clearTextOnFocus,
51
- enablesReturnKeyAutomatically,
52
- dataDetectorTypes,
53
- scrollEnabled,
54
- passwordRules,
55
- rejectResponderTermination,
56
- spellCheck,
57
- lineBreakStrategyIOS,
58
- lineBreakModeIOS,
59
- smartInsertDelete,
60
- inputAccessoryViewID,
61
- inputAccessoryViewButtonLabel,
62
- disableKeyboardShortcuts,
63
-
64
- // Android-only props (ignored on web)
65
- cursorColor,
66
- selectionHandleColor,
67
- underlineColorAndroid,
68
- importantForAutofill,
69
- disableFullscreenUI,
70
- inlineImageLeft,
71
- inlineImagePadding,
72
- returnKeyLabel,
73
- textBreakStrategy,
74
- textAlignVertical,
75
- verticalAlign,
76
- showSoftInputOnFocus,
77
- numberOfLines,
78
-
79
- ...rest
80
- } = props
81
-
82
- const { ref, composedRef } = useWebRef<HTMLInputElement>(_forwardedRef)
83
- const theme = useTheme()
84
-
85
- // convert native-style values to web equivalents
86
- const autoCorrect =
87
- autoCorrectProp === true ? 'on' : autoCorrectProp === false ? 'off' : autoCorrectProp
88
- const autoCapitalize =
89
- autoCapitalizeProp === 'sentences' || autoCapitalizeProp === 'words'
90
- ? 'on'
91
- : autoCapitalizeProp === 'none' || autoCapitalizeProp === 'characters'
92
- ? 'off'
93
- : autoCapitalizeProp
94
-
95
- // Handle selection changes
96
- React.useEffect(() => {
97
- if (!onSelectionChange) return
98
-
99
- const node = ref.current
100
- if (!node) return
101
-
102
- const handleSelectionChange = () => {
103
- onSelectionChange({
104
- nativeEvent: {
105
- selection: {
106
- start: node.selectionStart ?? 0,
107
- end: node.selectionEnd ?? 0,
14
+ export const Input = createStyledHOC(
15
+ StyledInput,
16
+ (
17
+ props: Omit<GetProps<typeof StyledInput>, keyof InputExtraProps> & InputExtraProps,
18
+ _forwardedRef
19
+ ) => {
20
+ const {
21
+ disabled,
22
+ id,
23
+ onChangeText,
24
+ onSubmitEditing,
25
+ onSelectionChange,
26
+ selection,
27
+ placeholderTextColor,
28
+ selectionColor,
29
+ rows,
30
+
31
+ // Native-only props (ignored on web)
32
+ keyboardAppearance,
33
+ returnKeyType,
34
+ submitBehavior,
35
+ blurOnSubmit,
36
+ caretHidden,
37
+ contextMenuHidden,
38
+ selectTextOnFocus,
39
+ secureTextEntry,
40
+ maxFontSizeMultiplier,
41
+ allowFontScaling,
42
+ multiline,
43
+ keyboardType,
44
+ autoCapitalize: autoCapitalizeProp,
45
+ autoCorrect: autoCorrectProp,
46
+ autoFocusNative,
47
+ textContentType,
48
+ onEndEditing,
49
+ onContentSizeChange,
50
+ onScroll,
51
+ onKeyPress,
52
+
53
+ // iOS-only props (ignored on web)
54
+ clearButtonMode,
55
+ clearTextOnFocus,
56
+ enablesReturnKeyAutomatically,
57
+ dataDetectorTypes,
58
+ scrollEnabled,
59
+ passwordRules,
60
+ rejectResponderTermination,
61
+ spellCheck,
62
+ lineBreakStrategyIOS,
63
+ lineBreakModeIOS,
64
+ smartInsertDelete,
65
+ inputAccessoryViewID,
66
+ inputAccessoryViewButtonLabel,
67
+ disableKeyboardShortcuts,
68
+
69
+ // Android-only props (ignored on web)
70
+ cursorColor,
71
+ selectionHandleColor,
72
+ underlineColorAndroid,
73
+ importantForAutofill,
74
+ disableFullscreenUI,
75
+ inlineImageLeft,
76
+ inlineImagePadding,
77
+ returnKeyLabel,
78
+ textBreakStrategy,
79
+ textAlignVertical,
80
+ verticalAlign,
81
+ showSoftInputOnFocus,
82
+ numberOfLines,
83
+
84
+ ...rest
85
+ } = props
86
+
87
+ const { ref, composedRef } = useWebRef<HTMLInputElement>(_forwardedRef)
88
+ const theme = useTheme()
89
+
90
+ // convert native-style values to web equivalents
91
+ const autoCorrect =
92
+ autoCorrectProp === true
93
+ ? 'on'
94
+ : autoCorrectProp === false
95
+ ? 'off'
96
+ : autoCorrectProp
97
+ const autoCapitalize =
98
+ autoCapitalizeProp === 'sentences' || autoCapitalizeProp === 'words'
99
+ ? 'on'
100
+ : autoCapitalizeProp === 'none' || autoCapitalizeProp === 'characters'
101
+ ? 'off'
102
+ : autoCapitalizeProp
103
+
104
+ // Handle selection changes
105
+ React.useEffect(() => {
106
+ if (!onSelectionChange) return
107
+
108
+ const node = ref.current
109
+ if (!node) return
110
+
111
+ const handleSelectionChange = () => {
112
+ onSelectionChange({
113
+ nativeEvent: {
114
+ selection: {
115
+ start: node.selectionStart ?? 0,
116
+ end: node.selectionEnd ?? 0,
117
+ },
108
118
  },
109
- },
119
+ })
120
+ }
121
+
122
+ node.addEventListener('select', handleSelectionChange)
123
+ return () => node.removeEventListener('select', handleSelectionChange)
124
+ }, [onSelectionChange])
125
+
126
+ // Sync selection prop
127
+ React.useEffect(() => {
128
+ if (selection && ref.current) {
129
+ ref.current.setSelectionRange(selection.start, selection.end ?? selection.start)
130
+ }
131
+ }, [selection?.start, selection?.end])
132
+
133
+ // Register focusable
134
+ React.useEffect(() => {
135
+ if (!id || disabled) return
136
+ return registerFocusable(id, {
137
+ focusAndSelect: () => ref.current?.focus(),
138
+ focus: () => ref.current?.focus(),
110
139
  })
140
+ }, [id, disabled])
141
+
142
+ // Handle keyboard submit
143
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
144
+ if (e.key === 'Enter' && onSubmitEditing) {
145
+ onSubmitEditing({
146
+ nativeEvent: { text: (e.target as HTMLInputElement).value },
147
+ })
148
+ }
149
+ rest.onKeyDown?.(e)
111
150
  }
112
151
 
113
- node.addEventListener('select', handleSelectionChange)
114
- return () => node.removeEventListener('select', handleSelectionChange)
115
- }, [onSelectionChange])
116
-
117
- // Sync selection prop
118
- React.useEffect(() => {
119
- if (selection && ref.current) {
120
- ref.current.setSelectionRange(selection.start, selection.end ?? selection.start)
121
- }
122
- }, [selection?.start, selection?.end])
123
-
124
- // Register focusable
125
- React.useEffect(() => {
126
- if (!id || disabled) return
127
- return registerFocusable(id, {
128
- focusAndSelect: () => ref.current?.focus(),
129
- focus: () => ref.current?.focus(),
130
- })
131
- }, [id, disabled])
132
-
133
- // Handle keyboard submit
134
- const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
135
- if (e.key === 'Enter' && onSubmitEditing) {
136
- onSubmitEditing({
137
- nativeEvent: { text: (e.target as HTMLInputElement).value },
138
- })
152
+ // Handle change with onChangeText support
153
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
154
+ onChangeText?.(e.target.value)
155
+ rest.onChange?.(e)
139
156
  }
140
- rest.onKeyDown?.(e)
141
- }
142
157
 
143
- // Handle change with onChangeText support
144
- const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
145
- onChangeText?.(e.target.value)
146
- rest.onChange?.(e)
158
+ const finalProps = {
159
+ ...rest,
160
+ disabled,
161
+ id,
162
+ rows,
163
+ autoCorrect,
164
+ autoCapitalize,
165
+ onKeyDown: onSubmitEditing ? handleKeyDown : rest.onKeyDown,
166
+ onChange: onChangeText ? handleChange : rest.onChange,
167
+ style: {
168
+ ...(rest.style as any),
169
+ ...(placeholderTextColor && {
170
+ '--t_placeholderColor':
171
+ theme[placeholderTextColor]?.variable || placeholderTextColor,
172
+ }),
173
+ ...(selectionColor && {
174
+ '--t_selectionColor': theme[selectionColor]?.variable || selectionColor,
175
+ }),
176
+ },
177
+ } as any
178
+
179
+ return <StyledInput ref={composedRef} {...finalProps} />
147
180
  }
148
-
149
- const finalProps = {
150
- ...rest,
151
- disabled,
152
- id,
153
- rows,
154
- autoCorrect,
155
- autoCapitalize,
156
- onKeyDown: onSubmitEditing ? handleKeyDown : rest.onKeyDown,
157
- onChange: onChangeText ? handleChange : rest.onChange,
158
- style: {
159
- ...(rest.style as any),
160
- ...(placeholderTextColor && {
161
- '--t_placeholderColor':
162
- theme[placeholderTextColor]?.variable || placeholderTextColor,
163
- }),
164
- ...(selectionColor && {
165
- '--t_selectionColor': theme[selectionColor]?.variable || selectionColor,
166
- }),
167
- },
168
- } as any
169
-
170
- return <StyledInput ref={composedRef} {...finalProps} />
171
- })
181
+ )
172
182
 
173
183
  export type InputProps = GetProps<typeof Input>
package/src/TextArea.tsx CHANGED
@@ -7,30 +7,22 @@ import { defaultStyles, textAreaSizeVariant } from './shared'
7
7
  * @see — Docs https://tamagui.dev/ui/inputs#textarea
8
8
  */
9
9
  export const TextArea = styled(Input, {
10
- name: 'TextArea',
10
+ displayName: 'TextArea',
11
11
  render: 'textarea',
12
12
 
13
13
  // this attribute fixes firefox newline issue
14
14
  // @ts-ignore
15
15
  whiteSpace: 'pre-wrap',
16
+ height: 'auto',
17
+ ...defaultStyles,
18
+ rows: 3,
16
19
 
17
20
  variants: {
18
- unstyled: {
19
- false: {
20
- height: 'auto',
21
- ...defaultStyles,
22
- rows: 3,
23
- },
24
- },
25
-
26
21
  size: {
27
- '...size': textAreaSizeVariant,
22
+ true: textAreaSizeVariant,
23
+ Size: textAreaSizeVariant,
28
24
  },
29
25
  } as const,
30
-
31
- defaultVariants: {
32
- unstyled: process.env.TAMAGUI_HEADLESS === '1',
33
- },
34
26
  })
35
27
 
36
28
  export type TextAreaProps = GetProps<typeof TextArea>
package/src/shared.tsx CHANGED
@@ -1,50 +1,68 @@
1
- import type { SizeVariantSpreadFunction } from '@tamagui/core'
1
+ import type { SizeVariantSpreadFunction, VariantSpreadExtras } from '@tamagui/core'
2
2
  import { Text } from '@tamagui/core'
3
- import { getVariableValue, isWeb } from '@tamagui/core'
4
- import { getButtonSized } from '@tamagui/get-button-sized'
3
+ import { getVariableValue, isWeb, resolveTokenSize } from '@tamagui/core'
5
4
  import { getFontSized } from '@tamagui/get-font-sized'
6
- import { getSpace } from '@tamagui/get-token'
7
5
 
6
+ // Structural-only defaults for the unstyled Input behavior primitive.
7
+ // Theme decoration (palette, border, background, font family, hover/focus color
8
+ // styling) lives in the tamagui skin (code/ui/tamagui/src/components/Input.tsx),
9
+ // NOT here. Kept: the size mechanism (functional dimensions), the native outline
10
+ // reset, tab focusability, and the flex-overflow fix.
8
11
  export const defaultStyles = {
9
- size: '$true',
10
- fontFamily: '$body',
11
- borderWidth: 1,
12
+ size: true,
12
13
  outlineWidth: 0,
13
- color: '$color',
14
-
15
- ...(isWeb
16
- ? {
17
- tabIndex: 0 as const,
18
- }
19
- : {
20
- focusable: true,
21
- }),
22
-
23
- borderColor: '$borderColor',
24
- backgroundColor: '$background',
14
+ tabIndex: 0,
25
15
 
26
16
  // this fixes a flex bug where it overflows container
27
17
  minWidth: 0,
18
+ } as const
28
19
 
29
- hoverStyle: {
30
- borderColor: '$borderColorHover',
31
- },
20
+ const resolveInputFrame = (val: any, extras: VariantSpreadExtras<any>) =>
21
+ resolveTokenSize(val, { tokens: extras.tokens, font: extras.font! }).frame
32
22
 
33
- focusStyle: {
34
- borderColor: '$borderColorFocus',
35
- },
23
+ const inputSizeKeys = [
24
+ '0',
25
+ '0-25',
26
+ '0-5',
27
+ '0-75',
28
+ '1',
29
+ '1-5',
30
+ '2',
31
+ '2-5',
32
+ '3',
33
+ '3-5',
34
+ '4',
35
+ '4-5',
36
+ '5',
37
+ '6',
38
+ '7',
39
+ '8',
40
+ '9',
41
+ '10',
42
+ '11',
43
+ '12',
44
+ '13',
45
+ '14',
46
+ '15',
47
+ '16',
48
+ '17',
49
+ '18',
50
+ '19',
51
+ '20',
52
+ ] as const
36
53
 
37
- focusVisibleStyle: {
38
- outlineColor: '$outlineColor',
39
- outlineWidth: 2,
40
- outlineStyle: 'solid',
41
- },
42
- } as const
54
+ const getInputPadding = (val: any, extras: VariantSpreadExtras<any>, steps: 1 | 2) => {
55
+ if (typeof val === 'number') {
56
+ return steps === 1
57
+ ? Math.max(0, Math.round(val * 0.6 - 12))
58
+ : Math.max(0, Math.round(val * 0.52 - 11.5))
59
+ }
60
+ const key = val === true ? '4' : val
61
+ const index = inputSizeKeys.indexOf(key)
62
+ return extras.tokens.space[inputSizeKeys[Math.max(0, index - steps)]]
63
+ }
43
64
 
44
- export const inputSizeVariant: SizeVariantSpreadFunction<any> = (
45
- val = '$true',
46
- extras
47
- ) => {
65
+ export const inputSizeVariant: SizeVariantSpreadFunction<any> = (val = true, extras) => {
48
66
  // Check for textarea mode via tag, rows, multiline, or numberOfLines
49
67
  if (
50
68
  extras.props.tag === 'textarea' ||
@@ -54,11 +72,7 @@ export const inputSizeVariant: SizeVariantSpreadFunction<any> = (
54
72
  ) {
55
73
  return textAreaSizeVariant(val, extras)
56
74
  }
57
- const buttonStyles = getButtonSized(val, extras)
58
- const paddingHorizontal = getSpace(val, {
59
- shift: -1,
60
- bounds: [2],
61
- })
75
+ const frame = resolveInputFrame(val, extras)
62
76
  const fontStyle = getFontSized(val as any, extras)
63
77
  // lineHeight messes up input on native
64
78
  if (!isWeb && fontStyle) {
@@ -66,17 +80,18 @@ export const inputSizeVariant: SizeVariantSpreadFunction<any> = (
66
80
  }
67
81
  return {
68
82
  ...fontStyle,
69
- ...buttonStyles,
70
- paddingHorizontal,
83
+ height: frame.size,
84
+ borderRadius: frame.radius,
85
+ paddingHorizontal: getInputPadding(val, extras, 1),
71
86
  }
72
87
  }
73
88
 
74
89
  export const textAreaSizeVariant: SizeVariantSpreadFunction<any> = (
75
- val = '$true',
90
+ val = true,
76
91
  extras
77
92
  ) => {
78
93
  const { props } = extras
79
- const buttonStyles = getButtonSized(val, extras)
94
+ const frame = resolveInputFrame(val, extras)
80
95
  const fontStyle = getFontSized(val as any, extras)!
81
96
  const lines = props.rows ?? props.numberOfLines
82
97
  const height =
@@ -85,19 +100,11 @@ export const textAreaSizeVariant: SizeVariantSpreadFunction<any> = (
85
100
  if (!isWeb && fontStyle) {
86
101
  delete fontStyle['lineHeight']
87
102
  }
88
- const paddingVertical = getSpace(val, {
89
- shift: -2,
90
- bounds: [2],
91
- })
92
- const paddingHorizontal = getSpace(val, {
93
- shift: -1,
94
- bounds: [2],
95
- })
96
103
  return {
97
- ...buttonStyles,
104
+ borderRadius: frame.radius,
98
105
  ...fontStyle,
99
- paddingVertical,
100
- paddingHorizontal,
106
+ paddingVertical: getInputPadding(val, extras, 2),
107
+ paddingHorizontal: getInputPadding(val, extras, 1),
101
108
  height,
102
109
  }
103
110
  }
@@ -107,29 +114,17 @@ export const styledBody = [
107
114
  {
108
115
  name: INPUT_NAME,
109
116
  render: 'input',
117
+ ...defaultStyles,
110
118
  variants: {
111
- unstyled: {
112
- true: {
113
- // reset browser <input>/<textarea> defaults
114
- outlineWidth: 0,
115
- borderWidth: 0,
116
- backgroundColor: 'transparent',
117
- },
118
- false: defaultStyles,
119
- },
120
-
121
119
  size: {
122
- '...size': inputSizeVariant,
120
+ true: inputSizeVariant,
121
+ Size: inputSizeVariant,
123
122
  },
124
123
 
125
124
  disabled: {
126
125
  true: {},
127
126
  },
128
127
  } as const,
129
-
130
- defaultVariants: {
131
- unstyled: process.env.TAMAGUI_HEADLESS === '1',
132
- },
133
128
  },
134
129
 
135
130
  {
package/src/types.ts CHANGED
@@ -4,7 +4,7 @@ import type { InputNativeProps } from './InputNativeProps'
4
4
 
5
5
  /**
6
6
  * Extra props that Input adds on top of the base styled component.
7
- * Used with .styleable<InputExtraProps>() - the Styleable merge
7
+ * Annotated on the createStyledHOC render fn - the StyledHOCMergedProps merge
8
8
  * (`Omit<BaseProps, keyof CustomProps> & CustomProps`) automatically overrides
9
9
  * base event handlers (HTMLDivElement) with these (HTMLInputElement).
10
10
  * Consumer-facing InputProps is derived via GetProps<typeof Input>.