AvatarGroup
AvatarGroup는 여러 아바타를 쌓아(stacked) 또는 그리드로 표시하고, 넘치는 개수(overflow count)를 표시하는 컴포넌트예요. 해요체로 쉽게 설명드릴게요.
본문
사용법 (Usage)
import { AvatarGroup, Avatar } from '@heroui/react';
{"name": "avatar-group-basic"}
구조 (Anatomy)
import { AvatarGroup, Avatar } from '@heroui/react';
export default () => (
<AvatarGroup>
<Avatar>
<Avatar.Image />
<Avatar.Fallback />
</Avatar>
<AvatarGroup.Count /> {/* Optional explicit child */}
</AvatarGroup>
);
예시 (Examples)
최대 개수 (Max)
{"name": "avatar-group-max"}
개수 표시 (With Count)
{"name": "avatar-group-count"}
크기 (Sizes)
{"name": "avatar-group-sizes"}
그리드 (Grid)
{"name": "avatar-group-grid"}
겹침 (Overlap)
{"name": "avatar-group-overlap"}
커스터마이징 (Customization)
Tailwind CSS
{"name": "avatar-group-custom-styles"}
Global CSS
AvatarGroup 컴포넌트 클래스를 커스터마이징하려면 @layer components 지시어를 사용할 수 있어요.
더 알아보기.
@layer components {
.avatar-group {
--avatar-group-overlap: 0.75rem;
--avatar-group-seam: 2px;
}
.avatar-group__count {
@apply font-semibold;
}
}
스타일링 참고 (Styling Reference)
HeroUI는 BEM 방법론을 따라 컴포넌트 변형과 상태를 재사용하고 쉽게 커스터마이징할 수 있게 해요.
CSS 클래스 (CSS Classes)
AvatarGroup 컴포넌트는 다음 CSS 클래스를 사용해요 (소스 스타일 보기):
Base 클래스 [!toc]
.avatar-group- 기본 아바타 그룹 컨테이너.avatar-group--grid- 그리드 레이아웃 수식어 (겹침 없음).avatar-group--clip- 초승달 모양 마스크 / 투명한 이음매 (기본 쌓기 겹침).avatar-group--ring---background를 통한 단색 box-shadow 외곽선.avatar-group__count- 넘침 개수 아바타
쌓기 레이아웃은 형제 요소 사이에 음수 마진(--avatar-group-overlap, 기본 0.5rem)을 사용해요. 클립 모드는 겹친 아바타(마지막 자식 / Count 제외)를 마스킹하고 폴백 글리프를 광학적으로 살짝 조정해요. 링 모드는 --background를 통한 얇은 box-shadow 외곽선을 사용해요.
API 참고 (API Reference)
AvatarGroup
| Prop | Type | Default | Description |
|---|---|---|---|
size |
'sm' | 'md' | 'lg' |
'md' |
Size applied to child Avatars (and the overflow count) when they omit size (synced with Avatar) |
color |
'default' | 'accent' | 'success' | 'warning' | 'danger' |
- | Color applied to child Avatars (and the overflow count) when they omit color |
variant |
'default' | 'soft' |
- | Variant applied to child Avatars (and the overflow count) when they omit variant |
max |
number |
- | Maximum number of avatar children to render; omit to show all |
isGrid |
boolean |
false |
Whether to use a wrapping grid layout without overlap |
overlap |
'clip' | 'ring' |
'clip' |
Stacked overlap style: crescent clip (default) or box-shadow ring; ignored when isGrid |
className |
string |
- | Additional CSS classes |
children |
React.ReactNode |
- | Avatar components (and optional AvatarGroup.Count) to group together |
AvatarGroup.Count
오버플로 표시기를 위해 Avatar + Avatar.Fallback를 구성해요. max에 의해 잘리지 않아요.
| Prop | Type | Default | Description |
|---|---|---|---|
children |
React.ReactNode |
- | Count content (e.g. +3) |
size |
'sm' | 'md' | 'lg' |
- | Override size from the group |
color |
'default' | 'accent' | 'success' | 'warning' | 'danger' |
- | Override color from the group |
variant |
'default' | 'soft' |
- | Override variant from the group |
className |
string |
- | Additional CSS classes |
참고 (Note)
- AvatarGroup은 React Context를 사용해
size,color,variant를 직접 자식 Avatar에만 전달해요 max를 설정하면 보이는 아바타를 잘라내고 나머지 자식을 자동으로 세어요. 설정하지 않으면 모두 표시돼요- 알려진 총 개수(예: 서버에서 받은 값)가 있으면 명시적인
AvatarGroup.Count를 렌더링해요 —max에 의해 잘리지 않고 자동 개수도 억제해요. 제거된 v2totalprop보다Count를 사용하는 걸 권장해요 isGrid는 겹침을 비활성화하고 대신 줄바꿈되는 그리드 레이아웃을 사용해요overlap의 기본값은"clip"(초승달 이음매)이에요. 단색 외곽선을 원하면"ring"을 사용해요.isGrid와 함께 사용하면 효과가 없어요- 기본
role="group"은 없어요 — 쌓인 목록이 의미 있는 경우(담당자, 뷰어 등)role="group"에aria-label또는aria-labelledby를 전달해요