phone_input.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React from "react";
  2. import { View, Text, TextInput, StyleSheet, ViewStyle, StyleProp, KeyboardTypeOptions, TextInputProps } from "react-native";
  3. interface PhoneInputProps {
  4. value: string | undefined;
  5. onChangeText: (text: string) => void;
  6. placeholder: string;
  7. extendedStyle?: StyleProp<ViewStyle>;
  8. editable?: boolean;
  9. textContentType?: TextInputProps['textContentType'];
  10. autoComplete?: TextInputProps['autoComplete']
  11. keyboardType?: KeyboardTypeOptions
  12. autoCapitalize?: TextInputProps['autoCapitalize']
  13. }
  14. const PhoneInput: React.FC<PhoneInputProps> = ({ value, onChangeText, placeholder, extendedStyle, editable, keyboardType, textContentType, autoComplete, autoCapitalize }) => {
  15. return (
  16. <View>
  17. <View style={[styles.inputContainer, extendedStyle]}>
  18. <Text style={styles.prefix}>+852</Text>
  19. <View style={styles.horizontalLine} />
  20. <TextInput
  21. value={value}
  22. onChangeText={onChangeText}
  23. keyboardType={keyboardType}
  24. placeholder={placeholder}
  25. style={[styles.input, {fontFamily: 'Roboto-Regular'}]}
  26. placeholderTextColor="#888888"
  27. editable={editable}
  28. textContentType={textContentType}
  29. autoComplete={autoComplete}
  30. autoCapitalize={autoCapitalize}
  31. />
  32. </View>
  33. </View>
  34. );
  35. };
  36. const styles = StyleSheet.create({
  37. inputContainer: {
  38. maxWidth: '100%',
  39. flexDirection: 'row',
  40. alignItems: 'center',
  41. justifyContent: 'center',
  42. borderWidth: 1,
  43. borderColor: '#bbbbbb',
  44. borderRadius: 12,
  45. padding: 20
  46. },
  47. prefix: {
  48. marginRight: 5,
  49. fontSize: 16
  50. },
  51. horizontalLine: {
  52. width: 24,
  53. borderColor: '#bbbbbb',
  54. borderWidth: 0.5,
  55. transform: [{ rotate: '90deg' }]
  56. },
  57. input: {
  58. flex: 1,
  59. marginLeft: 5,
  60. fontSize: 16,
  61. paddingVertical: 0
  62. },
  63. errorMessage: {
  64. fontSize: 14,
  65. color: '#ff0033',
  66. fontWeight: '400',
  67. marginLeft: 10,
  68. marginTop: 10
  69. }
  70. });
  71. export default PhoneInput;