Angular 工具库 | ng-hub-ui-utils

Angular 工具库,包含 pipes、焦点管理、overlay、过渡和翻译助手,供可复用 UI 组件共享使用。

API 参考

这里是 utils 的完整契约:你可以绑定、监听、投影和设置主题的一切,都集中在一处。接入你需要的部分,自定义你想要的样式——它是 standalone 的,且对 signal 友好。

输入

通过 4 个输入项精细调校 utils。像绑定任意 Angular @Input 一样绑定它们。

名称类型默认值描述
HubTranslationServiceService-用于管理翻译的可注入服务。方法:getTranslation()、setTranslations()
HubOverlayServiceService-用于以编程方式创建和管理遮罩层的服务
HubPopupServiceService-用于创建弹出元素的简化服务
TooltipDirectiveDirective-Directive ([tooltip]) that shows a positioned, themeable tooltip on hover/focus. Inputs: tooltip (text), placement, delay, offset.

输出

响应 utils 的行为——有 7 个事件可供你挂接逻辑。

名称类型描述
TranslatePipePipe使用 HubTranslationService 翻译某个键。用法:{{ "key" | translate }}
GetPipePipe获取嵌套属性值。用法:{{ object | get:"path.to.property" }}
IsStringPipePipe检查值是否为字符串。用法:{{ value | isString }}
IsObjectPipePipe检查值是否为对象。用法:{{ value | isObject }}
IsObservablePipePipe检查值是否为 Observable。用法:{{ value | isObservable }}
UcfirstPipePipe将首字母大写。用法:{{ "hello" | ucfirst }} → "Hello"
UnwrapAsyncPipePipe在模板中解包 Observable 或 Promise 值

模板

打造你自己的样式——4 个模板插槽让你可以投影自定义标记。

名称描述示例
hubFocusTrap()将键盘焦点限制在某个元素内。适用于模态框和对话框。hubFocusTrap(zone, element, stopFocusTrap$, refocusOnClick)
interpolateString()用对象中的值替换 {{ placeholders }} 占位符interpolateString("Hello {{name}}", { name: "World" }) → "Hello World"
getValue()使用点分表示法获取嵌套属性getValue(obj, "user.profile.name")
equals()对对象和数组进行深度相等比较equals({ a: 1 }, { a: 1 }) → true

CSS 变量

用 19 个 CSS 变量为每一个像素设置主题。在 :root 处覆盖它们,或将其限定到某个容器范围内。

Tooltip

Theming tokens for the [tooltip] directive.

变量默认值类型描述
--hub-tooltip-bgvar(--hub-ref-color-black, #000)color Tooltip background colour. var(--hub-sys-color-primary)#212529
--hub-tooltip-colorvar(--hub-ref-color-white, #fff)color Tooltip text colour. #fff#f8f9fa
--hub-tooltip-opacity0.9number Opacity of the shown tooltip. 10.85
--hub-tooltip-padding-xvar(--hub-ref-space-2, 0.5rem)length Horizontal padding inside the tooltip. 0.75rem1rem
--hub-tooltip-padding-yvar(--hub-ref-space-1, 0.25rem)length Vertical padding inside the tooltip. 0.375rem0.5rem
--hub-tooltip-border-radiusvar(--hub-sys-radius-md, 0.375rem)length Corner radius of the tooltip. 0.25rem999px
--hub-tooltip-font-sizevar(--hub-ref-font-size-sm, 0.875rem)length Font size of the tooltip text. 0.75rem1rem
--hub-tooltip-font-weightvar(--hub-ref-font-weight-base, 400)number Font weight of the tooltip text. 500600
--hub-tooltip-line-heightvar(--hub-ref-line-height-base, 1.5)number Line height of the tooltip text. 1.41.6
--hub-tooltip-max-width200pxlength Maximum width before the text wraps. 160px320px
--hub-tooltip-zindexvar(--hub-sys-zindex-tooltip, 1080)number Stacking order of the tooltip element. 10802000
--hub-tooltip-transition-duration0.15stransition Fade in/out duration. 0.1s0.25s
--hub-tooltip-shadownoneshadow Box shadow of the tooltip. var(--hub-sys-shadow)0 2px 8px rgba(0,0,0,.2)
--hub-tooltip-font-familyvar(--hub-ref-font-family-base, inherit)string Font family of the tooltip text. inheritmonospace

Overlay

CSS variables consumed by the overlay/popup system (`.hub-overlay-container` / `.hub-overlay-backdrop`).

变量默认值类型描述
--hub-overlay-bgvar(--hub-sys-surface-elevated, #f8f9fa)color Background of the overlay panel. #fffvar(--hub-sys-surface-page)
--hub-overlay-border-radiusvar(--hub-sys-radius-sm, 0.25rem)length Corner radius of the overlay panel. 0.5rem0
--hub-overlay-shadowvar(--hub-sys-shadow, 0 0.5rem 1rem rgba(0,0,0,.15))shadow Elevation shadow of the overlay panel. var(--hub-sys-shadow-lg)none
--hub-overlay-zindexvar(--hub-sys-zindex-dropdown, 1000)number Stacking order of the overlay panel. 10502000
--hub-overlay-backdrop-zindexcalc(var(--hub-sys-zindex-dropdown, 1000) - 1)number Stacking order of the overlay backdrop (just below the panel). 10491999

样式与主题

尚未记录任何样式示例。本节将包含自定义方案和主题示例。