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

Chip (칩)

원문 보기 위키 갱신

Chip은 캡슐(capsule) 모양의 컴팩트한 요소를 표시하는 컴포넌트예요. 라벨, 태그, 상태 표시 등 다양한 곳에 가볍게 사용할 수 있어요. size, variant, color prop으로 크기와 시각적 스타일을 조절할 수 있어요.

출처: 문서

본문

Import

import { Chip } from 'heroui-native';

Anatomy

<Chip>
  <Chip.Label>...</Chip.Label>
</Chip>
  • Chip: 컴팩트한 요소를 표시하는 메인 컨테이너예요.
  • Chip.Background: 칩 표면 뒤에 렌더링되는 테마 인식 배경 컨테이너예요. secondary variant와 color="default"를 사용하는 primary/soft variant에서 활성 테마가 기본 배경 콘텐츠(예: glass)를 등록하면 자동으로 마운트돼요. background prop으로 교체하거나 제거할 수 있어요.
  • Chip.Label: 칩의 텍스트 콘텐츠예요.

Usage

Basic Usage

Chip 컴포넌트는 캡슐 모양으로 텍스트나 커스텀 콘텐츠를 표시해요.

<Chip>Basic Chip</Chip>

Sizes

size prop으로 칩 크기를 조절해요.

<Chip size="sm">Small</Chip>
<Chip size="md">Medium</Chip>
<Chip size="lg">Large</Chip>

Variants

variant prop으로 다양한 시각적 스타일을 선택해요.

<Chip variant="primary">Primary</Chip>
<Chip variant="secondary">Secondary</Chip>
<Chip variant="tertiary">Tertiary</Chip>
<Chip variant="soft">Soft</Chip>

Colors

color prop으로 다양한 색상 테마를 적용해요.

<Chip color="accent">Accent</Chip>
<Chip color="default">Default</Chip>
<Chip color="success">Success</Chip>
<Chip color="warning">Warning</Chip>
<Chip color="danger">Danger</Chip>

With Icons

복합 컴포넌트를 사용해 텍스트와 함께 아이콘이나 커스텀 콘텐츠를 추가해요.

<Chip>
  <Icon name="star" size={12} />
  <Chip.Label>Featured</Chip.Label>
</Chip>

<Chip>
  <Chip.Label>Close</Chip.Label>
  <Icon name="close" size={12} />
</Chip>

Custom Styling

className 또는 style prop으로 커스텀 스타일을 적용해요.

<Chip className="bg-purple-600 px-6">
  <Chip.Label className="text-white">Custom</Chip.Label>
</Chip>

Disable All Animations

animation prop에 "disable-all" 값을 사용해 자식까지 포함한 모든 애니메이션을 비활성화해요.

{
  /* Disable all animations including children */
}
<Chip animation="disable-all">No Animations</Chip>;

Example

import { Chip } from 'heroui-native';
import { View, Text } from 'react-native';
import { Ionicons } from '@expo/vector-icons';

export default function ChipExample() {
  return (
    <View className="gap-4 p-4">
      <View className="flex-row flex-wrap gap-2">
        <Chip size="sm">Small</Chip>
        <Chip size="md">Medium</Chip>
        <Chip size="lg">Large</Chip>
      </View>

      <View className="flex-row flex-wrap gap-2">
        <Chip variant="primary" color="accent">
          Primary
        </Chip>
        <Chip variant="secondary" color="success">
          <View className="size-1.5 rounded-full bg-success" />
          <Chip.Label>Success</Chip.Label>
        </Chip>
        <Chip variant="tertiary" color="warning">
          <Ionicons name="star" size={12} color="#F59E0B" />
          <Chip.Label>Premium</Chip.Label>
        </Chip>
      </View>

      <View className="flex-row gap-2">
        <Chip variant="secondary">
          <Chip.Label>Remove</Chip.Label>
          <Ionicons name="close" size={14} color="#6B7280" />
        </Chip>
        <Chip className="bg-purple-600">
          <Chip.Label className="text-white font-semibold">Custom</Chip.Label>
        </Chip>
      </View>
    </View>
  );
}

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

API Reference

Chip

prop type default 설명
children React.ReactNode - 칩 안에 렌더링할 콘텐츠
size 'sm' | 'md' | 'lg' 'md' 칩의 크기
variant 'primary' | 'secondary' | 'tertiary' | 'soft' 'primary' 칩의 시각적 variant
color 'accent' | 'default' | 'success' | 'warning' | 'danger' 'accent' 칩의 색상 테마
className string - 적용할 추가 CSS 클래스
animation "disable-all" | undefined undefined 애니메이션 설정. "disable-all"을 사용하면 자식을 포함한 모든 애니메이션이 비활성화돼요
background React.ReactNode - 칩 표면 뒤의 배경 레이어. undefined는 secondary variant와 color="default"를 사용하는 primary/soft variant에 대해 테마 인식 기본값을 렌더링해요. 커스텀 노드로 교체하거나 null로 제거할 수 있어요
...PressableProps PressableProps - 모든 Pressable props가 지원돼요

Chip.Background

칩 표면 뒤에 렌더링되는 absolute-fill 컨테이너예요. 자식이 없으면 활성 라이브러리 테마가 기본 콘텐츠(예: 유리 블러 레이어)를 결정해요. 자식을 전달하면 같은 위치 지정과 클리핑으로 커스텀 콘텐츠를 호스팅할 수 있어요.

prop type default 설명
children React.ReactNode - 배경 컨테이너 안의 커스텀 콘텐츠
className string - 추가 CSS 클래스
...ViewProps ViewProps - 모든 표준 View props가 지원돼요

Chip.Label

prop type default 설명
children React.ReactNode - 라벨로 렌더링할 텍스트 또는 콘텐츠
className string - 적용할 추가 CSS 클래스
...TextProps TextProps - 모든 표준 Text props가 지원돼요

Hooks

useChip

Chip 컨텍스트 값에 접근하는 훅이에요. 칩의 size, variant, color를 반환해요.

import { useChip } from 'heroui-native';

const { size, variant, color } = useChip();

Return Value

property type 설명
size 'sm' | 'md' | 'lg' 칩의 크기
variant 'primary' | 'secondary' | 'tertiary' | 'soft' 칩의 시각적 variant
color 'accent' | 'default' | 'success' | 'warning' | 'danger' 칩의 색상 테마

Note: 이 훅은 반드시 Chip 컴포넌트 안에서 사용해야 해요. 칩 컨텍스트 밖에서 호출하면 에러가 발생해요.

더 알아보기 (Learn more)