본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Skeleton (스켈레톤)

원문 보기 위키 갱신

Skeleton은 로딩 상태와 컴포넌트의 예상 형태를 보여주는 플레이스홀더예요. 해요체로 쉽게 설명드릴게요.

출처: HeroUI Skeleton

본문

사용법 (Usage)

import { Skeleton } from '@heroui/react';
{"name": "skeleton-basic"}

예시 (Examples)

텍스트 콘텐츠 (Text Content)

{"name": "skeleton-text-content"}

사용자 프로필 (User Profile)

{"name": "skeleton-user-profile"}

목록 항목 (List Items)

{"name": "skeleton-list"}

그리드 (Grid)

{"name": "skeleton-grid"}

단일 샤이머 (Single Shimmer)

모든 스켈레톤 요소를 동시에 지나가는 동기화된 샤이머 효과예요. 부모 컨테이너에 skeleton--shimmer 클래스를 적용하고 자식 스켈레톤에는 animationType="none"을 설정해요.

{"name": "skeleton-single-shimmer", "style": {"contain": "none"}}

애니메이션 타입 (Animation Types)

{"name": "skeleton-animation-types"}

커스터마이징 (Customization)

Tailwind CSS

{"name": "skeleton-custom-styles"}

Global CSS

Skeleton 컴포넌트 클래스를 커스터마이징하려면 @layer components 지시어를 사용할 수 있어요. 더 알아보기.

@layer components {
  /* Base skeleton styles */
  .skeleton {
    @apply bg-surface-secondary/50; /* Change base background */
  }

  /* Shimmer animation gradient */
  .skeleton--shimmer:before {
    @apply viasurface; /* Change shimmer gradient color */
  }

  /* Pulse animation */
  .skeleton--pulse {
    @apply animate-pulse opacity-75; /* Customize pulse animation */
  }

  /* No animation variant */
  .skeleton--none {
    @apply opacity-50; /* Style for static skeleton */
  }
}

전역 애니메이션 설정 (Global Animation Configuration)

--skeleton-animation CSS 변수를 정의해 애플리케이션의 모든 Skeleton 컴포넌트의 기본 애니메이션 타입을 설정할 수 있어요:

/* In your global CSS file */
:root {
  /* Possible values: shimmer, pulse, none */
  --skeleton-animation: pulse;
}

/* You can also set different values for light/dark themes */
.light, [data-theme="light"] {
  --skeleton-animation: shimmer;
}

.dark, [data-theme="dark"] {
  --skeleton-animation: pulse;
}

이 전역 설정은 개별 컴포넌트에 animationType prop을 지정하면 재정의돼요.

스타일링 참고 (Styling Reference)

HeroUI는 BEM 방법론을 따라 컴포넌트 변형과 상태를 재사용하고 쉽게 커스터마이징할 수 있게 해요.

CSS 클래스 (CSS Classes)

Skeleton 컴포넌트는 다음 CSS 클래스를 사용해요 (소스 스타일 보기):

기본 클래스 [!toc]

.skeleton - 배경과 둥근 모서리가 있는 기본 스켈레톤 스타일

애니메이션 변형 클래스 [!toc]

  • .skeleton--shimmer - 그라데이션 효과와 함께 샤이머 애니메이션 추가 (기본값)
  • .skeleton--pulse - Tailwind의 animate-pulse를 사용한 펄스 애니메이션 추가
  • .skeleton--none - 애니메이션 없음, 정적 스켈레톤

애니메이션 (Animation)

Skeleton 컴포넌트는 각각 다른 시각 효과를 가진 세 가지 애니메이션 타입을 지원해요:

샤이머 애니메이션 [!toc]

샤이머 효과는 스켈레톤 요소를 가로지르는 그라데이션을 만들어요:

.skeleton--shimmer:before {
  @apply animate-skeleton via-surface-3 absolute inset-0 -translate-x-full
         bg-gradient-to-r from-transparent to-transparent content-[''];
}

샤이머 애니메이션은 테마에서 다음과 같이 정의돼요:

@theme inline {
  --animate-skeleton: skeleton 2s linear infinite;

  @keyframes skeleton {
    100% {
      transform: translateX(200%);
    }
  }
}

펄스 애니메이션 [!toc]

펄스 애니메이션은 Tailwind의 내장 animate-pulse 유틸리티를 사용해요:

.skeleton--pulse {
  @apply animate-pulse;
}

애니메이션 없음 [!toc]

애니메이션 없는 정적 스켈레톤의 경우:

.skeleton--none {
  /* No animation styles applied */
}

API 참고 (API Reference)

Skeleton

Prop Type Default Description
animationType "shimmer" | "pulse" | "none" "shimmer" or CSS variable The animation type for the skeleton. Can be globally configured via --skeleton-animation CSS variable
className string - Additional CSS classes

더 알아보기 (Learn more)