@tamagui/input 2.7.7 → 3.0.0-beta.1091.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 (169) hide show
  1. package/dist/cjs/Input.cjs +72 -163
  2. package/dist/cjs/Input.native.cjs +208 -0
  3. package/dist/cjs/Input.native.js +186 -283
  4. package/dist/cjs/Input.native.js.map +1 -1
  5. package/dist/cjs/InputNativeProps.cjs +9 -11
  6. package/dist/cjs/InputNativeProps.native.cjs +18 -0
  7. package/dist/cjs/InputNativeProps.native.js +9 -10
  8. package/dist/cjs/InputNativeProps.native.js.map +1 -1
  9. package/dist/cjs/TextArea.cjs +23 -39
  10. package/dist/cjs/TextArea.native.cjs +38 -0
  11. package/dist/cjs/TextArea.native.js +23 -38
  12. package/dist/cjs/TextArea.native.js.map +1 -1
  13. package/dist/cjs/index.cjs +15 -17
  14. package/dist/cjs/index.native.cjs +32 -0
  15. package/dist/cjs/index.native.js +15 -16
  16. package/dist/cjs/index.native.js.map +1 -1
  17. package/dist/cjs/shared.cjs +74 -124
  18. package/dist/cjs/shared.native.cjs +101 -0
  19. package/dist/cjs/shared.native.js +80 -129
  20. package/dist/cjs/shared.native.js.map +1 -1
  21. package/dist/cjs/types.cjs +9 -11
  22. package/dist/cjs/types.native.cjs +18 -0
  23. package/dist/cjs/types.native.js +9 -10
  24. package/dist/cjs/types.native.js.map +1 -1
  25. package/dist/esm/Input.mjs +59 -139
  26. package/dist/esm/Input.mjs.map +1 -1
  27. package/dist/esm/Input.native.js +174 -261
  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 -22
  32. package/dist/esm/TextArea.mjs.map +1 -1
  33. package/dist/esm/TextArea.native.js +12 -22
  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 +59 -107
  39. package/dist/esm/shared.mjs.map +1 -1
  40. package/dist/esm/shared.native.js +64 -112
  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 +59 -139
  45. package/dist/jsx/Input.mjs.map +1 -1
  46. package/dist/jsx/Input.native.cjs +208 -0
  47. package/dist/jsx/Input.native.js +186 -283
  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 +18 -0
  51. package/dist/jsx/InputNativeProps.native.js +9 -10
  52. package/dist/jsx/InputNativeProps.native.js.map +1 -1
  53. package/dist/jsx/TextArea.mjs +12 -22
  54. package/dist/jsx/TextArea.mjs.map +1 -1
  55. package/dist/jsx/TextArea.native.cjs +38 -0
  56. package/dist/jsx/TextArea.native.js +23 -38
  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 +32 -0
  61. package/dist/jsx/index.native.js +15 -16
  62. package/dist/jsx/index.native.js.map +1 -1
  63. package/dist/jsx/shared.mjs +59 -107
  64. package/dist/jsx/shared.mjs.map +1 -1
  65. package/dist/jsx/shared.native.cjs +101 -0
  66. package/dist/jsx/shared.native.js +80 -129
  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 +18 -0
  70. package/dist/jsx/types.native.js +9 -10
  71. package/dist/jsx/types.native.js.map +1 -1
  72. package/package.json +17 -17
  73. package/src/Input.native.tsx +267 -242
  74. package/src/Input.tsx +150 -154
  75. package/src/TextArea.tsx +9 -18
  76. package/src/shared.tsx +56 -109
  77. package/src/types.ts +2 -2
  78. package/types/Input.d.ts +32 -50
  79. package/types/Input.d.ts.map +1 -1
  80. package/types/Input.native.d.ts +32 -50
  81. package/types/Input.native.d.ts.map +1 -1
  82. package/types/TextArea.d.ts +16 -34
  83. package/types/TextArea.d.ts.map +1 -1
  84. package/types/shared.d.ts +38 -109
  85. package/types/shared.d.ts.map +1 -1
  86. package/types/types.d.ts +2 -2
  87. package/types/types.d.ts.map +1 -1
  88. package/dist/cjs/inputTypes.test-d.cjs +0 -128
  89. package/dist/cjs/inputTypes.test-d.native.js +0 -131
  90. package/dist/cjs/inputTypes.test-d.native.js.map +0 -1
  91. package/dist/cjs/v1/Input.cjs +0 -200
  92. package/dist/cjs/v1/Input.native.js +0 -183
  93. package/dist/cjs/v1/Input.native.js.map +0 -1
  94. package/dist/cjs/v1/TextArea.cjs +0 -52
  95. package/dist/cjs/v1/TextArea.native.js +0 -55
  96. package/dist/cjs/v1/TextArea.native.js.map +0 -1
  97. package/dist/cjs/v1/index.cjs +0 -21
  98. package/dist/cjs/v1/index.native.js +0 -24
  99. package/dist/cjs/v1/index.native.js.map +0 -1
  100. package/dist/cjs/v1/types.cjs +0 -18
  101. package/dist/cjs/v1/types.native.js +0 -21
  102. package/dist/cjs/v1/types.native.js.map +0 -1
  103. package/dist/esm/InputNativeProps.mjs.map +0 -1
  104. package/dist/esm/InputNativeProps.native.js.map +0 -1
  105. package/dist/esm/index.js.map +0 -1
  106. package/dist/esm/index.mjs.map +0 -1
  107. package/dist/esm/index.native.js.map +0 -1
  108. package/dist/esm/inputTypes.test-d.mjs +0 -129
  109. package/dist/esm/inputTypes.test-d.mjs.map +0 -1
  110. package/dist/esm/inputTypes.test-d.native.js +0 -129
  111. package/dist/esm/inputTypes.test-d.native.js.map +0 -1
  112. package/dist/esm/types.mjs.map +0 -1
  113. package/dist/esm/types.native.js.map +0 -1
  114. package/dist/esm/v1/Input.mjs +0 -164
  115. package/dist/esm/v1/Input.mjs.map +0 -1
  116. package/dist/esm/v1/Input.native.js +0 -144
  117. package/dist/esm/v1/Input.native.js.map +0 -1
  118. package/dist/esm/v1/TextArea.mjs +0 -27
  119. package/dist/esm/v1/TextArea.mjs.map +0 -1
  120. package/dist/esm/v1/TextArea.native.js +0 -27
  121. package/dist/esm/v1/TextArea.native.js.map +0 -1
  122. package/dist/esm/v1/index.mjs +0 -3
  123. package/dist/esm/v1/index.mjs.map +0 -1
  124. package/dist/esm/v1/index.native.js +0 -3
  125. package/dist/esm/v1/index.native.js.map +0 -1
  126. package/dist/esm/v1/types.mjs +0 -2
  127. package/dist/esm/v1/types.mjs.map +0 -1
  128. package/dist/esm/v1/types.native.js +0 -2
  129. package/dist/esm/v1/types.native.js.map +0 -1
  130. package/dist/jsx/InputNativeProps.mjs.map +0 -1
  131. package/dist/jsx/index.js.map +0 -1
  132. package/dist/jsx/index.mjs.map +0 -1
  133. package/dist/jsx/inputTypes.test-d.mjs +0 -129
  134. package/dist/jsx/inputTypes.test-d.mjs.map +0 -1
  135. package/dist/jsx/inputTypes.test-d.native.js +0 -131
  136. package/dist/jsx/inputTypes.test-d.native.js.map +0 -1
  137. package/dist/jsx/types.mjs.map +0 -1
  138. package/dist/jsx/v1/Input.mjs +0 -164
  139. package/dist/jsx/v1/Input.mjs.map +0 -1
  140. package/dist/jsx/v1/Input.native.js +0 -183
  141. package/dist/jsx/v1/Input.native.js.map +0 -1
  142. package/dist/jsx/v1/TextArea.mjs +0 -27
  143. package/dist/jsx/v1/TextArea.mjs.map +0 -1
  144. package/dist/jsx/v1/TextArea.native.js +0 -55
  145. package/dist/jsx/v1/TextArea.native.js.map +0 -1
  146. package/dist/jsx/v1/index.mjs +0 -3
  147. package/dist/jsx/v1/index.mjs.map +0 -1
  148. package/dist/jsx/v1/index.native.js +0 -24
  149. package/dist/jsx/v1/index.native.js.map +0 -1
  150. package/dist/jsx/v1/types.mjs +0 -2
  151. package/dist/jsx/v1/types.mjs.map +0 -1
  152. package/dist/jsx/v1/types.native.js +0 -21
  153. package/dist/jsx/v1/types.native.js.map +0 -1
  154. package/src/inputTypes.test-d.ts +0 -245
  155. package/src/v1/Input.native.tsx +0 -153
  156. package/src/v1/Input.tsx +0 -190
  157. package/src/v1/TextArea.tsx +0 -35
  158. package/src/v1/index.ts +0 -3
  159. package/src/v1/types.ts +0 -65
  160. package/types/v1/Input.d.ts +0 -64
  161. package/types/v1/Input.d.ts.map +0 -1
  162. package/types/v1/Input.native.d.ts +0 -63
  163. package/types/v1/Input.native.d.ts.map +0 -1
  164. package/types/v1/TextArea.d.ts +0 -41
  165. package/types/v1/TextArea.d.ts.map +0 -1
  166. package/types/v1/index.d.ts +0 -4
  167. package/types/v1/index.d.ts.map +0 -1
  168. package/types/v1/types.d.ts +0 -39
  169. package/types/v1/types.d.ts.map +0 -1
