# Skeleton

> 保持预期内容几何的加载占位，尊重减少动效偏好。

网页来源：/components/skeleton

版本：@quirekit/ui 0.3.1；源码修订：d79a6b48d00e+worktree。此文档对应当前源码构建，接入方式以开始使用为准。

接入前置：[开始使用](/raw/components/getting-started.md)（Vue、样式、主题与图标 Provider）。

## 加载与替换

`loading` 默认为 `true`，显示占位；设为 `false` 时显示默认插槽。按预期内容安排宽高，减少加载完成后的布局变化。

### 示例：skeleton/basic

文件：`basic.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireSkeleton, QuireButton, QuireAvatar } from '@quirekit/ui/vue';
const loading = ref(true);
</script>
<template>
  <div class="grid gap-qk-group p-qk-surface" data-skeleton-demo>
    <div><QuireButton variant="outline" @click="loading = !loading">{{ loading ? '显示内容' : '显示占位' }}</QuireButton></div>
    <div :aria-busy="loading" class="flex items-center gap-qk-surface" data-loading-content>
      <QuireSkeleton :loading="loading" shape="circle" height="var(--qk-control-large)"><QuireAvatar name="林舒" size="md" /></QuireSkeleton>
      <div class="grid min-w-0 flex-1 gap-qk-inline">
        <QuireSkeleton :loading="loading" width="60%"><span class="text-qk-body leading-qk-body">设计讨论记录</span></QuireSkeleton>
        <QuireSkeleton :loading="loading" width="90%"><span class="text-qk-body leading-qk-body text-qk-text-secondary">林舒 · 刚刚更新</span></QuireSkeleton>
      </div>
    </div>
    <span role="status" class="sr-only">{{ loading ? '正在加载文档信息' : '文档信息已加载' }}</span>
  </div>
</template>
```

## 形状与尺寸

`width` 默认占满可用宽度，`height` 默认为一行正文的高度。`shape="circle"` 的宽高都取 `height`，适合头像；矩形用于文字、封面等内容。

### 示例：skeleton/geometry

文件：`geometry.vue`

```vue
<script setup lang="ts">
import { QuireSkeleton } from '@quirekit/ui/vue';
</script>
<template>
  <div class="grid gap-qk-group p-qk-surface" data-skeleton-geometry>
    <div class="flex items-center gap-qk-surface"><QuireSkeleton shape="circle" height="var(--qk-control-large)" /><span class="text-qk-text-secondary">头像占位保持圆形</span></div>
    <div class="grid gap-qk-inline"><QuireSkeleton width="60%" /><QuireSkeleton /><QuireSkeleton width="80%" /></div>
    <QuireSkeleton height="calc(var(--qk-control-large) * 3)" />
  </div>
</template>
```

## 动效

`animated` 默认开启，设为 `false` 可关闭呼吸动效。系统开启减少动效时，占位自动保持静态。

### 示例：skeleton/motion

文件：`motion.vue`

```vue
<script setup lang="ts">
import { QuireSkeleton } from '@quirekit/ui/vue';
</script>
<template>
  <div class="grid gap-qk-surface p-qk-surface" data-skeleton-motion>
    <div class="grid gap-qk-inline"><span>默认呼吸动效</span><QuireSkeleton width="70%" /></div>
    <div class="grid gap-qk-inline"><span>静态占位</span><QuireSkeleton width="70%" :animated="false" /></div>
  </div>
</template>
```

## 加载提示

占位形状不向辅助技术朗读。在整个加载区域设置 `aria-busy`，并提供一次加载说明。刷新已有数据时优先保留内容，避免清空用户正在阅读的区域。

## API

### QuireSkeleton

#### Props

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| loading | 否 | true | Whether to display the placeholder instead of the slot. |
| width | 否 | "100%" | Expected content width; defaults to the available width. |
| height | 否 | "var(--qk-skeleton-line-height)" | Expected content height; defaults to one body line. |
| shape | 否 | "rectangle" | Circle for avatars, rectangle for text or content. |
| animated | 否 | true | Optional gentle pulse, automatically disabled for reduced motion. |

**loading**

```ts
boolean | undefined
```

**width**

```ts
string | undefined
```

```ts
undefined | string
```

**height**

```ts
string | undefined
```

```ts
undefined | string
```

**shape**

```ts
"circle" | "rectangle" | undefined
```

```ts
undefined | "circle" | "rectangle"
```

**animated**

```ts
boolean | undefined
```

#### Events

无。

#### Slots

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| default | 否 | — | Real content, mounted after loading finishes. |

**default**

```ts
any
```

#### 公开实例成员

无。
