ilink-world/components/TextInput/index.js

117 lines
3.6 KiB
JavaScript
Raw Normal View History

2020-04-24 15:11:08 +00:00
import React from 'react';
2021-11-15 20:15:24 +00:00
import {I18nManager, 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,
justifyContent: 'space-between',
alignItems: 'center',
flexDirection: 'row',
backgroundColor: cardColor
}, style]}>
{React.Children.map(icon, child =>
React.cloneElement(child, {
2021-11-15 20:15:24 +00:00
color: success ? Color.primaryLightColor : Color.accentColor,
2021-10-26 18:19:13 +00:00
style: {marginRight: Platform.OS === 'ios' ? 10 : 5}
}),
)}
2021-11-15 20:15:24 +00:00
{/* @ts-ignore */}
2021-10-26 18:19:13 +00:00
<TextInput
2020-04-24 15:11:08 +00:00
style={{
2021-11-15 20:15:24 +00:00
width: "100%",
2021-10-26 18:19:13 +00:00
height: '100%',
2021-11-15 20:15:24 +00:00
textAlign: I18nManager.isRTL ? 'right' : 'left',
color: success ? Color.textColor : Color.accentColor,
2021-10-26 18:19:13 +00:00
paddingTop: 5,
paddingBottom: 5,
2020-04-24 15:11:08 +00:00
}}
onChangeText={text => onChangeText(text)}
onFocus={() => onFocus()}
autoCorrect={false}
placeholder={placeholder}
2021-11-15 20:15:24 +00:00
placeholderTextColor={
success ? Color.grayColor : Color.accentColor
}
2020-04-24 15:11:08 +00:00
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
};