ng-hub-ui-utils 1.2.0 → 22.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,29 +1,70 @@
1
- # Hub UI - Angular Utilities Library
1
+ # ng-hub-ui-utils
2
2
 
3
3
  [![NPM Version](https://img.shields.io/npm/v/ng-hub-ui-utils.svg)](https://www.npmjs.com/package/ng-hub-ui-utils)
4
4
  [![License](https://img.shields.io/npm/l/ng-hub-ui-utils.svg)](LICENSE)
5
- [![Build Status](https://img.shields.io/github/workflow/status/carlos-morcillo/ng-hub-ui-utils/CI)](https://github.com/carlos-morcillo/ng-hub-ui-utils/actions)
5
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/carlos-morcillo/ng-hub-ui/ci.yml)](https://github.com/carlos-morcillo/ng-hub-ui/actions)
6
6
 
7
7
  > Common utilities library for Angular, fundamental support for the Hub UI ecosystem.
8
8
 
9
9
  [Español](./README.es.md) | **English**
10
10
 
11
- ## 🏡 Part of the Hub UI Family
12
-
13
- This library is part of the **Hub UI** ecosystem, which includes:
14
-
15
- - 🎨 [**ng-hub-ui-accordion**](https://github.com/carlos-morcillo/ng-hub-ui-accordion) - Accordion components
16
- - 📱 **ng-hub-ui-action-sheet** - Mobile action sheets
17
- - 👤 [**ng-hub-ui-avatar**](https://github.com/carlos-morcillo/ng-hub-ui-avatar) - Avatar components
18
- - 📋 [**ng-hub-ui-board**](https://github.com/carlos-morcillo/ng-hub-ui-board) - Kanban-style boards
19
- - 🧭 [**ng-hub-ui-breadcrumbs**](https://github.com/carlos-morcillo/ng-hub-ui-breadcrumbs) - Navigation breadcrumbs
20
- - 📜 **ng-hub-ui-dropdown** - Dropdown components
21
- - 📝 **ng-hub-ui-list** - List components
22
- - 🪟 [**ng-hub-ui-modal**](https://github.com/carlos-morcillo/ng-hub-ui-modal) - Modal components
23
- - 🌀 [**ng-hub-ui-portal**](https://github.com/carlos-morcillo/ng-hub-ui-portal) - Portal system
24
- - 🔀 [**ng-hub-ui-sortable**](https://github.com/carlos-morcillo/ng-hub-ui-sortable) - Sortable components
25
- - 📊 [**ng-hub-ui-stepper**](https://github.com/carlos-morcillo/ng-hub-ui-stepper) - Step-by-step components
26
- - 🛠️ [**ng-hub-ui-utils**](https://github.com/carlos-morcillo/ng-hub-ui-utils) ← you are here - Common utilities
11
+ ## 📝 Description
12
+
13
+ `ng-hub-ui-utils` is the foundational utilities library for the entire Hub UI ecosystem. It provides a curated set of framework-agnostic helper functions, type guards, standalone Angular pipes, a flexible overlay/popup system, focus-trap and accessibility helpers, scrollbar compensation, a smooth transition engine, and a lightweight internationalization (i18n) system. It ships no visual components — instead it powers the shared low-level behavior used across the rest of the `ng-hub-ui` libraries, while remaining tree-shakable so you only bundle what you import.
14
+
15
+ ## 📑 Table of Contents
16
+
17
+ - [Description](#-description)
18
+ - [Documentation and Live Examples](#-documentation-and-live-examples)
19
+ - [Library Family `ng-hub-ui`](#-library-family-ng-hub-ui)
20
+ - [Inspiration](#-inspiration)
21
+ - [Features](#-features)
22
+ - [Installation](#-installation)
23
+ - [Quick Start](#-quick-start)
24
+ - [Internationalization (i18n)](#-internationalization-i18n)
25
+ - [Utilities API](#-utilities-api)
26
+ - [Support Components](#-support-components)
27
+ - [Compatibility](#-compatibility)
28
+ - [Development](#-development)
29
+ - [Testing](#-testing)
30
+ - [Changelog](#-changelog)
31
+ - [Issues and Support](#-issues-and-support)
32
+ - [Support the Project](#-support-the-project)
33
+ - [Contributions](#-contributions)
34
+ - [License](#-license)
35
+
36
+ ## 📚 Documentation and Live Examples
37
+
38
+ This package is part of [Hub UI](https://hubui.dev/), a collection of Angular component libraries for standalone apps.
39
+
40
+ - Docs: https://hubui.dev/utils/overview/
41
+ - Live examples: https://hubui.dev/utils/examples/
42
+ - Hub UI: https://hubui.dev/
43
+
44
+ ## 🧩 Library Family `ng-hub-ui`
45
+
46
+ This library is part of the **ng-hub-ui** ecosystem:
47
+
48
+ - [**ng-hub-ui-accordion**](https://www.npmjs.com/package/ng-hub-ui-accordion) (deprecated — use ng-hub-ui-panels)
49
+ - [**ng-hub-ui-action-sheet**](https://www.npmjs.com/package/ng-hub-ui-action-sheet)
50
+ - [**ng-hub-ui-avatar**](https://www.npmjs.com/package/ng-hub-ui-avatar)
51
+ - [**ng-hub-ui-board**](https://www.npmjs.com/package/ng-hub-ui-board)
52
+ - [**ng-hub-ui-breadcrumbs**](https://www.npmjs.com/package/ng-hub-ui-breadcrumbs)
53
+ - [**ng-hub-ui-calendar**](https://www.npmjs.com/package/ng-hub-ui-calendar)
54
+ - [**ng-hub-ui-dropdown**](https://www.npmjs.com/package/ng-hub-ui-dropdown)
55
+ - [**ng-hub-ui-ds**](https://www.npmjs.com/package/ng-hub-ui-ds)
56
+ - [**ng-hub-ui-forms**](https://www.npmjs.com/package/ng-hub-ui-forms)
57
+ - [**ng-hub-ui-history**](https://www.npmjs.com/package/ng-hub-ui-history)
58
+ - [**ng-hub-ui-milestones**](https://www.npmjs.com/package/ng-hub-ui-milestones)
59
+ - [**ng-hub-ui-modal**](https://www.npmjs.com/package/ng-hub-ui-modal)
60
+ - [**ng-hub-ui-nav**](https://www.npmjs.com/package/ng-hub-ui-nav)
61
+ - [**ng-hub-ui-paginable**](https://www.npmjs.com/package/ng-hub-ui-paginable)
62
+ - [**ng-hub-ui-panels**](https://www.npmjs.com/package/ng-hub-ui-panels)
63
+ - [**ng-hub-ui-portal**](https://www.npmjs.com/package/ng-hub-ui-portal)
64
+ - [**ng-hub-ui-skeleton**](https://www.npmjs.com/package/ng-hub-ui-skeleton)
65
+ - [**ng-hub-ui-sortable**](https://www.npmjs.com/package/ng-hub-ui-sortable)
66
+ - [**ng-hub-ui-stepper**](https://www.npmjs.com/package/ng-hub-ui-stepper)
67
+ - [**ng-hub-ui-utils**](https://www.npmjs.com/package/ng-hub-ui-utils) ← You are here
27
68
 
28
69
  ## 💡 Inspiration
29
70
 
@@ -149,6 +190,45 @@ hubRunTransition(
149
190
  });
150
191
  ```
151
192
 
193
+ ### 🌐 Internationalization (i18n)
194
+
195
+ Lightweight, dependency-injection based translation system with a reactive pipe. Register translation dictionaries at bootstrap with `provideHubTranslation`, then translate keys in templates with the `translate` pipe.
196
+
197
+ ```typescript
198
+ import { provideHubTranslation, HubTranslationService, TranslatePipe } from 'ng-hub-ui-utils';
199
+
200
+ // In your application config / bootstrap providers
201
+ bootstrapApplication(AppComponent, {
202
+ providers: [
203
+ provideHubTranslation({
204
+ language: 'en',
205
+ fallbackLanguage: 'en',
206
+ dictionaries: {
207
+ en: { greeting: 'Hello {name}!' },
208
+ es: { greeting: '¡Hola {name}!' }
209
+ }
210
+ })
211
+ ]
212
+ });
213
+ ```
214
+
215
+ ```typescript
216
+ @Component({
217
+ standalone: true,
218
+ imports: [TranslatePipe],
219
+ template: `
220
+ <!-- Simple key -->
221
+ <p>{{ 'greeting' | translate }}</p>
222
+
223
+ <!-- With interpolation params -->
224
+ <p>{{ 'greeting' | translate: { name: 'Carlos' } }}</p>
225
+ `
226
+ })
227
+ export class ExampleComponent {}
228
+ ```
229
+
230
+ See [Internationalization (i18n)](#-internationalization-i18n) for the full API.
231
+
152
232
  ### 🧰 Standalone Angular Pipes
153
233
 
154
234
  Complete set of utility pipes for validation, transformation, and data manipulation.
@@ -268,6 +348,41 @@ import { hubRunTransition } from 'ng-hub-ui-utils';
268
348
  import { GetPipe, UcfirstPipe } from 'ng-hub-ui-utils';
269
349
  ```
270
350
 
351
+ ### 🏷️ Tooltip Directive
352
+
353
+ Add a lightweight, themeable tooltip to any element with the `[tooltip]` directive.
354
+ The tooltip is appended to `<body>` (never clipped) and shows on hover/focus.
355
+
356
+ ```typescript
357
+ import { TooltipDirective } from 'ng-hub-ui-utils';
358
+
359
+ @Component({
360
+ standalone: true,
361
+ imports: [TooltipDirective],
362
+ template: `<button tooltip="Save changes" placement="top">Save</button>`
363
+ })
364
+ export class ExampleComponent {}
365
+ ```
366
+
367
+ Inputs: `tooltip` (text), `placement` (`top` | `bottom` | `left` | `right`, default `top`),
368
+ `delay` (fade ms, default `150`), `offset` (px, default `8`).
369
+
370
+ Theme it from any scope with `--hub-tooltip-*` variables:
371
+
372
+ ```css
373
+ .my-scope {
374
+ --hub-tooltip-bg: var(--hub-sys-color-primary);
375
+ --hub-tooltip-color: #fff;
376
+ --hub-tooltip-border-radius: 999px;
377
+ --hub-tooltip-opacity: 1;
378
+ }
379
+ ```
380
+
381
+ Available tokens: `--hub-tooltip-bg`, `--hub-tooltip-color`, `--hub-tooltip-opacity`,
382
+ `--hub-tooltip-padding-x`, `--hub-tooltip-padding-y`, `--hub-tooltip-border-radius`,
383
+ `--hub-tooltip-font-size`, `--hub-tooltip-max-width`, `--hub-tooltip-z-index`,
384
+ `--hub-tooltip-transition-duration`, `--hub-tooltip-shadow`, `--hub-tooltip-font-family`.
385
+
271
386
  ## 🚀 Installation
272
387
 
273
388
  ```bash
@@ -323,6 +438,91 @@ export class ExampleComponent {
323
438
  }
324
439
  ```
325
440
 
441
+ ## 🌐 Internationalization (i18n)
442
+
443
+ The i18n system (available since `v1.2.0`) lets you register translation dictionaries via dependency injection and resolve keys reactively in templates. Updating the active translations at runtime automatically refreshes any `translate` pipe in the view.
444
+
445
+ ### `provideHubTranslation(config?)`
446
+
447
+ Environment provider helper that registers `HubTranslationService` and its configuration. Call it once in your application bootstrap providers.
448
+
449
+ ```typescript
450
+ function provideHubTranslation(config?: HubTranslationConfig): EnvironmentProviders;
451
+ ```
452
+
453
+ ### `HubTranslationConfig`
454
+
455
+ ```typescript
456
+ interface HubTranslationConfig {
457
+ /** Map of language code → translation dictionary. */
458
+ dictionaries?: Record<string, Record<string, any>>;
459
+ /** Active language code (defaults to fallbackLanguage, then 'en'). */
460
+ language?: string;
461
+ /** Fallback language merged under the active language (defaults to 'en'). */
462
+ fallbackLanguage?: string;
463
+ }
464
+ ```
465
+
466
+ The configuration is also exposed through the `HUB_TRANSLATION_CONFIG` injection token for advanced scenarios.
467
+
468
+ ### `HubTranslationService`
469
+
470
+ Injectable service that holds the active translations and notifies subscribers when they change.
471
+
472
+ ```typescript
473
+ @Injectable()
474
+ class HubTranslationService {
475
+ /** Currently active flat translations map. */
476
+ translations: Record<string, string>;
477
+ /** Emits whenever the active translations are updated. */
478
+ translationObserver: Observable<Record<string, string>>;
479
+
480
+ /** Resolves a key (supports dot notation) against the active translations. */
481
+ getTranslation(key: string): any;
482
+ /** Replaces the active translations, merging them over the fallback dictionary. */
483
+ setTranslations(translations?: Record<string, string>): void;
484
+ }
485
+ ```
486
+
487
+ ```typescript
488
+ import { HubTranslationService } from 'ng-hub-ui-utils';
489
+
490
+ @Component({ /* ... */ })
491
+ export class LanguageSwitcherComponent {
492
+ private translationSvc = inject(HubTranslationService);
493
+
494
+ switchToSpanish() {
495
+ // Swap the active dictionary at runtime; the `translate` pipe updates automatically.
496
+ this.translationSvc.setTranslations({ greeting: '¡Hola {name}!' });
497
+ }
498
+ }
499
+ ```
500
+
501
+ ### `TranslatePipe` (`translate`)
502
+
503
+ Impure standalone pipe that resolves a translation key with optional interpolation params. It subscribes to the service so the view stays in sync when translations change.
504
+
505
+ ```typescript
506
+ // Simple key
507
+ {{ 'greeting' | translate }}
508
+
509
+ // With an object of interpolation params
510
+ {{ 'greeting' | translate: { name: 'Carlos' } }}
511
+
512
+ // Params can also be written inline as a pseudo-object string
513
+ {{ 'greeting' | translate: "{name: 'Carlos'}" }}
514
+ ```
515
+
516
+ If a key has no matching translation, the key itself is returned. Interpolation tokens use the `{paramName}` syntax (powered by the `interpolateString` utility).
517
+
518
+ ### Supporting utilities
519
+
520
+ These functions back the i18n system and are exported for direct use:
521
+
522
+ - `getValue(target: any, key: string): any` - Reads a nested value by dot-notation key.
523
+ - `interpolateString(text: string, params?: object): string` - Replaces `{token}` placeholders in a string.
524
+ - `equals(o1: any, o2: any): boolean` - Deep equality check used to memoize the pipe value.
525
+
326
526
  ## 📊 Utilities API
327
527
 
328
528
  ### Conversion Functions
@@ -462,8 +662,8 @@ This library doesn't include visual components, but support utilities used by ot
462
662
 
463
663
  | Utility | Description | Used by |
464
664
  | --------------- | ----------------------------------- | -------------------------------------- |
465
- | Overlay Service | Flexible overlay positioning system | ng-hub-ui-dropdown, ng-hub-ui-modal |
466
- | Focus Trap | Focus management in modals/overlays | ng-hub-ui-modal, ng-hub-ui-dropdown |
665
+ | Overlay Service | Flexible overlay positioning system | ng-hub-ui-modal, ng-hub-ui-portal |
666
+ | Focus Trap | Focus management in modals/overlays | ng-hub-ui-modal, ng-hub-ui-portal |
467
667
  | Scrollbar | Scrollbar compensation | ng-hub-ui-modal, ng-hub-ui-portal |
468
668
  | Popup Service | Base class for popup components | ng-hub-ui-modal, ng-hub-ui-portal |
469
669
  | Transitions | Smooth animations | ng-hub-ui-accordion, ng-hub-ui-modal |
@@ -472,7 +672,7 @@ This library doesn't include visual components, but support utilities used by ot
472
672
 
473
673
  ## 🤝 Compatibility
474
674
 
475
- - Angular 15+
675
+ - Angular 16+
476
676
  - TypeScript 4.8+
477
677
  - Node.js 16+
478
678
  - Browsers: Chrome 90+, Firefox 88+, Safari 14+, Edge 90+
@@ -529,11 +729,21 @@ describe('ng-hub-ui-utils', () => {
529
729
  });
530
730
  ```
531
731
 
732
+ ## 📋 Changelog
733
+
734
+ All notable changes are documented in the [CHANGELOG.md](./CHANGELOG.md), following [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
735
+
736
+ Recent highlights:
737
+
738
+ - **1.2.1** — Renamed internal i18n files and refreshed `TranslatePipe`; added a test suite for `HubTranslationService`.
739
+ - **1.2.0** — Added the i18n system (`HubTranslationService`, `provideHubTranslation`, `TranslatePipe`, translation tokens) plus the `equals`, `interpolateString` and `getValue` utilities.
740
+
532
741
  ## 🐛 Issues and Support
533
742
 
534
743
  - [Report a bug](https://github.com/carlos-morcillo/ng-hub-ui-utils/issues)
535
744
  - [Request a feature](https://github.com/carlos-morcillo/ng-hub-ui-utils/issues/new?template=feature_request.md)
536
- - [Discussions](https://github.com/carlos-morcillo/ng-hub-ui-utils/discussions)
745
+ - [Repository](https://github.com/carlos-morcillo/ng-hub-ui-utils)
746
+ - **Author**: [Carlos Morcillo](https://www.carlosmorcillo.com)
537
747
 
538
748
  ## ☕ Support the Project
539
749
 
@@ -563,7 +773,7 @@ Check our [contribution guidelines](CONTRIBUTING.md) for more details.
563
773
 
564
774
  ## 📄 License
565
775
 
566
- MIT © [Hub UI Team](https://github.com/carlos-morcillo)
776
+ MIT © Hub UI contributors
567
777
 
568
778
  ```
569
779
  MIT License
@@ -593,4 +803,4 @@ SOFTWARE.
593
803
 
594
804
  ⭐ **If you like this project, don't forget to give it a star on GitHub!**
595
805
 
596
- [![GitHub stars](https://img.shields.io/github/stars/carlos-morcillo/ng-hub-ui-utils.svg?style=social&label=Star)](https://github.com/carlos-morcillo/ng-hub-ui-utils)
806
+ [![GitHub stars](https://img.shields.io/github/stars/carlos-morcillo/ng-hub-ui.svg?style=social&label=Star)](https://github.com/carlos-morcillo/ng-hub-ui)