TextInput
1줄의 텍스트를 입력하고 검증 상태(isError, isSuccess)를 나타낼 수 있는 컴포넌트입니다. 기본 입력 타입은 text
입니다.
Props
id
: id 값name
: 이름type
text(default)
: 문자열email
: 이메일number
: 숫자password
: 비밀번호search
: 검색어tel
: 전화번호date
: 날짜url
: 웹 주소
value
: 값defaultValue
: 기본값placeholder
: 도움말min
: date, number 타입의 최솟값max
: date, number 타입의 최댓값pattern
: 정규식required
: 필수 입력 여부isError
: 입력값 검증 실패isSuccess
: 입력값 검증 성공onChange
: onChange 이벤트 발생 시 처리할 핸들러onBlur
: onBlur 이벤트 발생 시 처리할 핸들러
export type TextInputProps = {
id?: string;
name?: string;
type?: TextInputTypes;
value?: string;
defaultValue?: string;
placeholder?: string;
min?: string;
max?: string;
pattern?: string;
required?: boolean;
isError?: boolean;
isSuccess?: boolean;
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
onBlur?: (e: FocusEvent<HTMLInputElement>) => void;
};
Usage
const TextInputDemo = () => {
const [value, setValue] = useState('');
const [isError, setIsError] = useState(false);
const handleOnChange = ({ target }: ChangeEvent<HTMLInputElement>) => {
const currentValue = target.value;
setValue(currentValue);
setIsError(currentValue.length > 10);
};
return (
<TextInput
name="textInputExample"
onChange={handleOnChange}
isError={isError}
required
/>
);
};