ion-skeleton-text
로딩 중에 표시할 플레이스홀더 콘텐츠를 렌더링하는 컴포넌트인 ion-skeleton-text예요. 이 요소는 지정된 너비의 회색 블록을 그려 주는데, 이렇게 하면 실제 콘텐츠가 로딩되는 동안 화면이 비어 보이지 않게 방지할 수 있어요.
출처: 문서
본문
Encapsulation: shadow
Skeleton Text는 플레이스홀더 콘텐츠를 렌더링하는 컴포넌트예요. 이 요소는 지정된 너비의 회색 블록을 그려 줘요.
Basic Usage
JavaScript
index.html
<ion-list></ion-list><br />
<ion-button onclick="toggle()">Toggle</ion-button>
<script>
const list = document.querySelector('ion-list');
let loaded = false;
function toggle() {
if (loaded) {
setSkeletonText();
} else {
setContent();
}
loaded = !loaded;
}
function setSkeletonText() {
list.innerHTML = `
<ion-list-header>
<ion-skeleton-text animated="true" style="width: 80px"></ion-skeleton-text>
</ion-list-header>
<ion-item>
<ion-thumbnail slot="start">
<ion-skeleton-text animated="true"></ion-skeleton-text>
</ion-thumbnail>
<ion-label>
<h3>
<ion-skeleton-text animated="true" style="width: 80%;"></ion-skeleton-text>
</h3>
<p>
<ion-skeleton-text animated="true" style="width: 60%;"></ion-skeleton-text>
</p>
<p>
<ion-skeleton-text animated="true" style="width: 30%;"></ion-skeleton-text>
</p>
</ion-label>
</ion-item>
`;
}
function setContent() {
list.innerHTML = `
<ion-list-header>Albums</ion-list-header>
<ion-item>
<ion-thumbnail slot="start">
<ion-icon style="width: 100%; height: 100%" name="musical-notes"></ion-icon>
</ion-thumbnail>
<ion-label>
<h3>Abbey Road</h3>
<p>The Beatles</p>
<p>1969</p>
</ion-label>
</ion-item>
`;
}
setSkeletonText();
</script>
index.ts
import { defineCustomElements } from '@ionic/core/loader';
import { addIcons } from 'ionicons';
import { musicalNotes } from 'ionicons/icons';
/* Core CSS required for Ionic components to work properly */
import '@ionic/core/css/core.css';
/* Basic CSS for apps built with Ionic */
import '@ionic/core/css/normalize.css';
import '@ionic/core/css/structure.css';
import '@ionic/core/css/typography.css';
/* Optional CSS utils that can be commented out */
import '@ionic/core/css/padding.css';
import '@ionic/core/css/float-elements.css';
import '@ionic/core/css/text-alignment.css';
import '@ionic/core/css/text-transformation.css';
import '@ionic/core/css/flex-utils.css';
import '@ionic/core/css/display.css';
/**
* Ionic Dark Palette
* -----------------------------------------------------
* For more information, please see:
* https://ionicframework.com/docs/theming/dark-mode
*/
// import '@ionic/core/css/palettes/dark.always.css';
// import '@ionic/core/css/palettes/dark.class.css';
import '@ionic/core/css/palettes/dark.system.css';
/* Theme variables */
import './theme/variables.css';
/**
* On Ionicons 7.2+ this icon
* gets mapped to a "musical-notes" key.
* Alternatively, developers can do:
* addIcons({ 'musical-notes': musicalNotes });
*/
addIcons({ musicalNotes });
defineCustomElements();
Angular
src/app/example.component.html
@if (loaded) {
<ion-list>
<ion-list-header>Albums</ion-list-header>
<ion-item>
<ion-thumbnail slot="start">
<ion-icon style="width: 100%; height: 100%" name="musical-notes"></ion-icon>
</ion-thumbnail>
<ion-label>
<h3>Abbey Road</h3>
<p>The Beatles</p>
<p>1969</p>
</ion-label>
</ion-item>
</ion-list>
} @else {
<ion-list>
<ion-list-header>
<ion-skeleton-text [animated]="true" style="width: 80px"></ion-skeleton-text>
</ion-list-header>
<ion-item>
<ion-thumbnail slot="start">
<ion-skeleton-text [animated]="true"></ion-skeleton-text>
</ion-thumbnail>
<ion-label>
<h3>
<ion-skeleton-text [animated]="true" style="width: 80%;"></ion-skeleton-text>
</h3>
<p>
<ion-skeleton-text [animated]="true" style="width: 60%;"></ion-skeleton-text>
</p>
<p>
<ion-skeleton-text [animated]="true" style="width: 30%;"></ion-skeleton-text>
</p>
</ion-label>
</ion-item>
</ion-list>
}
<ion-button (click)="loaded = !loaded">Toggle</ion-button>
src/app/example.component.ts
import { Component } from '@angular/core';
import {
IonButton,
IonIcon,
IonItem,
IonLabel,
IonList,
IonListHeader,
IonSkeletonText,
IonThumbnail,
} from '@ionic/angular';
import { addIcons } from 'ionicons';
import { musicalNotes } from 'ionicons/icons';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonButton, IonIcon, IonItem, IonLabel, IonList, IonListHeader, IonSkeletonText, IonThumbnail],
})
export class ExampleComponent {
public loaded = false;
constructor() {
/**
* Any icons you want to use in your application
* can be registered in app.component.ts and then
* referenced by name anywhere in your application.
*/
addIcons({ musicalNotes });
}
}
React
import React, { useState } from 'react';
import {
IonButton,
IonIcon,
IonItem,
IonLabel,
IonList,
IonListHeader,
IonSkeletonText,
IonThumbnail,
} from '@ionic/react';
import { musicalNotes } from 'ionicons/icons';
function Example() {
const [loaded, setLoaded] = useState(false);
return (
<>
{loaded && (
<IonList>
<IonListHeader>Albums</IonListHeader>
<IonItem>
<IonThumbnail slot="start">
<IonIcon style={{ width: '100%', height: '100%' }} icon={musicalNotes}></IonIcon>
</IonThumbnail>
<IonLabel>
<h3>Abbey Road</h3>
<p>The Beatles</p>
<p>1969</p>
</IonLabel>
</IonItem>
</IonList>
)}
{!loaded && (
<IonList>
<IonListHeader>
<IonSkeletonText animated={true} style={{ width: '80px' }}></IonSkeletonText>
</IonListHeader>
<IonItem>
<IonThumbnail slot="start">
<IonSkeletonText animated={true}></IonSkeletonText>
</IonThumbnail>
<IonLabel>
<h3>
<IonSkeletonText animated={true} style={{ width: '80%' }}></IonSkeletonText>
</h3>
<p>
<IonSkeletonText animated={true} style={{ width: '60%' }}></IonSkeletonText>
</p>
<p>
<IonSkeletonText animated={true} style={{ width: '30%' }}></IonSkeletonText>
</p>
</IonLabel>
</IonItem>
</IonList>
)}
<IonButton onClick={() => setLoaded(!loaded)}>Toggle</IonButton>
</>
);
}
export default Example;
Vue
<template>
<ion-list v-if="loaded">
<ion-list-header>Albums</ion-list-header>
<ion-item>
<ion-thumbnail slot="start">
<ion-icon style="width: 100%; height: 100%" :icon="musicalNotes"></ion-icon>
</ion-thumbnail>
<ion-label>
<h3>Abbey Road</h3>
<p>The Beatles</p>
<p>1969</p>
</ion-label>
</ion-item>
</ion-list>
<ion-list v-if="!loaded">
<ion-list-header>
<ion-skeleton-text :animated="true" style="width: 80px"></ion-skeleton-text>
</ion-list-header>
<ion-item>
<ion-thumbnail slot="start">
<ion-skeleton-text :animated="true"></ion-skeleton-text>
</ion-thumbnail>
<ion-label>
<h3>
<ion-skeleton-text :animated="true" style="width: 80%;"></ion-skeleton-text>
</h3>
<p>
<ion-skeleton-text :animated="true" style="width: 60%;"></ion-skeleton-text>
</p>
<p>
<ion-skeleton-text :animated="true" style="width: 30%;"></ion-skeleton-text>
</p>
</ion-label>
</ion-item>
</ion-list>
<ion-button @click="setLoaded(!loaded)">Toggle</ion-button>
</template>
<script setup lang="ts">
import {
IonButton,
IonIcon,
IonItem,
IonLabel,
IonList,
IonListHeader,
IonSkeletonText,
IonThumbnail,
} from '@ionic/vue';
import { musicalNotes } from 'ionicons/icons';
import { ref } from 'vue';
const loaded = ref(false);
const setLoaded = (state: boolean) => (loaded.value = state);
</script>
Theming
CSS Custom Properties
JavaScript
<style>
ion-skeleton-text {
--border-radius: 9999px;
--background: rgba(188, 0, 255, 0.065);
--background-rgb: 188, 0, 255;
}
</style>
<ion-list>
<ion-list-header>
<ion-skeleton-text animated="true" style="width: 80px"></ion-skeleton-text>
</ion-list-header>
<ion-item>
<ion-thumbnail slot="start">
<ion-skeleton-text animated="true"></ion-skeleton-text>
</ion-thumbnail>
<ion-label>
<h3>
<ion-skeleton-text animated="true" style="width: 80%;"></ion-skeleton-text>
</h3>
<p>
<ion-skeleton-text animated="true" style="width: 60%;"></ion-skeleton-text>
</p>
<p>
<ion-skeleton-text animated="true" style="width: 30%;"></ion-skeleton-text>
</p>
</ion-label>
</ion-item>
</ion-list>
Angular
src/app/example.component.html
<ion-list>
<ion-list-header>
<ion-skeleton-text [animated]="true" style="width: 80px"></ion-skeleton-text>
</ion-list-header>
<ion-item>
<ion-thumbnail slot="start">
<ion-skeleton-text [animated]="true"></ion-skeleton-text>
</ion-thumbnail>
<ion-label>
<h3>
<ion-skeleton-text [animated]="true" style="width: 80%;"></ion-skeleton-text>
</h3>
<p>
<ion-skeleton-text [animated]="true" style="width: 60%;"></ion-skeleton-text>
</p>
<p>
<ion-skeleton-text [animated]="true" style="width: 30%;"></ion-skeleton-text>
</p>
</ion-label>
</ion-item>
</ion-list>
src/app/example.component.css
ion-skeleton-text {
--border-radius: 9999px;
--background: rgba(188, 0, 255, 0.065);
--background-rgb: 188, 0, 255;
}
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonItem, IonLabel, IonList, IonListHeader, IonSkeletonText, IonThumbnail } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonItem, IonLabel, IonList, IonListHeader, IonSkeletonText, IonThumbnail],
})
export class ExampleComponent {}
React
src/main.tsx
import React from 'react';
import { IonItem, IonLabel, IonList, IonListHeader, IonSkeletonText, IonThumbnail } from '@ionic/react';
import './main.css';
function Example() {
return (
<IonList>
<IonListHeader>
<IonSkeletonText animated={true} style={{ width: '80px' }}></IonSkeletonText>
</IonListHeader>
<IonItem>
<IonThumbnail slot="start">
<IonSkeletonText animated={true}></IonSkeletonText>
</IonThumbnail>
<IonLabel>
<h3>
<IonSkeletonText animated={true} style={{ width: '80%' }}></IonSkeletonText>
</h3>
<p>
<IonSkeletonText animated={true} style={{ width: '60%' }}></IonSkeletonText>
</p>
<p>
<IonSkeletonText animated={true} style={{ width: '30%' }}></IonSkeletonText>
</p>
</IonLabel>
</IonItem>
</IonList>
);
}
export default Example;
src/main.css
ion-skeleton-text {
--border-radius: 9999px;
--background: rgba(188, 0, 255, 0.065);
--background-rgb: 188, 0, 255;
}
Vue
<template>
<ion-list>
<ion-list-header>
<ion-skeleton-text :animated="true" style="width: 80px"></ion-skeleton-text>
</ion-list-header>
<ion-item>
<ion-thumbnail slot="start">
<ion-skeleton-text :animated="true"></ion-skeleton-text>
</ion-thumbnail>
<ion-label>
<h3>
<ion-skeleton-text :animated="true" style="width: 80%;"></ion-skeleton-text>
</h3>
<p>
<ion-skeleton-text :animated="true" style="width: 60%;"></ion-skeleton-text>
</p>
<p>
<ion-skeleton-text :animated="true" style="width: 30%;"></ion-skeleton-text>
</p>
</ion-label>
</ion-item>
</ion-list>
</template>
<script setup lang="ts">
import { IonItem, IonLabel, IonList, IonListHeader, IonSkeletonText, IonThumbnail } from '@ionic/vue';
</script>
<style scoped>
ion-skeleton-text {
--border-radius: 9999px;
--background: rgba(188, 0, 255, 0.065);
--background-rgb: 188, 0, 255;
}
</style>
Properties
animated
Description: true로 설정하면 skeleton text가 애니메이션으로 움직여요.
Attribute: animated
Type: boolean
Default: false
Events
이 컴포넌트에는 사용할 수 있는 이벤트가 없어요.
Methods
이 컴포넌트에는 공개된 메서드가 없어요.
CSS Shadow Parts
이 컴포넌트에는 사용할 수 있는 CSS shadow part가 없어요.
CSS Custom Properties
| Name | Description |
|---|---|
--background |
skeleton text의 배경색 |
--background-rgb |
skeleton text의 배경색을 rgb 형식으로 나타낸 값 |
--border-radius |
skeleton text의 테두리 둥근 정도 |
Slots
이 컴포넌트에는 사용할 수 있는 슬롯이 없어요.
더 알아보기 (Learn more)
skeleton text는 데이터를 불러오는 동안 자연스러운 로딩 화면을 만들어 주는 유용한 컴포넌트예요. animated 프로퍼티와 CSS 커스텀 프로퍼티를 조합하면 더 세련된 스켈레톤 UI를 만들 수 있어요. 목록과 함께 사용하는 패턴은 thumbnail 문서를 참고해도 좋아요.