import * as React from 'react'; import { TextInput, ViewStyle, TextStyle, View, TouchableOpacity, } from 'react-native'; import { getColor } from './style-utils'; import { InputClearIcon } from './icons/input-clear'; import { ErrorSymbolIcon } from './icons/error-symbol'; import { ClearSymbolIcon } from './icons/clear-symbol'; import { IdDashIcon } from './icons/id-dash'; import { AbleEyeIcon } from './icons/able-eye'; import { UnableEyeIcon } from './icons/unable-eye'; import { useState } from 'react'; import Label from './label'; import Text from './text'; interface LabelConfig { text?: string; style?: TextStyle; className?: string; required?: boolean; } interface InputConfig { mode?: 'default' | 'password' | 'id'; value: string; placeholder?: string; textColor?: string; placeholderColor?: string; backgroundColor?: string; width?: string; height?: string; radius?: string; border?: | { borderWidth: string; borderColor: string; } | string; textStyle?: TextStyle; className?: string; style?: ViewStyle; disabled?: boolean; // ID 모드 관련 idValue?: { first: string; second: string; }; onIdChange?: { onFirstChange: (text: string) => void; onSecondChange: (text: string) => void; }; // 패스워드 모드 관련 isSecureTextEntry?: boolean; onSecureTextEntryChange?: (isSecure: boolean) => void; characterCount?: boolean; maxCharacterCount?: number; } export interface StatusConfig { status: 'none' | 'error' | 'success'; message: string; messageStyle?: TextStyle; messageClassName?: string; } interface TextFieldProps { label?: LabelConfig; input: InputConfig; statusConfig?: StatusConfig; onClear?: () => void; onChangeText?: (text: string) => void; } export default function TextField({ label, input, statusConfig = { status: 'none', message: '' }, onClear, onChangeText, }: TextFieldProps) { const [isFocused, setIsFocused] = useState(false); const secondInputRef = React.useRef(null); const { mode = 'default', value, placeholder = '', textColor = 'black', placeholderColor = 'gray', backgroundColor = 'white', width = 'w-full', height = 'h-[56px]', radius = 'rounded-2xl', border = { borderWidth: '1', borderColor: 'gray' }, textStyle, className, style, disabled = false, idValue, onIdChange, isSecureTextEntry = true, onSecureTextEntryChange, characterCount = false, maxCharacterCount = 0, } = input; const borderStyle = typeof border === 'string' ? border : ''; const getStatusStyles = () => { if (statusConfig.status === 'none') { return isFocused ? { borderWidth: 1, borderColor: getColor('gray-500') } : { borderWidth: 0, backgroundColor: getColor('gray-100') }; } const statusStyles = { error: { borderWidth: 2, borderColor: getColor('red-500'), backgroundColor: 'rgba(239, 68, 68, 0.1)', }, success: { borderWidth: 2, borderColor: getColor('green-500'), backgroundColor: 'rgba(34, 197, 94, 0.1)', }, }; return statusStyles[statusConfig.status]; }; const getMessageClassName = () => { const defaultClasses = { error: 'text-red-500', success: 'text-green-500', }; return statusConfig.status !== 'none' ? `${defaultClasses[statusConfig.status]} ${statusConfig.messageClassName || ''}` : ''; }; return ( {label && ( )} {mode === 'default' && ( )} {mode === 'password' && ( )} {mode === 'id' && ( {(idValue?.first || idValue?.second) && onClear && ( )} )} {statusConfig.status !== 'none' && statusConfig.message && ( {statusConfig.status === 'error' && ( )} {statusConfig.status === 'success' && ( )} {/* {statusConfig.message} */} {statusConfig && statusConfig.message && ( {statusConfig.message} )} )} ); }