Angular 徽章库 | ng-hub-ui-badges
面向状态、计数器与可移除筛选标签的语义化 Angular 徽章,提供 CSS 变量与公开 SCSS mixin,支持自定义颜色族。
最后更新 2026年8月8日
概览
团队为何搜索这个库
当你的 Angular 应用需要紧凑的语义状态标签、计数器与可关闭的筛选器,而不想退回到一次性的 span 或 Bootstrap 的 badge 类时,请使用 ng-hub-ui-badges。
安装
npm install ng-hub-ui-badges跳转到
适用于
- 工作流状态
- 表格与卡片元数据
- 激活的筛选栏
- 通知计数器
关于 badges
ng-hub-ui-badges 为 Angular 团队提供一个小而完整的徽章系统:语义颜色、多种视觉表面、尺寸与形状梯度、状态圆点、可选图标以及可关闭标签。一切都由共享的 `--hub-sys-color-*` token 族和公开的 `--hub-badge-*` 自定义属性驱动,因此该组件族能自然融入以设计系统为先的代码库。
功能指南
语义矩阵
徽章的核心表现形式:在 solid、soft、outline、ghost、subtle 和 surface 变体中呈现语义颜色。
示例:
语义矩阵
语义矩阵
尺寸与形状
紧凑的 XS 标签、更宽松的 LG 胶囊以及三种外壳形状,可适配密集表格或宽松的仪表盘。
示例:
尺寸与形状
尺寸与形状
状态与计数
使用同一个基础组件即可实现状态圆点、警报计数、图标徽章和轻量的元数据胶囊。
示例:
状态与计数
状态与计数
可移除筛选器
用于活动筛选器、限定范围搜索胶囊和轻量 token 界面的可移除标签。
示例:
可移除筛选器
可移除筛选器
开放式语义主题
内置颜色读取共享的 design system token,自定义强调色则通过公开的 SCSS mixin 接入。
示例:
开放式语义主题
开放式语义主题
截断与提示
较长的标签会以省略号截断,并在悬停时显示完整内容——使用原生 title,或在接入后使用 hub-ui 提示。
示例:
截断与提示
截断与提示
筛选 chip
可切换的 hub-chip 标签,由 hub-chip-set 统一协调实现单选或多选,并复用 badge 的强调色主题。
示例:
可交互的筛选 chip
可交互的筛选 chip
核心特性
最近更改
Version 22.6.1 - 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.6.0 - 7/7/26, 12:00 AM
added: hub-badge-theme(...) mixin — one-call token theming for <hub-badge> / <hub-chip>: accent (drives the shared role family) plus the shell tokens (bg, color, border-color, border-radius, border-width, padding-x/-y, gap, font-size, font-weight). Null-defaulted and additive; the existing variant-registration API (hub-badge-variant-rules / hub-badge-color-rules) stays for registering new named accents. @use 'ng-hub-ui-badges/styles' as *;.
changed: <hub-badge> / <hub-chip> [color] accepts ANY colour. On top of the built-in semantic accents, the input now also accepts a registered custom accent and a literal colour (#ff0000, rgb(...), oklch(...), a CSS named colour), resolved through the shared resolveHubAccent helper (imported from ng-hub-ui-utils): a bareword becomes var(--hub-sys-color-<name>, <name>); a literal is used as-is. The single --hub-<comp>-accent slot derives the rest of the family, so built-in colours are unchanged.
changed: Internal — host bindings moved to the host metadata object. @HostBinding / @HostListener decorators were replaced by the host object in the component/directive metadata (Angular style guide). No public API or behaviour change.
changed: Added ng-hub-ui-utils (>=22.7.0) as a peer dependency (already used at runtime; now declared).
Version 22.5.0 - 7/6/26, 12:00 AM
removed: BREAKING — HubBadgeGroupComponent (<hub-badge-group>) removed. It was a purely presentational flex wrapper whose four inputs (direction / align / gap / wrap) mapped 1:1 to CSS, redundant with the standard flex utilities the library already ships. Arrange badges with <div class="d-flex flex-wrap gap-2"> (add flex-column / align-items-* as needed). The HubBadgeGroupDirection / HubBadgeGroupAlign types and the internal --hub-badge-group-gap / --hub-badge-group-align tokens are gone too.
added: hub-chip + hub-chip-set — interactive filter-chip primitives. hub-chip is a togglable, optionally removable tag that reuses the badge accent contract for its colours (it points the shared --hub-badge-accent slot from its color input and derives every surface from that family via the new hub-badge-accent-family mixin). It exposes selected (two-way model), value, color, disabled, removable, removeLabel inputs and selectedChange / removed / chipClick outputs, projects a leading icon/avatar through [hubChipLeading], and behaves as a role="button" toggle with aria-pressed and Space/Enter support. hub-chip-set groups chips with selectionMode ('single' | 'multiple') and a two-way value model, deselecting siblings in single mode. New tokens: --hub-chip-bg, --hub-chip-color, --hub-chip-border-color, --hub-chip-selected-bg, --hub-chip-selected-color, --hub-chip-hover-bg, --hub-chip-gap, --hub-chip-focus-ring (plus the shell tokens --hub-chip-font-family/-size/-weight, --hub-chip-padding-x/-y, --hub-chip-border-width/-radius, --hub-chip-focus-ring-width, --hub-chip-transition and --hub-chip-set-gap).
added: Interactive badges. New interactive input turns a badge into a role="button" toggle with a keyboard tab stop that emits the new selected output on click / Enter / Space, and an active input toggles the pressed state (.hub-badge--active, aria-pressed) reading the new --hub-badge-active-bg slot. All default-off and additive.
added: Overlay status dot. New dotOverlay input renders the status dot absolutely positioned at a badge corner (distinct from the existing inline leading dot), with a dotPlacement input ('top-end' | 'top-start' | 'bottom-end' | 'bottom-start') and the new --hub-badge-overlay-offset token controlling the corner inset.
added: neutral, light and dark documented as built-in colours. HubBadgeBuiltinColor now lists all nine canonical accents the stylesheet already registers, so the type matches the runtime.
added: Designed bg/fg pair registration. hub-badge-variant-rules($type, $accent, $bg, $fg, $border, $subtle) gained optional $bg / $fg / $border / $subtle overrides: pass any of them to pin the corresponding final slot for a variant; omit them to keep today's runtime derivation. Fully backward compatible.
added: hub-badge-accent-family mixin. Exposes the runtime-derived accent role family (-emphasis / -subtle / -border / -on) as a single shared mixin, now included by both hub-badge and hub-chip so the colour derivation lives in one place.
Version 22.4.1 - 7/2/26, 12:00 AM
fixed: CSS variable fallbacks realigned to the ds light defaults (--hub-ref-font-family-base: inherit → system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif); fallbacks only apply when ng-hub-ui-ds is not loaded.
fixed: Docs: docs/css-variables-reference.md default values resynchronized with the actual code declarations (now guarded by the repo-level tokens-parity check F).
Version 22.4.0 - 6/29/26, 12:00 AM
added: Text truncation with ellipsis, bounded by the new `--hub-badge-max-width` CSS variable.
added: `tooltip` input plus auto tooltip on truncated content (native `title` by default).
added: Optional hub-ui tooltip integration via `provideHubBadgeTooltip(hubTooltipAdapter)` (from ng-hub-ui-utils).
Version 22.0.0 - 6/24/26, 12:00 AM
added: `HubBadgeComponent` with semantic variants, status dots and dismissible mode.
added: `HubBadgeGroupComponent` for wrapped and stacked badge layouts.
added: Public SCSS mixins at `ng-hub-ui-badges/styles` for registering custom semantic colour families.