-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordInput.js
77 lines (70 loc) · 2.03 KB
/
PasswordInput.js
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
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { TouchableOpacity, View, Text } from 'react-native'
import Icon from 'react-native-vector-icons/Entypo'
import TextInput from './RNTextInput'
class PasswordInput extends Component {
constructor (props) {
super(props)
this.state = {
show: false
}
}
toggleShow () {
this.setState({ show: !this.state.show })
}
render () {
const {
onRef,
value,
valid,
confirm,
editable,
validate,
errorText,
iconElement,
onChangeText,
returnKeyType,
errorTextStyle,
onSubmitEditing,
borderBottomColor,
editableTextStyle,
readOnlyTextStyle,
togglePasswordControlColor
} = this.props
return (
<View>
<TextInput
onRef={onRef}
value={value}
valid={valid}
validate={validate}
editable={editable}
secureTextEntry={!this.state.show}
returnKeyType={returnKeyType}
label={confirm ? 'Confirm password' : 'Password'}
errorText={errorText}
errorTextStyle={errorTextStyle}
editableTextStyle={editableTextStyle}
readOnlyTextStyle={readOnlyTextStyle}
borderBottomColor={borderBottomColor}
onChangeText={onChangeText}
onSubmitEditing={onSubmitEditing}
iconElement={iconElement || <Icon size={20} name='lock' style={{ color: borderBottomColor }} />}
/>
<TouchableOpacity onPress={this.toggleShow.bind(this)} style={{ position: 'absolute', top: 10, right: 0, padding: 10 }}>
<Text style={{ color: togglePasswordControlColor }}>{this.state.show ? 'HIDE' : 'SHOW'}</Text>
</TouchableOpacity>
</View>
)
}
}
PasswordInput.defaultProps = {
confirm: false
}
PasswordInput.propTypes = {
// You can ensure that your prop is limited to specific values by treating
// it as an enum.
validate: PropTypes.oneOf(['onBlur', 'onChangeText'])
}
export default PasswordInput