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
|
import React from 'react';
import {View, TextInput, StyleSheet, TextInputProps, ViewStyle, StyleProp} from 'react-native';
import * as Animatable from 'react-native-animatable';
import {TAGG_LIGHT_PURPLE} from '../../constants';
interface TaggInputProps extends TextInputProps {
valid?: boolean;
invalidWarning?: string;
attemptedSubmit?: boolean;
externalStyles?: Record<string, StyleProp<ViewStyle>>
}
/**
* An input component that receives all props a normal TextInput component does. TaggInput components grow to 60% of their parent's width by default, but this can be set using the `width` prop.
*/
const TaggInput = React.forwardRef((props: TaggInputProps, ref: any) => {
return (
<View style={styles.container}>
<TextInput
style={[styles.input, props.externalStyles?.inputWarning]}
placeholderTextColor="#ddd"
clearButtonMode="while-editing"
ref={ref}
{...props}
/>
{props.attemptedSubmit && !props.valid && (
<Animatable.Text
animation="shake"
duration={500}
style={[styles.warning, props.externalStyles?.warning]}>
{props.invalidWarning}
</Animatable.Text>
)}
</View>
);
});
const styles = StyleSheet.create({
container: {
alignItems: 'center',
marginVertical: 11,
},
input: {
width: '100%',
minWidth: '60%',
height: 40,
fontSize: 16,
fontWeight: '600',
color: '#fff',
borderColor: '#fffdfd',
borderWidth: 2,
borderRadius: 20,
paddingLeft: 13,
},
warning: {
fontSize: 14,
marginTop: 5,
color: TAGG_LIGHT_PURPLE,
maxWidth: 350,
textAlign: 'center',
},
});
export default TaggInput;
|