2020-04-24 15:11:08 +00:00
|
|
|
import React from 'react';
|
2021-10-26 18:19:13 +00:00
|
|
|
import {Platform, TextInput, View} from 'react-native';
|
2020-04-24 15:11:08 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2021-10-26 18:19:13 +00:00
|
|
|
import {Color} from '../../config/Color';
|
|
|
|
import Text from '../Text';
|
2020-04-24 15:11:08 +00:00
|
|
|
|
|
|
|
export default function Index(props) {
|
2021-10-26 18:19:13 +00:00
|
|
|
const cardColor = Color.cardBackgroundColor;
|
|
|
|
const {
|
|
|
|
style,
|
|
|
|
onChangeText,
|
|
|
|
onFocus,
|
|
|
|
placeholder,
|
|
|
|
value,
|
|
|
|
success,
|
|
|
|
secureTextEntry,
|
|
|
|
keyboardType,
|
|
|
|
multiline,
|
|
|
|
textAlignVertical,
|
|
|
|
icon,
|
|
|
|
onSubmitEditing,
|
|
|
|
error,
|
|
|
|
...rest
|
|
|
|
} = props;
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<View style={[{
|
|
|
|
height: 46,
|
|
|
|
borderRadius: 5,
|
|
|
|
paddingHorizontal: 10,
|
|
|
|
width: '100%',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
alignItems: 'center',
|
|
|
|
flexDirection: 'row',
|
|
|
|
backgroundColor: cardColor
|
|
|
|
}, style]}>
|
|
|
|
{React.Children.map(icon, child =>
|
|
|
|
React.cloneElement(child, {
|
|
|
|
color: success ? Color.primaryColor : Color.accentColor,
|
|
|
|
style: {marginRight: Platform.OS === 'ios' ? 10 : 5}
|
|
|
|
}),
|
|
|
|
)}
|
|
|
|
<TextInput
|
2020-04-24 15:11:08 +00:00
|
|
|
style={{
|
2021-10-26 18:19:13 +00:00
|
|
|
fontFamily: 'Raleway',
|
|
|
|
flex: 1,
|
|
|
|
height: '100%',
|
|
|
|
color: Color.textColor,
|
|
|
|
paddingTop: 5,
|
|
|
|
paddingBottom: 5,
|
2020-04-24 15:11:08 +00:00
|
|
|
}}
|
|
|
|
onChangeText={text => onChangeText(text)}
|
|
|
|
onFocus={() => onFocus()}
|
|
|
|
autoCorrect={false}
|
|
|
|
placeholder={placeholder}
|
|
|
|
placeholderTextColor={success ? Color.grayColor : Color.primaryColor}
|
|
|
|
secureTextEntry={secureTextEntry}
|
|
|
|
value={value}
|
|
|
|
selectionColor={Color.primaryColor}
|
|
|
|
keyboardType={keyboardType}
|
|
|
|
multiline={multiline}
|
|
|
|
textAlignVertical={textAlignVertical}
|
|
|
|
onSubmitEditing={onSubmitEditing}
|
2021-10-26 18:19:13 +00:00
|
|
|
{...rest}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
{error !== '' && !success && (
|
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
alignSelf: 'flex-start',
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
marginTop: 5,
|
|
|
|
}}>
|
|
|
|
<Text caption2 accentColor>
|
|
|
|
{`${error} `}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
);
|
2020-04-24 15:11:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Index.propTypes = {
|
2021-10-26 18:19:13 +00:00
|
|
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
|
|
onChangeText: PropTypes.func,
|
|
|
|
onFocus: PropTypes.func,
|
|
|
|
placeholder: PropTypes.string,
|
|
|
|
value: PropTypes.string,
|
|
|
|
success: PropTypes.bool,
|
|
|
|
secureTextEntry: PropTypes.bool,
|
|
|
|
keyboardType: PropTypes.string,
|
|
|
|
multiline: PropTypes.bool,
|
|
|
|
textAlignVertical: PropTypes.string,
|
|
|
|
icon: PropTypes.node,
|
|
|
|
onSubmitEditing: PropTypes.func,
|
2020-04-24 15:11:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Index.defaultProps = {
|
2021-10-26 18:19:13 +00:00
|
|
|
style: {},
|
|
|
|
onChangeText: text => {
|
|
|
|
},
|
|
|
|
onFocus: () => {
|
|
|
|
},
|
|
|
|
placeholder: 'Placeholder',
|
|
|
|
value: '',
|
|
|
|
success: true,
|
|
|
|
secureTextEntry: false,
|
|
|
|
keyboardType: 'default',
|
|
|
|
multiline: false,
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
icon: null,
|
|
|
|
onSubmitEditing: () => {
|
|
|
|
},
|
2020-04-24 15:11:08 +00:00
|
|
|
};
|