Flowbite 컴포넌트 — 스켈레톤(Skeleton)
Flowbite의 스켈레톤(Skeleton) 컴포넌트는 콘텐츠가 로딩되는 동안 자리를 대신하는 회색 블록으로, 사용자에게 로딩 상태를 시각적으로 알려줘요. Tailwind CSS 클래스를 조합해 다양한 로딩 플레이스홀더를 만들 수 있어요.
출처: 문서
본문
스켈레톤은 기본적으로 회색 배경의 블록과 펄스(pulse) 애니메이션을 조합해 로딩 효과를 만들어요. 아래는 기본 스켈레톤 예시예요.
<div class="max-w-sm p-4 border border-gray-200 rounded-lg shadow animate-pulse md:p-6 dark:border-gray-700">
<div class="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-48 mb-4"></div>
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
</div>
핵심은 컨테이너에 animate-pulse를, 각 스켈레톤 줄에 bg-gray-200 dark:bg-gray-700 rounded-full을 쓰는 거예요.
이미지 스켈레톤
이미지 로딩 상태를 표현하려면 원형이나 사각형의 스켈레톤을 만들어요.
<div role="status" class="max-w-sm animate-pulse">
<div class="flex items-center justify-center w-full h-48 bg-gray-300 rounded sm:w-96 dark:bg-gray-700">
<svg class="w-10 h-10 text-gray-200 dark:text-gray-600" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 18">
<path d="M18 0H2a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2Zm-5.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3Zm4.376 10.481A1 1 0 0 1 16 15H4a1 1 0 0 1-.895-1.447l3.5-7A1 1 0 0 1 7.468 6a.965.965 0 0 1 .9.5l2.775 4.757 1.546-1.887a1 1 0 0 1 1.618.1l2.541 4a1 1 0 0 1 .028 1.011Z"/>
</svg>
</div>
</div>
텍스트 뼈대(Text skeleton)
role="status"와 스크린 리더용 텍스트를 함께 쓰면 접근성도 확보할 수 있어요.
<div role="status" class="space-y-8 animate-pulse md:space-y-0 md:space-x-8 md:flex md:items-center">
<div class="w-full">
<div class="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-48 mb-4"></div>
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[480px] mb-2.5"></div>
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[440px] mb-2.5"></div>
</div>
<span class="sr-only">Loading...</span>
</div>
스켈레톤은 실제 데이터 로딩 시간 동안 레이아웃 이동을 최소화해 사용자 경험을 개선하는 데 아주 유용한 패턴이에요.