UNPKG

react-native-modern-elements

Version:

A modern, customizable UI component library for React Native

104 lines (103 loc) 4.81 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import CancelIcon from "../assets/svg/CancelIcon"; import { Ionicons } from "@expo/vector-icons"; import React, { memo, useState } from "react"; import { StyleSheet, Text, TextInput, TouchableOpacity, View, } from "react-native"; import { colors, radius, spacingX } from "../constants/theme"; import { verticalScale } from "../utils/styling"; // Issure // 1. input clear but first remove keyboard then clear input const Input = (props) => { const { error, secureTextEntry, isValid, cancelIcon, value = "", lable = "", wrapperStyle = {}, lableStyle = {}, onChangeText } = props, restProps = __rest(props, ["error", "secureTextEntry", "isValid", "cancelIcon", "value", "lable", "wrapperStyle", "lableStyle", "onChangeText"]); const [isSecure, setIsSecure] = useState(secureTextEntry || false); const handleClear = () => { onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(""); }; return (React.createElement(View, { style: [styles.wrapper, wrapperStyle] }, lable && React.createElement(Text, { style: [styles.lableStyles, lableStyle] }, lable), React.createElement(View, { style: [ styles.container, props.containerStyle, error ? { borderColor: "red" } : isValid ? { borderColor: "green" } : null, props.icon ? null : { paddingLeft: 10 }, ] }, props.icon && (React.createElement(View, { style: [ styles.iconDefaultStyle, props.iconStyle ? props.iconStyle : null, ] }, props === null || props === void 0 ? void 0 : props.icon)), React.createElement(TextInput, Object.assign({ style: [ styles.input, props.inputStyle, error ? { color: "red" } : isValid ? { color: "green" } : { color: "#333333" }, ], placeholderTextColor: "#7f7f7f", value: value, onChangeText: onChangeText, secureTextEntry: isSecure }, restProps)), secureTextEntry && (React.createElement(TouchableOpacity, { style: styles.iconContainer, onPress: () => setIsSecure((prev) => !prev) }, React.createElement(Ionicons, { name: isSecure ? "eye-off" : "eye", size: 20, color: "gray" }))), value.length > 0 && cancelIcon && (React.createElement(TouchableOpacity, { style: styles.iconContainer, onPress: handleClear }, cancelIcon ? (cancelIcon) : (React.createElement(CancelIcon, { color: "#333333", strokeWidth: 1 }))))), error && React.createElement(Text, { style: styles.errorText }, error))); }; const styles = StyleSheet.create({ wrapper: { width: "100%", gap: 10, }, container: { flexDirection: "row", height: verticalScale(44), alignItems: "center", borderWidth: 1, borderColor: colors.black_15, // borderRadius: radius._30, paddingRight: spacingX._10, // paddingLeft: props.icon ? spacingX._10 : 0, gap: spacingX._10, }, input: { flex: 1, fontSize: verticalScale(14), }, iconContainer: { justifyContent: "center", alignItems: "center", marginLeft: spacingX._10, // Add some space between the input and icon padding: 8, }, iconDefaultStyle: { height: "100%", width: verticalScale(40), backgroundColor: colors === null || colors === void 0 ? void 0 : colors.white_40, borderTopLeftRadius: radius === null || radius === void 0 ? void 0 : radius._10, borderBottomLeftRadius: radius === null || radius === void 0 ? void 0 : radius._10, flexDirection: "row", justifyContent: "center", alignItems: "center", }, errorText: { color: "red", fontSize: verticalScale(12), marginTop: verticalScale(4), marginLeft: spacingX._10, // Align error text with input padding }, lableStyles: { fontSize: verticalScale(14), color: colors === null || colors === void 0 ? void 0 : colors.black_80, }, }); export default memo(Input);