@tamagui/input 2.7.7 → 3.0.0-beta.1093.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 +72 -163
- package/dist/cjs/Input.native.cjs +208 -0
- package/dist/cjs/Input.native.js +186 -283
- package/dist/cjs/Input.native.js.map +1 -1
- package/dist/cjs/InputNativeProps.cjs +9 -11
- package/dist/cjs/InputNativeProps.native.cjs +18 -0
- package/dist/cjs/InputNativeProps.native.js +9 -10
- package/dist/cjs/InputNativeProps.native.js.map +1 -1
- package/dist/cjs/TextArea.cjs +23 -39
- package/dist/cjs/TextArea.native.cjs +38 -0
- package/dist/cjs/TextArea.native.js +23 -38
- package/dist/cjs/TextArea.native.js.map +1 -1
- package/dist/cjs/index.cjs +15 -17
- package/dist/cjs/index.native.cjs +32 -0
- package/dist/cjs/index.native.js +15 -16
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/shared.cjs +74 -124
- package/dist/cjs/shared.native.cjs +101 -0
- package/dist/cjs/shared.native.js +80 -129
- package/dist/cjs/shared.native.js.map +1 -1
- package/dist/cjs/types.cjs +9 -11
- package/dist/cjs/types.native.cjs +18 -0
- package/dist/cjs/types.native.js +9 -10
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/esm/Input.mjs +59 -139
- package/dist/esm/Input.mjs.map +1 -1
- package/dist/esm/Input.native.js +174 -261
- 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 -22
- package/dist/esm/TextArea.mjs.map +1 -1
- package/dist/esm/TextArea.native.js +12 -22
- 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 +59 -107
- package/dist/esm/shared.mjs.map +1 -1
- package/dist/esm/shared.native.js +64 -112
- 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 +59 -139
- package/dist/jsx/Input.mjs.map +1 -1
- package/dist/jsx/Input.native.cjs +208 -0
- package/dist/jsx/Input.native.js +186 -283
- package/dist/jsx/Input.native.js.map +1 -1
- package/dist/jsx/InputNativeProps.mjs +0 -2
- package/dist/jsx/InputNativeProps.native.cjs +18 -0
- package/dist/jsx/InputNativeProps.native.js +9 -10
- package/dist/jsx/InputNativeProps.native.js.map +1 -1
- package/dist/jsx/TextArea.mjs +12 -22
- package/dist/jsx/TextArea.mjs.map +1 -1
- package/dist/jsx/TextArea.native.cjs +38 -0
- package/dist/jsx/TextArea.native.js +23 -38
- 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 +32 -0
- package/dist/jsx/index.native.js +15 -16
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/shared.mjs +59 -107
- package/dist/jsx/shared.mjs.map +1 -1
- package/dist/jsx/shared.native.cjs +101 -0
- package/dist/jsx/shared.native.js +80 -129
- package/dist/jsx/shared.native.js.map +1 -1
- package/dist/jsx/types.mjs +0 -2
- package/dist/jsx/types.native.cjs +18 -0
- package/dist/jsx/types.native.js +9 -10
- package/dist/jsx/types.native.js.map +1 -1
- package/package.json +17 -17
- package/src/Input.native.tsx +267 -242
- package/src/Input.tsx +150 -154
- package/src/TextArea.tsx +9 -18
- package/src/shared.tsx +56 -109
- package/src/types.ts +2 -2
- package/types/Input.d.ts +32 -50
- package/types/Input.d.ts.map +1 -1
- package/types/Input.native.d.ts +32 -50
- package/types/Input.native.d.ts.map +1 -1
- package/types/TextArea.d.ts +16 -34
- package/types/TextArea.d.ts.map +1 -1
- package/types/shared.d.ts +38 -109
- package/types/shared.d.ts.map +1 -1
- package/types/types.d.ts +2 -2
- package/types/types.d.ts.map +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,173 +1,169 @@
|
|
|
1
|
-
import { type GetProps, View, styled
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
})
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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
|
|
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:
|
|
10
|
-
fontFamily: '$body',
|
|
11
|
-
borderWidth: 1,
|
|
10
|
+
size: true,
|
|
12
11
|
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',
|
|
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
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
...
|
|
69
|
-
|
|
70
|
-
paddingHorizontal,
|
|
36
|
+
...inputSizeVariant(val, env),
|
|
37
|
+
height: 'auto',
|
|
71
38
|
}
|
|
72
|
-
}
|
|
39
|
+
})
|
|
73
40
|
|
|
74
|
-
export const
|
|
75
|
-
|
|
76
|
-
|
|
41
|
+
export const resolveTextAreaSize = (
|
|
42
|
+
props: Record<string, any>,
|
|
43
|
+
env: Parameters<typeof textAreaSizeVariant>[1]
|
|
77
44
|
) => {
|
|
78
|
-
const
|
|
79
|
-
const
|
|
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'
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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>.
|