스켈레톤 (Skeleton)
SlSkeleton은 콘텐츠가 나중에 그려질 위치를 시각적으로 보여주기 위해 사용하는 요소예요. 로딩이 완료됐을 때 사용자가 보게 될 모습을 흉내 내는 간단한 비계(scaffolding) 컨테이너라고 생각하면 됩니다. 이렇게 하면 비동기 작업 중에 넓은 빈 영역이 생기는 것을 방지할 수 있어요.
Skeleton은 의도적으로 특정 규칙을 강요하지 않도록 설계되어 있어요. 레이아웃을 디자인하는 방법은 무한하니까요. 그래서 원하는 효과를 만들기 위해 여러 개의 skeleton을 조합해서 사용하는 경우가 많습니다. 자주 사용하게 된다면, 원하는 배치와 스타일로 렌더링해 주는 템플릿을 만들어 두는 것도 좋은 방법이에요.
출처: 문서
본문
<div class="skeleton-overview">
<header>
<sl-skeleton></sl-skeleton>
<sl-skeleton></sl-skeleton>
</header>
<sl-skeleton></sl-skeleton>
<sl-skeleton></sl-skeleton>
<sl-skeleton></sl-skeleton>
</div>
<style>
.skeleton-overview header {
display: flex;
align-items: center;
margin-bottom: 1rem;
}
.skeleton-overview header sl-skeleton:last-child {
flex: 0 0 auto;
width: 30%;
}
.skeleton-overview sl-skeleton {
margin-bottom: 1rem;
}
.skeleton-overview sl-skeleton:nth-child(1) {
float: left;
width: 3rem;
height: 3rem;
margin-right: 1rem;
vertical-align: middle;
}
.skeleton-overview sl-skeleton:nth-child(3) {
width: 95%;
}
.skeleton-overview sl-skeleton:nth-child(4) {
width: 80%;
}
</style>
import SlSkeleton from '@shoelace-style/shoelace/dist/react/skeleton';
const css = `
.skeleton-overview header {
display: flex;
align-items: center;
margin-bottom: 1rem;
}
.skeleton-overview header sl-skeleton:last-child {
flex: 0 0 auto;
width: 30%;
}
.skeleton-overview sl-skeleton {
margin-bottom: 1rem;
}
.skeleton-overview sl-skeleton:nth-child(1) {
float: left;
width: 3rem;
height: 3rem;
margin-right: 1rem;
vertical-align: middle;
}
.skeleton-overview sl-skeleton:nth-child(3) {
width: 95%;
}
.skeleton-overview sl-skeleton:nth-child(4) {
width: 80%;
}
`;
const App = () => (
<>
<div className="skeleton-overview">
<header>
<SlSkeleton />
<SlSkeleton />
</header>
<SlSkeleton />
<SlSkeleton />
<SlSkeleton />
</div>
<style>{css}</style>
</>
);
예시 (Examples)
효과 (Effects)
sheen과 pulse 두 가지 내장 효과가 있어요. 효과는 광범위하게 사용하면 산만해질 수 있기 때문에 의도적으로 은은하게 설계되어 있습니다. 기본값은 none으로, 애니메이션이 없는 정적인 skeleton을 표시해요.
<div class="skeleton-effects">
<sl-skeleton effect="none"></sl-skeleton>
None
<sl-skeleton effect="sheen"></sl-skeleton>
Sheen
<sl-skeleton effect="pulse"></sl-skeleton>
Pulse
</div>
<style>
.skeleton-effects {
font-size: var(--sl-font-size-small);
}
.skeleton-effects sl-skeleton:not(:first-child) {
margin-top: 1rem;
}
</style>
import SlSkeleton from '@shoelace-style/shoelace/dist/react/skeleton';
const css = `
.skeleton-effects {
font-size: var(--sl-font-size-small);
}
.skeleton-effects sl-skeleton:not(:first-child) {
margin-top: 1rem;
}
`;
const App = () => (
<>
<div className="skeleton-effects">
<SlSkeleton effect="none" />
None
<SlSkeleton effect="sheen" />
Sheen
<SlSkeleton effect="pulse" />
Pulse
</div>
<style>{css}</style>
</>
);
문단 (Paragraphs)
여러 개의 skeleton과 약간의 CSS 트릭으로 문단을 흉내 낼 수 있어요.
<div class="skeleton-paragraphs">
<sl-skeleton></sl-skeleton>
<sl-skeleton></sl-skeleton>
<sl-skeleton></sl-skeleton>
<sl-skeleton></sl-skeleton>
<sl-skeleton></sl-skeleton>
</div>
<style>
.skeleton-paragraphs sl-skeleton {
margin-bottom: 1rem;
}
.skeleton-paragraphs sl-skeleton:nth-child(2) {
width: 95%;
}
.skeleton-paragraphs sl-skeleton:nth-child(4) {
width: 90%;
}
.skeleton-paragraphs sl-skeleton:last-child {
width: 50%;
}
</style>
import SlSkeleton from '@shoelace-style/shoelace/dist/react/skeleton';
const css = `
.skeleton-paragraphs sl-skeleton {
margin-bottom: 1rem;
}
.skeleton-paragraphs sl-skeleton:nth-child(2) {
width: 95%;
}
.skeleton-paragraphs sl-skeleton:nth-child(4) {
width: 90%;
}
.skeleton-paragraphs sl-skeleton:last-child {
width: 50%;
}
`;
const App = () => (
<>
<div className="skeleton-paragraphs">
<SlSkeleton />
<SlSkeleton />
<SlSkeleton />
<SlSkeleton />
<SlSkeleton />
</div>
<style>{css}</style>
</>
);
아바타 (Avatars)
너비와 높이를 같게 설정하면 원형, 사각형, 또는 둥근 모서리의 아바타 skeleton을 만들 수 있어요.
<div class="skeleton-avatars">
<sl-skeleton></sl-skeleton>
<sl-skeleton></sl-skeleton>
<sl-skeleton></sl-skeleton>
</div>
<style>
.skeleton-avatars sl-skeleton {
display: inline-block;
width: 3rem;
height: 3rem;
margin-right: 0.5rem;
}
.skeleton-avatars sl-skeleton:nth-child(1) {
--border-radius: 0;
}
.skeleton-avatars sl-skeleton:nth-child(2) {
--border-radius: var(--sl-border-radius-medium);
}
</style>
import SlSkeleton from '@shoelace-style/shoelace/dist/react/skeleton';
const css = `
.skeleton-avatars sl-skeleton {
display: inline-block;
width: 3rem;
height: 3rem;
margin-right: .5rem;
}
.skeleton-avatars sl-skeleton:nth-child(1) {
--border-radius: 0;
}
.skeleton-avatars sl-skeleton:nth-child(2) {
--border-radius: var(--sl-border-radius-medium);
}
`;
const App = () => (
<>
<div className="skeleton-avatars">
<SlSkeleton />
<SlSkeleton />
<SlSkeleton />
</div>
<style>{css}</style>
</>
);
커스텀 도형 (Custom Shapes)
--border-radius 커스텀 프로퍼티로 원, 사각형, 직사각형을 만들 수 있어요. 더 복잡한 도형이 필요하다면 indicator 파트에 clip-path를 적용하면 됩니다. 커스텀 도형 생성이 어렵다면 Clippy를 시도해 보세요.
<div class="skeleton-shapes">
<sl-skeleton class="square"></sl-skeleton>
<sl-skeleton class="circle"></sl-skeleton>
<sl-skeleton class="triangle"></sl-skeleton>
<sl-skeleton class="cross"></sl-skeleton>
<sl-skeleton class="comment"></sl-skeleton>
</div>
<style>
.skeleton-shapes sl-skeleton {
display: inline-flex;
width: 50px;
height: 50px;
}
.skeleton-shapes .square::part(indicator) {
--border-radius: var(--sl-border-radius-medium);
}
.skeleton-shapes .circle::part(indicator) {
--border-radius: var(--sl-border-radius-circle);
}
.skeleton-shapes .triangle::part(indicator) {
--border-radius: 0;
clip-path: polygon(50% 0, 0 100%, 100% 100%);
}
.skeleton-shapes .cross::part(indicator) {
--border-radius: 0;
clip-path: polygon(
20% 0%,
0% 20%,
30% 50%,
0% 80%,
20% 100%,
50% 70%,
80% 100%,
100% 80%,
70% 50%,
100% 20%,
80% 0%,
50% 30%
);
}
.skeleton-shapes .comment::part(indicator) {
--border-radius: 0;
clip-path: polygon(0% 0%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%);
}
.skeleton-shapes sl-skeleton:not(:last-child) {
margin-right: 0.5rem;
}
</style>
import SlSkeleton from '@shoelace-style/shoelace/dist/react/skeleton';
const css = `
.skeleton-shapes sl-skeleton {
display: inline-flex;
width: 50px;
height: 50px;
}
.skeleton-shapes .square::part(indicator) {
--border-radius: var(--sl-border-radius-medium);
}
.skeleton-shapes .circle::part(indicator) {
--border-radius: var(--sl-border-radius-circle);
}
.skeleton-shapes .triangle::part(indicator) {
--border-radius: 0;
clip-path: polygon(50% 0, 0 100%, 100% 100%);
}
.skeleton-shapes .cross::part(indicator) {
--border-radius: 0;
clip-path: polygon(20% 0%, 0% 20%, 30% 50%, 0% 80%, 20% 100%, 50% 70%, 80% 100%, 100% 80%, 70% 50%, 100% 20%, 80% 0%, 50% 30%);
}
.skeleton-shapes .comment::part(indicator) {
--border-radius: 0;
clip-path: polygon(0% 0%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%);
}
.skeleton-shapes sl-skeleton:not(:last-child) {
margin-right: .5rem;
}
`;
const App = () => (
<>
<div className="skeleton-shapes">
<SlSkeleton className="square" />
<SlSkeleton className="circle" />
<SlSkeleton className="triangle" />
<SlSkeleton className="cross" />
<SlSkeleton className="comment" />
</div>
<style>{css}</style>
</>
);
커스텀 색상 (Custom Colors)
--color와 --sheen-color 커스텀 프로퍼티를 설정하면 skeleton의 색을 조절할 수 있어요.
<sl-skeleton effect="sheen" style="--color: tomato; --sheen-color: #ffb094;"></sl-skeleton>
import SlSkeleton from '@shoelace-style/shoelace/dist/react/skeleton';
const css = `
.skeleton-avatars sl-skeleton {
display: inline-block;
width: 3rem;
height: 3rem;
margin-right: .5rem;
}
.skeleton-avatars sl-skeleton:nth-child(1) {
--border-radius: 0;
}
.skeleton-avatars sl-skeleton:nth-child(2) {
--border-radius: var(--sl-border-radius-medium);
}
`;
const App = () => <SlSkeleton effect="sheen" style={{ '--color': 'tomato', '--sheen-color': '#ffb094' }} />;
불러오기 (Importing)
autoloader나 전통적인 loader를 사용 중이라면 이 부분은 무시해도 돼요. 그게 아니라면 아래 스니펫 중 원하는 방식으로 이 컴포넌트만 골라서 불러올 수 있어요.
Script 태그로 CDN에서 이 컴포넌트를 불러오려면:
<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/skeleton/skeleton.js"></script>
JavaScript import 구문으로 CDN에서 불러오려면:
import 'https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/skeleton/skeleton.js';
번들러(bundler)를 사용해 불러오려면:
import '@shoelace-style/shoelace/dist/components/skeleton/skeleton.js';
React 컴포넌트로 불러오려면:
import SlSkeleton from '@shoelace-style/shoelace/dist/react/skeleton';
속성 (Properties)
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
effect |
Determines which effect the skeleton will use. | 'pulse' | 'sheen' | 'none' |
'none' |
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
속성(attribute)과 프로퍼티(property)에 대해 더 알아보기.
커스텀 프로퍼티 (Custom Properties)
| Name | Description | Default |
|---|---|---|
--border-radius |
The skeleton’s border radius. | |
--color |
The color of the skeleton. | |
--sheen-color |
The sheen color when the skeleton is in its loading state. |
CSS 커스텀 프로퍼티 커스터마이징에 대해 더 알아보기.
파트 (Parts)
| Name | Description |
|---|---|
base |
The component’s base wrapper. |
indicator |
The skeleton’s indicator which is responsible for its color and animation. |
CSS 파트 커스터마이징에 대해 더 알아보기.