본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Label (라벨)

원문 보기 위키 갱신

Label은 폼 필드와 다른 UI 요소에 라벨을 붙이는 텍스트 컴포넌트예요. 필수(required) 표시와 검증 상태를 지원해요. 문자열을 자식으로 넣으면 자동으로 Label.Text로 렌더링된답니다.

출처: 문서

본문

Import

import { Label } from 'heroui-native';

Anatomy

<Label>
  <Label.Text>...</Label.Text>
</Label>
  • Label: 라벨 상태를 관리하고 자식 컴포넌트에 컨텍스트를 제공하는 루트 컨테이너예요. 문자열 자식이 제공되면 자동으로 Label.Text로 렌더링돼요. disabled, required, invalid 상태를 지원해요.
  • Label.Text: 라벨의 텍스트 콘텐츠예요. 라벨 텍스트를 표시하고 라벨이 필수일 때 별표(asterisk)를 자동으로 보여줘요. invalid 또는 disabled일 때 색상이 바뀌어요.

Usage

Basic Usage

텍스트 콘텐츠로 라벨을 표시해요. 문자열 자식은 자동으로 Label.Text로 렌더링돼요.

<Label>Username</Label>

With Form Fields

폼 필드와 함께 Label을 사용해 접근 가능한(accessible) 라벨을 제공해요.

<TextField>
  <Label>Username</Label>
  <Input placeholder="Choose a username" />
</TextField>

Required Fields

isRequired prop을 사용해 필수 필드에 별표 표시를 보여줘요.

<TextField>
  <Label isRequired>Password</Label>
  <Input placeholder="Create a password" secureTextEntry />
</TextField>

Invalid State

검증 오류를 나타내기 위해 라벨을 invalid 상태로 표시해요.

import { FieldError, Label, TextField } from 'heroui-native';

<TextField isInvalid>
  <Label isInvalid>Confirm password</Label>
  <Input
    placeholder="Confirm your password"
    secureTextEntry
    value="different"
    editable={false}
  />
  <FieldError>Passwords do not match</FieldError>
</TextField>

Disabled State

비상호작용 필드를 나타내기 위해 라벨을 비활성화해요.

<TextField isDisabled>
  <Label>Subscription plan</Label>
  <Input value="Premium" />
</TextField>

Custom Layout

복합 컴포넌트를 사용해 커스텀 라벨 레이아웃을 구성해요.

<Label>
  <Label.Text>Custom label</Label.Text>
</Label>

Custom Styling

className, classNames 또는 styles prop을 사용해 커스텀 스타일을 적용해요.

<Label className="mb-2">
  <Label.Text
    className="text-lg"
    classNames={{
      text: "font-bold",
      asterisk: "text-danger"
    }}
  >
    Custom styled label
  </Label.Text>
</Label>

Example

import { FieldError, Label, TextField } from 'heroui-native';
import { View } from 'react-native';

export default function LabelExample() {
  return (
    <View className="flex-1 justify-center px-5 gap-8">
      <TextField>
        <Label>Username</Label>
        <Input placeholder="Choose a username" />
      </TextField>
      <TextField>
        <Label isRequired>Password</Label>
        <Input placeholder="Create a password" secureTextEntry />
      </TextField>
      <TextField isInvalid>
        <Label isInvalid>Confirm password</Label>
        <Input
          placeholder="Confirm your password"
          secureTextEntry
          value="different"
          editable={false}
        />
        <FieldError>Passwords do not match</FieldError>
      </TextField>
      <TextField isDisabled>
        <Label>Subscription plan</Label>
        <Input value="Premium" />
      </TextField>
    </View>
  );
}

더 많은 예시는 GitHub repository에서 찾을 수 있어요.

API Reference

Label

prop type default 설명
children React.ReactNode - 라벨 콘텐츠. 문자열이 제공되면 자동으로 Label.Text로 렌더링돼요. 그 외에는 자식을 그대로 렌더링해요
isRequired boolean false 라벨이 필수인지 여부. true일 때 별표 표시를 보여줘요
isInvalid boolean false 라벨이 invalid 상태인지 여부. 텍스트 색상을 danger로 변경해요
isDisabled boolean false 라벨이 비활성화되었는지 여부. 비활성 스타일을 적용하고 상호작용을 막아요
className string - 적용할 추가 CSS 클래스
animation "disable-all" | undefined undefined 애니메이션 설정. "disable-all"을 사용하면 자식을 포함한 모든 애니메이션이 비활성화돼요
...PressableProps PressableProps - 모든 표준 React Native Pressable props가 지원돼요

Label.Text

prop type default 설명
children React.ReactNode - 라벨 텍스트 콘텐츠
className string - 텍스트 요소에 적용할 추가 CSS 클래스
classNames ElementSlots<LabelSlots> - 라벨의 다른 부분에 적용할 추가 CSS 클래스
styles Partial<Record<LabelSlots, TextStyle>> - 라벨의 다른 부분에 대한 스타일
nativeID string - 접근성용 네이티브 ID. aria-labelledby로 라벨을 폼 필드에 연결하는 데 사용돼요
...TextProps TextProps - 모든 표준 React Native Text props가 지원돼요

ElementSlots<LabelSlots>

prop type 설명
text string 라벨 텍스트용 CSS 클래스
asterisk string 별표용 CSS 클래스

styles

prop type 설명
text TextStyle 라벨 텍스트용 스타일
asterisk TextStyle 별표용 스타일

더 알아보기 (Learn more)