package/src/Input.tsx CHANGED
@@ -1,173 +1,169 @@
1
- import { type GetProps, View, styled, useTheme } from '@tamagui/core'
1
+ import { createStyledHOC, type GetProps, View, styled } from '@tamagui/core'
2
2
  import { registerFocusable } from '@tamagui/focusable'
3
3
  import { useWebRef } from '@tamagui/element'
4
4
  import React from 'react'
5
- import { styledBody } from './shared'
5
+ import { resolveMultilineInputSize, styledBody } from './shared'
6
6
  import type { InputExtraProps } from './types'
7
7
 
8
- const StyledInput = styled(View, styledBody[0], styledBody[1])
8
+ const StyledInput = styled(View, styledBody[0], styledBody[1]).resolve(
9
+ resolveMultilineInputSize
10
+ )
9
11
 
10
12
  /**
11
13
  * A web-aligned input component.
12
14
  * @see — Docs https://tamagui.dev/ui/inputs#input
13
15
  */
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,
16
+ export const Input = createStyledHOC(
17
+ StyledInput,
18
+ (
19
+ props: Omit<GetProps<typeof StyledInput>, keyof InputExtraProps> & InputExtraProps,
20
+ _forwardedRef
21
+ ) => {
22
+ const {
23
+ disabled,
24
+ id,
25
+ onChangeText,
26
+ onSubmitEditing,
27
+ onSelectionChange,
28
+ selection,
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
+ underlineColorAndroid,
71
+ importantForAutofill,
72
+ disableFullscreenUI,
73
+ inlineImageLeft,
74
+ inlineImagePadding,
75
+ returnKeyLabel,
76
+ textBreakStrategy,
77
+ textAlignVertical,
78
+ verticalAlign,
79
+ showSoftInputOnFocus,
80
+ numberOfLines,
81
+
82
+ ...rest
83
+ } = props
84
+
85
+ const { ref, composedRef } = useWebRef<HTMLInputElement>(_forwardedRef)
86
+ // convert native-style values to web equivalents
87
+ const autoCorrect =
88
+ autoCorrectProp === true
89
+ ? 'on'
90
+ : autoCorrectProp === false
91
+ ? 'off'
92
+ : autoCorrectProp
93
+ const autoCapitalize =
94
+ autoCapitalizeProp === 'sentences' || autoCapitalizeProp === 'words'
95
+ ? 'on'
96
+ : autoCapitalizeProp === 'none' || autoCapitalizeProp === 'characters'
97
+ ? 'off'
98
+ : autoCapitalizeProp
99
+
100
+ // Handle selection changes
101
+ React.useEffect(() => {
102
+ if (!onSelectionChange) return
103
+
104
+ const node = ref.current
105
+ if (!node) return
106
+
107
+ const handleSelectionChange = () => {
108
+ onSelectionChange({
109
+ nativeEvent: {
110
+ selection: {
111
+ start: node.selectionStart ?? 0,
112
+ end: node.selectionEnd ?? 0,
113
+ },
108
114
  },
109
- },
115
+ })
116
+ }
117
+
118
+ node.addEventListener('select', handleSelectionChange)
119
+ return () => node.removeEventListener('select', handleSelectionChange)
120
+ }, [onSelectionChange])
121
+
122
+ // Sync selection prop
123
+ React.useEffect(() => {
124
+ if (selection && ref.current) {
125
+ ref.current.setSelectionRange(selection.start, selection.end ?? selection.start)
126
+ }
127
+ }, [selection?.start, selection?.end])
128
+
129
+ // Register focusable
130
+ React.useEffect(() => {
131
+ if (!id || disabled) return
132
+ return registerFocusable(id, {
133
+ focusAndSelect: () => ref.current?.focus(),
134
+ focus: () => ref.current?.focus(),
110
135
  })
136
+ }, [id, disabled])
137
+
138
+ // Handle keyboard submit
139
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
140
+ if (e.key === 'Enter' && onSubmitEditing) {
141
+ onSubmitEditing({
142
+ nativeEvent: { text: (e.target as HTMLInputElement).value },
143
+ })
144
+ }
145
+ rest.onKeyDown?.(e)
111
146
  }
