import { useState } from "react"; import { Image, InputAccessoryView, Keyboard, Pressable, Text, TextInput, View, } from "react-native"; // import CountryPicker, { DARK_THEME } from "react-native-country-picker-modal"; import usePlaceApi from "react-native-minuit/src/hooks/usePlacesApi"; import { art, icons } from "../assets"; import { Fonts, Palette, Style, gutters } from "../styles"; import { FONT_FAMILY } from "../styles/Fonts"; import { BlurView } from "expo-blur"; import EyeSlashSVG from "../assets/UI/EyeSlashSVG"; import EyeSVG from "../assets/UI/EyeSVG"; import { GOOGLE_API_KEY } from "../data/keys"; import { isWeb } from "../hooks/useLayoutType"; const Input = ({ inputRef = null, label = "", placeholder = "", containerStyle = {}, textInputStyle = {}, value, setValue, textInputProps = {}, type = "default", // "default" | "password" | "textarea" | "coinAmount" | "countryPicker" | "autoCompleteAddress" theme = "default", // "default" | "radioactiv" | "dashed" borderType = "none", // "solid" | "dashed" | "none" layout = "default", // "default" | "line" isNumeric = false, isBlur = false, }) => { const [isFocused, setIsFocused] = useState(false); const [showPassword, setShowPassword] = useState(false); const isDefaultLayout = layout === "default"; const mainColor = theme === "radioactiv" ? Palette.radioactivGreen : Palette.primary; const isRoundedRectangle = ["textarea", "coinAmount"].includes(type) || layout === "default"; const inputAccessoryViewID = "uniqueID"; const { places } = usePlaceApi({ query: type === "autoCompleteAddress" ? value : "", apiKey: GOOGLE_API_KEY, // Your Google API Key queryFields: "formatted_address,geometry,name,address_components", queryCountries: ["fr"], language: "fr-FR", minChars: 2, }); const ContainerView = isBlur ? BlurView : View; const resolvedKeyboardType = textInputProps?.keyboardType ?? (isNumeric ? "numeric" : type === "email" ? "email-address" : "default"); return ( <> {label?.length > 0 && ( {label} )} {type === "search" ? ( ) : null} {type !== "countryPicker" && ( setIsFocused(true)} onBlur={() => setIsFocused(false)} style={{ width: "100%", ...(isRoundedRectangle ? { height: "100%", flex: 1, textAlignVertical: type === "textarea" ? "top" : "center", } : { textAlign: "center" }), fontSize: 14, color: Palette.white, fontFamily: FONT_FAMILY.InterRegular, ...(isWeb ? { lineHeight: "auto", } : {}), ...textInputStyle, }} {...(type === "password" ? { secureTextEntry: !showPassword, autoCapitalize: "none", autoCompleteType: "password", textContentType: "password", } : {})} {...(type === "email" ? { autoCapitalize: "none", autoCompleteType: "email", textContentType: "emailAddress", } : {})} keyboardType={resolvedKeyboardType} keyboardAppearance="dark" inputAccessoryViewID={inputAccessoryViewID} {...textInputProps} /> )} {type === "password" ? ( setShowPassword(!showPassword)}> {showPassword ? : } ) : type === "coinAmount" ? ( ) : null} {type === "autoCompleteAddress" && places?.[0]?.description && places?.[0]?.description !== value && places.map((place, index) => ( { setValue(place?.description); }} style={{ ...Style.containerSpaceBetween, marginBottom: index !== places.length - 1 ? gutters / 2 : 0, }} > {place?.description || "-"} ))} {(type === "textarea" || isNumeric) && !isWeb && ( Keyboard.dismiss()} style={{ ...Style.containerRow, justifyContent: "flex-end", backgroundColor: Palette.transparentPrimary, padding: gutters, paddingVertical: gutters / 2, }} > Fermer )} ); }; export { Input };