phone_input.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // import React, { useState } from "react";
  2. // import { View, Text, TextInput, StyleSheet, ViewStyle, StyleProp } from "react-native";
  3. // import { HandleSignUpFormDataChange } from "../../types/signup";
  4. // interface PhoneInputProps {
  5. // placeholder: string;
  6. // extendedStyle?: StyleProp<ViewStyle>;
  7. // handleFormDataChange?: HandleSignUpFormDataChange;
  8. // editable?: boolean;
  9. // }
  10. // const PhoneInput: React.FC<PhoneInputProps> = ({ placeholder, extendedStyle, handleFormDataChange, editable }) => {
  11. // const [error, setError] = useState("");
  12. // const handleTextChange = (text: string) => {
  13. // if (text.length >= 8) {
  14. // setError("");
  15. // handleFormDataChange?.("phone", text);
  16. // handleFormDataChange?.("phoneVerificationStatus", true);
  17. // } else {
  18. // setError("Please enter at least 8 digits");
  19. // handleFormDataChange?.("phone", text);
  20. // handleFormDataChange?.("phoneVerificationStatus", false);
  21. // }
  22. // };
  23. // return (
  24. // <View>
  25. // <View style={[styles.inputContainer, extendedStyle]}>
  26. // <Text style={styles.prefix}>+852</Text>
  27. // <View style={styles.horizontalLine} />
  28. // <TextInput
  29. // keyboardType="numeric"
  30. // onChangeText={handleTextChange}
  31. // placeholder={placeholder}
  32. // style={[styles.input]}
  33. // placeholderTextColor="#888888"
  34. // editable={editable}
  35. // />
  36. // </View>
  37. // {error && <Text style={styles.errorMessage}>{error}</Text>}
  38. // </View>
  39. // );
  40. // };
  41. // const styles = StyleSheet.create({
  42. // inputContainer: {
  43. // maxWidth: "100%",
  44. // flexDirection: "row",
  45. // alignItems: "center",
  46. // justifyContent: "center",
  47. // borderWidth: 1,
  48. // borderColor: "#bbbbbb",
  49. // borderRadius: 12,
  50. // padding: 20,
  51. // },
  52. // prefix: {
  53. // marginRight: 5,
  54. // fontSize: 16,
  55. // },
  56. // horizontalLine: {
  57. // width: 24,
  58. // borderColor: "#bbbbbb",
  59. // borderWidth: 0.5,
  60. // transform: [{ rotate: "90deg" }],
  61. // },
  62. // input: {
  63. // flex: 1,
  64. // marginLeft: 5,
  65. // fontSize: 16,
  66. // },
  67. // errorMessage: {
  68. // fontSize: 14,
  69. // color: "#ff0033",
  70. // fontWeight: "400",
  71. // marginLeft: 10,
  72. // marginTop: 10,
  73. // },
  74. // });
  75. // export default PhoneInput;
  76. // import React, { useState } from "react";
  77. // import { View, Text, TextInput, StyleSheet, ViewStyle, StyleProp } from "react-native";
  78. // import { SignUpFormData } from "../../types/signUpFormData";
  79. // interface PhoneInputProps {
  80. // placeholder: string;
  81. // extendedStyle?: StyleProp<ViewStyle>;
  82. // editable?: boolean;
  83. // signUpFormData?: SignUpFormData;
  84. // setSignUpFormData?: (newFormData: Partial<SignUpFormData>) => void;
  85. // }
  86. // const PhoneInput: React.FC<PhoneInputProps> = ({
  87. // placeholder,
  88. // extendedStyle,
  89. // editable,
  90. // signUpFormData,
  91. // setSignUpFormData,
  92. // }) => {
  93. // const [error, setError] = useState("");
  94. // const handleTextChange = (text: string) => {
  95. // if (text.length >= 8) {
  96. // setError("");
  97. // setSignUpFormData({
  98. // ...signUpFormData,
  99. // phone: text,
  100. // phoneVerificationStatus: true,
  101. // });
  102. // } else {
  103. // setError("Please enter at least 8 digits");
  104. // setSignUpFormData({
  105. // ...signUpFormData,
  106. // phone: text,
  107. // phoneVerificationStatus: false,
  108. // });
  109. // }
  110. // };
  111. // return (
  112. // <View>
  113. // <View style={[styles.inputContainer, extendedStyle]}>
  114. // <Text style={styles.prefix}>+852</Text>
  115. // <View style={styles.horizontalLine} />
  116. // <TextInput
  117. // value={signUpFormData?.phone}
  118. // keyboardType="numeric"
  119. // onChangeText={handleTextChange}
  120. // placeholder={placeholder}
  121. // style={[styles.input]}
  122. // placeholderTextColor="#888888"
  123. // editable={editable}
  124. // />
  125. // </View>
  126. // {error && <Text style={styles.errorMessage}>{error}</Text>}
  127. // </View>
  128. // );
  129. // };
  130. // const styles = StyleSheet.create({
  131. // inputContainer: {
  132. // maxWidth: "100%",
  133. // flexDirection: "row",
  134. // alignItems: "center",
  135. // justifyContent: "center",
  136. // borderWidth: 1,
  137. // borderColor: "#bbbbbb",
  138. // borderRadius: 12,
  139. // padding: 20,
  140. // },
  141. // prefix: {
  142. // marginRight: 5,
  143. // fontSize: 16,
  144. // },
  145. // horizontalLine: {
  146. // width: 24,
  147. // borderColor: "#bbbbbb",
  148. // borderWidth: 0.5,
  149. // transform: [{ rotate: "90deg" }],
  150. // },
  151. // input: {
  152. // flex: 1,
  153. // marginLeft: 5,
  154. // fontSize: 16,
  155. // },
  156. // errorMessage: {
  157. // fontSize: 14,
  158. // color: "#ff0033",
  159. // fontWeight: "400",
  160. // marginLeft: 10,
  161. // marginTop: 10,
  162. // },
  163. // });
  164. // export default PhoneInput;
  165. import React from "react";
  166. import { View, Text, TextInput, StyleSheet, ViewStyle, StyleProp } from "react-native";
  167. interface PhoneInputProps {
  168. value: string | undefined;
  169. onChangeText: (text: string) => void;
  170. placeholder: string;
  171. extendedStyle?: StyleProp<ViewStyle>;
  172. editable?: boolean;
  173. }
  174. const PhoneInput: React.FC<PhoneInputProps> = ({ value, onChangeText, placeholder, extendedStyle, editable }) => {
  175. return (
  176. <View>
  177. <View style={[styles.inputContainer, extendedStyle]}>
  178. <Text style={styles.prefix}>+852</Text>
  179. <View style={styles.horizontalLine} />
  180. <TextInput
  181. value={value}
  182. onChangeText={onChangeText}
  183. keyboardType="numeric"
  184. placeholder={placeholder}
  185. style={[styles.input]}
  186. placeholderTextColor="#888888"
  187. editable={editable}
  188. />
  189. </View>
  190. </View>
  191. );
  192. };
  193. const styles = StyleSheet.create({
  194. inputContainer: {
  195. maxWidth: '100%',
  196. flexDirection: 'row',
  197. alignItems: 'center',
  198. justifyContent: 'center',
  199. borderWidth: 1,
  200. borderColor: '#bbbbbb',
  201. borderRadius: 12,
  202. padding: 20
  203. },
  204. prefix: {
  205. marginRight: 5,
  206. fontSize: 16
  207. },
  208. horizontalLine: {
  209. width: 24,
  210. borderColor: '#bbbbbb',
  211. borderWidth: 0.5,
  212. transform: [{ rotate: '90deg' }]
  213. },
  214. input: {
  215. flex: 1,
  216. marginLeft: 5,
  217. fontSize: 16
  218. },
  219. errorMessage: {
  220. fontSize: 14,
  221. color: '#ff0033',
  222. fontWeight: '400',
  223. marginLeft: 10,
  224. marginTop: 10
  225. }
  226. });
  227. export default PhoneInput;