@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.
- package/dist/cjs/Input.cjs +78 -162
- package/dist/cjs/Input.native.cjs +209 -0
- package/dist/cjs/Input.native.js +186 -282
- package/dist/cjs/Input.native.js.map +1 -1
- package/dist/cjs/InputNativeProps.cjs +10 -11
- package/dist/cjs/InputNativeProps.native.cjs +19 -0
- package/dist/cjs/InputNativeProps.native.js +10 -10
- package/dist/cjs/InputNativeProps.native.js.map +1 -1
- package/dist/cjs/TextArea.cjs +25 -38
- package/dist/cjs/TextArea.native.cjs +41 -0
- package/dist/cjs/TextArea.native.js +25 -37
- package/dist/cjs/TextArea.native.js.map +1 -1
- package/dist/cjs/index.cjs +16 -17
- package/dist/cjs/index.native.cjs +33 -0
- package/dist/cjs/index.native.js +16 -16
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/shared.cjs +115 -122
- package/dist/cjs/shared.native.cjs +144 -0
- package/dist/cjs/shared.native.js +120 -126
- package/dist/cjs/shared.native.js.map +1 -1
- package/dist/cjs/types.cjs +10 -11
- package/dist/cjs/types.native.cjs +19 -0
- package/dist/cjs/types.native.js +10 -10
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/esm/Input.mjs +63 -137
- package/dist/esm/Input.mjs.map +1 -1
- package/dist/esm/Input.native.js +172 -259
- package/dist/esm/Input.native.js.map +1 -1
- package/dist/esm/InputNativeProps.mjs +0 -2
- package/dist/esm/InputNativeProps.native.js +0 -2
- package/dist/esm/TextArea.mjs +12 -20
- package/dist/esm/TextArea.mjs.map +1 -1
- package/dist/esm/TextArea.native.js +12 -20
- package/dist/esm/TextArea.native.js.map +1 -1
- package/dist/esm/index.js +6 -4
- package/dist/esm/index.mjs +6 -4
- package/dist/esm/index.native.js +6 -4
- package/dist/esm/shared.mjs +99 -104
- package/dist/esm/shared.mjs.map +1 -1
- package/dist/esm/shared.native.js +104 -109
- package/dist/esm/shared.native.js.map +1 -1
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/types.native.js +0 -2
- package/dist/jsx/Input.mjs +63 -137
- package/dist/jsx/Input.mjs.map +1 -1
- package/dist/jsx/Input.native.cjs +209 -0
- package/dist/jsx/Input.native.js +186 -282
- package/dist/jsx/Input.native.js.map +1 -1
- package/dist/jsx/InputNativeProps.mjs +0 -2
- package/dist/jsx/InputNativeProps.native.cjs +19 -0
- package/dist/jsx/InputNativeProps.native.js +10 -10
- package/dist/jsx/InputNativeProps.native.js.map +1 -1
- package/dist/jsx/TextArea.mjs +12 -20
- package/dist/jsx/TextArea.mjs.map +1 -1
- package/dist/jsx/TextArea.native.cjs +41 -0
- package/dist/jsx/TextArea.native.js +25 -37
- package/dist/jsx/TextArea.native.js.map +1 -1
- package/dist/jsx/index.js +6 -4
- package/dist/jsx/index.mjs +6 -4
- package/dist/jsx/index.native.cjs +33 -0
- package/dist/jsx/index.native.js +16 -16
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/shared.mjs +99 -104
- package/dist/jsx/shared.mjs.map +1 -1
- package/dist/jsx/shared.native.cjs +144 -0
- package/dist/jsx/shared.native.js +120 -126
- package/dist/jsx/shared.native.js.map +1 -1
- package/dist/jsx/types.mjs +0 -2
- package/dist/jsx/types.native.cjs +19 -0
- package/dist/jsx/types.native.js +10 -10
- package/dist/jsx/types.native.js.map +1 -1
- package/package.json +13 -15
- package/src/Input.native.tsx +263 -240
- package/src/Input.tsx +162 -152
- package/src/TextArea.tsx +6 -14
- package/src/shared.tsx +65 -70
- package/src/types.ts +1 -1
- package/types/Input.d.ts +57 -41
- package/types/Input.d.ts.map +1 -1
- package/types/Input.native.d.ts +57 -41
- package/types/Input.native.d.ts.map +1 -1
- package/types/TextArea.d.ts +172 -24
- package/types/TextArea.d.ts.map +1 -1
- package/types/shared.d.ts +14 -99
- package/types/shared.d.ts.map +1 -1
- package/types/types.d.ts +1 -1
- package/dist/cjs/inputTypes.test-d.cjs +0 -128
- package/dist/cjs/inputTypes.test-d.native.js +0 -131
- package/dist/cjs/inputTypes.test-d.native.js.map +0 -1
- package/dist/cjs/v1/Input.cjs +0 -200
- package/dist/cjs/v1/Input.native.js +0 -183
- package/dist/cjs/v1/Input.native.js.map +0 -1
- package/dist/cjs/v1/TextArea.cjs +0 -52
- package/dist/cjs/v1/TextArea.native.js +0 -55
- package/dist/cjs/v1/TextArea.native.js.map +0 -1
- package/dist/cjs/v1/index.cjs +0 -21
- package/dist/cjs/v1/index.native.js +0 -24
- package/dist/cjs/v1/index.native.js.map +0 -1
- package/dist/cjs/v1/types.cjs +0 -18
- package/dist/cjs/v1/types.native.js +0 -21
- package/dist/cjs/v1/types.native.js.map +0 -1
- package/dist/esm/InputNativeProps.mjs.map +0 -1
- package/dist/esm/InputNativeProps.native.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/esm/inputTypes.test-d.mjs +0 -129
- package/dist/esm/inputTypes.test-d.mjs.map +0 -1
- package/dist/esm/inputTypes.test-d.native.js +0 -129
- package/dist/esm/inputTypes.test-d.native.js.map +0 -1
- package/dist/esm/types.mjs.map +0 -1
- package/dist/esm/types.native.js.map +0 -1
- package/dist/esm/v1/Input.mjs +0 -164
- package/dist/esm/v1/Input.mjs.map +0 -1
- package/dist/esm/v1/Input.native.js +0 -144
- package/dist/esm/v1/Input.native.js.map +0 -1
- package/dist/esm/v1/TextArea.mjs +0 -27
- package/dist/esm/v1/TextArea.mjs.map +0 -1
- package/dist/esm/v1/TextArea.native.js +0 -27
- package/dist/esm/v1/TextArea.native.js.map +0 -1
- package/dist/esm/v1/index.mjs +0 -3
- package/dist/esm/v1/index.mjs.map +0 -1
- package/dist/esm/v1/index.native.js +0 -3
- package/dist/esm/v1/index.native.js.map +0 -1
- package/dist/esm/v1/types.mjs +0 -2
- package/dist/esm/v1/types.mjs.map +0 -1
- package/dist/esm/v1/types.native.js +0 -2
- package/dist/esm/v1/types.native.js.map +0 -1
- package/dist/jsx/InputNativeProps.mjs.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
- package/dist/jsx/inputTypes.test-d.mjs +0 -129
- package/dist/jsx/inputTypes.test-d.mjs.map +0 -1
- package/dist/jsx/inputTypes.test-d.native.js +0 -131
- package/dist/jsx/inputTypes.test-d.native.js.map +0 -1
- package/dist/jsx/types.mjs.map +0 -1
- package/dist/jsx/v1/Input.mjs +0 -164
- package/dist/jsx/v1/Input.mjs.map +0 -1
- package/dist/jsx/v1/Input.native.js +0 -183
- package/dist/jsx/v1/Input.native.js.map +0 -1
- package/dist/jsx/v1/TextArea.mjs +0 -27
- package/dist/jsx/v1/TextArea.mjs.map +0 -1
- package/dist/jsx/v1/TextArea.native.js +0 -55
- package/dist/jsx/v1/TextArea.native.js.map +0 -1
- package/dist/jsx/v1/index.mjs +0 -3
- package/dist/jsx/v1/index.mjs.map +0 -1
- package/dist/jsx/v1/index.native.js +0 -24
- package/dist/jsx/v1/index.native.js.map +0 -1
- package/dist/jsx/v1/types.mjs +0 -2
- package/dist/jsx/v1/types.mjs.map +0 -1
- package/dist/jsx/v1/types.native.js +0 -21
- package/dist/jsx/v1/types.native.js.map +0 -1
- package/src/inputTypes.test-d.ts +0 -245
- package/src/v1/Input.native.tsx +0 -153
- package/src/v1/Input.tsx +0 -190
- package/src/v1/TextArea.tsx +0 -35
- package/src/v1/index.ts +0 -3
- package/src/v1/types.ts +0 -65
- package/types/v1/Input.d.ts +0 -64
- package/types/v1/Input.d.ts.map +0 -1
- package/types/v1/Input.native.d.ts +0 -63
- package/types/v1/Input.native.d.ts.map +0 -1
- package/types/v1/TextArea.d.ts +0 -41
- package/types/v1/TextArea.d.ts.map +0 -1
- package/types/v1/index.d.ts +0 -4
- package/types/v1/index.d.ts.map +0 -1
- package/types/v1/types.d.ts +0 -39
- 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 =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
10
|
-
fontFamily: '$body',
|
|
11
|
-
borderWidth: 1,
|
|
12
|
+
size: true,
|
|
12
13
|
outlineWidth: 0,
|
|
13
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
20
|
+
const resolveInputFrame = (val: any, extras: VariantSpreadExtras<any>) =>
|
|
21
|
+
resolveTokenSize(val, { tokens: extras.tokens, font: extras.font! }).frame
|
|
32
22
|
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
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
|
|
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
|
-
|
|
70
|
-
|
|
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 =
|
|
90
|
+
val = true,
|
|
76
91
|
extras
|
|
77
92
|
) => {
|
|
78
93
|
const { props } = extras
|
|
79
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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>.
|