Trên trang này

Skeleton

Ví dụ chạy được của Skeleton, kèm đúng file Vue tạo ra từng ví dụ.

Mỗi ví dụ là một file Vue hoàn chỉnh. Chép vào app đã cài registry, hoặc mở trong StackBlitz.

Một thẻ

Các khối có kích thước của avatar, hai dòng chữ và ghi chú. Thẻ báo một lần rằng nó đang tải.

Đang tải khách hàng
SkeletonCard.vue
<script setup lang="ts">
import { Skeleton } from '@/components/ui/skeleton'
</script>

<template>
  <!-- Thẻ đang tải báo một lần (aria-busy và một dòng chữ ẩn); các khối skeleton bị ẩn với trình đọc màn hình. -->
  <div
    aria-busy="true"
    class="flex w-full max-w-80 flex-col gap-(--bh-space-150) rounded-(--bh-radius-card) border-(length:--bh-border-width-default) border-(--bh-color-border) bg-(--bh-color-surface) p-(--bh-space-200)"
  >
    <span class="sr-only">Đang tải khách hàng</span>
    <div class="flex items-center gap-(--bh-space-150)">
      <Skeleton class="size-(--bh-size-control-large) rounded-(--bh-radius-full)" />
      <div class="flex flex-1 flex-col gap-(--bh-space-100)">
        <Skeleton class="h-(--bh-space-200) w-3/4" />
        <Skeleton class="h-(--bh-space-150) w-1/2" />
      </div>
    </div>
    <Skeleton class="h-(--bh-space-600) w-full" />
  </div>
</template>

Các hàng của bảng

Tiêu đề thật và cùng chiều cao hàng, nên bảng không nhảy khi dữ liệu tới.

Đơn hàng, đang tải
Đơn hàngKhách hàngTổng tiền
SkeletonTable.vue
<script setup lang="ts">
import { Skeleton } from '@/components/ui/skeleton'

// Cùng chiều cao hàng và cột như bảng đã tải, nên không có gì xê dịch khi dữ liệu tới.
const rows = 4
</script>

<template>
  <table aria-busy="true" class="w-full max-w-120 border-collapse [font:var(--bh-font-body-default)]">
    <caption class="sr-only">Đơn hàng, đang tải</caption>
    <thead>
      <tr class="border-b-(length:--bh-border-width-default) border-(--bh-color-border) text-start text-(--bh-color-text-subtle) [font:var(--bh-font-label-default)]">
        <th class="px-(--bh-space-table-cell-x) py-(--bh-space-table-cell-y) text-start">Đơn hàng</th>
        <th class="px-(--bh-space-table-cell-x) py-(--bh-space-table-cell-y) text-start">Khách hàng</th>
        <th class="px-(--bh-space-table-cell-x) py-(--bh-space-table-cell-y) text-end">Tổng tiền</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="row in rows" :key="row" class="border-b-(length:--bh-border-width-default) border-(--bh-color-border)">
        <td class="px-(--bh-space-table-cell-x) py-(--bh-space-table-cell-y)"><Skeleton class="h-(--bh-space-200) w-20" /></td>
        <td class="px-(--bh-space-table-cell-x) py-(--bh-space-table-cell-y)"><Skeleton class="h-(--bh-space-200) w-32" /></td>
        <td class="px-(--bh-space-table-cell-x) py-(--bh-space-table-cell-y)"><Skeleton class="ms-auto h-(--bh-space-200) w-16" /></td>
      </tr>
    </tbody>
  </table>
</template>