112
147
 
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
- })
148
+ // Handle change with onChangeText support
149
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
150
+ onChangeText?.(e.target.value)
151
+ rest.onChange?.(e)
139
152
  }
140
- rest.onKeyDown?.(e)
141
- }
142
153
 
143
- // Handle change with onChangeText support
144
- const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
145
- onChangeText?.(e.target.value)
146
- rest.onChange?.(e)
154
+ const finalProps = {
155
+ ...rest,
156
+ disabled,
157
+ id,
158
+ rows,
159
+ autoCorrect,
160
+ autoCapitalize,
161
+ onKeyDown: onSubmitEditing ? handleKeyDown : rest.onKeyDown,
162
+ onChange: onChangeText ? handleChange : rest.onChange,
163
+ } as any
164
+
165
+ return <StyledInput ref={composedRef} {...finalProps} />
147
166
  }
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
- })
167
+ )
172
168
 
173
169
  export type InputProps = GetProps<typeof Input>
package/src/TextArea.tsx CHANGED
@@ -1,36 +1,27 @@
1
1
  import { type GetProps, styled } from '@tamagui/web'
2
2
  import { Input } from './Input'
3
- import { defaultStyles, textAreaSizeVariant } from './shared'
3
+ import { defaultStyles, resolveTextAreaSize, textAreaSizeVariant } from './shared'
4
4
 
