@cngx/common 0.1.0-rc.3 → 0.1.0-rc.5
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/audio/README.md +180 -0
- package/display/README.md +1 -0
- package/fesm2022/cngx-common-a11y.mjs +123 -3
- package/fesm2022/cngx-common-a11y.mjs.map +1 -1
- package/fesm2022/cngx-common-audio.mjs +1205 -0
- package/fesm2022/cngx-common-audio.mjs.map +1 -0
- package/fesm2022/cngx-common-card.mjs +8 -8
- package/fesm2022/cngx-common-card.mjs.map +1 -1
- package/fesm2022/cngx-common-chart.mjs +2 -2
- package/fesm2022/cngx-common-chart.mjs.map +1 -1
- package/fesm2022/cngx-common-data.mjs +996 -55
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-display.mjs +320 -8
- package/fesm2022/cngx-common-display.mjs.map +1 -1
- package/fesm2022/cngx-common-interactive.mjs +1633 -80
- package/fesm2022/cngx-common-interactive.mjs.map +1 -1
- package/fesm2022/cngx-common-layout.mjs +187 -3
- package/fesm2022/cngx-common-layout.mjs.map +1 -1
- package/fesm2022/cngx-common-popover.mjs +63 -8
- package/fesm2022/cngx-common-popover.mjs.map +1 -1
- package/fesm2022/cngx-common.mjs +1 -1
- package/interactive/README.md +101 -0
- package/layout/README.md +39 -1
- package/package.json +5 -1
- package/theming/components/cngx-accordion.css +147 -0
- package/theming/components/cngx-badge.css +6 -0
- package/theming/components/cngx-bottom-sheet.css +8 -1
- package/theming/components/cngx-breadcrumb.css +108 -0
- package/theming/components/cngx-button-toggle.css +6 -0
- package/theming/components/cngx-data-grid.css +154 -0
- package/theming/components/cngx-dialog.css +4 -0
- package/theming/components/cngx-divider.css +4 -0
- package/theming/components/cngx-listbox.css +6 -0
- package/theming/components/cngx-menu.css +7 -0
- package/theming/components/cngx-slider.css +237 -0
- package/theming/components/cngx-tooltip.css +6 -0
- package/types/cngx-common-a11y.d.ts +67 -2
- package/types/cngx-common-audio.d.ts +736 -0
- package/types/cngx-common-data.d.ts +632 -22
- package/types/cngx-common-display.d.ts +189 -1
- package/types/cngx-common-interactive.d.ts +1028 -31
- package/types/cngx-common-layout.d.ts +88 -3
- package/types/cngx-common-popover.d.ts +25 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { input, signal, computed, output, Directive, inject, TemplateRef, model, contentChild,
|
|
2
|
+
import { input, signal, afterNextRender, computed, output, Directive, inject, TemplateRef, model, contentChild, DestroyRef, ChangeDetectionStrategy, Component, effect, untracked, InjectionToken, Injector, Injectable, makeEnvironmentProviders, ViewContainerRef, LOCALE_ID, ViewEncapsulation, ElementRef, isDevMode, isSignal, runInInjectionContext } from '@angular/core';
|
|
3
3
|
import { NgTemplateOutlet, DOCUMENT } from '@angular/common';
|
|
4
4
|
import { CngxChip } from '@cngx/common/display';
|
|
5
5
|
import { CngxMultiChipGroup, CngxChipInGroup, CngxSearch } from '@cngx/common/interactive';
|
|
@@ -7,8 +7,9 @@ import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
|
|
|
7
7
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
8
8
|
import { DataSource } from '@angular/cdk/collections';
|
|
9
9
|
import { arrayEqual } from '@cngx/utils';
|
|
10
|
-
import { buildAsyncStateView, createTransitionTracker } from '@cngx/core/utils';
|
|
11
|
-
import { isObservable, firstValueFrom, defer, tap, filter, map } from 'rxjs';
|
|
10
|
+
import { buildAsyncStateView, nextUid, createTransitionTracker } from '@cngx/core/utils';
|
|
11
|
+
import { isObservable, firstValueFrom, defer, tap, filter, map, finalize } from 'rxjs';
|
|
12
|
+
import { HttpContextToken, HttpContext, HttpEventType, provideHttpClient, withInterceptors } from '@angular/common/http';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Atom directive that tracks sort state (active field + direction).
|
|
@@ -18,6 +19,11 @@ import { isObservable, firstValueFrom, defer, tap, filter, map } from 'rxjs';
|
|
|
18
19
|
* precedence over the internal state - pair with `sortChange` to keep them
|
|
19
20
|
* in sync.
|
|
20
21
|
*
|
|
22
|
+
* An uncontrolled sort may declare a **starting** column + direction via
|
|
23
|
+
* `[cngxSortInitial]`: it seeds the internal state exactly once on init, then
|
|
24
|
+
* user clicks take over. Distinct from the controlled `cngxSortActive` /
|
|
25
|
+
* `cngxSortDirection` pins - the seed is skipped when a controlled pin is bound.
|
|
26
|
+
*
|
|
21
27
|
* When `multiSort` is `true`, holding **Shift** while clicking a sort header
|
|
22
28
|
* adds it as a secondary (tertiary, …) sort key instead of replacing the
|
|
23
29
|
* primary one. Shift-clicking an active column cycles it asc → desc → removed.
|
|
@@ -36,9 +42,6 @@ import { isObservable, firstValueFrom, defer, tap, filter, map } from 'rxjs';
|
|
|
36
42
|
* <example-url>http://localhost:4200/#/common/data/sort/multi-sort</example-url>
|
|
37
43
|
* <example-url>http://localhost:4200/#/common/data/sort/controlled</example-url>
|
|
38
44
|
* <example-url>http://localhost:4200/#/common/data/sort/aria-and-keyboard</example-url>
|
|
39
|
-
// * <example-url>http://localhost:4200/#/common/data/smart-data-source/auto-wired</example-url>
|
|
40
|
-
// * <example-url>http://localhost:4200/#/common/data/smart-data-source/how-it-works-hostdirectives-inject</example-url>
|
|
41
|
-
// * <example-url>http://localhost:4200/#/common/data/smart-data-source/smartdatasource-cngxpaginate-hostdirective</example-url>
|
|
42
45
|
*/
|
|
43
46
|
class CngxSort {
|
|
44
47
|
/** Controlled active column. When bound, takes precedence over internal state (single-sort only). */
|
|
@@ -50,7 +53,25 @@ class CngxSort {
|
|
|
50
53
|
* replacing the current sort.
|
|
51
54
|
*/
|
|
52
55
|
multiSort = input(false, ...(ngDevMode ? [{ debugName: "multiSort" }] : /* istanbul ignore next */ []));
|
|
56
|
+
/**
|
|
57
|
+
* Uncontrolled starting sort. Seeds the internal state once on init if no sort
|
|
58
|
+
* is set yet and no controlled `cngxSortActive` pin is bound; user clicks own
|
|
59
|
+
* it thereafter. Ignored in controlled mode.
|
|
60
|
+
*/
|
|
61
|
+
initialSort = input(undefined, { ...(ngDevMode ? { debugName: "initialSort" } : /* istanbul ignore next */ {}), alias: 'cngxSortInitial' });
|
|
53
62
|
sortsState = signal([], ...(ngDevMode ? [{ debugName: "sortsState" }] : /* istanbul ignore next */ []));
|
|
63
|
+
constructor() {
|
|
64
|
+
// One-shot uncontrolled seed: not a reactive derivation, so afterNextRender
|
|
65
|
+
// (single-shot, outside the signal graph) rather than an effect. The empty +
|
|
66
|
+
// no-controlled-pin guards keep it from clobbering an early click or writing
|
|
67
|
+
// an invisible state that would surface when a controlled pin unbinds.
|
|
68
|
+
afterNextRender(() => {
|
|
69
|
+
const seed = this.initialSort();
|
|
70
|
+
if (seed && this.sortsState().length === 0 && this.activeInput() === undefined) {
|
|
71
|
+
this.sortsState.set([seed]);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
54
75
|
/** The active sort column of the primary entry (controlled takes precedence in single-sort mode). */
|
|
55
76
|
active = computed(() => this.activeInput() ?? this.sortsState()[0]?.active, ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
|
|
56
77
|
/** The active sort direction of the primary entry (controlled takes precedence in single-sort mode). */
|
|
@@ -78,7 +99,7 @@ class CngxSort {
|
|
|
78
99
|
* Sets or toggles the sort for `field`.
|
|
79
100
|
*
|
|
80
101
|
* **`additive = false`** (default, plain click):
|
|
81
|
-
* - Same field →
|
|
102
|
+
* - Same field → cycle `asc` → `desc` → cleared (a third click removes the sort)
|
|
82
103
|
* - Different field → replace stack with `{ field, asc }`
|
|
83
104
|
*
|
|
84
105
|
* **`additive = true`** (Shift+click when `multiSort` is enabled on the header):
|
|
@@ -106,11 +127,19 @@ class CngxSort {
|
|
|
106
127
|
}
|
|
107
128
|
else {
|
|
108
129
|
const current = this.sortsState();
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
130
|
+
if (field === current[0]?.active && current[0].direction === 'desc') {
|
|
131
|
+
// Third click on the active column: cycle desc -> cleared.
|
|
132
|
+
this.sortsState.set([]);
|
|
133
|
+
this.sortChange.emit(undefined);
|
|
134
|
+
this.sortsChange.emit([]);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
const dir = field === current[0]?.active ? 'desc' : 'asc';
|
|
138
|
+
const entry = { active: field, direction: dir };
|
|
139
|
+
this.sortsState.set([entry]);
|
|
140
|
+
this.sortChange.emit(entry);
|
|
141
|
+
this.sortsChange.emit([entry]);
|
|
142
|
+
}
|
|
114
143
|
}
|
|
115
144
|
}
|
|
116
145
|
/** Clears all active sorts. Emits both `sortChange(undefined)` and `sortsChange([])`. */
|
|
@@ -120,7 +149,7 @@ class CngxSort {
|
|
|
120
149
|
this.sortsChange.emit([]);
|
|
121
150
|
}
|
|
122
151
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSort, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
123
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxSort, isStandalone: true, selector: "[cngxSort]", inputs: { activeInput: { classPropertyName: "activeInput", publicName: "cngxSortActive", isSignal: true, isRequired: false, transformFunction: null }, directionInput: { classPropertyName: "directionInput", publicName: "cngxSortDirection", isSignal: true, isRequired: false, transformFunction: null }, multiSort: { classPropertyName: "multiSort", publicName: "multiSort", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { sortChange: "sortChange", sortsChange: "sortsChange" }, exportAs: ["cngxSort"], ngImport: i0 });
|
|
152
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxSort, isStandalone: true, selector: "[cngxSort]", inputs: { activeInput: { classPropertyName: "activeInput", publicName: "cngxSortActive", isSignal: true, isRequired: false, transformFunction: null }, directionInput: { classPropertyName: "directionInput", publicName: "cngxSortDirection", isSignal: true, isRequired: false, transformFunction: null }, multiSort: { classPropertyName: "multiSort", publicName: "multiSort", isSignal: true, isRequired: false, transformFunction: null }, initialSort: { classPropertyName: "initialSort", publicName: "cngxSortInitial", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { sortChange: "sortChange", sortsChange: "sortsChange" }, exportAs: ["cngxSort"], ngImport: i0 });
|
|
124
153
|
}
|
|
125
154
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSort, decorators: [{
|
|
126
155
|
type: Directive,
|
|
@@ -129,7 +158,44 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
129
158
|
exportAs: 'cngxSort',
|
|
130
159
|
standalone: true,
|
|
131
160
|
}]
|
|
132
|
-
}], propDecorators: { activeInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxSortActive", required: false }] }], directionInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxSortDirection", required: false }] }], multiSort: [{ type: i0.Input, args: [{ isSignal: true, alias: "multiSort", required: false }] }], sortChange: [{ type: i0.Output, args: ["sortChange"] }], sortsChange: [{ type: i0.Output, args: ["sortsChange"] }] } });
|
|
161
|
+
}], ctorParameters: () => [], propDecorators: { activeInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxSortActive", required: false }] }], directionInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxSortDirection", required: false }] }], multiSort: [{ type: i0.Input, args: [{ isSignal: true, alias: "multiSort", required: false }] }], initialSort: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxSortInitial", required: false }] }], sortChange: [{ type: i0.Output, args: ["sortChange"] }], sortsChange: [{ type: i0.Output, args: ["sortsChange"] }] } });
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Derives the shared sort-header state for one column from a {@link CngxSort} getter.
|
|
165
|
+
*
|
|
166
|
+
* Both {@link CngxSortHeader} (table context, `aria-sort`) and `CngxDgaSortHeader`
|
|
167
|
+
* (disclosure context, `role="button"` + `aria-describedby`) compose this factory
|
|
168
|
+
* and keep only their own a11y presentation. The factory is a11y-agnostic - it
|
|
169
|
+
* returns the plain derived signals each header maps to its own DOM/ARIA surface.
|
|
170
|
+
*
|
|
171
|
+
* @param sort Getter for the owning `CngxSort` engine (`() => sortRef`, `() => grid.sort`).
|
|
172
|
+
* @param field Getter for the column's field key.
|
|
173
|
+
* @returns The derived `{ entry, isActive, isAsc, isDesc, priority, toggle }` bundle.
|
|
174
|
+
*
|
|
175
|
+
* @category common/data/sort
|
|
176
|
+
* @since 0.1.0
|
|
177
|
+
* @relatedTo CngxSort, CngxSortHeader
|
|
178
|
+
*/
|
|
179
|
+
function createSortHeaderState(sort, field) {
|
|
180
|
+
const entry = computed(() => sort().sorts().find((s) => s.active === field()), ...(ngDevMode ? [{ debugName: "entry" }] : /* istanbul ignore next */ []));
|
|
181
|
+
const isActive = computed(() => entry() !== undefined, ...(ngDevMode ? [{ debugName: "isActive" }] : /* istanbul ignore next */ []));
|
|
182
|
+
const isAsc = computed(() => entry()?.direction === 'asc', ...(ngDevMode ? [{ debugName: "isAsc" }] : /* istanbul ignore next */ []));
|
|
183
|
+
const isDesc = computed(() => entry()?.direction === 'desc', ...(ngDevMode ? [{ debugName: "isDesc" }] : /* istanbul ignore next */ []));
|
|
184
|
+
const priority = computed(() => {
|
|
185
|
+
const idx = sort().sorts().findIndex((s) => s.active === field());
|
|
186
|
+
return idx === -1 ? 0 : idx + 1;
|
|
187
|
+
}, ...(ngDevMode ? [{ debugName: "priority" }] : /* istanbul ignore next */ []));
|
|
188
|
+
return {
|
|
189
|
+
entry,
|
|
190
|
+
isActive,
|
|
191
|
+
isAsc,
|
|
192
|
+
isDesc,
|
|
193
|
+
priority,
|
|
194
|
+
toggle(additive = false) {
|
|
195
|
+
sort().setSort(field(), additive && sort().multiSort());
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
133
199
|
|
|
134
200
|
/**
|
|
135
201
|
* Molecule directive for sort-header elements.
|
|
@@ -170,36 +236,28 @@ class CngxSortHeader {
|
|
|
170
236
|
field = input.required({ ...(ngDevMode ? { debugName: "field" } : /* istanbul ignore next */ {}), alias: 'cngxSortHeader' });
|
|
171
237
|
/** Explicit reference to the owning `CngxSort`. */
|
|
172
238
|
cngxSortRef = input.required(...(ngDevMode ? [{ debugName: "cngxSortRef" }] : /* istanbul ignore next */ []));
|
|
173
|
-
|
|
174
|
-
.sorts()
|
|
175
|
-
.find((s) => s.active === this.field()), ...(ngDevMode ? [{ debugName: "entry" }] : /* istanbul ignore next */ []));
|
|
239
|
+
state = createSortHeaderState(this.cngxSortRef, this.field);
|
|
176
240
|
/** `true` when this column is part of the active sort (primary or secondary). */
|
|
177
|
-
isActive =
|
|
241
|
+
isActive = this.state.isActive;
|
|
178
242
|
/** `true` when this column is active and sorted ascending. */
|
|
179
|
-
isAsc =
|
|
243
|
+
isAsc = this.state.isAsc;
|
|
180
244
|
/** `true` when this column is active and sorted descending. */
|
|
181
|
-
isDesc =
|
|
245
|
+
isDesc = this.state.isDesc;
|
|
182
246
|
/**
|
|
183
247
|
* 1-based position of this column in the sort stack.
|
|
184
248
|
* Returns `0` when the column is not part of the active sort.
|
|
185
249
|
* Only meaningful when `multiSort` is enabled on the owning `CngxSort`.
|
|
186
250
|
*/
|
|
187
|
-
priority =
|
|
188
|
-
const idx = this.cngxSortRef()
|
|
189
|
-
.sorts()
|
|
190
|
-
.findIndex((s) => s.active === this.field());
|
|
191
|
-
return idx === -1 ? 0 : idx + 1;
|
|
192
|
-
}, ...(ngDevMode ? [{ debugName: "priority" }] : /* istanbul ignore next */ []));
|
|
251
|
+
priority = this.state.priority;
|
|
193
252
|
/** The `aria-sort` attribute value for the host element. */
|
|
194
253
|
ariaSort = computed(() => {
|
|
195
|
-
if (!this.isActive()) {
|
|
254
|
+
if (!this.state.isActive()) {
|
|
196
255
|
return null;
|
|
197
256
|
}
|
|
198
|
-
return this.isAsc() ? 'ascending' : 'descending';
|
|
257
|
+
return this.state.isAsc() ? 'ascending' : 'descending';
|
|
199
258
|
}, ...(ngDevMode ? [{ debugName: "ariaSort" }] : /* istanbul ignore next */ []));
|
|
200
259
|
handleSort(event) {
|
|
201
|
-
|
|
202
|
-
this.cngxSortRef().setSort(this.field(), additive);
|
|
260
|
+
this.state.toggle(event?.shiftKey ?? false);
|
|
203
261
|
}
|
|
204
262
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSortHeader, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
205
263
|
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxSortHeader, isStandalone: true, selector: "[cngxSortHeader]", inputs: { field: { classPropertyName: "field", publicName: "cngxSortHeader", isSignal: true, isRequired: true, transformFunction: null }, cngxSortRef: { classPropertyName: "cngxSortRef", publicName: "cngxSortRef", isSignal: true, isRequired: true, transformFunction: null } }, host: { listeners: { "click": "handleSort($event)" }, properties: { "attr.aria-sort": "ariaSort()", "class.cngx-sort-header--active": "isActive()", "class.cngx-sort-header--asc": "isAsc()", "class.cngx-sort-header--desc": "isDesc()" } }, exportAs: ["cngxSortHeader"], ngImport: i0 });
|
|
@@ -603,14 +661,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
603
661
|
/**
|
|
604
662
|
* Atom directive that tracks pagination state (current page index and page size).
|
|
605
663
|
*
|
|
606
|
-
* Supports both **uncontrolled** (internal state) and **controlled** modes.
|
|
664
|
+
* Supports both **uncontrolled** (internal state) and **controlled** modes. \
|
|
607
665
|
* In controlled mode the `cngxPageIndex` / `cngxPageSize` inputs take precedence
|
|
608
|
-
* over internal state - pair with
|
|
666
|
+
* over internal state - pair with \
|
|
667
|
+
* `pageChange` / `pageSizeChange` to keep them
|
|
609
668
|
* in sync.
|
|
610
669
|
*
|
|
611
670
|
* Consumer connects this to a list or table via `range()` - nothing is injected
|
|
612
671
|
* automatically.
|
|
613
672
|
*
|
|
673
|
+
* ```
|
|
614
674
|
* // Headless: read range() from a template ref
|
|
615
675
|
* <div cngxPaginate #pg="cngxPaginate" [total]="items.length">
|
|
616
676
|
* @for (item of items.slice(pg.range()[0], pg.range()[1]); track item.id) { ... }
|
|
@@ -620,7 +680,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
620
680
|
* <mat-paginator
|
|
621
681
|
* [length]="pg.total()" [pageIndex]="pg.pageIndex()" [pageSize]="pg.pageSize()"
|
|
622
682
|
* (page)="pg.setPageSize($event.pageSize, false); pg.setPage($event.pageIndex)" />
|
|
623
|
-
*
|
|
683
|
+
* ```
|
|
624
684
|
* @category common/data/paginate
|
|
625
685
|
* @docsKind primary
|
|
626
686
|
* @wcag AA
|
|
@@ -629,8 +689,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
629
689
|
* @relatedTo CngxSort, CngxFilter, CngxSmartDataSource
|
|
630
690
|
*
|
|
631
691
|
* <example-url>http://localhost:4200/#/common/data/data-source/datasource-cngxpaginate-manual-pipeline</example-url>
|
|
632
|
-
* <example-url>http://localhost:4200/#/common/data/paginate-list/bridge-announce-page-changes</example-url>
|
|
633
|
-
* <example-url>http://localhost:4200/#/common/data/paginate-list/instrumentation-bridge-cngxmatpaginator</example-url>
|
|
634
692
|
* <example-url>http://localhost:4200/#/common/data/paginate-list/paginated-list-cngxpaginate-cngxmatpaginator</example-url>
|
|
635
693
|
* <example-url>http://localhost:4200/#/common/data/paginate-list/uncontrolled-mode-zero-class-boilerplate</example-url>
|
|
636
694
|
* <example-url>http://localhost:4200/#/common/data/smart-data-source/smartdatasource-cngxpaginate-hostdirective</example-url>
|
|
@@ -776,8 +834,8 @@ function connectPaginateResetOn(paginate, key) {
|
|
|
776
834
|
}
|
|
777
835
|
/**
|
|
778
836
|
* Resets a `cngxPaginate` host to the first page whenever the bound key
|
|
779
|
-
* changes - the composable form of {@link connectPaginateResetOn}.
|
|
780
|
-
* the same element as `cngxPaginate` (or a `CngxPaginator` / `CngxMatPaginator`,
|
|
837
|
+
* changes - the composable form of {@link connectPaginateResetOn}. \
|
|
838
|
+
* Drop it on the same element as `cngxPaginate` (or a `CngxPaginator` / `CngxMatPaginator`,
|
|
781
839
|
* which provide the brain), and bind the sort / filter / search value a result
|
|
782
840
|
* set depends on, so a narrowed result never strands the user on a now-empty
|
|
783
841
|
* page.
|
|
@@ -788,9 +846,11 @@ function connectPaginateResetOn(paginate, key) {
|
|
|
788
846
|
* ```html
|
|
789
847
|
* <table cngxPaginate [cngxPaginateResetOn]="filter()"><!-- ... --></table>
|
|
790
848
|
* ```
|
|
849
|
+
* <example-url>http://localhost:4200/#/ui/paginator/paginator-behaviors/reset-on-filter</example-url>
|
|
791
850
|
*
|
|
792
851
|
* @category common/data/paginate
|
|
793
852
|
* @docsKind primary
|
|
853
|
+
* @wcag AA
|
|
794
854
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/paginate/paginate-reset.directive.ts
|
|
795
855
|
* @since 0.1.0
|
|
796
856
|
* @relatedTo CngxPaginate, CngxPaginator, CngxMatPaginator
|
|
@@ -814,6 +874,74 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
814
874
|
}]
|
|
815
875
|
}], ctorParameters: () => [], propDecorators: { key: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPaginateResetOn", required: false }] }] } });
|
|
816
876
|
|
|
877
|
+
/**
|
|
878
|
+
* Wires the {@link CngxPaginate} brain's page / page-size changes onto a host's
|
|
879
|
+
* two-way outputs with exactly-once emit semantics. Two paths feed each handler,
|
|
880
|
+
* sharing a last-emitted guard:
|
|
881
|
+
* - a subscription forwards the brain's nav-only `pageChange` / `pageSizeChange`
|
|
882
|
+
* - the only signal that captures a controlled-mode `setPage`, because the
|
|
883
|
+
* brain's `pageIndex()` stays pinned to the input until the consumer feeds it
|
|
884
|
+
* back;
|
|
885
|
+
* - an `effect()` reads the effective `pageIndex()` / `pageSize()` and covers a
|
|
886
|
+
* `total`-shrink clamp the nav-only output misses.
|
|
887
|
+
*
|
|
888
|
+
* The shared guard makes a value one path already emitted a no-op on the other,
|
|
889
|
+
* so each change emits exactly once. Seeded with the current effective values,
|
|
890
|
+
* so wiring emits no initial change.
|
|
891
|
+
*
|
|
892
|
+
* Shared verbatim by the `CngxPaginator` shell and the `CngxIncrementalList`
|
|
893
|
+
* organism, so the two-way emit behaviour is byte-identical. Call inside an
|
|
894
|
+
* injection context (constructor or field initialiser) - it reads `DestroyRef`
|
|
895
|
+
* and creates effects.
|
|
896
|
+
*
|
|
897
|
+
* @category common/data/paginate
|
|
898
|
+
* @since 0.1.0
|
|
899
|
+
*/
|
|
900
|
+
function connectPaginateEmit(paginate, handlers) {
|
|
901
|
+
const destroyRef = inject(DestroyRef);
|
|
902
|
+
// Shared last-emitted guards across the nav (subscription) and clamp (effect)
|
|
903
|
+
// paths. Plain locals, so the effects carry no signal write. Seeded with the
|
|
904
|
+
// current effective values so wiring emits no initial change.
|
|
905
|
+
let lastIndex = paginate.pageIndex();
|
|
906
|
+
let lastSize = paginate.pageSize();
|
|
907
|
+
// Nav path. Forwards the brain's nav-only outputs: in controlled mode a
|
|
908
|
+
// setPage leaves the effective pageIndex() pinned to the input, so this event
|
|
909
|
+
// is the only thing that reports the navigation.
|
|
910
|
+
const indexSub = paginate.pageChange.subscribe((index) => {
|
|
911
|
+
if (index !== lastIndex) {
|
|
912
|
+
lastIndex = index;
|
|
913
|
+
handlers.onIndex(index);
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
const sizeSub = paginate.pageSizeChange.subscribe((size) => {
|
|
917
|
+
if (size !== lastSize) {
|
|
918
|
+
lastSize = size;
|
|
919
|
+
handlers.onSize(size);
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
destroyRef.onDestroy(() => {
|
|
923
|
+
indexSub.unsubscribe();
|
|
924
|
+
sizeSub.unsubscribe();
|
|
925
|
+
});
|
|
926
|
+
// Clamp path. The effective pageIndex moved without a nav (a total-shrink
|
|
927
|
+
// clamp the nav-only pageChange misses). The shared guard means a value the
|
|
928
|
+
// nav path already emitted is a no-op here, so each change emits once.
|
|
929
|
+
effect(() => {
|
|
930
|
+
const index = paginate.pageIndex();
|
|
931
|
+
if (index !== lastIndex) {
|
|
932
|
+
lastIndex = index;
|
|
933
|
+
handlers.onIndex(index);
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
effect(() => {
|
|
937
|
+
const size = paginate.pageSize();
|
|
938
|
+
if (size !== lastSize) {
|
|
939
|
+
lastSize = size;
|
|
940
|
+
handlers.onSize(size);
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
|
|
817
945
|
/**
|
|
818
946
|
* Persists a `cngxPaginate` host's page / size in the URL query string, so a
|
|
819
947
|
* paginated view is deep-linkable and survives reload / back / forward.
|
|
@@ -827,7 +955,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
827
955
|
* ```
|
|
828
956
|
*
|
|
829
957
|
* Two paginators on one route must take distinct param names via
|
|
830
|
-
* `[cngxPaginatePageParam]` / `[cngxPaginateSizeParam]` to avoid a collision.
|
|
958
|
+
* `[cngxPaginatePageParam]` / `[cngxPaginateSizeParam]` to avoid a collision. \
|
|
831
959
|
* Requires `@angular/router` (`provideRouter`); without it the directive is an
|
|
832
960
|
* inert no-op (a dev-mode warning is logged). Framework-agnostic of any UI - it
|
|
833
961
|
* needs only the brain and the router.
|
|
@@ -1401,6 +1529,141 @@ function createAsyncState() {
|
|
|
1401
1529
|
};
|
|
1402
1530
|
}
|
|
1403
1531
|
|
|
1532
|
+
/** @internal Length-then-key-set equality for the operations Map signal. */
|
|
1533
|
+
function mapKeySetEqual(a, b) {
|
|
1534
|
+
if (a === b) {
|
|
1535
|
+
return true;
|
|
1536
|
+
}
|
|
1537
|
+
if (a.size !== b.size) {
|
|
1538
|
+
return false;
|
|
1539
|
+
}
|
|
1540
|
+
for (const key of a.keys()) {
|
|
1541
|
+
if (!b.has(key)) {
|
|
1542
|
+
return false;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
return true;
|
|
1546
|
+
}
|
|
1547
|
+
/** @internal Element-wise equality on (id, label, status) for the view array. */
|
|
1548
|
+
function operationsEqual(a, b) {
|
|
1549
|
+
if (a === b) {
|
|
1550
|
+
return true;
|
|
1551
|
+
}
|
|
1552
|
+
if (a.length !== b.length) {
|
|
1553
|
+
return false;
|
|
1554
|
+
}
|
|
1555
|
+
for (let i = 0; i < a.length; i++) {
|
|
1556
|
+
const x = a[i];
|
|
1557
|
+
const y = b[i];
|
|
1558
|
+
if (x.id !== y.id || x.label !== y.label || x.status !== y.status) {
|
|
1559
|
+
return false;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
return true;
|
|
1563
|
+
}
|
|
1564
|
+
/**
|
|
1565
|
+
* Opt-in aggregation registry for in-flight async operations.
|
|
1566
|
+
*
|
|
1567
|
+
* A single derived source for "is anything loading?" across a whole app: the
|
|
1568
|
+
* shell binds one `isAnythingLoading()` instead of N hand-maintained flags.
|
|
1569
|
+
* Producers register their `CngxAsyncState` (via `injectAsyncState({ register:
|
|
1570
|
+
* true })`, the HTTP interceptor, or directly) and unregister on teardown.
|
|
1571
|
+
*
|
|
1572
|
+
* Not `providedIn: 'root'` - consumers opt in with {@link provideAsyncRegistry}.
|
|
1573
|
+
* When the registry is absent, producers skip registration entirely.
|
|
1574
|
+
*
|
|
1575
|
+
* **Keyed by a per-operation uid, not the human label.** Async operations are
|
|
1576
|
+
* transient and collide on label; uid identity keeps N concurrent same-label
|
|
1577
|
+
* (or unlabeled) operations independent, so one `unregister` evicts exactly
|
|
1578
|
+
* its own entry. This is the one deliberate divergence from `CngxErrorRegistry`
|
|
1579
|
+
* (which keys by a stable scope name).
|
|
1580
|
+
*
|
|
1581
|
+
* Both views are `computed()` only - no `effect`, no service calls. Inner
|
|
1582
|
+
* status reactivity flows through each entry's `CngxAsyncState` signals; the
|
|
1583
|
+
* Map signal's `mapKeySetEqual` short-circuits register/unregister churn
|
|
1584
|
+
* without hiding status changes.
|
|
1585
|
+
*
|
|
1586
|
+
* @category common/data/async-registry
|
|
1587
|
+
*/
|
|
1588
|
+
class CngxAsyncRegistry {
|
|
1589
|
+
entriesState = signal(new Map(), { ...(ngDevMode ? { debugName: "entriesState" } : /* istanbul ignore next */ {}), equal: mapKeySetEqual });
|
|
1590
|
+
/**
|
|
1591
|
+
* `true` when at least one registered operation reports `isLoading()`
|
|
1592
|
+
* (`loading`, `pending`, or `refreshing`).
|
|
1593
|
+
*/
|
|
1594
|
+
isAnythingLoading = computed(() => {
|
|
1595
|
+
for (const entry of this.entriesState().values()) {
|
|
1596
|
+
if (entry.state.isLoading()) {
|
|
1597
|
+
return true;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
return false;
|
|
1601
|
+
}, ...(ngDevMode ? [{ debugName: "isAnythingLoading" }] : /* istanbul ignore next */ []));
|
|
1602
|
+
/** Every registered operation with its current status, in registration order. */
|
|
1603
|
+
activeOperations = computed(() => Array.from(this.entriesState(), ([id, entry]) => ({
|
|
1604
|
+
id,
|
|
1605
|
+
label: entry.label,
|
|
1606
|
+
status: entry.state.status(),
|
|
1607
|
+
})), { ...(ngDevMode ? { debugName: "activeOperations" } : /* istanbul ignore next */ {}), equal: operationsEqual });
|
|
1608
|
+
/**
|
|
1609
|
+
* Registers an async state under a fresh per-operation uid and returns it.
|
|
1610
|
+
* The optional `label` is display metadata only - never the map key, so
|
|
1611
|
+
* concurrent same-label (or unlabeled) operations stay independent.
|
|
1612
|
+
*/
|
|
1613
|
+
register(state, label) {
|
|
1614
|
+
const id = nextUid('cngx-async-op');
|
|
1615
|
+
const next = new Map(this.entriesState());
|
|
1616
|
+
next.set(id, { label, state });
|
|
1617
|
+
this.entriesState.set(next);
|
|
1618
|
+
return id;
|
|
1619
|
+
}
|
|
1620
|
+
/** Removes the operation with the given uid. No-op if absent. */
|
|
1621
|
+
unregister(id) {
|
|
1622
|
+
const current = this.entriesState();
|
|
1623
|
+
if (!current.has(id)) {
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1626
|
+
const next = new Map(current);
|
|
1627
|
+
next.delete(id);
|
|
1628
|
+
this.entriesState.set(next);
|
|
1629
|
+
}
|
|
1630
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxAsyncRegistry, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1631
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxAsyncRegistry });
|
|
1632
|
+
}
|
|
1633
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxAsyncRegistry, decorators: [{
|
|
1634
|
+
type: Injectable
|
|
1635
|
+
}] });
|
|
1636
|
+
|
|
1637
|
+
/**
|
|
1638
|
+
* Provides {@link CngxAsyncRegistry} in the host environment.
|
|
1639
|
+
*
|
|
1640
|
+
* Opt-in - not `providedIn: 'root'`. Add it to `bootstrapApplication`
|
|
1641
|
+
* providers to enable app-wide async observability; producers that opt in
|
|
1642
|
+
* (`injectAsyncState({ register: true })`, `provideAsyncHttpObservability()`)
|
|
1643
|
+
* then surface in `isAnythingLoading()` / `activeOperations()`.
|
|
1644
|
+
*
|
|
1645
|
+
* ```ts
|
|
1646
|
+
* bootstrapApplication(AppComponent, {
|
|
1647
|
+
* providers: [provideAsyncRegistry()],
|
|
1648
|
+
* });
|
|
1649
|
+
* ```
|
|
1650
|
+
*
|
|
1651
|
+
* @category common/data/async-registry
|
|
1652
|
+
*/
|
|
1653
|
+
function provideAsyncRegistry() {
|
|
1654
|
+
return makeEnvironmentProviders([CngxAsyncRegistry]);
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* Returns the ambient {@link CngxAsyncRegistry}, or `null` when the consumer
|
|
1658
|
+
* did not opt in via {@link provideAsyncRegistry}. Must run in an injection
|
|
1659
|
+
* context.
|
|
1660
|
+
*
|
|
1661
|
+
* @category common/data/async-registry
|
|
1662
|
+
*/
|
|
1663
|
+
function injectAsyncRegistry() {
|
|
1664
|
+
return inject(CngxAsyncRegistry, { optional: true });
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1404
1667
|
/**
|
|
1405
1668
|
* Create a reactive async state that auto-loads when signal dependencies change.
|
|
1406
1669
|
*
|
|
@@ -1439,6 +1702,16 @@ function injectAsyncState(fn, options) {
|
|
|
1439
1702
|
debounceTimer = undefined;
|
|
1440
1703
|
}
|
|
1441
1704
|
});
|
|
1705
|
+
// Opt-in observability: register with the ambient CngxAsyncRegistry (if any)
|
|
1706
|
+
// under a fresh per-operation uid, and unregister on destroy. No-op when the
|
|
1707
|
+
// caller did not opt in, or when no registry is provided.
|
|
1708
|
+
if (options?.register) {
|
|
1709
|
+
const registry = injectAsyncRegistry();
|
|
1710
|
+
if (registry) {
|
|
1711
|
+
const operationId = registry.register(state, options.label);
|
|
1712
|
+
destroyRef.onDestroy(() => registry.unregister(operationId));
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1442
1715
|
function executeQuery(computation) {
|
|
1443
1716
|
cancelInFlight();
|
|
1444
1717
|
// first load -> loading, subsequent -> refreshing
|
|
@@ -1872,6 +2145,119 @@ function tapHttpAsyncState(state, options) {
|
|
|
1872
2145
|
});
|
|
1873
2146
|
}
|
|
1874
2147
|
|
|
2148
|
+
/**
|
|
2149
|
+
* Per-request label surfaced in `CngxAsyncRegistry.activeOperations` when the
|
|
2150
|
+
* request is tracked by `cngxAsyncInterceptor`. Display only, never a key.
|
|
2151
|
+
*
|
|
2152
|
+
* @category common/data/async-registry
|
|
2153
|
+
*/
|
|
2154
|
+
const CNGX_ASYNC_LABEL = new HttpContextToken(() => undefined);
|
|
2155
|
+
/**
|
|
2156
|
+
* Per-request opt-out. When `true`, `cngxAsyncInterceptor` passes the request
|
|
2157
|
+
* through without registering it - keeps polling / telemetry pings out of the
|
|
2158
|
+
* aggregate without a global allow-list.
|
|
2159
|
+
*
|
|
2160
|
+
* @category common/data/async-registry
|
|
2161
|
+
*/
|
|
2162
|
+
const CNGX_ASYNC_SKIP = new HttpContextToken(() => false);
|
|
2163
|
+
/**
|
|
2164
|
+
* Returns an `HttpContext` that labels the request for async observability.
|
|
2165
|
+
* Pass an existing context to chain with other tokens.
|
|
2166
|
+
*
|
|
2167
|
+
* ```typescript
|
|
2168
|
+
* this.http.get('/api/users', { context: withAsyncLabel('users') });
|
|
2169
|
+
* ```
|
|
2170
|
+
*
|
|
2171
|
+
* @category common/data/async-registry
|
|
2172
|
+
*/
|
|
2173
|
+
function withAsyncLabel(label, context = new HttpContext()) {
|
|
2174
|
+
return context.set(CNGX_ASYNC_LABEL, label);
|
|
2175
|
+
}
|
|
2176
|
+
/**
|
|
2177
|
+
* Returns an `HttpContext` that opts the request out of async observability.
|
|
2178
|
+
* Pass an existing context to chain with other tokens.
|
|
2179
|
+
*
|
|
2180
|
+
* ```typescript
|
|
2181
|
+
* this.http.get('/api/ping', { context: withAsyncSkip() });
|
|
2182
|
+
* ```
|
|
2183
|
+
*
|
|
2184
|
+
* @category common/data/async-registry
|
|
2185
|
+
*/
|
|
2186
|
+
function withAsyncSkip(context = new HttpContext()) {
|
|
2187
|
+
return context.set(CNGX_ASYNC_SKIP, true);
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
/**
|
|
2191
|
+
* Functional HTTP interceptor that surfaces every in-flight `HttpRequest` in
|
|
2192
|
+
* the ambient {@link CngxAsyncRegistry}, so `isAnythingLoading()` aggregates
|
|
2193
|
+
* raw HTTP traffic alongside explicit component states.
|
|
2194
|
+
*
|
|
2195
|
+
* Fully opt-in and self-contained:
|
|
2196
|
+
* - Resolves `inject(CngxAsyncRegistry, { optional: true })` and passes the
|
|
2197
|
+
* request straight through when no registry is provided - zero behaviour
|
|
2198
|
+
* change for consumers who do not opt in.
|
|
2199
|
+
* - Passes through without registering when `CNGX_ASYNC_SKIP` is set.
|
|
2200
|
+
* - Otherwise registers a fresh `createManualState` (set `loading`) under a
|
|
2201
|
+
* per-request uid, maps the final response / error onto it, and
|
|
2202
|
+
* `unregister`s in a `finalize` that fires on success **and** error (and on
|
|
2203
|
+
* unsubscribe), so a request can never pin the global loading state.
|
|
2204
|
+
*
|
|
2205
|
+
* Per-request uid identity (from `CngxAsyncRegistry`) means concurrent requests
|
|
2206
|
+
* sharing a label never evict one another - completing one leaves the other
|
|
2207
|
+
* tracked. The interceptor does not swallow errors: `setError` records the
|
|
2208
|
+
* failure, then the error propagates to the caller unchanged.
|
|
2209
|
+
*
|
|
2210
|
+
* @category common/data/async-registry
|
|
2211
|
+
*/
|
|
2212
|
+
const cngxAsyncInterceptor = (req, next) => {
|
|
2213
|
+
const registry = inject(CngxAsyncRegistry, { optional: true });
|
|
2214
|
+
if (!registry || req.context.get(CNGX_ASYNC_SKIP)) {
|
|
2215
|
+
return next(req);
|
|
2216
|
+
}
|
|
2217
|
+
const state = createManualState();
|
|
2218
|
+
state.set('loading');
|
|
2219
|
+
const operationId = registry.register(state, req.context.get(CNGX_ASYNC_LABEL));
|
|
2220
|
+
return next(req).pipe(tap({
|
|
2221
|
+
next: (event) => {
|
|
2222
|
+
if (event.type === HttpEventType.Response) {
|
|
2223
|
+
state.setSuccess(event.body);
|
|
2224
|
+
}
|
|
2225
|
+
},
|
|
2226
|
+
error: (err) => state.setError(err),
|
|
2227
|
+
}), finalize(() => registry.unregister(operationId)));
|
|
2228
|
+
};
|
|
2229
|
+
/**
|
|
2230
|
+
* Sets up `HttpClient` with {@link cngxAsyncInterceptor} so every request
|
|
2231
|
+
* surfaces in {@link CngxAsyncRegistry}. Opt-in - add it to
|
|
2232
|
+
* `bootstrapApplication` providers alongside `provideAsyncRegistry()`.
|
|
2233
|
+
*
|
|
2234
|
+
* ```ts
|
|
2235
|
+
* bootstrapApplication(AppComponent, {
|
|
2236
|
+
* providers: [
|
|
2237
|
+
* provideAsyncRegistry(),
|
|
2238
|
+
* provideAsyncHttpObservability(),
|
|
2239
|
+
* ],
|
|
2240
|
+
* });
|
|
2241
|
+
* ```
|
|
2242
|
+
*
|
|
2243
|
+
* **Use this only when cngx owns the `HttpClient` setup.** It calls
|
|
2244
|
+
* `provideHttpClient(withInterceptors([cngxAsyncInterceptor]))` internally, so
|
|
2245
|
+
* an app that already calls `provideHttpClient` (especially with `withFetch()`
|
|
2246
|
+
* or other features) would get a second, feature-less `HttpClient`
|
|
2247
|
+
* configuration - last-provider-wins on `HttpBackend` can silently revert
|
|
2248
|
+
* `withFetch()` to the XHR backend. In that case do not call this; add the
|
|
2249
|
+
* exported {@link cngxAsyncInterceptor} to your own `withInterceptors` instead:
|
|
2250
|
+
*
|
|
2251
|
+
* ```ts
|
|
2252
|
+
* provideHttpClient(withFetch(), withInterceptors([authInterceptor, cngxAsyncInterceptor]))
|
|
2253
|
+
* ```
|
|
2254
|
+
*
|
|
2255
|
+
* @category common/data/async-registry
|
|
2256
|
+
*/
|
|
2257
|
+
function provideAsyncHttpObservability() {
|
|
2258
|
+
return makeEnvironmentProviders([provideHttpClient(withInterceptors([cngxAsyncInterceptor]))]);
|
|
2259
|
+
}
|
|
2260
|
+
|
|
1875
2261
|
/**
|
|
1876
2262
|
* Structural directive for async state-driven content rendering.
|
|
1877
2263
|
*
|
|
@@ -2074,26 +2460,83 @@ class CngxMetric {
|
|
|
2074
2460
|
return u ? `${v} ${u}` : v;
|
|
2075
2461
|
}, ...(ngDevMode ? [{ debugName: "accessibleValue" }] : /* istanbul ignore next */ []));
|
|
2076
2462
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMetric, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2077
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxMetric, isStandalone: true, selector: "cngx-metric", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, unit: { classPropertyName: "unit", publicName: "unit", isSignal: true, isRequired: false, transformFunction: null }, format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.aria-label": "accessibleValue()" }, classAttribute: "cngx-metric" }, ngImport: i0, template: `
|
|
2463
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxMetric, isStandalone: true, selector: "cngx-metric", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, unit: { classPropertyName: "unit", publicName: "unit", isSignal: true, isRequired: false, transformFunction: null }, format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "img" }, properties: { "attr.aria-label": "accessibleValue()" }, classAttribute: "cngx-metric" }, ngImport: i0, template: `
|
|
2078
2464
|
<span class="cngx-metric__value">{{ formattedValue() }}</span>
|
|
2079
2465
|
@if (unit()) {
|
|
2080
2466
|
<span class="cngx-metric__unit">{{ unit() }}</span>
|
|
2081
2467
|
}
|
|
2082
|
-
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-metric-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-metric-value-size{syntax: \"*\"; inherits: true; initial-value: 1.75rem;}@property --cngx-metric-value-weight{syntax: \"<number>\"; inherits: true; initial-value: 600;}@property --cngx-metric-value-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.2 .01 290);}@property --cngx-metric-unit-size{syntax: \"*\"; inherits: true; initial-value: .875rem;}@property --cngx-metric-unit-weight{syntax: \"<number>\"; inherits: true; initial-value: 400;}@property --cngx-metric-unit-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}}[data-color-scheme=dark],.dark{--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}[data-color-scheme=light],.light{--cngx-metric-value-color: oklch(.2 .01 290);--cngx-metric-unit-color: oklch(.36 .02 290)}}@layer cngx.components{@scope(.cngx-metric){:scope{display:inline-flex;align-items:baseline;gap:var(--cngx-metric-gap, 2px)}.cngx-metric__value{font-size:var(--cngx-metric-value-size, 1.75rem);font-weight:var(--cngx-metric-value-weight, 600);color:var(--cngx-metric-value-color, var(--cngx-color-text, oklch(.2 .01 290)));line-height:1.2}.cngx-metric__unit{font-size:var(--cngx-metric-unit-size, .875rem);font-weight:var(--cngx-metric-unit-weight, 400);color:var(--cngx-metric-unit-color, oklch(.36 .02 290))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2468
|
+
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-metric-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-metric-value-size{syntax: \"*\"; inherits: true; initial-value: 1.75rem;}@property --cngx-metric-value-weight{syntax: \"<number>\"; inherits: true; initial-value: 600;}@property --cngx-metric-value-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.2 .01 290);}@property --cngx-metric-unit-size{syntax: \"*\"; inherits: true; initial-value: .875rem;}@property --cngx-metric-unit-weight{syntax: \"<number>\"; inherits: true; initial-value: 400;}@property --cngx-metric-unit-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}}[data-color-scheme=dark],.dark{--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}[data-color-scheme=light],.light{--cngx-metric-value-color: oklch(.2 .01 290);--cngx-metric-unit-color: oklch(.36 .02 290)}}@layer cngx.components{@scope(.cngx-metric){:scope{--cngx-metric-gap: var(--cngx-space-xs);display:inline-flex;align-items:baseline;gap:var(--cngx-metric-gap, 2px)}.cngx-metric__value{font-size:var(--cngx-metric-value-size, 1.75rem);font-weight:var(--cngx-metric-value-weight, 600);color:var(--cngx-metric-value-color, var(--cngx-color-text, oklch(.2 .01 290)));line-height:1.2}.cngx-metric__unit{font-size:var(--cngx-metric-unit-size, .875rem);font-weight:var(--cngx-metric-unit-weight, 400);color:var(--cngx-metric-unit-color, oklch(.36 .02 290))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2083
2469
|
}
|
|
2084
2470
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMetric, decorators: [{
|
|
2085
2471
|
type: Component,
|
|
2086
2472
|
args: [{ selector: 'cngx-metric', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
2087
2473
|
class: 'cngx-metric',
|
|
2474
|
+
// role=img makes the host a single labelled graphic so AT announces the
|
|
2475
|
+
// curated `aria-label` (value + unit) instead of the raw text on an
|
|
2476
|
+
// otherwise role=generic custom element, where aria-label is unreliably
|
|
2477
|
+
// exposed. Mirrors CngxDelta / CngxTrend.
|
|
2478
|
+
role: 'img',
|
|
2088
2479
|
'[attr.aria-label]': 'accessibleValue()',
|
|
2089
2480
|
}, template: `
|
|
2090
2481
|
<span class="cngx-metric__value">{{ formattedValue() }}</span>
|
|
2091
2482
|
@if (unit()) {
|
|
2092
2483
|
<span class="cngx-metric__unit">{{ unit() }}</span>
|
|
2093
2484
|
}
|
|
2094
|
-
`, styles: ["@layer cngx.tokens{@property --cngx-metric-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-metric-value-size{syntax: \"*\"; inherits: true; initial-value: 1.75rem;}@property --cngx-metric-value-weight{syntax: \"<number>\"; inherits: true; initial-value: 600;}@property --cngx-metric-value-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.2 .01 290);}@property --cngx-metric-unit-size{syntax: \"*\"; inherits: true; initial-value: .875rem;}@property --cngx-metric-unit-weight{syntax: \"<number>\"; inherits: true; initial-value: 400;}@property --cngx-metric-unit-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}}[data-color-scheme=dark],.dark{--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}[data-color-scheme=light],.light{--cngx-metric-value-color: oklch(.2 .01 290);--cngx-metric-unit-color: oklch(.36 .02 290)}}@layer cngx.components{@scope(.cngx-metric){:scope{display:inline-flex;align-items:baseline;gap:var(--cngx-metric-gap, 2px)}.cngx-metric__value{font-size:var(--cngx-metric-value-size, 1.75rem);font-weight:var(--cngx-metric-value-weight, 600);color:var(--cngx-metric-value-color, var(--cngx-color-text, oklch(.2 .01 290)));line-height:1.2}.cngx-metric__unit{font-size:var(--cngx-metric-unit-size, .875rem);font-weight:var(--cngx-metric-unit-weight, 400);color:var(--cngx-metric-unit-color, oklch(.36 .02 290))}}}\n"] }]
|
|
2485
|
+
`, styles: ["@layer cngx.tokens{@property --cngx-metric-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-metric-value-size{syntax: \"*\"; inherits: true; initial-value: 1.75rem;}@property --cngx-metric-value-weight{syntax: \"<number>\"; inherits: true; initial-value: 600;}@property --cngx-metric-value-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.2 .01 290);}@property --cngx-metric-unit-size{syntax: \"*\"; inherits: true; initial-value: .875rem;}@property --cngx-metric-unit-weight{syntax: \"<number>\"; inherits: true; initial-value: 400;}@property --cngx-metric-unit-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}}[data-color-scheme=dark],.dark{--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}[data-color-scheme=light],.light{--cngx-metric-value-color: oklch(.2 .01 290);--cngx-metric-unit-color: oklch(.36 .02 290)}}@layer cngx.components{@scope(.cngx-metric){:scope{--cngx-metric-gap: var(--cngx-space-xs);display:inline-flex;align-items:baseline;gap:var(--cngx-metric-gap, 2px)}.cngx-metric__value{font-size:var(--cngx-metric-value-size, 1.75rem);font-weight:var(--cngx-metric-value-weight, 600);color:var(--cngx-metric-value-color, var(--cngx-color-text, oklch(.2 .01 290)));line-height:1.2}.cngx-metric__unit{font-size:var(--cngx-metric-unit-size, .875rem);font-weight:var(--cngx-metric-unit-weight, 400);color:var(--cngx-metric-unit-color, oklch(.36 .02 290))}}}\n"] }]
|
|
2095
2486
|
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], unit: [{ type: i0.Input, args: [{ isSignal: true, alias: "unit", required: false }] }], format: [{ type: i0.Input, args: [{ isSignal: true, alias: "format", required: false }] }] } });
|
|
2096
2487
|
|
|
2488
|
+
/**
|
|
2489
|
+
* Pure, framework-agnostic helpers that turn a signed delta value into the
|
|
2490
|
+
* three orthogonal signals a KPI atom renders: **direction** (which way the
|
|
2491
|
+
* arrow points), **sentiment** (whether the change is good or bad, which
|
|
2492
|
+
* drives colour and the SR word), and the formatted magnitude.
|
|
2493
|
+
*
|
|
2494
|
+
* Direction and sentiment are deliberately separate. `CngxTrend` colours by
|
|
2495
|
+
* direction (up = green); `CngxDelta` colours by sentiment, so a value that
|
|
2496
|
+
* dropped can still read as an improvement (churn down, latency down). Both
|
|
2497
|
+
* consume these helpers so the direction / glyph / format logic has a single
|
|
2498
|
+
* source of truth (Pillar 1) with no Angular dependency.
|
|
2499
|
+
*/
|
|
2500
|
+
/** `> 0 → up`, `< 0 → down`, `0 → flat`. */
|
|
2501
|
+
function deltaDirection(value) {
|
|
2502
|
+
return value > 0 ? 'up' : value < 0 ? 'down' : 'flat';
|
|
2503
|
+
}
|
|
2504
|
+
/**
|
|
2505
|
+
* Combine movement with the caller's polarity. `flat` or `neutral` polarity
|
|
2506
|
+
* collapse to `neutral`; otherwise up is positive under `higher-is-better`
|
|
2507
|
+
* and negative under `lower-is-better` (and the reverse for down).
|
|
2508
|
+
*/
|
|
2509
|
+
function deltaSentiment(direction, polarity) {
|
|
2510
|
+
if (direction === 'flat' || polarity === 'neutral') {
|
|
2511
|
+
return 'neutral';
|
|
2512
|
+
}
|
|
2513
|
+
const upIsGood = polarity === 'higher-is-better';
|
|
2514
|
+
const isGood = direction === 'up' ? upIsGood : !upIsGood;
|
|
2515
|
+
return isGood ? 'positive' : 'negative';
|
|
2516
|
+
}
|
|
2517
|
+
/** Arrow glyph for the direction: `↑` / `↓` / `→`. */
|
|
2518
|
+
function directionGlyph(direction) {
|
|
2519
|
+
return direction === 'up' ? '↑' : direction === 'down' ? '↓' : '→';
|
|
2520
|
+
}
|
|
2521
|
+
/**
|
|
2522
|
+
* Format the magnitude. The sign is carried by the arrow and colour, not the
|
|
2523
|
+
* digits: a positive value gains a leading `+`, everything else prints its
|
|
2524
|
+
* absolute value unsigned. Percent mode appends a narrow-no-break-space + `%`
|
|
2525
|
+
* and defaults to one fraction digit; absolute mode uses the locale grouping.
|
|
2526
|
+
* A supplied `Intl.NumberFormatOptions` overrides the default digit handling
|
|
2527
|
+
* in both modes.
|
|
2528
|
+
*/
|
|
2529
|
+
function formatDelta(value, mode, locale, format) {
|
|
2530
|
+
const abs = Math.abs(value);
|
|
2531
|
+
const prefix = value > 0 ? '+' : '';
|
|
2532
|
+
if (mode === 'percent') {
|
|
2533
|
+
const num = format ? new Intl.NumberFormat(locale, format).format(abs) : abs.toFixed(1);
|
|
2534
|
+
return `${prefix}${num}\u202f%`;
|
|
2535
|
+
}
|
|
2536
|
+
const num = format ? new Intl.NumberFormat(locale, format).format(abs) : abs.toLocaleString(locale);
|
|
2537
|
+
return `${prefix}${num}`;
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2097
2540
|
/**
|
|
2098
2541
|
* Displays a trend indicator with directional arrow and formatted percentage.
|
|
2099
2542
|
*
|
|
@@ -2132,45 +2575,494 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2132
2575
|
* <example-url>http://localhost:4200/#/common/data/trend/trend-directions</example-url>
|
|
2133
2576
|
*/
|
|
2134
2577
|
class CngxTrend {
|
|
2578
|
+
locale = inject(LOCALE_ID);
|
|
2135
2579
|
/** Trend percentage. Positive = up, negative = down, zero = flat. */
|
|
2136
2580
|
value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
2137
2581
|
/** Consumer-provided SR label override. When set, replaces the generated default. */
|
|
2138
2582
|
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
2139
2583
|
/** @internal */
|
|
2140
|
-
icon = computed(() =>
|
|
2584
|
+
icon = computed(() => directionGlyph(deltaDirection(this.value())), ...(ngDevMode ? [{ debugName: "icon" }] : /* istanbul ignore next */ []));
|
|
2141
2585
|
/** @internal */
|
|
2142
|
-
formattedValue = computed(() => {
|
|
2143
|
-
const v = this.value();
|
|
2144
|
-
const abs = Math.abs(v);
|
|
2145
|
-
return `${v > 0 ? '+' : ''}${abs.toFixed(1)}\u202F%`;
|
|
2146
|
-
}, ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
2586
|
+
formattedValue = computed(() => formatDelta(this.value(), 'percent', this.locale), ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
2147
2587
|
/** @internal */
|
|
2148
2588
|
resolvedLabel = computed(() => {
|
|
2149
2589
|
if (this.label()) {
|
|
2150
2590
|
return this.label();
|
|
2151
2591
|
}
|
|
2152
|
-
const
|
|
2592
|
+
const direction = deltaDirection(this.value());
|
|
2593
|
+
const dir = direction === 'up' ? 'up' : direction === 'down' ? 'down' : 'unchanged';
|
|
2153
2594
|
return `${this.formattedValue()} ${dir}`;
|
|
2154
2595
|
}, ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
|
|
2155
2596
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTrend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2156
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxTrend, isStandalone: true, selector: "cngx-trend", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-trend--up": "value() > 0", "class.cngx-trend--down": "value() < 0", "attr.aria-label": "resolvedLabel()" }, classAttribute: "cngx-trend" }, ngImport: i0, template: `
|
|
2597
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxTrend, isStandalone: true, selector: "cngx-trend", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "img" }, properties: { "class.cngx-trend--up": "value() > 0", "class.cngx-trend--down": "value() < 0", "attr.aria-label": "resolvedLabel()" }, classAttribute: "cngx-trend" }, ngImport: i0, template: `
|
|
2157
2598
|
<span aria-hidden="true">{{ icon() }}</span>
|
|
2158
2599
|
{{ formattedValue() }}
|
|
2159
|
-
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-trend-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-trend-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-trend-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-trend-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-trend-up-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-trend-down-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-trend-color: oklch(.36 .02 290);--cngx-trend-up-color: oklch(.65 .18 145);--cngx-trend-down-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-trend){:scope{display:inline-flex;align-items:center;gap:var(--cngx-trend-gap, 2px);font-size:var(--cngx-trend-size, .8125rem);font-weight:var(--cngx-trend-weight, 500);color:var(--cngx-trend-color, oklch(.36 .02 290))}:scope.cngx-trend--up{color:var(--cngx-trend-up-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-trend--down{color:var(--cngx-trend-down-color, var(--cngx-color-danger, oklch(.65 .22 25)))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2600
|
+
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-trend-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-trend-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-trend-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-trend-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-trend-up-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-trend-down-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-trend-color: oklch(.36 .02 290);--cngx-trend-up-color: oklch(.65 .18 145);--cngx-trend-down-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-trend){:scope{--cngx-trend-gap: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-trend-gap, 2px);font-size:var(--cngx-trend-size, .8125rem);font-weight:var(--cngx-trend-weight, 500);color:var(--cngx-trend-color, oklch(.36 .02 290))}:scope.cngx-trend--up{color:var(--cngx-trend-up-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-trend--down{color:var(--cngx-trend-down-color, var(--cngx-color-danger, oklch(.65 .22 25)))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2160
2601
|
}
|
|
2161
2602
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTrend, decorators: [{
|
|
2162
2603
|
type: Component,
|
|
2163
2604
|
args: [{ selector: 'cngx-trend', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
2164
2605
|
class: 'cngx-trend',
|
|
2606
|
+
// role=img makes the host a single labelled graphic so AT announces the
|
|
2607
|
+
// curated `aria-label` instead of the raw glyph text on an otherwise
|
|
2608
|
+
// role=generic custom element, where aria-label is unreliably exposed.
|
|
2609
|
+
role: 'img',
|
|
2165
2610
|
'[class.cngx-trend--up]': 'value() > 0',
|
|
2166
2611
|
'[class.cngx-trend--down]': 'value() < 0',
|
|
2167
2612
|
'[attr.aria-label]': 'resolvedLabel()',
|
|
2168
2613
|
}, template: `
|
|
2169
2614
|
<span aria-hidden="true">{{ icon() }}</span>
|
|
2170
2615
|
{{ formattedValue() }}
|
|
2171
|
-
`, styles: ["@layer cngx.tokens{@property --cngx-trend-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-trend-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-trend-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-trend-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-trend-up-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-trend-down-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-trend-color: oklch(.36 .02 290);--cngx-trend-up-color: oklch(.65 .18 145);--cngx-trend-down-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-trend){:scope{display:inline-flex;align-items:center;gap:var(--cngx-trend-gap, 2px);font-size:var(--cngx-trend-size, .8125rem);font-weight:var(--cngx-trend-weight, 500);color:var(--cngx-trend-color, oklch(.36 .02 290))}:scope.cngx-trend--up{color:var(--cngx-trend-up-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-trend--down{color:var(--cngx-trend-down-color, var(--cngx-color-danger, oklch(.65 .22 25)))}}}\n"] }]
|
|
2616
|
+
`, styles: ["@layer cngx.tokens{@property --cngx-trend-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-trend-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-trend-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-trend-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-trend-up-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-trend-down-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-trend-color: oklch(.36 .02 290);--cngx-trend-up-color: oklch(.65 .18 145);--cngx-trend-down-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-trend){:scope{--cngx-trend-gap: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-trend-gap, 2px);font-size:var(--cngx-trend-size, .8125rem);font-weight:var(--cngx-trend-weight, 500);color:var(--cngx-trend-color, oklch(.36 .02 290))}:scope.cngx-trend--up{color:var(--cngx-trend-up-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-trend--down{color:var(--cngx-trend-down-color, var(--cngx-color-danger, oklch(.65 .22 25)))}}}\n"] }]
|
|
2172
2617
|
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }] } });
|
|
2173
2618
|
|
|
2619
|
+
const SENTIMENT_WORD = {
|
|
2620
|
+
positive: 'improved',
|
|
2621
|
+
negative: 'declined',
|
|
2622
|
+
neutral: 'unchanged',
|
|
2623
|
+
};
|
|
2624
|
+
/**
|
|
2625
|
+
* Sentiment-aware delta indicator. Where `CngxTrend` colours strictly by
|
|
2626
|
+
* direction (up = green), `CngxDelta` colours by **sentiment**: a `polarity`
|
|
2627
|
+
* of `lower-is-better` makes a drop read as an improvement (churn, latency,
|
|
2628
|
+
* error rate). The arrow glyph always tracks the raw direction, so colour is
|
|
2629
|
+
* never the only signal - a green value can carry a down arrow, and the SR
|
|
2630
|
+
* label speaks the sentiment word.
|
|
2631
|
+
*
|
|
2632
|
+
* Sentiment, direction, glyph and the formatted magnitude are each a
|
|
2633
|
+
* `computed()` off the single `value`/`polarity` input pair (Pillar 1); the
|
|
2634
|
+
* colour class and the arrow are bound from independent signals so they can
|
|
2635
|
+
* diverge (Pillar 2).
|
|
2636
|
+
*
|
|
2637
|
+
* ### Basic (higher-is-better default)
|
|
2638
|
+
* ```html
|
|
2639
|
+
* <cngx-delta [value]="5.3" />
|
|
2640
|
+
* ```
|
|
2641
|
+
*
|
|
2642
|
+
* ### Lower-is-better (a drop is good)
|
|
2643
|
+
* ```html
|
|
2644
|
+
* <cngx-delta [value]="-2.1" polarity="lower-is-better" />
|
|
2645
|
+
* ```
|
|
2646
|
+
*
|
|
2647
|
+
* ### Absolute magnitude
|
|
2648
|
+
* ```html
|
|
2649
|
+
* <cngx-delta [value]="1240" mode="absolute" [format]="{ maximumFractionDigits: 0 }" />
|
|
2650
|
+
* ```
|
|
2651
|
+
*
|
|
2652
|
+
* @category common/data/metric
|
|
2653
|
+
* @docsKind primary
|
|
2654
|
+
* @wcag AA
|
|
2655
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/display/delta/delta.component.ts
|
|
2656
|
+
* @since 0.1.0
|
|
2657
|
+
* @relatedTo CngxTrend, CngxMetric, CngxStat
|
|
2658
|
+
*
|
|
2659
|
+
* <example-url>http://localhost:4200/#/common/data/delta/sentiment-polarity</example-url>
|
|
2660
|
+
*/
|
|
2661
|
+
class CngxDelta {
|
|
2662
|
+
locale = inject(LOCALE_ID);
|
|
2663
|
+
/** Signed delta. Positive = up, negative = down, zero = flat. */
|
|
2664
|
+
value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
2665
|
+
/**
|
|
2666
|
+
* How to read the sign. `higher-is-better` (default) treats a rise as
|
|
2667
|
+
* positive; `lower-is-better` inverts it; `neutral` disables sentiment
|
|
2668
|
+
* (direction still renders, colour stays neutral).
|
|
2669
|
+
*/
|
|
2670
|
+
polarity = input('higher-is-better', ...(ngDevMode ? [{ debugName: "polarity" }] : /* istanbul ignore next */ []));
|
|
2671
|
+
/** `percent` (default, one fraction digit + `%`) or `absolute`. */
|
|
2672
|
+
mode = input('percent', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
2673
|
+
/** `Intl.NumberFormatOptions` applied to the magnitude in either mode. */
|
|
2674
|
+
format = input(undefined, ...(ngDevMode ? [{ debugName: "format" }] : /* istanbul ignore next */ []));
|
|
2675
|
+
/** Consumer-provided SR label override. Replaces the generated default. */
|
|
2676
|
+
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
2677
|
+
/** @internal Raw movement, independent of polarity. Drives the glyph. */
|
|
2678
|
+
direction = computed(() => deltaDirection(this.value()), ...(ngDevMode ? [{ debugName: "direction" }] : /* istanbul ignore next */ []));
|
|
2679
|
+
/** @internal Good / bad / indifferent. Drives colour and the SR word. */
|
|
2680
|
+
sentiment = computed(() => deltaSentiment(this.direction(), this.polarity()), ...(ngDevMode ? [{ debugName: "sentiment" }] : /* istanbul ignore next */ []));
|
|
2681
|
+
/** @internal Arrow glyph bound from direction only. */
|
|
2682
|
+
glyph = computed(() => directionGlyph(this.direction()), ...(ngDevMode ? [{ debugName: "glyph" }] : /* istanbul ignore next */ []));
|
|
2683
|
+
/** @internal Formatted magnitude. */
|
|
2684
|
+
formattedValue = computed(() => formatDelta(this.value(), this.mode(), this.locale, this.format()), ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
2685
|
+
/** @internal Full SR label: magnitude plus the sentiment word. */
|
|
2686
|
+
resolvedLabel = computed(() => {
|
|
2687
|
+
const override = this.label();
|
|
2688
|
+
if (override) {
|
|
2689
|
+
return override;
|
|
2690
|
+
}
|
|
2691
|
+
return `${this.formattedValue()} ${SENTIMENT_WORD[this.sentiment()]}`;
|
|
2692
|
+
}, ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
|
|
2693
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDelta, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2694
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxDelta, isStandalone: true, selector: "cngx-delta", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, polarity: { classPropertyName: "polarity", publicName: "polarity", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "img" }, properties: { "class.cngx-delta--positive": "sentiment() === 'positive'", "class.cngx-delta--negative": "sentiment() === 'negative'", "class.cngx-delta--neutral": "sentiment() === 'neutral'", "attr.aria-label": "resolvedLabel()" }, classAttribute: "cngx-delta" }, ngImport: i0, template: `
|
|
2695
|
+
<span aria-hidden="true">{{ glyph() }}</span>
|
|
2696
|
+
{{ formattedValue() }}
|
|
2697
|
+
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-delta-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-delta-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-delta-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-delta-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-delta-positive-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-delta-negative-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-delta-neutral-color: oklch(.7 .01 290);--cngx-delta-positive-color: oklch(.78 .16 145);--cngx-delta-negative-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-delta-neutral-color: oklch(.7 .01 290);--cngx-delta-positive-color: oklch(.78 .16 145);--cngx-delta-negative-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-delta-neutral-color: oklch(.36 .02 290);--cngx-delta-positive-color: oklch(.65 .18 145);--cngx-delta-negative-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-delta){:scope{--cngx-delta-gap: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-delta-gap, 2px);font-size:var(--cngx-delta-size, .8125rem);font-weight:var(--cngx-delta-weight, 500);color:var(--cngx-delta-neutral-color, oklch(.36 .02 290))}:scope.cngx-delta--positive{color:var(--cngx-delta-positive-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-delta--negative{color:var(--cngx-delta-negative-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-delta--neutral{color:var(--cngx-delta-neutral-color, oklch(.36 .02 290))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2698
|
+
}
|
|
2699
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDelta, decorators: [{
|
|
2700
|
+
type: Component,
|
|
2701
|
+
args: [{ selector: 'cngx-delta', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
2702
|
+
class: 'cngx-delta',
|
|
2703
|
+
// role=img makes the host a single labelled graphic so AT announces the
|
|
2704
|
+
// curated `aria-label` (the sentiment word) instead of the raw glyph text
|
|
2705
|
+
// on an otherwise role=generic custom element, where aria-label is
|
|
2706
|
+
// unreliably exposed.
|
|
2707
|
+
role: 'img',
|
|
2708
|
+
'[class.cngx-delta--positive]': "sentiment() === 'positive'",
|
|
2709
|
+
'[class.cngx-delta--negative]': "sentiment() === 'negative'",
|
|
2710
|
+
'[class.cngx-delta--neutral]': "sentiment() === 'neutral'",
|
|
2711
|
+
'[attr.aria-label]': 'resolvedLabel()',
|
|
2712
|
+
}, template: `
|
|
2713
|
+
<span aria-hidden="true">{{ glyph() }}</span>
|
|
2714
|
+
{{ formattedValue() }}
|
|
2715
|
+
`, styles: ["@layer cngx.tokens{@property --cngx-delta-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-delta-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-delta-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-delta-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-delta-positive-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-delta-negative-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-delta-neutral-color: oklch(.7 .01 290);--cngx-delta-positive-color: oklch(.78 .16 145);--cngx-delta-negative-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-delta-neutral-color: oklch(.7 .01 290);--cngx-delta-positive-color: oklch(.78 .16 145);--cngx-delta-negative-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-delta-neutral-color: oklch(.36 .02 290);--cngx-delta-positive-color: oklch(.65 .18 145);--cngx-delta-negative-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-delta){:scope{--cngx-delta-gap: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-delta-gap, 2px);font-size:var(--cngx-delta-size, .8125rem);font-weight:var(--cngx-delta-weight, 500);color:var(--cngx-delta-neutral-color, oklch(.36 .02 290))}:scope.cngx-delta--positive{color:var(--cngx-delta-positive-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-delta--negative{color:var(--cngx-delta-negative-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-delta--neutral{color:var(--cngx-delta-neutral-color, oklch(.36 .02 290))}}}\n"] }]
|
|
2716
|
+
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], polarity: [{ type: i0.Input, args: [{ isSignal: true, alias: "polarity", required: false }] }], mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], format: [{ type: i0.Input, args: [{ isSignal: true, alias: "format", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }] } });
|
|
2717
|
+
|
|
2718
|
+
/** DI token carrying the {@link CngxStatRegistry} a `CngxStat` provides. */
|
|
2719
|
+
const CNGX_STAT = new InjectionToken('CNGX_STAT');
|
|
2720
|
+
|
|
2721
|
+
/** Fixed reading order for the coordinated slots. */
|
|
2722
|
+
const SLOT_ORDER = ['label', 'value', 'delta', 'caption'];
|
|
2723
|
+
/** Structural equality so an unchanged id set never cascades `labelledBy`. */
|
|
2724
|
+
const idsEqual = (a, b) => a.length === b.length && a.every((id, i) => id === b[i]);
|
|
2725
|
+
/**
|
|
2726
|
+
* Coordination molecule for a KPI stat. Its sole reason to exist is the
|
|
2727
|
+
* screen-reader layer (Pillar 2): hand-assembling a heading, a `<cngx-metric>`
|
|
2728
|
+
* and a `<cngx-delta>` makes a screen reader announce three disconnected
|
|
2729
|
+
* fragments. `CngxStat` projects the label / value / delta / caption slots,
|
|
2730
|
+
* collects the id each slot registers, and derives one `aria-labelledby` that
|
|
2731
|
+
* reads the whole stat as a single accessible name in reading order.
|
|
2732
|
+
*
|
|
2733
|
+
* Composition, never a config bag (Pillar 3): the molecule owns only the id
|
|
2734
|
+
* coordination `computed()` graph; the visuals are whatever atoms the
|
|
2735
|
+
* consumer projects into the slots.
|
|
2736
|
+
*
|
|
2737
|
+
* ```html
|
|
2738
|
+
* <cngx-stat aria-live="polite">
|
|
2739
|
+
* <span cngxStatLabel>Revenue</span>
|
|
2740
|
+
* <cngx-metric cngxStatValue [value]="1.2" unit="M EUR" />
|
|
2741
|
+
* <cngx-delta cngxStatDelta [value]="5.3" />
|
|
2742
|
+
* <span cngxStatCaption>vs. last quarter</span>
|
|
2743
|
+
* </cngx-stat>
|
|
2744
|
+
* ```
|
|
2745
|
+
*
|
|
2746
|
+
* @category common/data/metric
|
|
2747
|
+
* @docsKind primary
|
|
2748
|
+
* @wcag AA
|
|
2749
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/display/stat/stat.component.ts
|
|
2750
|
+
* @since 0.1.0
|
|
2751
|
+
* @relatedTo CngxMetric, CngxDelta, CngxTrend
|
|
2752
|
+
*
|
|
2753
|
+
* <example-url>http://localhost:4200/#/common/data/stat/composed-kpi</example-url>
|
|
2754
|
+
*/
|
|
2755
|
+
class CngxStat {
|
|
2756
|
+
slots = signal(new Map(), ...(ngDevMode ? [{ debugName: "slots" }] : /* istanbul ignore next */ []));
|
|
2757
|
+
/**
|
|
2758
|
+
* Politeness of the live region. `off` (default) for a static stat;
|
|
2759
|
+
* `polite` / `assertive` for a KPI whose value updates in place.
|
|
2760
|
+
*/
|
|
2761
|
+
live = input('off', ...(ngDevMode ? [{ debugName: "live" }] : /* istanbul ignore next */ []));
|
|
2762
|
+
/** {@inheritDoc CngxStatRegistry.register} */
|
|
2763
|
+
register(kind, id) {
|
|
2764
|
+
this.slots.update((prev) => new Map(prev).set(kind, id));
|
|
2765
|
+
}
|
|
2766
|
+
/** {@inheritDoc CngxStatRegistry.unregister} */
|
|
2767
|
+
unregister(kind) {
|
|
2768
|
+
this.slots.update((prev) => {
|
|
2769
|
+
const next = new Map(prev);
|
|
2770
|
+
next.delete(kind);
|
|
2771
|
+
return next;
|
|
2772
|
+
});
|
|
2773
|
+
}
|
|
2774
|
+
/** @internal Present slot ids in reading order; structurally stable. */
|
|
2775
|
+
orderedIds = computed(() => {
|
|
2776
|
+
const map = this.slots();
|
|
2777
|
+
return SLOT_ORDER.map((kind) => map.get(kind)).filter((id) => id !== undefined);
|
|
2778
|
+
}, { ...(ngDevMode ? { debugName: "orderedIds" } : /* istanbul ignore next */ {}), equal: idsEqual });
|
|
2779
|
+
/** @internal Combined accessible name; `null` when no slot is present. */
|
|
2780
|
+
labelledBy = computed(() => this.orderedIds().join(' ') || null, ...(ngDevMode ? [{ debugName: "labelledBy" }] : /* istanbul ignore next */ []));
|
|
2781
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStat, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2782
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxStat, isStandalone: true, selector: "cngx-stat", inputs: { live: { classPropertyName: "live", publicName: "live", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "group" }, properties: { "attr.aria-labelledby": "labelledBy()", "attr.aria-live": "live()" }, classAttribute: "cngx-stat" }, providers: [{ provide: CNGX_STAT, useExisting: CngxStat }], ngImport: i0, template: `
|
|
2783
|
+
<ng-content select="[cngxStatLabel]" />
|
|
2784
|
+
<div class="cngx-stat__row">
|
|
2785
|
+
<ng-content select="[cngxStatValue]" />
|
|
2786
|
+
<ng-content select="[cngxStatDelta]" />
|
|
2787
|
+
</div>
|
|
2788
|
+
<ng-content select="[cngxStatCaption]" />
|
|
2789
|
+
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-stat-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-stat-row-gap{syntax: \"<length>\"; inherits: false; initial-value: 8px;}}@layer cngx.components{@scope(.cngx-stat){:scope{--cngx-stat-gap: var(--cngx-space-xs);--cngx-stat-row-gap: var(--cngx-space-sm);display:grid;gap:var(--cngx-stat-gap, 2px)}.cngx-stat__row{display:inline-flex;align-items:baseline;gap:var(--cngx-stat-row-gap, 8px)}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2790
|
+
}
|
|
2791
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStat, decorators: [{
|
|
2792
|
+
type: Component,
|
|
2793
|
+
args: [{ selector: 'cngx-stat', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [{ provide: CNGX_STAT, useExisting: CngxStat }], host: {
|
|
2794
|
+
class: 'cngx-stat',
|
|
2795
|
+
role: 'group',
|
|
2796
|
+
'[attr.aria-labelledby]': 'labelledBy()',
|
|
2797
|
+
'[attr.aria-live]': 'live()',
|
|
2798
|
+
}, template: `
|
|
2799
|
+
<ng-content select="[cngxStatLabel]" />
|
|
2800
|
+
<div class="cngx-stat__row">
|
|
2801
|
+
<ng-content select="[cngxStatValue]" />
|
|
2802
|
+
<ng-content select="[cngxStatDelta]" />
|
|
2803
|
+
</div>
|
|
2804
|
+
<ng-content select="[cngxStatCaption]" />
|
|
2805
|
+
`, styles: ["@layer cngx.tokens{@property --cngx-stat-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-stat-row-gap{syntax: \"<length>\"; inherits: false; initial-value: 8px;}}@layer cngx.components{@scope(.cngx-stat){:scope{--cngx-stat-gap: var(--cngx-space-xs);--cngx-stat-row-gap: var(--cngx-space-sm);display:grid;gap:var(--cngx-stat-gap, 2px)}.cngx-stat__row{display:inline-flex;align-items:baseline;gap:var(--cngx-stat-row-gap, 8px)}}}\n"] }]
|
|
2806
|
+
}], propDecorators: { live: [{ type: i0.Input, args: [{ isSignal: true, alias: "live", required: false }] }] } });
|
|
2807
|
+
|
|
2808
|
+
/**
|
|
2809
|
+
* Generate a stable id, register it with the enclosing `CngxStat` (if any),
|
|
2810
|
+
* and withdraw it on destroy. Shared by the four slot directives via plain
|
|
2811
|
+
* composition - no base class, no inheritance (Pillar 3).
|
|
2812
|
+
*/
|
|
2813
|
+
function useStatSlot(kind) {
|
|
2814
|
+
const registry = inject(CNGX_STAT, { optional: true });
|
|
2815
|
+
const id = nextUid(`cngx-stat-${kind}`);
|
|
2816
|
+
registry?.register(kind, id);
|
|
2817
|
+
inject(DestroyRef).onDestroy(() => registry?.unregister(kind));
|
|
2818
|
+
return id;
|
|
2819
|
+
}
|
|
2820
|
+
/**
|
|
2821
|
+
* Marks the label element of a {@link CngxStat}. Its generated id leads the
|
|
2822
|
+
* molecule's `aria-labelledby`.
|
|
2823
|
+
*
|
|
2824
|
+
* @category common/data/metric
|
|
2825
|
+
* @since 0.1.0
|
|
2826
|
+
* @relatedTo CngxStat
|
|
2827
|
+
*/
|
|
2828
|
+
class CngxStatLabel {
|
|
2829
|
+
/** Auto-generated id bound to the host `[id]`; consumed by `CngxStat`. */
|
|
2830
|
+
id = useStatSlot('label');
|
|
2831
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2832
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStatLabel, isStandalone: true, selector: "[cngxStatLabel]", host: { properties: { "id": "id" } }, ngImport: i0 });
|
|
2833
|
+
}
|
|
2834
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatLabel, decorators: [{
|
|
2835
|
+
type: Directive,
|
|
2836
|
+
args: [{
|
|
2837
|
+
selector: '[cngxStatLabel]',
|
|
2838
|
+
standalone: true,
|
|
2839
|
+
host: { '[id]': 'id' },
|
|
2840
|
+
}]
|
|
2841
|
+
}] });
|
|
2842
|
+
/**
|
|
2843
|
+
* Marks the primary value element of a {@link CngxStat} (typically a
|
|
2844
|
+
* `<cngx-metric>`).
|
|
2845
|
+
*
|
|
2846
|
+
* @category common/data/metric
|
|
2847
|
+
* @since 0.1.0
|
|
2848
|
+
* @relatedTo CngxStat
|
|
2849
|
+
*/
|
|
2850
|
+
class CngxStatValue {
|
|
2851
|
+
/** Auto-generated id bound to the host `[id]`; consumed by `CngxStat`. */
|
|
2852
|
+
id = useStatSlot('value');
|
|
2853
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatValue, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2854
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStatValue, isStandalone: true, selector: "[cngxStatValue]", host: { properties: { "id": "id" } }, ngImport: i0 });
|
|
2855
|
+
}
|
|
2856
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatValue, decorators: [{
|
|
2857
|
+
type: Directive,
|
|
2858
|
+
args: [{
|
|
2859
|
+
selector: '[cngxStatValue]',
|
|
2860
|
+
standalone: true,
|
|
2861
|
+
host: { '[id]': 'id' },
|
|
2862
|
+
}]
|
|
2863
|
+
}] });
|
|
2864
|
+
/**
|
|
2865
|
+
* Marks the delta element of a {@link CngxStat} (typically a `<cngx-delta>`
|
|
2866
|
+
* or `<cngx-trend>`).
|
|
2867
|
+
*
|
|
2868
|
+
* @category common/data/metric
|
|
2869
|
+
* @since 0.1.0
|
|
2870
|
+
* @relatedTo CngxStat
|
|
2871
|
+
*/
|
|
2872
|
+
class CngxStatDelta {
|
|
2873
|
+
/** Auto-generated id bound to the host `[id]`; consumed by `CngxStat`. */
|
|
2874
|
+
id = useStatSlot('delta');
|
|
2875
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatDelta, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2876
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStatDelta, isStandalone: true, selector: "[cngxStatDelta]", host: { properties: { "id": "id" } }, ngImport: i0 });
|
|
2877
|
+
}
|
|
2878
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatDelta, decorators: [{
|
|
2879
|
+
type: Directive,
|
|
2880
|
+
args: [{
|
|
2881
|
+
selector: '[cngxStatDelta]',
|
|
2882
|
+
standalone: true,
|
|
2883
|
+
host: { '[id]': 'id' },
|
|
2884
|
+
}]
|
|
2885
|
+
}] });
|
|
2886
|
+
/**
|
|
2887
|
+
* Marks the caption element of a {@link CngxStat} - the trailing context
|
|
2888
|
+
* line (e.g. "vs. last quarter").
|
|
2889
|
+
*
|
|
2890
|
+
* @category common/data/metric
|
|
2891
|
+
* @since 0.1.0
|
|
2892
|
+
* @relatedTo CngxStat
|
|
2893
|
+
*/
|
|
2894
|
+
class CngxStatCaption {
|
|
2895
|
+
/** Auto-generated id bound to the host `[id]`; consumed by `CngxStat`. */
|
|
2896
|
+
id = useStatSlot('caption');
|
|
2897
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatCaption, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2898
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStatCaption, isStandalone: true, selector: "[cngxStatCaption]", host: { properties: { "id": "id" } }, ngImport: i0 });
|
|
2899
|
+
}
|
|
2900
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatCaption, decorators: [{
|
|
2901
|
+
type: Directive,
|
|
2902
|
+
args: [{
|
|
2903
|
+
selector: '[cngxStatCaption]',
|
|
2904
|
+
standalone: true,
|
|
2905
|
+
host: { '[id]': 'id' },
|
|
2906
|
+
}]
|
|
2907
|
+
}] });
|
|
2908
|
+
|
|
2909
|
+
/** Tone glyph rendered inside the decorative dot - the non-colour signal. */
|
|
2910
|
+
const TONE_GLYPH = {
|
|
2911
|
+
success: '✓',
|
|
2912
|
+
warning: '!',
|
|
2913
|
+
danger: '✕',
|
|
2914
|
+
info: 'i',
|
|
2915
|
+
neutral: '•',
|
|
2916
|
+
};
|
|
2917
|
+
/**
|
|
2918
|
+
* Semantic health indicator - a decorative tone dot paired with a visible
|
|
2919
|
+
* label. Distinct from `CngxBadge` (count overlay), `CngxChip` (interactive)
|
|
2920
|
+
* and `CngxTag` (labeled token): its single job is to communicate a status
|
|
2921
|
+
* (operational / degraded / down / info).
|
|
2922
|
+
*
|
|
2923
|
+
* Colour is never the only signal (Pillar 2): the tone drives the dot colour
|
|
2924
|
+
* *and* a tone glyph, so a colour-blind reader still distinguishes the states,
|
|
2925
|
+
* and the visible `label` carries the meaning for assistive tech (the dot is
|
|
2926
|
+
* `aria-hidden`). Set `live` for a status that changes in place.
|
|
2927
|
+
*
|
|
2928
|
+
* ### Basic
|
|
2929
|
+
* ```html
|
|
2930
|
+
* <cngx-status tone="success" label="Operational" />
|
|
2931
|
+
* ```
|
|
2932
|
+
*
|
|
2933
|
+
* ### Live-updating
|
|
2934
|
+
* ```html
|
|
2935
|
+
* <cngx-status tone="danger" label="Outage" live="assertive" />
|
|
2936
|
+
* ```
|
|
2937
|
+
*
|
|
2938
|
+
* @category common/data/metric
|
|
2939
|
+
* @docsKind primary
|
|
2940
|
+
* @wcag AA
|
|
2941
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/display/status/status.component.ts
|
|
2942
|
+
* @since 0.1.0
|
|
2943
|
+
* @relatedTo CngxBadge, CngxTag, CngxChip
|
|
2944
|
+
*
|
|
2945
|
+
* <example-url>http://localhost:4200/#/common/data/status/tone-matrix</example-url>
|
|
2946
|
+
*/
|
|
2947
|
+
class CngxStatus {
|
|
2948
|
+
elRef = inject((ElementRef));
|
|
2949
|
+
/** Semantic health. Drives both the dot colour and the tone glyph. */
|
|
2950
|
+
tone = input('neutral', ...(ngDevMode ? [{ debugName: "tone" }] : /* istanbul ignore next */ []));
|
|
2951
|
+
/** Visible status text. Carries the meaning for assistive tech. */
|
|
2952
|
+
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
2953
|
+
/**
|
|
2954
|
+
* Politeness of the live region. `off` (default) for a static status;
|
|
2955
|
+
* `polite` / `assertive` for a status that changes in place.
|
|
2956
|
+
*/
|
|
2957
|
+
live = input('off', ...(ngDevMode ? [{ debugName: "live" }] : /* istanbul ignore next */ []));
|
|
2958
|
+
/** @internal Tone glyph bound into the decorative dot. */
|
|
2959
|
+
glyph = computed(() => TONE_GLYPH[this.tone()], ...(ngDevMode ? [{ debugName: "glyph" }] : /* istanbul ignore next */ []));
|
|
2960
|
+
constructor() {
|
|
2961
|
+
if (isDevMode()) {
|
|
2962
|
+
afterNextRender(() => {
|
|
2963
|
+
const el = this.elRef.nativeElement;
|
|
2964
|
+
if (!this.label() && !el.getAttribute('aria-label') && !el.getAttribute('aria-labelledby')) {
|
|
2965
|
+
console.warn('cngx-status: no `label` and no external `aria-label`/`aria-labelledby`; ' +
|
|
2966
|
+
'the status has no accessible name and reads only as a coloured dot. ' +
|
|
2967
|
+
'Set [label] or an aria-label on the host.');
|
|
2968
|
+
}
|
|
2969
|
+
});
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatus, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2973
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxStatus, isStandalone: true, selector: "cngx-status", inputs: { tone: { classPropertyName: "tone", publicName: "tone", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, live: { classPropertyName: "live", publicName: "live", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-status--success": "tone() === 'success'", "class.cngx-status--warning": "tone() === 'warning'", "class.cngx-status--danger": "tone() === 'danger'", "class.cngx-status--info": "tone() === 'info'", "class.cngx-status--neutral": "tone() === 'neutral'", "attr.aria-live": "live()" }, classAttribute: "cngx-status" }, ngImport: i0, template: `
|
|
2974
|
+
<span class="cngx-status__dot" aria-hidden="true">{{ glyph() }}</span>
|
|
2975
|
+
@if (label()) {
|
|
2976
|
+
<span class="cngx-status__label">{{ label() }}</span>
|
|
2977
|
+
}
|
|
2978
|
+
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-status-gap{syntax: \"<length>\"; inherits: false; initial-value: 6px;}@property --cngx-status-dot-size{syntax: \"<length>\"; inherits: false; initial-value: 1rem;}@property --cngx-status-glyph-size{syntax: \"*\"; inherits: true; initial-value: .7em;}@property --cngx-status-dot-fg{syntax: \"<color>\"; inherits: true; initial-value: white;}@property --cngx-status-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-status-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-status-success-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-status-warning-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.75 .15 85);}@property --cngx-status-danger-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@property --cngx-status-info-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .14 250);}@property --cngx-status-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}}[data-color-scheme=dark],.dark{--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}[data-color-scheme=light],.light{--cngx-status-success-color: oklch(.65 .18 145);--cngx-status-warning-color: oklch(.75 .15 85);--cngx-status-danger-color: oklch(.65 .22 25);--cngx-status-info-color: oklch(.6 .14 250);--cngx-status-neutral-color: oklch(.6 .02 290)}}@layer cngx.components{@scope(.cngx-status){:scope{--cngx-status-gap: var(--cngx-space-sm);display:inline-flex;align-items:center;gap:var(--cngx-status-gap, 6px);font-size:var(--cngx-status-size, .8125rem);font-weight:var(--cngx-status-weight, 500)}.cngx-status__dot{display:inline-flex;align-items:center;justify-content:center;inline-size:var(--cngx-status-dot-size, 1rem);block-size:var(--cngx-status-dot-size, 1rem);border-radius:50%;font-size:var(--cngx-status-glyph-size, .7em);line-height:1;color:var(--cngx-status-dot-fg, white);background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}:scope.cngx-status--success .cngx-status__dot{background:var(--cngx-status-success-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-status--warning .cngx-status__dot{background:var(--cngx-status-warning-color, oklch(.75 .15 85))}:scope.cngx-status--danger .cngx-status__dot{background:var(--cngx-status-danger-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-status--info .cngx-status__dot{background:var(--cngx-status-info-color, oklch(.6 .14 250))}:scope.cngx-status--neutral .cngx-status__dot{background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2979
|
+
}
|
|
2980
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatus, decorators: [{
|
|
2981
|
+
type: Component,
|
|
2982
|
+
args: [{ selector: 'cngx-status', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
2983
|
+
class: 'cngx-status',
|
|
2984
|
+
'[class.cngx-status--success]': "tone() === 'success'",
|
|
2985
|
+
'[class.cngx-status--warning]': "tone() === 'warning'",
|
|
2986
|
+
'[class.cngx-status--danger]': "tone() === 'danger'",
|
|
2987
|
+
'[class.cngx-status--info]': "tone() === 'info'",
|
|
2988
|
+
'[class.cngx-status--neutral]': "tone() === 'neutral'",
|
|
2989
|
+
'[attr.aria-live]': 'live()',
|
|
2990
|
+
}, template: `
|
|
2991
|
+
<span class="cngx-status__dot" aria-hidden="true">{{ glyph() }}</span>
|
|
2992
|
+
@if (label()) {
|
|
2993
|
+
<span class="cngx-status__label">{{ label() }}</span>
|
|
2994
|
+
}
|
|
2995
|
+
`, styles: ["@layer cngx.tokens{@property --cngx-status-gap{syntax: \"<length>\"; inherits: false; initial-value: 6px;}@property --cngx-status-dot-size{syntax: \"<length>\"; inherits: false; initial-value: 1rem;}@property --cngx-status-glyph-size{syntax: \"*\"; inherits: true; initial-value: .7em;}@property --cngx-status-dot-fg{syntax: \"<color>\"; inherits: true; initial-value: white;}@property --cngx-status-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-status-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-status-success-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-status-warning-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.75 .15 85);}@property --cngx-status-danger-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@property --cngx-status-info-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .14 250);}@property --cngx-status-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}}[data-color-scheme=dark],.dark{--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}[data-color-scheme=light],.light{--cngx-status-success-color: oklch(.65 .18 145);--cngx-status-warning-color: oklch(.75 .15 85);--cngx-status-danger-color: oklch(.65 .22 25);--cngx-status-info-color: oklch(.6 .14 250);--cngx-status-neutral-color: oklch(.6 .02 290)}}@layer cngx.components{@scope(.cngx-status){:scope{--cngx-status-gap: var(--cngx-space-sm);display:inline-flex;align-items:center;gap:var(--cngx-status-gap, 6px);font-size:var(--cngx-status-size, .8125rem);font-weight:var(--cngx-status-weight, 500)}.cngx-status__dot{display:inline-flex;align-items:center;justify-content:center;inline-size:var(--cngx-status-dot-size, 1rem);block-size:var(--cngx-status-dot-size, 1rem);border-radius:50%;font-size:var(--cngx-status-glyph-size, .7em);line-height:1;color:var(--cngx-status-dot-fg, white);background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}:scope.cngx-status--success .cngx-status__dot{background:var(--cngx-status-success-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-status--warning .cngx-status__dot{background:var(--cngx-status-warning-color, oklch(.75 .15 85))}:scope.cngx-status--danger .cngx-status__dot{background:var(--cngx-status-danger-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-status--info .cngx-status__dot{background:var(--cngx-status-info-color, oklch(.6 .14 250))}:scope.cngx-status--neutral .cngx-status__dot{background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}}}\n"] }]
|
|
2996
|
+
}], ctorParameters: () => [], propDecorators: { tone: [{ type: i0.Input, args: [{ isSignal: true, alias: "tone", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], live: [{ type: i0.Input, args: [{ isSignal: true, alias: "live", required: false }] }] } });
|
|
2997
|
+
|
|
2998
|
+
/**
|
|
2999
|
+
* Determinate attainment bar - a continuous progress toward a target
|
|
3000
|
+
* (quota reached, budget spent, goal met). Named `CngxGoal` because
|
|
3001
|
+
* `cngx-progress` is the indeterminate async loading bar; this is the
|
|
3002
|
+
* finished-fraction indicator, distinct from that and from the discrete
|
|
3003
|
+
* `CngxSegmentedProgress`.
|
|
3004
|
+
*
|
|
3005
|
+
* Mirrors the `CngxSegmentedProgress` a11y shape: `role="progressbar"` with
|
|
3006
|
+
* the whole `aria-value*` set plus `aria-valuetext` living in the `computed()`
|
|
3007
|
+
* graph (Pillar 2). The value is clamped to `[0, max]`; the fill width is a
|
|
3008
|
+
* derived percent bound as a CSS custom property.
|
|
3009
|
+
*
|
|
3010
|
+
* ```html
|
|
3011
|
+
* <cngx-goal [value]="73" [max]="100" />
|
|
3012
|
+
* <cngx-goal [value]="q()" [max]="target()" [valueTextFormat]="quotaText" />
|
|
3013
|
+
* ```
|
|
3014
|
+
*
|
|
3015
|
+
* @category common/data/metric
|
|
3016
|
+
* @docsKind primary
|
|
3017
|
+
* @wcag AA
|
|
3018
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/display/goal/goal.component.ts
|
|
3019
|
+
* @since 0.1.0
|
|
3020
|
+
* @relatedTo CngxSegmentedProgress, CngxMetric
|
|
3021
|
+
*
|
|
3022
|
+
* <example-url>http://localhost:4200/#/common/data/goal/quota-attainment</example-url>
|
|
3023
|
+
*/
|
|
3024
|
+
class CngxGoal {
|
|
3025
|
+
/** Current attainment. Clamped to `[0, max]`. */
|
|
3026
|
+
value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
3027
|
+
/** Target the value works toward. Defaults to `100`. */
|
|
3028
|
+
max = input(100, ...(ngDevMode ? [{ debugName: "max" }] : /* istanbul ignore next */ []));
|
|
3029
|
+
/**
|
|
3030
|
+
* Override the `aria-valuetext` string. Receives `(now, max)` - the clamped
|
|
3031
|
+
* value and the target. The default is `(now, max) => \`${now} of ${max}\``.
|
|
3032
|
+
* Supply a localised closure for richer text (e.g.
|
|
3033
|
+
* `(n, m) => \`${n} of ${m}, ${Math.round((n / m) * 100)}% of quota\``).
|
|
3034
|
+
*/
|
|
3035
|
+
valueTextFormat = input(undefined, ...(ngDevMode ? [{ debugName: "valueTextFormat" }] : /* istanbul ignore next */ []));
|
|
3036
|
+
/** `aria-valuemax` - the target, floored at 0. */
|
|
3037
|
+
maxValue = computed(() => Math.max(0, this.max()), ...(ngDevMode ? [{ debugName: "maxValue" }] : /* istanbul ignore next */ []));
|
|
3038
|
+
/** `aria-valuenow` - value clamped into `[0, max]`. */
|
|
3039
|
+
now = computed(() => Math.max(0, Math.min(this.value(), this.maxValue())), ...(ngDevMode ? [{ debugName: "now" }] : /* istanbul ignore next */ []));
|
|
3040
|
+
/** Fill width as a percent of the target; `0` when the target is `0`. */
|
|
3041
|
+
fillPercent = computed(() => {
|
|
3042
|
+
const max = this.maxValue();
|
|
3043
|
+
return max === 0 ? 0 : (this.now() / max) * 100;
|
|
3044
|
+
}, ...(ngDevMode ? [{ debugName: "fillPercent" }] : /* istanbul ignore next */ []));
|
|
3045
|
+
/** `aria-valuetext` - human-readable attainment via the resolved closure. */
|
|
3046
|
+
valueText = computed(() => {
|
|
3047
|
+
const fmt = this.valueTextFormat() ?? ((now, max) => `${now} of ${max}`);
|
|
3048
|
+
return fmt(this.now(), this.maxValue());
|
|
3049
|
+
}, ...(ngDevMode ? [{ debugName: "valueText" }] : /* istanbul ignore next */ []));
|
|
3050
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxGoal, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3051
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxGoal, isStandalone: true, selector: "cngx-goal", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, valueTextFormat: { classPropertyName: "valueTextFormat", publicName: "valueTextFormat", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "progressbar" }, properties: { "attr.aria-valuemin": "0", "attr.aria-valuemax": "maxValue()", "attr.aria-valuenow": "now()", "attr.aria-valuetext": "valueText()", "style.--cngx-goal-fill.%": "fillPercent()" }, classAttribute: "cngx-goal" }, ngImport: i0, template: `<span class="cngx-goal__track"><span class="cngx-goal__fill"></span></span>`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-goal-fill{syntax: \"<percentage>\"; inherits: true; initial-value: 0%;}@property --cngx-goal-height{syntax: \"<length>\"; inherits: false; initial-value: 8px;}@property --cngx-goal-radius{syntax: \"<length>\"; inherits: false; initial-value: 999px;}@property --cngx-goal-track-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.92 .01 290);}@property --cngx-goal-fill-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-goal-track-color: oklch(.3 .01 290);--cngx-goal-fill-color: oklch(.78 .16 145)}}[data-color-scheme=dark],.dark{--cngx-goal-track-color: oklch(.3 .01 290);--cngx-goal-fill-color: oklch(.78 .16 145)}[data-color-scheme=light],.light{--cngx-goal-track-color: oklch(.92 .01 290);--cngx-goal-fill-color: oklch(.65 .18 145)}}@layer cngx.components{@scope(.cngx-goal){:scope{display:block;inline-size:100%}.cngx-goal__track{display:block;inline-size:100%;block-size:var(--cngx-goal-height, 8px);border-radius:var(--cngx-goal-radius, 999px);background:var(--cngx-goal-track-color, oklch(.92 .01 290));overflow:hidden}.cngx-goal__fill{display:block;block-size:100%;inline-size:var(--cngx-goal-fill, 0%);border-radius:inherit;background:var(--cngx-goal-fill-color, var(--cngx-color-success, oklch(.65 .18 145)))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
3052
|
+
}
|
|
3053
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxGoal, decorators: [{
|
|
3054
|
+
type: Component,
|
|
3055
|
+
args: [{ selector: 'cngx-goal', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
3056
|
+
class: 'cngx-goal',
|
|
3057
|
+
role: 'progressbar',
|
|
3058
|
+
'[attr.aria-valuemin]': '0',
|
|
3059
|
+
'[attr.aria-valuemax]': 'maxValue()',
|
|
3060
|
+
'[attr.aria-valuenow]': 'now()',
|
|
3061
|
+
'[attr.aria-valuetext]': 'valueText()',
|
|
3062
|
+
'[style.--cngx-goal-fill.%]': 'fillPercent()',
|
|
3063
|
+
}, template: `<span class="cngx-goal__track"><span class="cngx-goal__fill"></span></span>`, styles: ["@layer cngx.tokens{@property --cngx-goal-fill{syntax: \"<percentage>\"; inherits: true; initial-value: 0%;}@property --cngx-goal-height{syntax: \"<length>\"; inherits: false; initial-value: 8px;}@property --cngx-goal-radius{syntax: \"<length>\"; inherits: false; initial-value: 999px;}@property --cngx-goal-track-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.92 .01 290);}@property --cngx-goal-fill-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-goal-track-color: oklch(.3 .01 290);--cngx-goal-fill-color: oklch(.78 .16 145)}}[data-color-scheme=dark],.dark{--cngx-goal-track-color: oklch(.3 .01 290);--cngx-goal-fill-color: oklch(.78 .16 145)}[data-color-scheme=light],.light{--cngx-goal-track-color: oklch(.92 .01 290);--cngx-goal-fill-color: oklch(.65 .18 145)}}@layer cngx.components{@scope(.cngx-goal){:scope{display:block;inline-size:100%}.cngx-goal__track{display:block;inline-size:100%;block-size:var(--cngx-goal-height, 8px);border-radius:var(--cngx-goal-radius, 999px);background:var(--cngx-goal-track-color, oklch(.92 .01 290));overflow:hidden}.cngx-goal__fill{display:block;block-size:100%;inline-size:var(--cngx-goal-fill, 0%);border-radius:inherit;background:var(--cngx-goal-fill-color, var(--cngx-color-success, oklch(.65 .18 145)))}}}\n"] }]
|
|
3064
|
+
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "max", required: false }] }], valueTextFormat: [{ type: i0.Input, args: [{ isSignal: true, alias: "valueTextFormat", required: false }] }] } });
|
|
3065
|
+
|
|
2174
3066
|
const EMPTY_RANGE = {
|
|
2175
3067
|
start: 0,
|
|
2176
3068
|
end: 0,
|
|
@@ -2312,7 +3204,23 @@ function createScrollObserver(elementRef, destroyRef) {
|
|
|
2312
3204
|
// when the element wasn't found on the first attempt (routed components,
|
|
2313
3205
|
// content projection, lazy rendering).
|
|
2314
3206
|
const retryTick = signal(0, ...(ngDevMode ? [{ debugName: "retryTick" }] : /* istanbul ignore next */ []));
|
|
3207
|
+
// Late-mount watcher for the string-selector path. A viewport gated behind
|
|
3208
|
+
// async data (or a skeleton->content swap) can mount many renders after the
|
|
3209
|
+
// one-shot afterNextRender retry fires, so a single retry misses it. This
|
|
3210
|
+
// observer bumps retryTick the instant the selector matches, then
|
|
3211
|
+
// disconnects. Created only in the unresolved-string case; stays null on
|
|
3212
|
+
// every faster path.
|
|
3213
|
+
let mutationObserver = null;
|
|
3214
|
+
function disconnectMutationObserver() {
|
|
3215
|
+
mutationObserver?.disconnect();
|
|
3216
|
+
mutationObserver = null;
|
|
3217
|
+
}
|
|
2315
3218
|
function attachListeners(el, onCleanup) {
|
|
3219
|
+
// A viewport resolved: the late-mount watcher has done its job. Disconnect
|
|
3220
|
+
// it on attach so it can never outlive a resolved element — the node is
|
|
3221
|
+
// already in the DOM, so the observer would otherwise never fire again and
|
|
3222
|
+
// leak until destroy.
|
|
3223
|
+
disconnectMutationObserver();
|
|
2316
3224
|
elementState.set(el);
|
|
2317
3225
|
scrollTopState.set(el.scrollTop);
|
|
2318
3226
|
clientHeightState.set(el.clientHeight);
|
|
@@ -2359,11 +3267,38 @@ function createScrollObserver(elementRef, destroyRef) {
|
|
|
2359
3267
|
// untracked: afterNextRender may run in the same microtask as the effect.
|
|
2360
3268
|
// Reading elementState() without untracked could create an unintended dependency
|
|
2361
3269
|
// in whatever reactive context is active.
|
|
2362
|
-
if (untracked(() => elementState())
|
|
2363
|
-
|
|
3270
|
+
if (untracked(() => elementState()) != null) {
|
|
3271
|
+
return;
|
|
3272
|
+
}
|
|
3273
|
+
// Element missing after the first render. Bump once for the common
|
|
3274
|
+
// next-render mount (routed component, content projection, lazy rendering).
|
|
3275
|
+
retryTick.update((v) => v + 1);
|
|
3276
|
+
// A string selector can still be unresolved because its viewport mounts
|
|
3277
|
+
// arbitrarily late — an async-gated list, a skeleton->content swap. Watch
|
|
3278
|
+
// the document and attach the instant it appears. Non-string refs
|
|
3279
|
+
// (HTMLElement / ElementRef) are not document-queryable, so the watcher
|
|
3280
|
+
// cannot help them; they stay on the single-retry path. Guard MutationObserver
|
|
3281
|
+
// for SSR.
|
|
3282
|
+
if (typeof elementRef !== 'string' || typeof MutationObserver === 'undefined') {
|
|
3283
|
+
return;
|
|
2364
3284
|
}
|
|
3285
|
+
if (isDevMode()) {
|
|
3286
|
+
console.warn(`recycler scrollElement '${elementRef}' not found on first render; ` +
|
|
3287
|
+
'it will attach automatically once it mounts. If it never does, check the selector.');
|
|
3288
|
+
}
|
|
3289
|
+
mutationObserver = new MutationObserver(() => {
|
|
3290
|
+
if (resolveElement(elementRef, doc) == null) {
|
|
3291
|
+
return;
|
|
3292
|
+
}
|
|
3293
|
+
// Found it. Disconnect before the retry bump so the resolving effect run
|
|
3294
|
+
// never observes a live-but-spent watcher, then let the effect attach.
|
|
3295
|
+
disconnectMutationObserver();
|
|
3296
|
+
retryTick.update((v) => v + 1);
|
|
3297
|
+
});
|
|
3298
|
+
mutationObserver.observe(doc.documentElement, { childList: true, subtree: true });
|
|
2365
3299
|
});
|
|
2366
3300
|
destroyRef.onDestroy(() => {
|
|
3301
|
+
disconnectMutationObserver();
|
|
2367
3302
|
elementState.set(null);
|
|
2368
3303
|
});
|
|
2369
3304
|
return {
|
|
@@ -2535,7 +3470,13 @@ function injectRecycler(config) {
|
|
|
2535
3470
|
}
|
|
2536
3471
|
return typeof config.columns === 'function' ? config.columns() : config.columns;
|
|
2537
3472
|
}, ...(ngDevMode ? [{ debugName: "columns" }] : /* istanbul ignore next */ []));
|
|
2538
|
-
|
|
3473
|
+
// A Signal is a zero-arg function but resolves to a uniform height, not a
|
|
3474
|
+
// per-index measurement - it carries no O(n) per-frame cost, so exclude it
|
|
3475
|
+
// from the variable-height warning (a reactive scalar estimate is a
|
|
3476
|
+
// sanctioned pattern; see the resolveSize note below).
|
|
3477
|
+
if (typeof config.estimateSize === 'function' &&
|
|
3478
|
+
!isSignal(config.estimateSize) &&
|
|
3479
|
+
isDevMode()) {
|
|
2539
3480
|
const count = config.totalCount();
|
|
2540
3481
|
if (count > 10_000) {
|
|
2541
3482
|
console.warn(`[CngxRecycler] estimateSize as a function with ${count} items has O(n) ` +
|
|
@@ -3364,5 +4305,5 @@ function createMaterialBidirectionalSync(opts) {
|
|
|
3364
4305
|
* Generated bundle index. Do not edit.
|
|
3365
4306
|
*/
|
|
3366
4307
|
|
|
3367
|
-
export { CNGX_BUCKET_PAGINATE_HOST, CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_RECYCLER_I18N, CngxAsync, CngxBucketPaginate, CngxDataSource, CngxFilter, CngxFilterChip, CngxFilterChips, CngxMeasure, CngxMetric, CngxPaginate, CngxPaginateResetOn, CngxPaginateRouting, CngxRecyclerAnnouncer, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxTrend, CngxVirtualItem, connectPaginateResetOn, connectRecyclerToActiveDescendant, connectRecyclerToRoving, createAsyncState, createCommitController, createManualState, createMaterialBidirectionalSync, fromHttpResource, fromResource, injectAsyncState, injectDataSource, injectRecycler, injectSmartDataSource, provideRecyclerI18n, resolveAsyncView, tapAsyncProgress, tapAsyncState, tapHttpAsyncState };
|
|
4308
|
+
export { CNGX_ASYNC_LABEL, CNGX_ASYNC_SKIP, CNGX_BUCKET_PAGINATE_HOST, CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_RECYCLER_I18N, CNGX_STAT, CngxAsync, CngxAsyncRegistry, CngxBucketPaginate, CngxDataSource, CngxDelta, CngxFilter, CngxFilterChip, CngxFilterChips, CngxGoal, CngxMeasure, CngxMetric, CngxPaginate, CngxPaginateResetOn, CngxPaginateRouting, CngxRecyclerAnnouncer, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxStat, CngxStatCaption, CngxStatDelta, CngxStatLabel, CngxStatValue, CngxStatus, CngxTrend, CngxVirtualItem, cngxAsyncInterceptor, connectPaginateEmit, connectPaginateResetOn, connectRecyclerToActiveDescendant, connectRecyclerToRoving, createAsyncState, createCommitController, createManualState, createMaterialBidirectionalSync, createSortHeaderState, fromHttpResource, fromResource, injectAsyncRegistry, injectAsyncState, injectDataSource, injectRecycler, injectSmartDataSource, provideAsyncHttpObservability, provideAsyncRegistry, provideRecyclerI18n, resolveAsyncView, tapAsyncProgress, tapAsyncState, tapHttpAsyncState, withAsyncLabel, withAsyncSkip };
|
|
3368
4309
|
//# sourceMappingURL=cngx-common-data.mjs.map
|