import Styles from "@/constants/Styles";
import { useTheme } from "@/providers/ThemeProvider";
import { Dimensions, Platform, TextInput, View } from "react-native";
import Text from "./Text";
type Props = {
label?: string;
placeholder?: string;
onChange?: (val: string) => void;
info?: string;
itemLeft?: React.ReactNode;
itemRight?: React.ReactNode;
error?: boolean;
errorText?: string;
required?: boolean;
type: 'default' | 'visible-password' | 'numeric'
round?: boolean
width?: number
bg?: string
value?: string
disable?: boolean
multiline?: boolean
mb?: boolean
focus?: boolean
};
export function InputForm({ label, value, placeholder, onChange, info, disable, error, errorText, required, itemLeft, itemRight, type, round, width, bg, multiline, mb = true, focus }: Props) {
const lebar = Dimensions.get("window").width;
const { colors } = useTheme();
if (itemLeft != undefined || itemRight != undefined) {
const hasBothItems = itemLeft != undefined && itemRight != undefined;
const baseInputWidth = width ? lebar * width / 100 : lebar * 0.78;
// When both icons present, shrink TextInput by right icon size to keep container width stable
const textInputWidth = hasBothItems ? baseInputWidth - 30 : baseInputWidth;
return (
{
label != undefined && (
{label}
{required && (*)}
)
}
{hasBothItems ? itemLeft : (itemRight != undefined ? itemRight : itemLeft)}
{hasBothItems && itemRight}
{error && ({errorText})}
{info != undefined && ({info})}
)
}
return (
{
label != undefined && (
{label}
{required && (*)}
)
}
{error && ({errorText})}
{info != undefined && ({info})}
)
}