태그 그룹 (Tag Group)
TagGroup 컴포넌트는 선택 가능한 여러 개의 태그를 관리하는 컴포넌트예요. 단일/다중 선택 모드, 비활성화, 제거 버튼, 렌더 함수 등 다양한 기능을 지원해서 필터나 카테고리 선택 UI를 쉽게 만들 수 있어요.
출처: 문서
본문
Import
import { TagGroup } from 'heroui-native';
Anatomy
<TagGroup>
<TagGroup.List>
<TagGroup.Item id="tag-1">
<TagGroup.ItemLabel>...</TagGroup.ItemLabel>
<TagGroup.ItemRemoveButton />
</TagGroup.Item>
</TagGroup.List>
</TagGroup>
- TagGroup: 태그 선택 상태, 비활성화 키, 제거 기능을 관리하는 메인 컨테이너예요. 모든 자식 컴포넌트에 size와 variant 컨텍스트를 제공해요.
- TagGroup.List: 선택적 빈 상태 렌더링과 함께 태그 목록을 렌더링하는 컨테이너예요.
- TagGroup.Item: 그룹 안의 개별 태그예요. 문자열 자식(TagGroup.ItemLabel에 자동으로 감싸짐), 렌더 함수 자식, 또는 커스텀 레이아웃을 지원해요.
- TagGroup.ItemBackground: 태그 표면 뒤에 렌더링되는 선택적 테마 인식 배경 컨테이너예요. 활성 테마가 기본 배경 콘텐츠(예:
glass)를 등록하면 선택되지 않은 항목에 자동으로 마운트되고, 폴백 색상은 variant(surface또는default)를 따릅니다.TagGroup.Item의backgroundprop으로 대체하거나 제거할 수 있어요. - TagGroup.ItemLabel: 태그의 텍스트 라벨이에요. 문자열 자식이 제공되면 자동으로 렌더링되고, 명시적으로 사용할 수도 있어요.
- TagGroup.ItemRemoveButton: 태그의 제거 버튼이에요. 제거가 필요할 때 명시적으로 배치해야 해요. TagGroup에
onRemove가 제공되었을 때만 동작해요.
Usage
기본 사용법 (Basic Usage)
선택 가능한 항목이 있는 간단한 태그 그룹을 표시해요.
<TagGroup selectionMode="single">
<TagGroup.List>
<TagGroup.Item id="news">News</TagGroup.Item>
<TagGroup.Item id="travel">Travel</TagGroup.Item>
<TagGroup.Item id="gaming">Gaming</TagGroup.Item>
</TagGroup.List>
</TagGroup>
단일 선택 모드 (Single Selection Mode)
한 번에 하나의 태그만 선택할 수 있게 해요.
<TagGroup selectionMode="single" defaultSelectedKeys={['news']}>
<TagGroup.List>
<TagGroup.Item id="news">News</TagGroup.Item>
<TagGroup.Item id="travel">Travel</TagGroup.Item>
<TagGroup.Item id="gaming">Gaming</TagGroup.Item>
</TagGroup.List>
</TagGroup>
다중 선택 모드 (Multiple Selection Mode)
동시에 여러 태그를 선택할 수 있게 해요.
<TagGroup selectionMode="multiple" defaultSelectedKeys={['news', 'travel']}>
<TagGroup.List>
<TagGroup.Item id="news">News</TagGroup.Item>
<TagGroup.Item id="travel">Travel</TagGroup.Item>
<TagGroup.Item id="gaming">Gaming</TagGroup.Item>
</TagGroup.List>
</TagGroup>
제어된 선택 (Controlled Selection)
selectedKeys와 onSelectionChange로 선택 상태를 제어해요.
const [selected, setSelected] = useState(new Set(['news']));
<TagGroup
selectionMode="single"
selectedKeys={selected}
onSelectionChange={setSelected}
>
<TagGroup.List>
<TagGroup.Item id="news">News</TagGroup.Item>
<TagGroup.Item id="travel">Travel</TagGroup.Item>
<TagGroup.Item id="gaming">Gaming</TagGroup.Item>
</TagGroup.List>
</TagGroup>;
변형 (Variants)
태그에 다양한 시각적 변형을 적용해요.
<TagGroup selectionMode="single" variant="default">
<TagGroup.List>
<TagGroup.Item id="news">News</TagGroup.Item>
<TagGroup.Item id="travel">Travel</TagGroup.Item>
</TagGroup.List>
</TagGroup>
<TagGroup selectionMode="single" variant="surface">
<TagGroup.List>
<TagGroup.Item id="news">News</TagGroup.Item>
<TagGroup.Item id="travel">Travel</TagGroup.Item>
</TagGroup.List>
</TagGroup>
크기 (Sizes)
그룹 안의 모든 태그 크기를 제어해요.
<TagGroup selectionMode="single" size="sm">
<TagGroup.List>
<TagGroup.Item id="news">News</TagGroup.Item>
</TagGroup.List>
</TagGroup>
<TagGroup selectionMode="single" size="md">
<TagGroup.List>
<TagGroup.Item id="news">News</TagGroup.Item>
</TagGroup.List>
</TagGroup>
<TagGroup selectionMode="single" size="lg">
<TagGroup.List>
<TagGroup.Item id="news">News</TagGroup.Item>
</TagGroup.List>
</TagGroup>
제거 버튼과 함께 (With Remove Button)
onRemove를 제공하고 각 항목에 TagGroup.ItemRemoveButton을 배치해 태그에 제거 버튼을 추가해요.
const [tags, setTags] = useState([
{ id: 'news', name: 'News' },
{ id: 'travel', name: 'Travel' },
]);
const onRemove = (keys) => {
setTags((prev) => prev.filter((tag) => !keys.has(tag.id)));
};
<TagGroup selectionMode="single" onRemove={onRemove}>
<TagGroup.List>
{tags.map((tag) => (
<TagGroup.Item key={tag.id} id={tag.id}>
<TagGroup.ItemLabel>{tag.name}</TagGroup.ItemLabel>
<TagGroup.ItemRemoveButton />
</TagGroup.Item>
))}
</TagGroup.List>
</TagGroup>;
렌더 함수 자식 (Render Function Children)
렌더 함수를 사용해 커스텀 레이아웃을 위한 isSelected와 isDisabled에 접근해요.
<TagGroup selectionMode="single">
<TagGroup.List>
<TagGroup.Item id="news">
{({ isSelected }) => (
<>
<SquareArticleIcon
size={16}
colorClassName={
isSelected
? 'accent-accent-soft-foreground'
: 'accent-field-foreground'
}
/>
<TagGroup.ItemLabel>News</TagGroup.ItemLabel>
</>
)}
</TagGroup.Item>
</TagGroup.List>
</TagGroup>
빈 상태 (Empty State)
목록에 태그가 없을 때 커스텀 콘텐츠를 렌더링해요.
<TagGroup onRemove={onRemove}>
<TagGroup.List
renderEmptyState={() => (
<Text className="text-sm text-muted">No categories found</Text>
)}
>
{tags.map((tag) => (
<TagGroup.Item key={tag.id} id={tag.id}>
<TagGroup.ItemLabel>{tag.name}</TagGroup.ItemLabel>
<TagGroup.ItemRemoveButton />
</TagGroup.Item>
))}
</TagGroup.List>
</TagGroup>
비활성화된 태그 (Disabled Tags)
개별 태그 또는 전체 그룹을 비활성화해요.
<TagGroup selectionMode="single" disabledKeys={new Set(['travel'])}>
<TagGroup.List>
<TagGroup.Item id="news">News</TagGroup.Item>
<TagGroup.Item id="travel">Travel</TagGroup.Item>
<TagGroup.Item id="gaming" isDisabled>
Gaming
</TagGroup.Item>
</TagGroup.List>
</TagGroup>
Example
import { TagGroup, Label, Description, FieldError } from 'heroui-native';
import { useState, useMemo } from 'react';
import { View } from 'react-native';
export default function TagGroupExample() {
const [selected, setSelected] = useState(new Set());
const isInvalid = useMemo(
() => Array.from(selected).length === 0,
[selected]
);
return (
<View className="gap-4">
<TagGroup
selectedKeys={selected}
selectionMode="multiple"
onSelectionChange={setSelected}
isInvalid={isInvalid}
>
<Label isInvalid={false}>Amenities</Label>
<TagGroup.List>
<TagGroup.Item id="laundry">Laundry</TagGroup.Item>
<TagGroup.Item id="fitness">Fitness center</TagGroup.Item>
<TagGroup.Item id="parking">Parking</TagGroup.Item>
<TagGroup.Item id="pool">Swimming pool</TagGroup.Item>
<TagGroup.Item id="breakfast">Breakfast</TagGroup.Item>
</TagGroup.List>
<Description hideOnInvalid>
{`Selected: ${Array.from(selected).join(', ')}`}
</Description>
<FieldError>Please select at least one category</FieldError>
</TagGroup>
</View>
);
}
더 많은 예시는 GitHub 저장소에서 찾을 수 있어요.
API Reference
TagGroup
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
- | 태그 그룹 안에 렌더링할 자식 요소 |
size |
'sm' | 'md' | 'lg' |
'md' |
그룹 안의 모든 태그 크기 |
variant |
'default' | 'surface' |
'default' |
그룹 안의 모든 태그의 시각적 변형 |
selectionMode |
'none' | 'single' | 'multiple' |
'none' |
태그 그룹에서 허용되는 선택 유형 |
selectedKeys |
Iterable |
- | 현재 선택된 키 (제어) |
defaultSelectedKeys |
Iterable |
- | 초기 선택 키 (비제어) |
disabledKeys |
Iterable |
- | 비활성화할 태그의 키 |
isDisabled |
boolean |
false |
전체 태그 그룹이 비활성화되었는지 여부 |
isInvalid |
boolean |
false |
태그 그룹이 잘못된 상태인지 여부 |
isRequired |
boolean |
false |
태그 그룹이 필수인지 여부 |
className |
string |
- | 태그 그룹 컨테이너의 추가 CSS 클래스 |
style |
StyleProp |
- | 태그 그룹 컨테이너의 추가 스타일 |
animation |
"disable-all" | undefined |
- | "disable-all"을 사용해 자식을 포함한 모든 애니메이션 비활성화 |
onSelectionChange |
(keys: Set) => void |
- | 선택이 변경될 때 호출되는 핸들러 |
onRemove |
(keys: Set) => void |
- | 태그가 제거될 때 호출되는 핸들러 |
...ViewProps |
ViewProps |
- | 모든 표준 React Native View props 지원 |
TagKey
string | number — TagGroup 안에서 태그를 식별하는 키 유형이에요.
Animation
자식을 포함한 모든 애니메이션을 비활성화하려면 animation="disable-all"을 사용해요. 생략하거나 undefined를 사용하면 기본 애니메이션을 써요.
TagGroup.List
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
- | 목록 안에 렌더링할 자식 요소 |
className |
string |
- | 목록 컨테이너의 추가 CSS 클래스 |
style |
StyleProp |
- | 목록 컨테이너의 추가 스타일 |
renderEmptyState |
() => React.ReactNode |
- | 목록에 태그가 없을 때 렌더링할 함수 |
...ViewProps |
ViewProps |
- | 모든 표준 React Native View props 지원 |
TagGroup.Item
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode | ((renderProps: TagRenderProps) => React.ReactNode) |
- | 태그 콘텐츠: 문자열, 요소, 또는 TagRenderProps를 받는 렌더 함수 |
id |
TagKey |
- | 이 태그의 고유 식별자 |
isDisabled |
boolean |
- | 이 특정 태그가 비활성화되었는지 여부 |
className |
string |
- | 태그의 추가 CSS 클래스 |
style |
StyleProp |
- | 태그의 추가 스타일 |
background |
React.ReactNode |
- | 태그 표면 뒤의 배경 레이어. undefined는 선택되지 않은 상태에서 테마 인식 기본값을 렌더링(폴백 색상은 variant를 따름); 커스텀 노드는 이를 대체; null은 제거 |
...PressableProps |
PressableProps |
- | 모든 표준 React Native Pressable props 지원 |
TagRenderProps
| prop | type | description |
|---|---|---|
isSelected |
boolean |
태그가 현재 선택되었는지 여부 |
isDisabled |
boolean |
태그가 비활성화되었는지 여부 (루트, disabledKeys, 항목 prop에서 병합) |
TagGroup.ItemBackground
태그 표면 뒤에 렌더링되는 절대-채움(absolute-fill) 컨테이너예요. 자식이 없으면 활성 라이브러리 테마가 기본 콘텐츠(예: glass 블러 레이어)를 결정하고, 자식을 전달하면 동일한 위치 지정과 클리핑으로 커스텀 콘텐츠를 호스팅해요. 폴백 색상은 활성 variant를 따릅니다 (surface → surface 토큰, default → default 토큰).
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
- | 배경 컨테이너 안의 커스텀 콘텐츠 |
className |
string |
- | 추가 CSS 클래스 |
...ViewProps |
ViewProps |
- | 모든 표준 View props 지원 |
TagGroup.ItemLabel
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
- | 렌더링할 텍스트 콘텐츠 |
className |
string |
- | 라벨의 추가 CSS 클래스 |
...TextProps |
TextProps |
- | 모든 표준 React Native Text props 지원 |
TagGroup.ItemRemoveButton
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
- | 제거 버튼의 커스텀 아이콘 또는 콘텐츠. 생략하면 기본적으로 닫기 아이콘 사용 |
className |
string |
- | 제거 버튼의 추가 CSS 클래스 |
iconProps |
TagRemoveButtonIconProps |
- | 기본 닫기 아이콘 커스터마이징 props. 자식이 제공되지 않을 때만 적용 |
hitSlop |
number |
8 |
터치 영역 확장 |
...PressableProps |
PressableProps |
- | 모든 표준 React Native Pressable props 지원 |
TagRemoveButtonIconProps
| prop | type | default | description |
|---|---|---|---|
size |
number |
12 |
아이콘 크기 |
color |
string |
- | 아이콘 색상 |
Hooks
useTagGroup
태그 그룹 루트 컨텍스트에 접근하는 훅이에요. TagGroup 컴포넌트 안에서 사용해야 해요.
import { useTagGroup } from 'heroui-native';
const {
selectedKeys,
disabledKeys,
selectionMode,
onSelectionChange,
onRemove,
isDisabled,
isInvalid,
isRequired,
} = useTagGroup();
Returns
| property | type | description |
|---|---|---|
selectionMode |
'none' | 'single' | 'multiple' |
태그 그룹에서 허용되는 선택 유형 |
selectedKeys |
Set |
현재 선택된 태그 키 |
disabledKeys |
Set |
비활성화된 태그의 키 |
onSelectionChange |
(keys: Set) => void |
선택이 변경될 때의 콜백 |
onRemove |
((keys: Set) => void) | undefined |
태그가 제거될 때의 콜백 |
isDisabled |
boolean |
전체 태그 그룹이 비활성화되었는지 여부 |
isInvalid |
boolean |
태그 그룹이 잘못된 상태인지 여부 |
isRequired |
boolean |
태그 그룹이 필수인지 여부 |
useTagGroupItem
태그 항목 컨텍스트에 접근하는 훅이에요. TagGroup.Item 컴포넌트 안에서 사용해야 해요.
import { useTagGroupItem } from 'heroui-native';
const { id, isSelected, isDisabled, allowsRemoving } = useTagGroupItem();
Returns
| property | type | description |
|---|---|---|
id |
TagKey |
이 태그의 고유 식별자 |
isSelected |
boolean |
태그가 현재 선택되었는지 여부 |
isDisabled |
boolean |
태그가 비활성화되었는지 여부 |
allowsRemoving |
boolean |
태그를 제거할 수 있는지 여부 (TagGroup에 onRemove가 제공되면 true) |