Angular 工具库 | ng-hub-ui-utils
Angular 工具库,包含 pipes、焦点管理、overlay、过渡和翻译助手,供可复用 UI 组件共享使用。
API 参考
这里是 utils 的完整契约:你可以绑定、监听、投影和设置主题的一切,都集中在一处。接入你需要的部分,自定义你想要的样式——它是 standalone 的,且对 signal 友好。
输入
通过 4 个输入项精细调校 utils。像绑定任意 Angular @Input 一样绑定它们。
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
HubTranslationService | Service | - | 用于管理翻译的可注入服务。方法:getTranslation()、setTranslations() |
HubOverlayService | Service | - | 用于以编程方式创建和管理遮罩层的服务 |
HubPopupService | Service | - | 用于创建弹出元素的简化服务 |
TooltipDirective | Directive | - | Directive ([tooltip]) that shows a positioned, themeable tooltip on hover/focus. Inputs: tooltip (text), placement, delay, offset. |
输出
响应 utils 的行为——有 7 个事件可供你挂接逻辑。
| 名称 | 类型 | 描述 |
|---|---|---|
TranslatePipe | Pipe | 使用 HubTranslationService 翻译某个键。用法:{{ "key" | translate }} |
GetPipe | Pipe | 获取嵌套属性值。用法:{{ object | get:"path.to.property" }} |
IsStringPipe | Pipe | 检查值是否为字符串。用法:{{ value | isString }} |
IsObjectPipe | Pipe | 检查值是否为对象。用法:{{ value | isObject }} |
IsObservablePipe | Pipe | 检查值是否为 Observable。用法:{{ value | isObservable }} |
UcfirstPipe | Pipe | 将首字母大写。用法:{{ "hello" | ucfirst }} → "Hello" |
UnwrapAsyncPipe | Pipe | 在模板中解包 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-bg | var(--hub-ref-color-black, #000) | color | Tooltip background colour. var(--hub-sys-color-primary)#212529 |
--hub-tooltip-color | var(--hub-ref-color-white, #fff) | color | Tooltip text colour. #fff#f8f9fa |
--hub-tooltip-opacity | 0.9 | number | Opacity of the shown tooltip. 10.85 |
--hub-tooltip-padding-x | var(--hub-ref-space-2, 0.5rem) | length | Horizontal padding inside the tooltip. 0.75rem1rem |
--hub-tooltip-padding-y | var(--hub-ref-space-1, 0.25rem) | length | Vertical padding inside the tooltip. 0.375rem0.5rem |
--hub-tooltip-border-radius | var(--hub-sys-radius-md, 0.375rem) | length | Corner radius of the tooltip. 0.25rem999px |
--hub-tooltip-font-size | var(--hub-ref-font-size-sm, 0.875rem) | length | Font size of the tooltip text. 0.75rem1rem |
--hub-tooltip-font-weight | var(--hub-ref-font-weight-base, 400) | number | Font weight of the tooltip text. 500600 |
--hub-tooltip-line-height | var(--hub-ref-line-height-base, 1.5) | number | Line height of the tooltip text. 1.41.6 |
--hub-tooltip-max-width | 200px | length | Maximum width before the text wraps. 160px320px |
--hub-tooltip-zindex | var(--hub-sys-zindex-tooltip, 1080) | number | Stacking order of the tooltip element. 10802000 |
--hub-tooltip-transition-duration | 0.15s | transition | Fade in/out duration. 0.1s0.25s |
--hub-tooltip-shadow | none | shadow | Box shadow of the tooltip. var(--hub-sys-shadow)0 2px 8px rgba(0,0,0,.2) |
--hub-tooltip-font-family | var(--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-bg | var(--hub-sys-surface-elevated, #f8f9fa) | color | Background of the overlay panel. #fffvar(--hub-sys-surface-page) |
--hub-overlay-border-radius | var(--hub-sys-radius-sm, 0.25rem) | length | Corner radius of the overlay panel. 0.5rem0 |
--hub-overlay-shadow | var(--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-zindex | var(--hub-sys-zindex-dropdown, 1000) | number | Stacking order of the overlay panel. 10502000 |
--hub-overlay-backdrop-zindex | calc(var(--hub-sys-zindex-dropdown, 1000) - 1) | number | Stacking order of the overlay backdrop (just below the panel). 10491999 |
样式与主题
尚未记录任何样式示例。本节将包含自定义方案和主题示例。