Badge API
Badge API (배지 API)
React Badge 컴포넌트의 API 레퍼런스 문서예요. 이 모듈에서 내보내는 props, CSS, 그리고 기타 API에 대해 알아볼 수 있어요.
출처: Badge API
본문
데모
이 React 컴포넌트의 사용 예시와 자세한 내용은 컴포넌트 데모 페이지를 방문해 주세요: Avatar Badge
가져오기 (Import)
import Badge from '@mui/material/Badge';
// or
import { Badge } from '@mui/material';
번들 크기 최소화 가이드를 읽고 두 방식의 차이에 대해 알아보세요.
Props
네이티브 컴포넌트의 props도 사용할 수 있어요.
| 이름 | 타입 | 기본값 | 설명 |
|---|---|---|---|
| anchorOrigin | { horizontal?: 'left'| 'right', vertical?: 'bottom'| 'top' } | { vertical: 'top', horizontal: 'right' } | 배지의 앵커(anchor)예요. |
| badgeContent | node | - | 배지 내부에 렌더링되는 내용이에요. |
| children | node | - | 배지가 이 노드에 상대적으로 추가돼요. |
| classes | object | - | 컴포넌트에 적용된 스타일을 재정의하거나 확장해요. 자세한 내용은 아래의 CSS 클래스 API를 참고하세요. |
| color | 'default'| 'primary'| 'secondary'| 'error'| 'info'| 'success'| 'warning'| string | 'default' | 컴포넌트의 색상이에요. 기본 및 커스텀 테마 색상을 모두 지원하며, 팔레트 사용자 지정 가이드에 나와 있는 것처럼 추가할 수 있어요. |
| component | elementType | - | 루트 노드에 사용되는 컴포넌트예요. HTML 요소를 사용하려면 문자열이거나 컴포넌트일 수 있어요. |
| invisible | bool | false | true라면 배지가 보이지 않게 돼요. |
| max | number | 99 | 표시할 최대 카운트예요. |
| overlap | 'circular'| 'rectangular' | 'rectangular' | 배지가 겹쳐야 하는 래핑된(wrapped) 모양이에요. |
| showZero | bool | false | badgeContent가 0일 때 배지가 숨겨지는지 여부를 제어해요. |
| slotProps | { badge?: func| object, root?: func| object } | {} | 내부의 각 슬롯에 사용되는 props예요. |
| slots | { badge?: elementType, root?: elementType } | {} | 내부의 각 슬롯에 사용되는 컴포넌트예요. |
| sx | Array<func| object| bool>| func| object | - | 시스템 오버라이드와 추가 CSS 스타일을 정의할 수 있게 해주는 시스템 prop이에요. 자세한 내용은 sx 페이지를 참고하세요. |
| variant | 'dot'| 'standard'| string | 'standard' | 사용할 변형(variant)이에요. |
ref는 루트 요소로 전달돼요.
테마 기본 props (Theme default props)
MuiBadge을 사용해 테마에서 이 컴포넌트의 기본 props를 변경할 수 있어요.
슬롯 (Slots)
| 슬롯 이름 | 클래스 이름 | 기본 컴포넌트 | 설명 |
|---|---|---|---|
| root | .MuiBadge-root | span |
루트를 렌더링하는 컴포넌트예요. |
| badge | .MuiBadge-badge | span |
배지를 렌더링하는 컴포넌트예요. |
CSS 클래스
이 클래스 이름들은 CSS로 스타일링할 때 유용해요. 특정 상태가 트리거되면 컴포넌트의 슬롯에 적용돼요.
| 클래스 이름 | 규칙 이름 | 설명 |
|---|---|---|
| .MuiBadge-anchorOriginBottomLeft | anchorOriginBottomLeft | anchorOrigin={{ 'bottom', 'left' }}일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-anchorOriginBottomLeftCircular | anchorOriginBottomLeftCircular | anchorOrigin={{ 'bottom', 'left' }} overlap="circular"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-anchorOriginBottomLeftRectangular | anchorOriginBottomLeftRectangular | anchorOrigin={{ 'bottom', 'left' }} overlap="rectangular"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-anchorOriginBottomRight | anchorOriginBottomRight | anchorOrigin={{ 'bottom', 'right' }}일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-anchorOriginBottomRightCircular | anchorOriginBottomRightCircular | anchorOrigin={{ 'bottom', 'right' }} overlap="circular"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-anchorOriginBottomRightRectangular | anchorOriginBottomRightRectangular | anchorOrigin={{ 'bottom', 'right' }} overlap="rectangular"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-anchorOriginTopLeft | anchorOriginTopLeft | anchorOrigin={{ 'top', 'left' }}일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-anchorOriginTopLeftCircular | anchorOriginTopLeftCircular | anchorOrigin={{ 'top', 'left' }} overlap="circular"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-anchorOriginTopLeftRectangular | anchorOriginTopLeftRectangular | anchorOrigin={{ 'top', 'left' }} overlap="rectangular"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-anchorOriginTopRight | anchorOriginTopRight | anchorOrigin={{ 'top', 'right' }}일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-anchorOriginTopRightCircular | anchorOriginTopRightCircular | anchorOrigin={{ 'top', 'right' }} overlap="circular"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-anchorOriginTopRightRectangular | anchorOriginTopRightRectangular | anchorOrigin={{ 'top', 'right' }} overlap="rectangular"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-colorError | colorError | color="error"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-colorInfo | colorInfo | color="info"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-colorPrimary | colorPrimary | color="primary"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-colorSecondary | colorSecondary | color="secondary"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-colorSuccess | colorSuccess | color="success"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-colorWarning | colorWarning | color="warning"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-dot | dot | variant="dot"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-invisible | invisible | invisible={true}일 때 배지 span 요소에 적용되는 상태 클래스예요. |
| .MuiBadge-overlapCircular | overlapCircular | overlap="circular"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-overlapRectangular | overlapRectangular | overlap="rectangular"일 때 배지 span 요소에 적용되는 스타일이에요. |
| .MuiBadge-standard | standard | variant="standard"일 때 배지 span 요소에 적용되는 스타일이에요. |
다음과 같은 사용자 지정 옵션 중 하나를 사용해 컴포넌트의 스타일을 재정의할 수 있어요:
- 전역 클래스 이름(global class name)과 함께 사용하는 방법
- 커스텀 테마에서 컴포넌트의
styleOverrides속성의 일부로 규칙 이름(rule name)을 사용하는 방법
소스 코드 (Source code)
이 페이지에서 원하는 정보를 찾지 못했다면, 컴포넌트의 구현을 살펴보면 더 자세한 내용을 알 수 있어요.
더 알아보기
더 자세한 내용은 MUI 공식 문서를 참고해 주세요.