Label
Label은 콘텐츠를 분류/태그하기 위해 짧은 텍스트나 아이콘을 표시하는 컴포넌트예요. 색상, 상태, 채움(filled)/아웃라인(outline)/컴팩트(compact) 변형과 제거 가능, 링크, 편집 가능 형태를 지원해요.
출처: 문서
본문
예제 (Examples)
채워진 라벨 (Filled labels)
비상태(Non-status):
- Grey, Grey icon, Grey removable, Grey icon removable, Grey link, Grey link removable, Grey label with icon that overflows, Grey link removable (disabled)
- Blue, Blue icon, Blue removable, Blue icon removable, Blue link, Blue link removable, Blue label with icon that overflows, Blue link removable (disabled)
- Green, Green icon, Green removable, Green icon removable, Green link, Green link removable, Green label with icon that overflows, Green link removable (disabled)
- Orange, Orange icon, Orange removable, Orange icon removable, Orange link, Orange link removable, Orange label with icon that overflows, Orange link removable (disabled)
- Red, Red icon, Red removable, Red icon removable, Red link, Red link removable, Red label with icon that overflows, Red link removable (disabled)
- Orange red, Orange red icon, Orange red removable, Orange red icon removable, Orange red link, Orange red link removable, Orange red label with icon that overflows
- Purple, Purple icon, Purple removable, Purple icon removable, Purple link, Purple link removable, Purple label with icon that overflows, Purple link removable (disabled)
- Teal, Teal icon, Teal removable, Teal icon removable, Teal link, Teal link removable, Teal label with icon that overflows, Teal link removable (disabled)
- Yellow, Yellow icon, Yellow removable, Yellow icon removable, Yellow link, Yellow link removable, Yellow label with icon that overflows, Yellow link removable (disabled)
Label that overflows its parent, but has no textMaxWidth on its own
상태(Status):
- Success, Success removable, Success link, Success link removable, Success label with text that overflows
- Warning, Warning removable, Warning link, Warning link removable, Warning label with text that overflows
- Danger, Danger removable, Danger link, Danger link removable, Danger label with text that overflows
- Info, Info removable, Info link, Info link removable, Info label with text that overflows
- Custom, Custom removable, Custom link, Custom link removable, Custom label with text that overflows
아웃라인 라벨 (Outlined labels)
비상태(Non-status):
- Grey, Grey icon, Grey removable, Grey icon removable, Grey link, Grey link removable, Grey label with icon that overflows, Grey link removable (disabled)
- Blue, Blue icon, Blue removable, Blue icon removable, Blue link, Blue link removable, Blue label with icon that overflows, Blue link removable (disabled)
- Green, Green icon, Green removable, Green icon removable, Green link, Green link removable, Green label with icon that overflows, Green link removable (disabled)
- Orange, Orange icon, Orange removable, Orange icon removable, Orange link, Orange link removable, Orange label with icon that overflows, Orange link removable (disabled)
- Red, Red icon, Red removable, Red icon removable, Red link, Red link removable, Red label with icon that overflows
- Orange red, Orange red icon, Orange red removable, Orange red icon removable, Orange red link, Orange red link removable, Orange red label with icon that overflows
- Purple, Purple icon, Purple removable, Purple icon removable, Purple link, Purple link removable, Purple label with icon that overflows, Purple link removable (disabled)
- Teal, Teal icon, Teal removable, Teal icon removable, Teal link, Teal link removable, Teal label with icon that overflows, Teal link removable (disabled)
- Yellow, Yellow icon, Yellow removable, Yellow icon removable, Yellow link, Yellow link removable, Yellow label with icon that overflows, Yellow link removable (disabled)
상태(Status):
- Success, Success removable, Success link, Success link removable, Success label with text that overflows
- Warning, Warning removable, Warning link, Warning link removable, Warning label with text that overflows
- Danger, Danger removable, Danger link, Danger link removable, Danger label with text that overflows
- Info, Info removable, Info link, Info link removable, Info label with text that overflows
- Custom, Custom removable, Custom link, Custom link removable, Custom label with text that overflows
컴팩트 라벨 (Compact labels)
- Compact, Compact icon, Compact removable, Compact icon removable, Compact link, Compact link removable, Compact label with icon that overflows, Compact link removable (disabled)
- Compact icon, Compact removable, Compact icon removable, Compact link, Compact link removable, Compact label with icon that overflows, Compact link removable (disabled)
커스텀 렌더링 라벨 (Label with custom render)
라벨은 커스터마이즈된 콘텐츠를 표시하거나 라우터 컴포넌트와 함께 사용하기 위해 커스텀 렌더러를 전달받을 수 있어요. 커스텀 렌더를 사용할 때는 isClickable을 함께 전달해 앵커 또는 라우터 링크의 밑줄 텍스트 장식을 제거할 수도 있어요.
Blue label router link with icon that overflows
편집 가능한 라벨 (Editable labels)
라벨 편집을 시작하려면 클릭하거나 엔터/스페이스를 누르세요. 편집 후에는 라벨 바깥을 클릭하거나 엔터를 다시 눌러 편집을 완료해요. 편집을 취소하려면 escape를 누르세요.
또한 이 예제의 closeBtnAriaLabel처럼 어떤 Label의 닫기 버튼 aria-label도 커스터마이즈할 수 있어요.
기본 라벨 그룹 (Basic label group)
여러 라벨을 한 번에 표시해야 할 때는 라벨 그룹을 사용하세요.
- Label 1
- Label 2
- Label 3
오버플로가 있는 라벨 그룹 (Label group with overflow)
라벨 수가 임계값을 초과하면 공간을 아끼기 위해 그룹 끝에 오버플로 라벨을 추가할 수 있어요. 오버플로 라벨을 클릭하면 그룹이 펼쳐지고 접혀요.
- Label 1
- Label 2
- Label 3
- (overflow)
카테고리가 있는 라벨 그룹 (Label group with categories)
카테고리 이름을 사용해 라벨 집합을 정리할 수 있어요.
Group label
- Label 1
- Label 2
- Label 3
제거 가능한 카테고리가 있는 라벨 그룹 (Label group with removable categories)
Group label
- Label 1
- Label 2
- Label 3
- (overflow)
세로 라벨 그룹 (Vertical label group)
그룹 안의 라벨을 세로로 쌓을 수도 있어요. 이 예제는 카테고리 이름과 오버플로가 있는 세로 라벨 그룹을 보여 줘요.
Group label with a very long name
- Label 1
- Label 2
- Label 3
- (overflow)
편집 가능한 라벨 그룹 (Editable label group)
- (editable)
- Static label
- (editable)
- (editable)
추가 버튼이 있는 편집 가능한 라벨 그룹 (Editable label group with add button)
라벨 그룹의 내용은 라벨을 제거하거나 추가 버튼으로 새 라벨을 추가해 수정할 수 있어요. 새 라벨 추가를 보여 주는 추가 문서는 label demos를 참조하세요.
Label group 1
- Label 1
- Label 2
- (add)
- (editable)
라우터 링크 사용 (Using router links)
라우터 링크는 React 환경에서 페이지 리로딩을 막기 위한 앱 내 링크에 사용할 수 있어요. 라우터 패키지의 Link 컴포넌트를 사용하려면 Label의 render 프로퍼티를 사용하세요:
<Label
render={({ className, content, componentRef }) => (
<Link to="/" className={className} innerRef={componentRef}>
{content}
</Link>
)}
>
Label router link
</Label>
Props
Label
*required
| Name | Type | Default | Description | |
|---|---|---|---|---|
| children | React.ReactNode | 라벨 안에 렌더링되는 콘텐츠. | ||
| className | string | '' | 라벨에 추가되는 클래스. | |
| closeBtn | React.ReactNode | 커스텀 닫기 버튼을 위한 노드. | ||
| closeBtnAriaLabel | string | 닫기 버튼의 aria label. | ||
| closeBtnProps | any | 기본 닫기 버튼에 대한 추가 프로퍼티. | ||
| color | 'blue' | 'teal' | 'green' | 'orange' | 'purple' | 'red' | 'orangered' | 'grey' | 'yellow' | LabelColor | LabelColor.grey | 라벨의 색상. | |
| editableProps | any | 편집 가능한 라벨 텍스트 div에 전달되는 추가 props. 선택적으로 onInput과 onBlur 콜백을 전달하면 텍스트 입력을 더 세밀하게 제어할 수 있어요. | ||
| href | string | 링크인 라벨의 href. 존재하면 라벨이 앵커 요소로 바뀌어요. onClick prop과 함께 전달하면 안 돼요. | ||
| icon | React.ReactNode | 라벨 텍스트 왼쪽에 추가되는 아이콘. status 프로퍼티로 설정된 아이콘을 재정의해요. | ||
| isClickable | boolean | false | 라벨이 클릭 가능한지 나타내는 플래그. href가 전달되거나 onClick 핸들러가 전달되고 라벨이 오버플로/추가 변형이 아닐 때 자동으로 설정돼요. render prop을 사용할 때는 수동으로 설정해야 해요. | |
| isCompact | boolean | false | 라벨이 컴팩트인지 나타내는 플래그. | |
| isDisabled | boolean | false | 라벨이 비활성 상태인지 나타내는 플래그. 클릭 가능한 라벨에서만 동작하므로 href 또는 onClick props를 전달해야 해요. | |
| isEditable | boolean | false | 라벨이 편집 가능한지 나타내는 플래그. | |
| onClick | (event: React.MouseEvent) => void | 라벨이 클릭될 때의 콜백. href 또는 isEditable props와 함께 전달하면 안 돼요. | ||
| onClose | (event: React.MouseEvent) => void | 제거 가능한 라벨의 닫기 클릭 콜백. 존재하면 라벨에 닫기 버튼이 생겨요. | ||
| onEditCancel | (event: KeyboardEvent, previousText: string) => void | 편집 가능한 라벨이 편집을 취소할 때의 콜백. | ||
| onEditComplete | (event: MouseEvent | KeyboardEvent, newText: string) => void | 편집 가능한 라벨이 편집을 완료할 때의 콜백. | ||
| render | ({ className, content, componentRef }: { className: string; content: React.ReactNode; componentRef: any; }) => React.ReactNode | 라벨 콘텐츠와 className을 렌더 함수에 전달해요. react router 지원에 이 prop을 사용하세요. | ||
| status | 'success' | 'warning' | 'danger' | 'info' | 'custom' | 각각의 아이콘과 색상이 있는 라벨의 상태. color 프로퍼티로 설정된 색상을 재정의해요. | ||
| textMaxWidth | string | 라벨이 잘리기 전의 최대 너비. '100%', '100px', '16ch' 같은 유효한 CSS 단위가 될 수 있어요. | ||
| tooltipPosition | TooltipPosition | 'auto' | 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-start' | 'left-end' | 'right-start' | 'right-end' | 텍스트가 잘릴 때 표시되는 툴팁의 위치. | ||
| variant | 'outline' | 'filled' | 'overflow' | 'add' | 'filled' | 라벨의 변형. |
LabelGroup
*required
| Name | Type | Default | Description | |
|---|---|---|---|---|
| addLabelControl | React.ReactNode | 새 라벨을 추가하기 위한 컨트롤. | ||
| aria-label | string | 'Label group category' | 카테고리 이름이 없는 라벨 그룹의 aria label. | |
| categoryName | string | '' | 라벨 그룹 카테고리의 카테고리 이름 텍스트. 이 prop이 제공되면 라벨 그룹에 라벨과 카테고리 스타일이 적용돼요. | |
| children | React.ReactNode | 라벨 그룹 안에 렌더링되는 콘텐츠. <Label> 요소여야 해요. |
||
| className | string | 라벨 항목에 추가되는 클래스. | ||
| closeBtnAriaLabel | string | 'Close label group' | 닫기 버튼의 aria label. | |
| collapsedText | string | '${remaining} more' | 커스터마이즈 가능한 템플릿 문자열. 오버플로 라벨 개수에 ${remaining} 변수를 사용해요. |
|
| defaultIsOpen | boolean | false | 라벨 그룹이 기본적으로 펼쳐져 있는지 여부. | |
| editableTextAreaProps | any | 편집 가능한 textarea에 전달되는 추가 props. | ||
| expandedText | string | 'Show Less' | 커스터마이즈 가능한 "Show Less" 텍스트 문자열. | |
| hasEditableTextArea | boolean | false | 편집 가능한 라벨 그룹에 textarea를 덧붙여야 하는지 나타내는 플래그. | |
| isClosable | boolean | false | 라벨 그룹을 닫을 수 있는지 여부. | |
| isCompact | boolean | false | 그룹 안 라벨이 컴팩트인지 나타내는 플래그. | |
| isEditable | boolean | false | 포함된 라벨이 편집 가능한지 나타내는 플래그. 라벨 뒤에 텍스트 입력 공간을 허용해요. | |
| isVertical | boolean | false | 세로 레이아웃을 구현하기 위한 플래그. | |
| numLabels | number | 3 | 오버플로 전에 보여 줄 라벨 수. | |
| onClick | (event: React.MouseEvent) => void | (_e: React.MouseEvent) => undefined as any | 라벨 그룹 닫기 버튼을 클릭할 때 호출되는 함수. | |
| tooltipPosition | TooltipPosition | 'auto' | 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-start' | 'left-end' | 'right-start' | 'right-end' | 'top' | 카테고리 이름 텍스트가 길 때 표시되는 툴팁의 위치. |