-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-input.tsx
81 lines (77 loc) · 1.84 KB
/
custom-input.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
import React, { useEffect, useState } from 'react';
import {
View,
TextInput,
type TextStyle,
type TextInputProps,
} from 'react-native';
import tw from './tailwind';
import { neutral700 } from './colors';
interface CustomInputProps extends TextInputProps {
onTextChange: (text: string) => void;
variant: string;
placeholder: string;
placeholderTextColor?: string;
viewStyle?: string;
textStyle?: TextStyle;
icon?: React.ReactNode;
disabled?: boolean;
caps?: boolean;
length?: number;
inputMode?: any;
props?: TextInputProps;
}
export function Input({
onTextChange,
variant,
placeholder,
placeholderTextColor,
viewStyle,
textStyle,
icon,
disabled,
caps,
length,
inputMode,
props,
}: CustomInputProps) {
const [height, setHeight] = useState(0);
const [isMultiline, setIsMultiline] = useState(false);
useEffect(() => {
if (variant === 'small') {
setHeight(8);
setIsMultiline(false);
} else if (variant === 'medium') {
setHeight(40);
setIsMultiline(true);
} else if (variant === 'large') {
setHeight(80);
setIsMultiline(true);
}
}, [variant]);
return (
<View
style={tw`flex-row border border-neutral rounded-lg p-2 ${
viewStyle ? viewStyle : ' '
}`}
>
<TextInput
style={[tw`flex-1 font-body min-h-${height}`, textStyle]}
placeholder={placeholder}
placeholderTextColor={
placeholderTextColor ? placeholderTextColor : neutral700
}
autoCapitalize={caps ? 'characters' : 'sentences'}
multiline={isMultiline}
maxLength={length ? length : undefined}
onChangeText={(text) => {
onTextChange(text);
}}
inputMode={inputMode ? inputMode : 'text'}
editable={!disabled}
{...props}
/>
{icon && icon}
</View>
);
}