텍스트 영역 (TextArea)
TextArea는 여러 줄의 긴 사용자 입력을 받기 위한 텍스트 입력 컴포넌트로, 스타일링된 테두리와 배경을 제공해요. 단독으로 사용할 수도 있고 TextField 컴포넌트 안에서 완전한 폼 구조를 만들 때도 자연스럽게 어울린답니다. 이 문서에서는 기본 사용법부터 검증, 비활성화, 변형, 커스터마이징까지 하나씩 살펴볼게요.
출처: 문서
본문
Import
import { TextArea } from 'heroui-native';
Usage
Basic Usage
TextArea는 단독으로 사용하거나 TextField 컴포넌트 안에서 사용할 수 있어요.
import { TextArea } from 'heroui-native';
<TextArea placeholder="Enter your message" />
Within TextField
TextArea는 완전한 폼 구조를 위해 TextField와 매끄럽게 함께 동작해요.
import { Description, Label, TextArea, TextField } from 'heroui-native';
<TextField>
<Label>Message</Label>
<TextArea placeholder="Enter your message here..." />
<Description>Please provide as much detail as possible.</Description>
</TextField>
With Validation
텍스트 영역이 유효하지 않을 때 오류 상태를 표시해요.
import { FieldError, Label, TextArea, TextField } from 'heroui-native';
<TextField isRequired isInvalid={true}>
<Label>Message</Label>
<TextArea placeholder="Enter your message" />
<FieldError>Please enter a valid message</FieldError>
</TextField>
Disabled State
텍스트 영역을 비활성화해서 상호작용을 막을 수 있어요.
import { Label, TextArea, TextField } from 'heroui-native';
<TextField isDisabled>
<Label>Disabled Field</Label>
<TextArea placeholder="Cannot edit" value="Read only value" />
</TextField>
With Variant
상황에 따라 다양한 변형을 사용해 텍스트 영역을 스타일링할 수 있어요.
import { Label, TextArea, TextField } from 'heroui-native';
<TextField>
<Label>Primary Variant</Label>
<TextArea placeholder="Primary style text area" variant="primary" />
</TextField>
<TextField>
<Label>Secondary Variant</Label>
<TextArea placeholder="Secondary style text area" variant="secondary" />
</TextField>
Custom Styling
className을 사용해 텍스트 영역의 모양을 커스터마이즈할 수 있어요.
import { Label, TextArea, TextField } from 'heroui-native';
<TextField>
<Label>Custom Styled</Label>
<TextArea
placeholder="Custom colors"
className="bg-blue-50 border-blue-500 focus:border-blue-700"
/>
</TextField>
Example
import { Description, FieldError, Label, TextArea, TextField } from 'heroui-native';
import { View } from 'react-native';
export default function TextAreaExample() {
return (
<View className="gap-8">
<TextField>
<Label>Primary Variant</Label>
<TextArea placeholder="Primary style text area" variant="primary" />
<Description>Default variant with primary styling</Description>
</TextField>
<TextField>
<Label>Secondary Variant</Label>
<TextArea
placeholder="Secondary style text area"
variant="secondary"
/>
<Description>Secondary variant for surfaces</Description>
</TextField>
</View>
);
}
더 많은 예시는 GitHub 저장소에서 찾아볼 수 있어요.
API Reference
TextArea는 Input 컴포넌트를 확장하며 모든 prop을 상속해요. 차이는 기본값뿐이에요: multiline은 기본적으로 true, textAlignVertical은 기본적으로 'top'이에요.