Flowbite 컴포넌트 — 배지(Badge)
Flowbite의 배지(Badge) 컴포넌트는 상태, 카운트, 라벨 등을 작고 눈에 띄게 표시할 때 쓰는 작은 요소예요. Tailwind CSS 유틸리티 클래스로 색상, 크기, 형태를 다양하게 조합할 수 있어요.
출처: 문서
본문
배지는 기본적으로 작은 배경색 블록과 텍스트(또는 숫자)로 구성돼요. 아래는 기본 배지 예시예요.
<span class="bg-blue-100 text-blue-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300">Default</span>
<span class="bg-gray-100 text-gray-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-gray-300">Dark</span>
<span class="bg-red-100 text-red-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-red-900 dark:text-red-300">Red</span>
<span class="bg-green-100 text-green-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-green-900 dark:text-green-300">Green</span>
<span class="bg-yellow-100 text-yellow-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-yellow-900 dark:text-yellow-300">Yellow</span>
둥근 배지(Rounded)
배지의 형태는 radius 클래스를 조절해 바꿀 수 있어요. rounded-full을 쓰면 알약 형태가 돼요.
<span class="bg-blue-100 text-blue-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded-full dark:bg-blue-900 dark:text-blue-300">Default</span>
<span class="bg-gray-100 text-gray-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded-full dark:bg-gray-700 dark:text-gray-300">Dark</span>
아이콘이 있는 배지
SVG 아이콘을 배지 안에 함께 넣을 수도 있어요. 아이콘은 inline-flex와 items-center로 정렬해요.
<span class="bg-blue-100 text-blue-800 text-xs font-medium inline-flex items-center px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300">
<svg class="w-2.5 h-2.5 me-1.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M10 0a10 10 0 1 0 10 10A10.011 10.011 0 0 0 10 0Zm3.982 13.982a1 1 0 0 1-1.414 0l-3.274-3.274A1.012 1.012 0 0 1 9 10V6a1 1 0 0 1 2 0v3.586l2.982 2.982a1 1 0 0 1 0 1.414Z"/>
</svg>
Icon badge
</span>
링크 배지
배지를 링크(<a>)로 감싸면 호버 시 색이 변하는 상호작용 배지를 만들 수 있어요.
<a href="#" class="bg-blue-100 hover:bg-blue-200 text-blue-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:hover:bg-blue-700 dark:text-blue-300">Link badge</a>
카운트 배지
버튼이나 아이콘 위에 숫자를 표시하는 카운트 배지도 흔히 사용해요. 버튼을 relative로 두고 배지를 절대 위치로 배치해요.
<button type="button" class="relative inline-flex items-center p-3 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300">
<svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M18 10h-2v2h2v2h-2v2h2v2H0v-2h2v-2H0v-2h2v-2H0V8h18v2Z"/>
</svg>
<span class="sr-only">Notifications</span>
<div class="absolute inline-flex items-center justify-center w-6 h-6 text-xs font-bold text-white bg-red-500 border-2 border-white rounded-full -top-2 -end-2 dark:border-gray-900">99</div>
</button>
배지는 상태 표시, 알림 카운트, 태그 등 다양한 곳에 유용하게 쓰여요. 색상 팔레트와 반경을 조절해 여러 스타일에 대응할 수 있답니다.