5
5
  /**
6
6
  * A web-aligned textarea component (multi-line input).
7
7
  * @see — Docs https://tamagui.dev/ui/inputs#textarea
8
8
  */
9
- export const TextArea = styled(Input, {
10
- name: 'TextArea',
9
+ const TextAreaFrame = styled(Input, {
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
- size: {
27
- '...size': textAreaSizeVariant,
28
- },
21
+ size: textAreaSizeVariant,
29
22
  } as const,
30
-
31
- defaultVariants: {
32
- unstyled: process.env.TAMAGUI_HEADLESS === '1',
33
- },
34
23
  })
35
24
 
25
+ export const TextArea = TextAreaFrame.resolve(resolveTextAreaSize)
26
+
36
27
  export type TextAreaProps = GetProps<typeof TextArea>
package/src/shared.tsx CHANGED
@@ -1,147 +1,94 @@
1
- import type { SizeVariantSpreadFunction } from '@tamagui/core'
2
- import { Text } from '@tamagui/core'
3
- import { getVariableValue, isWeb } from '@tamagui/core'
4
- import { getButtonSized } from '@tamagui/get-button-sized'
1
+ import { getVariableValue, isWeb, resolveSize, styled } from '@tamagui/core'
5
2
  import { getFontSized } from '@tamagui/get-font-sized'
6
- import { getSpace } from '@tamagui/get-token'
7
3
 
4
+ // Structural-only defaults for the unstyled Input behavior primitive.
5
+ // Theme decoration (palette, border, background, font family, hover/focus color
6
+ // styling) lives in the tamagui skin (code/ui/tamagui/src/components/Input.tsx),
7
+ // NOT here. Kept: the size mechanism (functional dimensions), the native outline
8
+ // reset, tab focusability, and the flex-overflow fix.
8
9
  export const defaultStyles = {
9
- size: '$true',
10
- fontFamily: '$body',
11
- borderWidth: 1,
10
+ size: true,
12
11
  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',
12
+ tabIndex: 0,
25
13
 
26
14
  // this fixes a flex bug where it overflows container
27
15
  minWidth: 0,
28
-
29
- hoverStyle: {
30
- borderColor: '$borderColorHover',
31
- },
32
-
33
- focusStyle: {
34
- borderColor: '$borderColorFocus',
35
- },
36
-
37
- focusVisibleStyle: {
38
- outlineColor: '$outlineColor',
39
- outlineWidth: 2,
40
- outlineStyle: 'solid',
41
- },
42
16
  } as const
43
17
 
44
- export const inputSizeVariant: SizeVariantSpreadFunction<any> = (
45
- val = '$true',
46
- extras
47
- ) => {
48
- // Check for textarea mode via tag, rows, multiline, or numberOfLines
49
- if (
50
- extras.props.tag === 'textarea' ||
51
- extras.props.rows > 1 ||
52
- extras.props.multiline ||
53
- extras.props.numberOfLines > 1
54
- ) {
55
- return textAreaSizeVariant(val, extras)
56
- }
57
- const buttonStyles = getButtonSized(val, extras)
58
- const paddingHorizontal = getSpace(val, {
59
- shift: -1,
60
- bounds: [2],
61
- })
62
- const fontStyle = getFontSized(val as any, extras)
63
- // lineHeight messes up input on native
64
- if (!isWeb && fontStyle) {
65
- delete fontStyle['lineHeight']
18
+ export const inputSizeVariant = styled.dynamic<any>((val = true, env) => {
19
+ const { frame } = resolveSize(val, env)
20
+ const fontStyle = getFontSized(val as any, env)
21
+ return {
22
+ color: fontStyle?.color,
23
+ fontFamily: fontStyle?.fontFamily,
24
+ fontSize: fontStyle?.fontSize,
25
+ fontStyle: fontStyle?.fontStyle,
26
+ fontWeight: fontStyle?.fontWeight,
27
+ letterSpacing: fontStyle?.letterSpacing,
28
+ lineHeight: isWeb ? fontStyle?.lineHeight : undefined,
29
+ textTransform: fontStyle?.textTransform,
30
+ ...frame,
66
31
  }
32
+ })
33
+
34
+ export const textAreaSizeVariant = styled.dynamic<any>((val = true, env) => {
67
35
  return {
68
- ...fontStyle,
69
- ...buttonStyles,
70
- paddingHorizontal,
36
+ ...inputSizeVariant(val, env),
37
+ height: 'auto',
71
38
  }
72
- }
39
+ })
73
40
 
74
- export const textAreaSizeVariant: SizeVariantSpreadFunction<any> = (
75
- val = '$true',
76
- extras
41
+ export const resolveTextAreaSize = (
42
+ props: Record<string, any>,
43
+ env: Parameters<typeof textAreaSizeVariant>[1]
77
44
  ) => {
78
- const { props } = extras
79
- const buttonStyles = getButtonSized(val, extras)
80
- const fontStyle = getFontSized(val as any, extras)!
45
+ const sized = textAreaSizeVariant(props.size ?? true, env)
46
+ const fontStyle = getFontSized(props.size ?? true, env)
81
47
  const lines = props.rows ?? props.numberOfLines
82
48
  const height =
83
- typeof lines === 'number' ? lines * getVariableValue(fontStyle.lineHeight) : 'auto'
84
- // lineHeight messes up input on native
85
- if (!isWeb && fontStyle) {
86
- delete fontStyle['lineHeight']
87
- }
88
- const paddingVertical = getSpace(val, {
89
- shift: -2,
90
- bounds: [2],
91
- })
92
- const paddingHorizontal = getSpace(val, {
93
- shift: -1,
94
- bounds: [2],
95
- })
49
+ typeof lines === 'number'
50
+ ? lines * getVariableValue(fontStyle?.lineHeight)
51
+ : sized?.height
96
52
  return {
97
- ...buttonStyles,
98
- ...fontStyle,
99
- paddingVertical,
100
- paddingHorizontal,
53
+ borderRadius: sized?.borderRadius,
54
+ color: sized?.color,
55
+ fontFamily: sized?.fontFamily,
56
+ fontSize: sized?.fontSize,
57
+ fontStyle: sized?.fontStyle,
58
+ fontWeight: sized?.fontWeight,
59
+ letterSpacing: sized?.letterSpacing,
60
+ lineHeight: sized?.lineHeight,
61
+ textTransform: sized?.textTransform,
62
+ paddingVertical: sized?.paddingVertical,
63
+ paddingHorizontal: sized?.paddingHorizontal,
101
64
  height,
102
65
  }
103
66
  }
67
+
68
+ export const resolveMultilineInputSize = (
69
+ props: Record<string, any>,
70
+ env: Parameters<typeof textAreaSizeVariant>[1]
71
+ ) => {
72
+ if (!(props.rows > 1 || props.multiline || props.numberOfLines > 1)) return
73
+ return resolveTextAreaSize(props, env)
74
+ }
104
75
  export const INPUT_NAME = 'Input'
105
76
 
106
77
  export const styledBody = [
107
78
  {
108
79
  name: INPUT_NAME,
109
80
  render: 'input',
81
+ ...defaultStyles,
110
82
  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
- size: {
122
- '...size': inputSizeVariant,
123
- },
83
+ size: inputSizeVariant,
124
84
 
125
85
  disabled: {
126
86
  true: {},
127
87
  },
128
88
  } as const,
129
-
130
- defaultVariants: {
131
- unstyled: process.env.TAMAGUI_HEADLESS === '1',
132
- },
133
89
  },
134
90
 
135
91
  {
136
92
  isInput: true,
137
- accept: {
138
- placeholderTextColor: 'color',
139
- selectionColor: 'color',
140
- cursorColor: 'color',
141
- selectionHandleColor: 'color',
142
- underlineColorAndroid: 'color',
143
- } as const,
144
-
145
- validStyles: Text.staticConfig.validStyles,
146
93
  },
147
94
  ] as const
package/src/types.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import type { ColorTokens, TextStyle, TamaguiElementMethods } from '@tamagui/web'
2
- import type { TextInput } from 'react-native'
2
+ import type { TextInput } from '@tamagui/react-native-types'
3
3
  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>.