Angular 骨架屏加载组件 | ng-hub-ui-skeleton
Angular 骨架屏加载占位符,提供可复用预设、内联 DSL 模板、响应式取值以及用于微光状态的 CSS 变量。
最后更新 2026年9月16日
概览
团队为何搜索这个库
当加载状态需要保持系统化、可复用且产品就绪,而不是退化成一次性的微光标记时,请选择这个 Angular 骨架屏库。
安装
npm install ng-hub-ui-skeleton跳转到
适用于
- 卡片与信息流
- 数据表格
- 表单
- 仪表盘
关于 skeleton
ng-hub-ui-skeleton 为 Angular 团队提供了一种结构化的方式来设计加载占位符:为常见 UI 模式内置的预设、用于自定义形状的紧凑 DSL,以及能让同一套骨架屏适配多种布局的响应式取值。
功能指南
Preset 目录
内置目录刻意做得很宽泛,因为加载状态通常是重复出现的业务 UI,而非孤立的占位符。它包含 card、list-item、table-row、detail-view、form-section、dashboard-widget、stat-card、chart-panel、profile-summary、master-detail、kanban-card、feed-item、search-result、table-toolbar、filter-bar 和 empty-state-skeleton。其理念是让团队从面向生产的加载词汇起步,而不是在每个功能里重建相同的 shimmer 块。实际上,这意味着表格密集的页面可以从 `table-toolbar` 加上重复的 `table-row` 起步,dashboard 页面可以混用 `stat-card`、`chart-panel` 和 `dashboard-widget`,而以内容为主的流程可以使用 `card`、`feed-item` 或 `search-result`,无需从零编写新的布局标记。
示例:
Preset 目录展示
把内置 presets 并列展示,便于团队在编写自定义模板前挑选最接近的起点。
card
Content card with media, title and body lines.
list-item
Compact row with avatar and text.
table-row
Tabular data row placeholder.
detail-view
Detail screen with media and metadata.
form-section
Form group with responsive fields.
dashboard-widget
Panel with chart or metric content.
stat-card
Quick KPI summary card.
chart-panel
Large chart region with legend rows.
profile-summary
Profile hero with avatar and stats.
master-detail
List and detail layout together.
kanban-card
Small board card loading state.
feed-item
Activity or timeline row.
search-result
Search result with metadata lines.
table-toolbar
Toolbar with title, filters and actions.
filter-bar
Row of filter controls.
empty-state-skeleton
Illustrative empty or onboarding state.
card
Dense card variant for tighter layouts.
代码
导入:
模板:
组件:
内置 card preset
以默认 shimmer 渲染内置的 card 骨架屏。
代码
导入:
模板:
组件:
Dashboard 组合
组合多个 presets,模拟加载中的分析 dashboard。
代码
导入:
模板:
组件:
紧凑的 DSL 编写
内联模板使用紧凑的类 Emmet 语法,因为该库为 Angular 代码库内的快速迭代做了优化。兄弟节点组合使用 `+`,嵌套使用 `>`,修饰符位于括号内,重复使用 `*N`,参数通过 `{{param}}` 插值。这为团队提供了一个紧凑的编写界面,在 pull request 中依然易读,并允许进行小改动而无需重写整棵对象树。关键不在于语法的巧妙,而在于布局意图始终贴近组件用法,并且便于 diff、重构和评审。
示例:
紧凑的 DSL 模式
结合结构、params 与响应式 token 的可视化结果,讲解 DSL 的基本构件。
Structure
`+` creates siblings and `>` nests children.
Params & repeats
Use {{param}} placeholders and *N repeaters to scale rows quickly.
Responsive values
Switch spacing or columns inline with compact breakpoint tokens.
代码
导入:
模板:
组件:
内联的类 Emmet 模板
以内联方式定义自定义骨架形状,并对 params 做插值。
代码
导入:
模板:
组件:
变体与响应式布局
加载状态不应忽视布局密度或断点,因为当 skeleton 与真实 UI 毫无关联时用户会察觉到。Presets 可以暴露诸如 `compact` 的变体,单个修饰符的值也可以使用紧凑的响应式令牌在断点之间切换。这使得既能保留一份语义化的 skeleton 定义,又能在移动端、平板和桌面端环境中适配宽度、列数、间距和尺寸。实际效果是更少的重复模板,以及占位阶段与真实渲染界面之间更好的一致性。
示例:
紧凑变体
对比默认 card preset 与其紧凑变体,用于更密集的界面。
代码
导入:
模板:
组件:
响应式表格布局
在内置 presets 中使用响应式取值,从紧凑布局适配到更宽的布局。
代码
导入:
模板:
组件:
编程式注册与主题
内置预设是起点,而非上限。团队可以通过 Angular 依赖注入注册项目专属的预设,并像使用内置目录一样按名称使用它们——当产品拥有自己重复出现的 skeleton 语言时,这一点至关重要。视觉调优保留在 CSS 变量中,因此 shimmer 强度、基础颜色、高亮颜色、间距和圆角都可以与 design system 对齐,而不会把硬编码的值泄漏到功能组件中。这种分离很重要:结构属于预设和 DSL,而视觉策略属于主题化。
示例:
编程式自定义 preset
注册一个本地 preset,并像内置目录一样按名称使用。
代码
导入:
模板:
组件:
Dashboard 组合
组合多个 presets,模拟加载中的分析 dashboard。
代码
导入:
模板:
组件:
核心特性
最近更改
Version 22.3.2 - 9/16/26, 12:00 AM
changed: Repository, issue and README links follow the move to the hub-env organization. Issues for every Hub UI package are now gathered in hub-env/hub-ui, and the repository and bugs fields of the manifest point at the new addresses. No code, types or styles change.
Version 22.3.1 - 9/7/26, 12:00 AM
fixed: Both READMEs stop presenting six internal DSL helpers as part of the API. They listed parseHubSkeletonDsl, interpolateHubSkeletonParams, resolveTemplateDsl, resolveResponsiveToken, resolveBreakpointFromWidth and resolveHubSkeletonNodes as exported, and public-api.ts has never re-exported the module that declares them, so a reader who followed the documentation and imported one got a build error. They stay internal: a layout is written as a template string and handed to the component or registered as a preset, so nothing outside the package has to call them.
Version 22.3.0 - 9/6/26, 12:00 AM
added: FUNCTIONALITIES.md now ships with the library, the same coverage table the rest of the family provides: which parts of the component, the DSL, the preset catalogue, the registry and the styling surface a live example actually demonstrates, and which are only prose. Nothing stated it before, so a reader had to open the documentation site and infer it.
changed: One preset registry is shared again instead of one per placeholder. The component listed HubSkeletonPresetRegistryService in its own providers, so every <hub-skeleton> on screen built a private instance and merged the sixteen bundled presets into a fresh Map, twenty times over on a screen with twenty placeholders, while the README described the service as the providedIn: 'root' singleton a consumer who injects it actually gets. The component now resolves the root instance, which changes where custom presets are read from: see BREAKING_CHANGES.md.
changed: Both READMEs teach the canonical ng-hub-ui-skeleton/styles entry for the theming mixin. They still reached for the deep path ng-hub-ui-skeleton/styles/mixins/skeleton-theme, which resolves but is not the entry 22.2.0 introduced and not what BREAKING_CHANGES.md, the mixin's own header and the generated mixin reference all show, so a reader comparing two sources had to guess which one was current.
fixed: The ariaLabel input is finally reachable by assistive technology. The container carried role="presentation" and aria-label at once, a conflict that costs the name whichever way a user agent resolves it, while every placeholder shape inside is aria-hidden, so nothing was left to carry the name either. A consumer setting the input, or relying on its non-empty default, got silence and had to announce the loading state from an outer element of their own. The container is now a polite role="status" region with aria-busy="true", matching ng-hub-ui-loading, and keeps the label as its accessible name.
fixed: The styles subpath the docs prescribe is now declared in the manifest exports. Since 22.2.0 the stylesheets have shipped at styles/, and both the README and BREAKING_CHANGES.md tell consumers to reach them with @use ng-hub-ui-skeleton/styles. The generated exports map declared only . and ./package.json, so anything that enforces the map, from Node subpath resolution to the Sass pkg: importer and bundlers that honour exports, refused the very import the documentation teaches. An Angular CLI build happened to survive because it resolves bare Sass specifiers through loadPaths instead, which is why the block went unnoticed. The theming entry and the skeleton-theme mixin are now declared explicitly, as the sibling libraries already do.
deprecated: HubSkeletonModule is deprecated and will be removed in 23.0.0. It imports and exports HubSkeletonComponent and provides nothing of its own, so importing the component directly is the whole migration; custom presets go through provideHubSkeletonPresets(), which never travelled through the module either. The class described itself as kept for compatibility with module-based apps but carried no @deprecated tag, so neither an editor nor the build warned anyone. See BREAKING_CHANGES.md.
Version 22.2.4 - 9/1/26, 12:00 AM
changed: The homepage in the manifest points at this library's own documentation page rather than at the site root. It is the link a registry shows beside the package and the one a reader clicks from it, and landing on a front page they then have to search is a worse answer than landing on the reference for the package they were already looking at. Metadata only — no code, no types, no styles change, and nothing a consumer imports is affected.
Version 22.2.3 - 8/17/26, 12:00 AM
fixed: The package shipped without its licence notice. package.json declared MIT, but no LICENSE file travelled in the tarball — and MIT itself requires the copyright notice to be included in distributions. The notice ships now.
Version 22.2.2 - 8/8/26, 12:00 AM
fixed: Documentation links now point at the canonical localized URLs. The README linked to https://hubui.dev/<path> with no locale prefix and no trailing slash, and both forms are 301-redirected, so every reader arriving from npm or GitHub landed on a redirect instead of the canonical page.
Version 22.2.1 - 7/28/26, 12:00 AM
added: Comprehensive test suite for the skeleton DSL parser and preset registry: full grammar coverage (node types, nesting, siblings, props, variants, multipliers, responsive tokens), every parser error path with its exact message, preset expansion/override/variant resolution, and component render round-trips. No runtime changes.
Version 22.2.0 - 7/7/26, 12:00 AM
changed: BREAKING (packaging) — SCSS ships at ng-hub-ui-skeleton/styles. The theme mixin now builds to dist/skeleton/styles/... (was dist/skeleton/src/lib/styles/...), so @use 'ng-hub-ui-skeleton/styles' resolves. Update any @use that reached into src/lib/styles.
Version 22.1.0 - 6/24/26, 12:00 AM
added: New hub-skeleton-theme() Sass mixin (styles/mixins/skeleton-theme) — theme the loading placeholders in one call: base / highlight surfaces (the shimmer gradient), corner radius, node gap and shimmer speed. Every parameter is optional and defaults to null, so only the ones you pass are emitted as --hub-skeleton-* overrides. Token-based, no Bootstrap dependency. (A skeleton is a neutral placeholder — there is no semantic colour variant; per-node sizes still come from the template DSL / presets.) The five theming tokens (--hub-skeleton-bg / -highlight / -radius / -gap / -animation-duration) are now documented in the design-token reference.
Version 22.0.0 - 6/17/26, 12:00 AM
changed: Aligned with Angular 22.
changed: README documentation standardized.
Version 0.1.1 - 6/14/26, 12:00 AM
changed: Replaced the deprecated ngStyle directive with the native [style] binding (Angular soft-deprecated ngStyle/ngClass in November 2024 in favour of native bindings, for better performance and smaller bundles).
Version 0.1.0 - 4/14/26, 12:00 AM
added: Added the initial dynamic skeleton component for Angular.
added: Added a compact Emmet-like DSL with preset composition and repeat support.
added: Added responsive property values, variants, and programmatic preset registration.
added: Added the first preset catalogue for cards, lists, tables, forms, dashboards, and empty states.
相关库
常见问题
如何在 Angular 中显示骨架屏占位?
安装 ng-hub-ui-skeleton,在数据到达之前渲染 HubSkeletonComponent。你描述占位的形状——线条、方块、圆形——它会播放微光动画,直到真实内容将其替换,这样数据到达时布局不会跳动。
同一个骨架形状可以在多个组件间复用吗?
可以。HubSkeletonPreset 只需注册一次具名形状,随后在出现该布局的任何地方复用,卡片的占位因此只定义一处,而不必复制到每个渲染卡片的列表和详情页。
如何修改骨架屏微光的颜色或速度?
ng-hub-ui-skeleton 的每一种颜色、圆角和动画都是 CSS 自定义属性,你可以在运行时用自己的样式表重新设定,并且无需重新构建就能跟随深色模式。HubSkeletonAppearance 可在内置微光与纯静态占位之间切换。
加载时该用骨架屏还是加载动画?
当你已经知道即将出现的内容形状时用骨架屏,因为它会预留空间,避免加载动画留下的布局偏移。加载动画更适合结果布局未知的短暂、不确定的等待。