145a208687
HD-04 scope, against heroui ce90ea3 cn sources: - stale/fictional content: input.md no longer claims TextField is unmigrated; color-field.md no longer claims ColorPicker is private; header.md drops the fictional Header.Root subcomponent and the stale 'menus not migrated' wording (MenuSection label registration is now documented from HeaderRoot source); radio-group.md drops three copied CheckboxGroup wordings (variant override is Radio's, scalar emits, native single-value submit); input-otp.md drops the fictional data-complete state and lists the real missing upstream props - toggle-button disabled row now matches the real CSS hooks (:disabled / [aria-disabled], with data-disabled as a marker only) - part API / CSS classes / interactive states restored per pinned sources: button (full class lists + real variable-based global CSS), accordion (per-part tables + variant/state lists), card (per-part tables + variant list), switch (SwitchGroup snippet + Switch/ SwitchGroup class lists + states), color-field Group (class list + states), input-otp (variant notes, global CSS, class/state lists); input-group gains the two upstream usage chapters - RelatedComponents restored from the pinned componentRelationships (first-3, filtered against componentsMap): 64 pages rewritten, list-box/slider sections added, 7 empty-mapping pages' fabricated entries removed; RelatedShowcases left unmigrated with its real data inventory recorded (2 cases, showcase-site cards) - defaults unified on implementation evidence: granularity (inferred day/minute) and visibleYears (full min-max span, no "or 20" fallback); HD-03 hand-offs resolved (trigger focus-visible noted for HD-06, width guards kept) - new demos: header-collection-grouping (MenuSection/ListBoxSection label wiring), empty-state-collection (collection empty slot); empty-state page deduplicated with a boundary compatibility note - ComponentPreview minHeight/isBgSolid restored per the 30 upstream marks; tabs-overflow max-w-full kept after measuring internal scroll - tests: +3 header registration/demo cases, +1 empty-state collection case; full suite 110 files / 1630 tests, typecheck and build:docs pass
4.3 KiB
4.3 KiB
title, description, component, group
| title | description | component | group |
|---|---|---|---|
| Skeleton 骨架屏 | Skeleton 用于展示加载状态,并预览组件的预期形状。 | skeleton | 组件 |
用法
<script setup lang="ts">
import { Skeleton } from "@heroui-vue/components";
</script>
示例
文本内容
用户资料
列表项
网格
单次闪烁
同步的 shimmer 效果会一次性扫过所有骨架元素。在父容器上应用 hv-skeleton--shimmer 类,并将子骨架的 animationType 设为 "none"。
动画类型
自定义样式
Tailwind CSS
全局 CSS
若要自定义组件类,可使用 @layer components 指令。
@layer components {
/* Base skeleton styles */
.hv-skeleton {
@apply bg-surface-secondary/50; /* Change base background */
}
/* Shimmer animation gradient */
.hv-skeleton--shimmer::after {
@apply via-surface-tertiary; /* Change shimmer gradient color */
}
/* Pulse animation */
.hv-skeleton--pulse {
@apply animate-pulse opacity-75; /* Customize pulse animation */
}
/* No animation variant */
.hv-skeleton--none {
@apply opacity-50; /* Style for static skeleton */
}
}
全局动画配置
可在全局 CSS 中通过 --skeleton-animation 变量为所有 Skeleton 组件设置默认动画类型:
/* 全局 CSS 文件 */
:root {
/* 可选值:shimmer、pulse、none */
--skeleton-animation: pulse;
}
/* 也可为浅色/深色主题设置不同值 */
.light,
[data-theme="light"] {
--skeleton-animation: shimmer;
}
.dark,
[data-theme="dark"] {
--skeleton-animation: pulse;
}
在单个组件上指定 animation-type 属性会覆盖此全局设置。
样式参考
HeroUI 遵循 BEM 方法论,确保组件变体与状态可复用且易于自定义。
CSS 类
Skeleton 使用以下 CSS 类:
基础类 [!toc]
.hv-skeleton - 包含背景与圆角等基础骨架样式
动画变体类 [!toc]
.hv-skeleton--shimmer- 添加带渐变效果的闪烁动画(默认).hv-skeleton--pulse- 使用 Tailwind 的animate-pulse添加脉冲动画.hv-skeleton--none- 无动画的静态骨架
动画
Skeleton 支持三种动画类型,视觉效果各不相同:
闪烁动画 [!toc]
闪烁效果会在骨架元素上移动渐变:
.hv-skeleton--shimmer::after {
@apply absolute inset-0 -translate-x-full animate-skeleton
bg-linear-to-r from-transparent via-surface-tertiary to-transparent content-[''];
}
闪烁动画在主题中通过以下方式定义:
@theme inline {
--animate-skeleton: skeleton 2s linear infinite;
@keyframes skeleton {
100% {
transform: translateX(200%);
}
}
}
脉冲动画 [!toc]
脉冲动画使用 Tailwind 内置的 animate-pulse 工具类:
.hv-skeleton--pulse {
@apply animate-pulse;
}
无动画 [!toc]
用于不需要任何动画的静态骨架:
.hv-skeleton--none {
/* No animation styles applied */
}
API 参考
Skeleton
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
animationType |
"shimmer" | "pulse" | "none" |
"shimmer" 或 CSS 变量 |
Skeleton 的动画类型;也可通过 --skeleton-animation CSS 变量进行全局配置 |
class |
string |
- | 额外的 CSS 类名 |
animationType 未指定时,客户端挂载后读取 --skeleton-animation;服务端渲染与首次客户端渲染使用 "shimmer" 兜底。挂载后修改该 CSS 变量不会自动更新已渲染的 Skeleton。