@cngx/common 0.1.0-rc.2 → 0.1.0-rc.4
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/data/README.md +10 -3
- 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-card.mjs +8 -8
- package/fesm2022/cngx-common-card.mjs.map +1 -1
- package/fesm2022/cngx-common-data.mjs +999 -54
- 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 +1603 -75
- 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 +1 -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-data.d.ts +837 -23
- package/types/cngx-common-display.d.ts +189 -1
- package/types/cngx-common-interactive.d.ts +1014 -31
- package/types/cngx-common-layout.d.ts +88 -3
- package/types/cngx-common-popover.d.ts +25 -4
|
@@ -1,12 +1,13 @@
|
|
|
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, 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';
|
|
6
|
+
import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
|
|
7
|
+
import { Router, ActivatedRoute } from '@angular/router';
|
|
6
8
|
import { DataSource } from '@angular/cdk/collections';
|
|
7
|
-
import { toObservable, takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
8
9
|
import { arrayEqual } from '@cngx/utils';
|
|
9
|
-
import { buildAsyncStateView, createTransitionTracker } from '@cngx/core/utils';
|
|
10
|
+
import { buildAsyncStateView, nextUid, createTransitionTracker } from '@cngx/core/utils';
|
|
10
11
|
import { isObservable, firstValueFrom, defer, tap, filter, map } from 'rxjs';
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -17,6 +18,11 @@ import { isObservable, firstValueFrom, defer, tap, filter, map } from 'rxjs';
|
|
|
17
18
|
* precedence over the internal state - pair with `sortChange` to keep them
|
|
18
19
|
* in sync.
|
|
19
20
|
*
|
|
21
|
+
* An uncontrolled sort may declare a **starting** column + direction via
|
|
22
|
+
* `[cngxSortInitial]`: it seeds the internal state exactly once on init, then
|
|
23
|
+
* user clicks take over. Distinct from the controlled `cngxSortActive` /
|
|
24
|
+
* `cngxSortDirection` pins - the seed is skipped when a controlled pin is bound.
|
|
25
|
+
*
|
|
20
26
|
* When `multiSort` is `true`, holding **Shift** while clicking a sort header
|
|
21
27
|
* adds it as a secondary (tertiary, …) sort key instead of replacing the
|
|
22
28
|
* primary one. Shift-clicking an active column cycles it asc → desc → removed.
|
|
@@ -35,9 +41,6 @@ import { isObservable, firstValueFrom, defer, tap, filter, map } from 'rxjs';
|
|
|
35
41
|
* <example-url>http://localhost:4200/#/common/data/sort/multi-sort</example-url>
|
|
36
42
|
* <example-url>http://localhost:4200/#/common/data/sort/controlled</example-url>
|
|
37
43
|
* <example-url>http://localhost:4200/#/common/data/sort/aria-and-keyboard</example-url>
|
|
38
|
-
// * <example-url>http://localhost:4200/#/common/data/smart-data-source/auto-wired</example-url>
|
|
39
|
-
// * <example-url>http://localhost:4200/#/common/data/smart-data-source/how-it-works-hostdirectives-inject</example-url>
|
|
40
|
-
// * <example-url>http://localhost:4200/#/common/data/smart-data-source/smartdatasource-cngxpaginate-hostdirective</example-url>
|
|
41
44
|
*/
|
|
42
45
|
class CngxSort {
|
|
43
46
|
/** Controlled active column. When bound, takes precedence over internal state (single-sort only). */
|
|
@@ -49,7 +52,25 @@ class CngxSort {
|
|
|
49
52
|
* replacing the current sort.
|
|
50
53
|
*/
|
|
51
54
|
multiSort = input(false, ...(ngDevMode ? [{ debugName: "multiSort" }] : /* istanbul ignore next */ []));
|
|
55
|
+
/**
|
|
56
|
+
* Uncontrolled starting sort. Seeds the internal state once on init if no sort
|
|
57
|
+
* is set yet and no controlled `cngxSortActive` pin is bound; user clicks own
|
|
58
|
+
* it thereafter. Ignored in controlled mode.
|
|
59
|
+
*/
|
|
60
|
+
initialSort = input(undefined, { ...(ngDevMode ? { debugName: "initialSort" } : /* istanbul ignore next */ {}), alias: 'cngxSortInitial' });
|
|
52
61
|
sortsState = signal([], ...(ngDevMode ? [{ debugName: "sortsState" }] : /* istanbul ignore next */ []));
|
|
62
|
+
constructor() {
|
|
63
|
+
// One-shot uncontrolled seed: not a reactive derivation, so afterNextRender
|
|
64
|
+
// (single-shot, outside the signal graph) rather than an effect. The empty +
|
|
65
|
+
// no-controlled-pin guards keep it from clobbering an early click or writing
|
|
66
|
+
// an invisible state that would surface when a controlled pin unbinds.
|
|
67
|
+
afterNextRender(() => {
|
|
68
|
+
const seed = this.initialSort();
|
|
69
|
+
if (seed && this.sortsState().length === 0 && this.activeInput() === undefined) {
|
|
70
|
+
this.sortsState.set([seed]);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
53
74
|
/** The active sort column of the primary entry (controlled takes precedence in single-sort mode). */
|
|
54
75
|
active = computed(() => this.activeInput() ?? this.sortsState()[0]?.active, ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
|
|
55
76
|
/** The active sort direction of the primary entry (controlled takes precedence in single-sort mode). */
|
|
@@ -77,7 +98,7 @@ class CngxSort {
|
|
|
77
98
|
* Sets or toggles the sort for `field`.
|
|
78
99
|
*
|
|
79
100
|
* **`additive = false`** (default, plain click):
|
|
80
|
-
* - Same field →
|
|
101
|
+
* - Same field → cycle `asc` → `desc` → cleared (a third click removes the sort)
|
|
81
102
|
* - Different field → replace stack with `{ field, asc }`
|
|
82
103
|
*
|
|
83
104
|
* **`additive = true`** (Shift+click when `multiSort` is enabled on the header):
|
|
@@ -105,11 +126,19 @@ class CngxSort {
|
|
|
105
126
|
}
|
|
106
127
|
else {
|
|
107
128
|
const current = this.sortsState();
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
129
|
+
if (field === current[0]?.active && current[0].direction === 'desc') {
|
|
130
|
+
// Third click on the active column: cycle desc -> cleared.
|
|
131
|
+
this.sortsState.set([]);
|
|
132
|
+
this.sortChange.emit(undefined);
|
|
133
|
+
this.sortsChange.emit([]);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const dir = field === current[0]?.active ? 'desc' : 'asc';
|
|
137
|
+
const entry = { active: field, direction: dir };
|
|
138
|
+
this.sortsState.set([entry]);
|
|
139
|
+
this.sortChange.emit(entry);
|
|
140
|
+
this.sortsChange.emit([entry]);
|
|
141
|
+
}
|
|
113
142
|
}
|
|
114
143
|
}
|
|
115
144
|
/** Clears all active sorts. Emits both `sortChange(undefined)` and `sortsChange([])`. */
|
|
@@ -119,7 +148,7 @@ class CngxSort {
|
|
|
119
148
|
this.sortsChange.emit([]);
|
|
120
149
|
}
|
|
121
150
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSort, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
122
|
-
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 });
|
|
151
|
+
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 });
|
|
123
152
|
}
|
|
124
153
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSort, decorators: [{
|
|
125
154
|
type: Directive,
|
|
@@ -128,7 +157,44 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
128
157
|
exportAs: 'cngxSort',
|
|
129
158
|
standalone: true,
|
|
130
159
|
}]
|
|
131
|
-
}], 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"] }] } });
|
|
160
|
+
}], 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"] }] } });
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Derives the shared sort-header state for one column from a {@link CngxSort} getter.
|
|
164
|
+
*
|
|
165
|
+
* Both {@link CngxSortHeader} (table context, `aria-sort`) and `CngxDgaSortHeader`
|
|
166
|
+
* (disclosure context, `role="button"` + `aria-describedby`) compose this factory
|
|
167
|
+
* and keep only their own a11y presentation. The factory is a11y-agnostic - it
|
|
168
|
+
* returns the plain derived signals each header maps to its own DOM/ARIA surface.
|
|
169
|
+
*
|
|
170
|
+
* @param sort Getter for the owning `CngxSort` engine (`() => sortRef`, `() => grid.sort`).
|
|
171
|
+
* @param field Getter for the column's field key.
|
|
172
|
+
* @returns The derived `{ entry, isActive, isAsc, isDesc, priority, toggle }` bundle.
|
|
173
|
+
*
|
|
174
|
+
* @category common/data/sort
|
|
175
|
+
* @since 0.1.0
|
|
176
|
+
* @relatedTo CngxSort, CngxSortHeader
|
|
177
|
+
*/
|
|
178
|
+
function createSortHeaderState(sort, field) {
|
|
179
|
+
const entry = computed(() => sort().sorts().find((s) => s.active === field()), ...(ngDevMode ? [{ debugName: "entry" }] : /* istanbul ignore next */ []));
|
|
180
|
+
const isActive = computed(() => entry() !== undefined, ...(ngDevMode ? [{ debugName: "isActive" }] : /* istanbul ignore next */ []));
|
|
181
|
+
const isAsc = computed(() => entry()?.direction === 'asc', ...(ngDevMode ? [{ debugName: "isAsc" }] : /* istanbul ignore next */ []));
|
|
182
|
+
const isDesc = computed(() => entry()?.direction === 'desc', ...(ngDevMode ? [{ debugName: "isDesc" }] : /* istanbul ignore next */ []));
|
|
183
|
+
const priority = computed(() => {
|
|
184
|
+
const idx = sort().sorts().findIndex((s) => s.active === field());
|
|
185
|
+
return idx === -1 ? 0 : idx + 1;
|
|
186
|
+
}, ...(ngDevMode ? [{ debugName: "priority" }] : /* istanbul ignore next */ []));
|
|
187
|
+
return {
|
|
188
|
+
entry,
|
|
189
|
+
isActive,
|
|
190
|
+
isAsc,
|
|
191
|
+
isDesc,
|
|
192
|
+
priority,
|
|
193
|
+
toggle(additive = false) {
|
|
194
|
+
sort().setSort(field(), additive && sort().multiSort());
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
132
198
|
|
|
133
199
|
/**
|
|
134
200
|
* Molecule directive for sort-header elements.
|
|
@@ -169,36 +235,28 @@ class CngxSortHeader {
|
|
|
169
235
|
field = input.required({ ...(ngDevMode ? { debugName: "field" } : /* istanbul ignore next */ {}), alias: 'cngxSortHeader' });
|
|
170
236
|
/** Explicit reference to the owning `CngxSort`. */
|
|
171
237
|
cngxSortRef = input.required(...(ngDevMode ? [{ debugName: "cngxSortRef" }] : /* istanbul ignore next */ []));
|
|
172
|
-
|
|
173
|
-
.sorts()
|
|
174
|
-
.find((s) => s.active === this.field()), ...(ngDevMode ? [{ debugName: "entry" }] : /* istanbul ignore next */ []));
|
|
238
|
+
state = createSortHeaderState(this.cngxSortRef, this.field);
|
|
175
239
|
/** `true` when this column is part of the active sort (primary or secondary). */
|
|
176
|
-
isActive =
|
|
240
|
+
isActive = this.state.isActive;
|
|
177
241
|
/** `true` when this column is active and sorted ascending. */
|
|
178
|
-
isAsc =
|
|
242
|
+
isAsc = this.state.isAsc;
|
|
179
243
|
/** `true` when this column is active and sorted descending. */
|
|
180
|
-
isDesc =
|
|
244
|
+
isDesc = this.state.isDesc;
|
|
181
245
|
/**
|
|
182
246
|
* 1-based position of this column in the sort stack.
|
|
183
247
|
* Returns `0` when the column is not part of the active sort.
|
|
184
248
|
* Only meaningful when `multiSort` is enabled on the owning `CngxSort`.
|
|
185
249
|
*/
|
|
186
|
-
priority =
|
|
187
|
-
const idx = this.cngxSortRef()
|
|
188
|
-
.sorts()
|
|
189
|
-
.findIndex((s) => s.active === this.field());
|
|
190
|
-
return idx === -1 ? 0 : idx + 1;
|
|
191
|
-
}, ...(ngDevMode ? [{ debugName: "priority" }] : /* istanbul ignore next */ []));
|
|
250
|
+
priority = this.state.priority;
|
|
192
251
|
/** The `aria-sort` attribute value for the host element. */
|
|
193
252
|
ariaSort = computed(() => {
|
|
194
|
-
if (!this.isActive()) {
|
|
253
|
+
if (!this.state.isActive()) {
|
|
195
254
|
return null;
|
|
196
255
|
}
|
|
197
|
-
return this.isAsc() ? 'ascending' : 'descending';
|
|
256
|
+
return this.state.isAsc() ? 'ascending' : 'descending';
|
|
198
257
|
}, ...(ngDevMode ? [{ debugName: "ariaSort" }] : /* istanbul ignore next */ []));
|
|
199
258
|
handleSort(event) {
|
|
200
|
-
|
|
201
|
-
this.cngxSortRef().setSort(this.field(), additive);
|
|
259
|
+
this.state.toggle(event?.shiftKey ?? false);
|
|
202
260
|
}
|
|
203
261
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSortHeader, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
204
262
|
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 });
|
|
@@ -602,22 +660,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
602
660
|
/**
|
|
603
661
|
* Atom directive that tracks pagination state (current page index and page size).
|
|
604
662
|
*
|
|
605
|
-
* Supports both **uncontrolled** (internal state) and **controlled** modes.
|
|
663
|
+
* Supports both **uncontrolled** (internal state) and **controlled** modes. \
|
|
606
664
|
* In controlled mode the `cngxPageIndex` / `cngxPageSize` inputs take precedence
|
|
607
|
-
* over internal state - pair with
|
|
665
|
+
* over internal state - pair with \
|
|
666
|
+
* `pageChange` / `pageSizeChange` to keep them
|
|
608
667
|
* in sync.
|
|
609
668
|
*
|
|
610
669
|
* Consumer connects this to a list or table via `range()` - nothing is injected
|
|
611
670
|
* automatically.
|
|
612
671
|
*
|
|
672
|
+
* ```
|
|
613
673
|
* // Headless: read range() from a template ref
|
|
614
674
|
* <div cngxPaginate #pg="cngxPaginate" [total]="items.length">
|
|
615
675
|
* @for (item of items.slice(pg.range()[0], pg.range()[1]); track item.id) { ... }
|
|
616
676
|
* </div>
|
|
617
677
|
*
|
|
618
|
-
* //
|
|
619
|
-
* <
|
|
620
|
-
*
|
|
678
|
+
* // Drive any UI off the brain - e.g. a Material paginator wired by hand:
|
|
679
|
+
* <mat-paginator
|
|
680
|
+
* [length]="pg.total()" [pageIndex]="pg.pageIndex()" [pageSize]="pg.pageSize()"
|
|
681
|
+
* (page)="pg.setPageSize($event.pageSize, false); pg.setPage($event.pageIndex)" />
|
|
682
|
+
* ```
|
|
621
683
|
* @category common/data/paginate
|
|
622
684
|
* @docsKind primary
|
|
623
685
|
* @wcag AA
|
|
@@ -626,11 +688,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
626
688
|
* @relatedTo CngxSort, CngxFilter, CngxSmartDataSource
|
|
627
689
|
*
|
|
628
690
|
* <example-url>http://localhost:4200/#/common/data/data-source/datasource-cngxpaginate-manual-pipeline</example-url>
|
|
629
|
-
* <example-url>http://localhost:4200/#/common/data/data-source/signal-observable-bridge</example-url>
|
|
630
691
|
* <example-url>http://localhost:4200/#/common/data/paginate-list/paginated-list-cngxpaginate-cngxmatpaginator</example-url>
|
|
631
692
|
* <example-url>http://localhost:4200/#/common/data/paginate-list/uncontrolled-mode-zero-class-boilerplate</example-url>
|
|
632
|
-
* <example-url>http://localhost:4200/#/common/data/smart-data-source/auto-wired</example-url>
|
|
633
|
-
* <example-url>http://localhost:4200/#/common/data/smart-data-source/how-it-works-hostdirectives-inject</example-url>
|
|
634
693
|
* <example-url>http://localhost:4200/#/common/data/smart-data-source/smartdatasource-cngxpaginate-hostdirective</example-url>
|
|
635
694
|
*/
|
|
636
695
|
class CngxPaginate {
|
|
@@ -674,7 +733,16 @@ class CngxPaginate {
|
|
|
674
733
|
range = computed(() => {
|
|
675
734
|
const start = this.pageIndex() * this.pageSize();
|
|
676
735
|
return [start, start + this.pageSize()];
|
|
677
|
-
}, ...(ngDevMode ?
|
|
736
|
+
}, { ...(ngDevMode ? { debugName: "range" } : /* istanbul ignore next */ {}), equal: (a, b) => a[0] === b[0] && a[1] === b[1] });
|
|
737
|
+
/**
|
|
738
|
+
* `[0, end]` cumulative slice indices for append-don't-replace (load-more)
|
|
739
|
+
* consumers: every page already stepped through, sliced from the top. `end`
|
|
740
|
+
* is `(pageIndex + 1) * pageSize` - the count revealed so far, uncapped (a
|
|
741
|
+
* partial final page is clamped by the consumer against `total`).
|
|
742
|
+
* Pure derivation of `pageIndex` / `pageSize`; the explicit tuple `equal`
|
|
743
|
+
* stops a fresh-array identity from cascading downstream.
|
|
744
|
+
*/
|
|
745
|
+
cumulativeRange = computed(() => [0, (this.pageIndex() + 1) * this.pageSize()], { ...(ngDevMode ? { debugName: "cumulativeRange" } : /* istanbul ignore next */ {}), equal: (a, b) => a[0] === b[0] && a[1] === b[1] });
|
|
678
746
|
/** Emitted when the page index changes. */
|
|
679
747
|
pageChange = output();
|
|
680
748
|
/** Emitted when the page size changes. */
|
|
@@ -734,6 +802,371 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
734
802
|
}]
|
|
735
803
|
}], propDecorators: { pageIndexInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPageIndex", required: false }] }], pageSizeInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPageSize", required: false }] }], total: [{ type: i0.Input, args: [{ isSignal: true, alias: "total", required: false }] }], state: [{ type: i0.Input, args: [{ isSignal: true, alias: "state", required: false }] }], pageChange: [{ type: i0.Output, args: ["pageChange"] }], pageSizeChange: [{ type: i0.Output, args: ["pageSizeChange"] }] } });
|
|
736
804
|
|
|
805
|
+
/**
|
|
806
|
+
* Wires the reset-on-change behaviour onto a {@link CngxPaginate} brain: when
|
|
807
|
+
* `key()` changes (after the initial run) the paginator jumps to the first
|
|
808
|
+
* page. The first run captures the mounting value without resetting, and an
|
|
809
|
+
* already-first paginator emits nothing.
|
|
810
|
+
*
|
|
811
|
+
* Shared by `[cngxPaginateResetOn]`, the `CngxPaginator` shell's `resetOn`
|
|
812
|
+
* input, and the `CngxMatPaginator` bridge's `resetOn` input, so the behaviour
|
|
813
|
+
* is byte-identical across all three. Call inside an injection context
|
|
814
|
+
* (constructor or field initialiser).
|
|
815
|
+
*
|
|
816
|
+
* @category common/data/paginate
|
|
817
|
+
* @since 0.1.0
|
|
818
|
+
*/
|
|
819
|
+
function connectPaginateResetOn(paginate, key) {
|
|
820
|
+
let seen = false;
|
|
821
|
+
effect(() => {
|
|
822
|
+
key();
|
|
823
|
+
if (!seen) {
|
|
824
|
+
seen = true;
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
untracked(() => {
|
|
828
|
+
if (paginate.pageIndex() !== 0) {
|
|
829
|
+
paginate.setPage(0);
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Resets a `cngxPaginate` host to the first page whenever the bound key
|
|
836
|
+
* changes - the composable form of {@link connectPaginateResetOn}. \
|
|
837
|
+
* Drop it on the same element as `cngxPaginate` (or a `CngxPaginator` / `CngxMatPaginator`,
|
|
838
|
+
* which provide the brain), and bind the sort / filter / search value a result
|
|
839
|
+
* set depends on, so a narrowed result never strands the user on a now-empty
|
|
840
|
+
* page.
|
|
841
|
+
*
|
|
842
|
+
* Bind a primitive or a `computed` - an inline array / object literal recomputes
|
|
843
|
+
* every change-detection pass and would reset on each.
|
|
844
|
+
*
|
|
845
|
+
* ```html
|
|
846
|
+
* <table cngxPaginate [cngxPaginateResetOn]="filter()"><!-- ... --></table>
|
|
847
|
+
* ```
|
|
848
|
+
* <example-url>http://localhost:4200/#/ui/paginator/paginator-behaviors/reset-on-filter</example-url>
|
|
849
|
+
*
|
|
850
|
+
* @category common/data/paginate
|
|
851
|
+
* @docsKind primary
|
|
852
|
+
* @wcag AA
|
|
853
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/paginate/paginate-reset.directive.ts
|
|
854
|
+
* @since 0.1.0
|
|
855
|
+
* @relatedTo CngxPaginate, CngxPaginator, CngxMatPaginator
|
|
856
|
+
*/
|
|
857
|
+
class CngxPaginateResetOn {
|
|
858
|
+
paginate = inject(CngxPaginate);
|
|
859
|
+
/** The reset key. A change (after mount) jumps the paginator to page 0. */
|
|
860
|
+
key = input(undefined, { ...(ngDevMode ? { debugName: "key" } : /* istanbul ignore next */ {}), alias: 'cngxPaginateResetOn' });
|
|
861
|
+
constructor() {
|
|
862
|
+
connectPaginateResetOn(this.paginate, this.key);
|
|
863
|
+
}
|
|
864
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPaginateResetOn, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
865
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxPaginateResetOn, isStandalone: true, selector: "[cngxPaginateResetOn]", inputs: { key: { classPropertyName: "key", publicName: "cngxPaginateResetOn", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxPaginateResetOn"], ngImport: i0 });
|
|
866
|
+
}
|
|
867
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPaginateResetOn, decorators: [{
|
|
868
|
+
type: Directive,
|
|
869
|
+
args: [{
|
|
870
|
+
selector: '[cngxPaginateResetOn]',
|
|
871
|
+
exportAs: 'cngxPaginateResetOn',
|
|
872
|
+
standalone: true,
|
|
873
|
+
}]
|
|
874
|
+
}], ctorParameters: () => [], propDecorators: { key: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPaginateResetOn", required: false }] }] } });
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* Wires the {@link CngxPaginate} brain's page / page-size changes onto a host's
|
|
878
|
+
* two-way outputs with exactly-once emit semantics. Two paths feed each handler,
|
|
879
|
+
* sharing a last-emitted guard:
|
|
880
|
+
* - a subscription forwards the brain's nav-only `pageChange` / `pageSizeChange`
|
|
881
|
+
* - the only signal that captures a controlled-mode `setPage`, because the
|
|
882
|
+
* brain's `pageIndex()` stays pinned to the input until the consumer feeds it
|
|
883
|
+
* back;
|
|
884
|
+
* - an `effect()` reads the effective `pageIndex()` / `pageSize()` and covers a
|
|
885
|
+
* `total`-shrink clamp the nav-only output misses.
|
|
886
|
+
*
|
|
887
|
+
* The shared guard makes a value one path already emitted a no-op on the other,
|
|
888
|
+
* so each change emits exactly once. Seeded with the current effective values,
|
|
889
|
+
* so wiring emits no initial change.
|
|
890
|
+
*
|
|
891
|
+
* Shared verbatim by the `CngxPaginator` shell and the `CngxIncrementalList`
|
|
892
|
+
* organism, so the two-way emit behaviour is byte-identical. Call inside an
|
|
893
|
+
* injection context (constructor or field initialiser) - it reads `DestroyRef`
|
|
894
|
+
* and creates effects.
|
|
895
|
+
*
|
|
896
|
+
* @category common/data/paginate
|
|
897
|
+
* @since 0.1.0
|
|
898
|
+
*/
|
|
899
|
+
function connectPaginateEmit(paginate, handlers) {
|
|
900
|
+
const destroyRef = inject(DestroyRef);
|
|
901
|
+
// Shared last-emitted guards across the nav (subscription) and clamp (effect)
|
|
902
|
+
// paths. Plain locals, so the effects carry no signal write. Seeded with the
|
|
903
|
+
// current effective values so wiring emits no initial change.
|
|
904
|
+
let lastIndex = paginate.pageIndex();
|
|
905
|
+
let lastSize = paginate.pageSize();
|
|
906
|
+
// Nav path. Forwards the brain's nav-only outputs: in controlled mode a
|
|
907
|
+
// setPage leaves the effective pageIndex() pinned to the input, so this event
|
|
908
|
+
// is the only thing that reports the navigation.
|
|
909
|
+
const indexSub = paginate.pageChange.subscribe((index) => {
|
|
910
|
+
if (index !== lastIndex) {
|
|
911
|
+
lastIndex = index;
|
|
912
|
+
handlers.onIndex(index);
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
const sizeSub = paginate.pageSizeChange.subscribe((size) => {
|
|
916
|
+
if (size !== lastSize) {
|
|
917
|
+
lastSize = size;
|
|
918
|
+
handlers.onSize(size);
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
destroyRef.onDestroy(() => {
|
|
922
|
+
indexSub.unsubscribe();
|
|
923
|
+
sizeSub.unsubscribe();
|
|
924
|
+
});
|
|
925
|
+
// Clamp path. The effective pageIndex moved without a nav (a total-shrink
|
|
926
|
+
// clamp the nav-only pageChange misses). The shared guard means a value the
|
|
927
|
+
// nav path already emitted is a no-op here, so each change emits once.
|
|
928
|
+
effect(() => {
|
|
929
|
+
const index = paginate.pageIndex();
|
|
930
|
+
if (index !== lastIndex) {
|
|
931
|
+
lastIndex = index;
|
|
932
|
+
handlers.onIndex(index);
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
effect(() => {
|
|
936
|
+
const size = paginate.pageSize();
|
|
937
|
+
if (size !== lastSize) {
|
|
938
|
+
lastSize = size;
|
|
939
|
+
handlers.onSize(size);
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Persists a `cngxPaginate` host's page / size in the URL query string, so a
|
|
946
|
+
* paginated view is deep-linkable and survives reload / back / forward.
|
|
947
|
+
*
|
|
948
|
+
* Drop it on the same element as `cngxPaginate` (or a `CngxPaginator` /
|
|
949
|
+
* `CngxMatPaginator`, which provide the brain). The page is written 1-based
|
|
950
|
+
* (`?page=2`) for human-readable URLs; the brain stays 0-based.
|
|
951
|
+
*
|
|
952
|
+
* ```html
|
|
953
|
+
* <cngx-paginator cngxPaginateRouting [total]="items().length"></cngx-paginator>
|
|
954
|
+
* ```
|
|
955
|
+
*
|
|
956
|
+
* Two paginators on one route must take distinct param names via
|
|
957
|
+
* `[cngxPaginatePageParam]` / `[cngxPaginateSizeParam]` to avoid a collision. \
|
|
958
|
+
* Requires `@angular/router` (`provideRouter`); without it the directive is an
|
|
959
|
+
* inert no-op (a dev-mode warning is logged). Framework-agnostic of any UI - it
|
|
960
|
+
* needs only the brain and the router.
|
|
961
|
+
*
|
|
962
|
+
* @category common/data/paginate
|
|
963
|
+
* @docsKind primary
|
|
964
|
+
* @wcag AA
|
|
965
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/paginate/paginate-routing.directive.ts
|
|
966
|
+
* @since 0.1.0
|
|
967
|
+
* @relatedTo CngxPaginate, CngxPaginator, CngxMatPaginator
|
|
968
|
+
* <example-url>http://localhost:4200/#/ui/paginator/paginator-behaviors/url-synced-paging</example-url>
|
|
969
|
+
*/
|
|
970
|
+
class CngxPaginateRouting {
|
|
971
|
+
paginate = inject(CngxPaginate);
|
|
972
|
+
router = inject(Router, { optional: true });
|
|
973
|
+
route = inject(ActivatedRoute, { optional: true });
|
|
974
|
+
destroyRef = inject(DestroyRef);
|
|
975
|
+
/** Query-param name for the 1-based page. */
|
|
976
|
+
pageParam = input('page', { ...(ngDevMode ? { debugName: "pageParam" } : /* istanbul ignore next */ {}), alias: 'cngxPaginatePageParam' });
|
|
977
|
+
/** Query-param name for the page size. */
|
|
978
|
+
sizeParam = input('pageSize', { ...(ngDevMode ? { debugName: "sizeParam" } : /* istanbul ignore next */ {}), alias: 'cngxPaginateSizeParam' });
|
|
979
|
+
// Set while applying a URL change to the brain, so the brain -> URL effect
|
|
980
|
+
// does not bounce the same value straight back as a redundant navigation.
|
|
981
|
+
applyingFromUrl = false;
|
|
982
|
+
constructor() {
|
|
983
|
+
const router = this.router;
|
|
984
|
+
const route = this.route;
|
|
985
|
+
if (!router || !route) {
|
|
986
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
987
|
+
console.warn('[cngxPaginateRouting]: no Router available - directive is a no-op. ' +
|
|
988
|
+
'Provide @angular/router via provideRouter(...) to enable URL-synced pagination.');
|
|
989
|
+
}
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
// brain -> URL. Tracks the effective page / size; merges into the existing
|
|
993
|
+
// query string and replaces history so paging does not stack back entries.
|
|
994
|
+
// The param-name inputs are read lazily inside untracked, so a late-bound
|
|
995
|
+
// alias is already set by the time the first navigation fires.
|
|
996
|
+
effect(() => {
|
|
997
|
+
const page = this.paginate.pageIndex() + 1;
|
|
998
|
+
const size = this.paginate.pageSize();
|
|
999
|
+
if (this.applyingFromUrl) {
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
untracked(() => {
|
|
1003
|
+
void router.navigate([], {
|
|
1004
|
+
relativeTo: route,
|
|
1005
|
+
queryParams: { [this.pageParam()]: page, [this.sizeParam()]: size },
|
|
1006
|
+
queryParamsHandling: 'merge',
|
|
1007
|
+
replaceUrl: true,
|
|
1008
|
+
});
|
|
1009
|
+
});
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
ngOnInit() {
|
|
1013
|
+
const route = this.route;
|
|
1014
|
+
if (!route) {
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
// URL -> brain, wired in ngOnInit so the param-name inputs are resolved
|
|
1018
|
+
// before queryParamMap replays the current params on subscribe (a
|
|
1019
|
+
// deep-linked page / size therefore lands before first paint). The
|
|
1020
|
+
// subscription stays live for back / forward navigation.
|
|
1021
|
+
route.queryParamMap.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((params) => {
|
|
1022
|
+
const size = Number(params.get(this.sizeParam()));
|
|
1023
|
+
const page = Number(params.get(this.pageParam()));
|
|
1024
|
+
this.applyingFromUrl = true;
|
|
1025
|
+
try {
|
|
1026
|
+
if (Number.isFinite(size) && size > 0 && size !== this.paginate.pageSize()) {
|
|
1027
|
+
this.paginate.setPageSize(size, false);
|
|
1028
|
+
}
|
|
1029
|
+
const index = (Number.isFinite(page) && page > 0 ? page : 1) - 1;
|
|
1030
|
+
if (index !== this.paginate.pageIndex()) {
|
|
1031
|
+
this.paginate.setPage(index);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
finally {
|
|
1035
|
+
this.applyingFromUrl = false;
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPaginateRouting, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1040
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxPaginateRouting, isStandalone: true, selector: "[cngxPaginateRouting]", inputs: { pageParam: { classPropertyName: "pageParam", publicName: "cngxPaginatePageParam", isSignal: true, isRequired: false, transformFunction: null }, sizeParam: { classPropertyName: "sizeParam", publicName: "cngxPaginateSizeParam", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxPaginateRouting"], ngImport: i0 });
|
|
1041
|
+
}
|
|
1042
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPaginateRouting, decorators: [{
|
|
1043
|
+
type: Directive,
|
|
1044
|
+
args: [{
|
|
1045
|
+
selector: '[cngxPaginateRouting]',
|
|
1046
|
+
exportAs: 'cngxPaginateRouting',
|
|
1047
|
+
standalone: true,
|
|
1048
|
+
}]
|
|
1049
|
+
}], ctorParameters: () => [], propDecorators: { pageParam: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPaginatePageParam", required: false }] }], sizeParam: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPaginateSizeParam", required: false }] }] } });
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* DI token the `CngxBucketPaginate` range model provides via `useExisting`.
|
|
1053
|
+
* The category chips segment (`cngx-pgn-alpha`) injects this rather than the
|
|
1054
|
+
* concrete directive class, keeping the strip decompose-ready and the model
|
|
1055
|
+
* swappable.
|
|
1056
|
+
*
|
|
1057
|
+
* @category common/data/paginate
|
|
1058
|
+
* @wcag AA
|
|
1059
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/paginate/bucket-paginate-host.token.ts
|
|
1060
|
+
* @since 0.1.0
|
|
1061
|
+
*/
|
|
1062
|
+
const CNGX_BUCKET_PAGINATE_HOST = new InjectionToken('CngxBucketPaginateHost');
|
|
1063
|
+
|
|
1064
|
+
/** Two `ReadonlySet`s are equal when they hold the same members. */
|
|
1065
|
+
function setEquals(a, b) {
|
|
1066
|
+
if (a.size !== b.size) {
|
|
1067
|
+
return false;
|
|
1068
|
+
}
|
|
1069
|
+
for (const value of a) {
|
|
1070
|
+
if (!b.has(value)) {
|
|
1071
|
+
return false;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
return true;
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Range/category pagination model - a sibling to {@link CngxPaginate}, NOT a
|
|
1078
|
+
* mode flag on it. Where `CngxPaginate` steps a page index over a slice window,
|
|
1079
|
+
* this directive partitions a collection into labelled buckets (letter ranges,
|
|
1080
|
+
* date bands, price tiers) and tracks which one is active. The page-index brain
|
|
1081
|
+
* stays single-responsibility; a consumer composes whichever model the data
|
|
1082
|
+
* calls for (Komposition statt Konfiguration).
|
|
1083
|
+
*
|
|
1084
|
+
* The empty/disabled state of every bucket is **derived**, never managed: a
|
|
1085
|
+
* bucket is empty when no bound item matches its predicate, computed from the
|
|
1086
|
+
* `items` / `buckets` inputs. There is no synced flag and no effect.
|
|
1087
|
+
*
|
|
1088
|
+
* `active` is the two-way primary value (a `model<string | null>()`):
|
|
1089
|
+
* `null` shows the unfiltered collection; a label filters to that bucket.
|
|
1090
|
+
* `select(label)` toggles - re-selecting the active bucket clears it.
|
|
1091
|
+
*
|
|
1092
|
+
* ```html
|
|
1093
|
+
* <div
|
|
1094
|
+
* cngxBucketPaginate
|
|
1095
|
+
* #bp="cngxBucketPaginate"
|
|
1096
|
+
* [buckets]="letterBuckets"
|
|
1097
|
+
* [items]="people"
|
|
1098
|
+
* [(active)]="activeBucket"
|
|
1099
|
+
* >
|
|
1100
|
+
* @for (p of bp.active() ? people.filter(byActiveBucket) : people; track p.id) { ... }
|
|
1101
|
+
* </div>
|
|
1102
|
+
* ```
|
|
1103
|
+
*
|
|
1104
|
+
* @category common/data/paginate
|
|
1105
|
+
* @docsKind primary
|
|
1106
|
+
* @wcag AA
|
|
1107
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/paginate/bucket-paginate.directive.ts
|
|
1108
|
+
* @since 0.1.0
|
|
1109
|
+
* @relatedTo CngxPaginate, CngxFilter
|
|
1110
|
+
* <example-url>http://localhost:4200/#/ui/paginator/paginator-modes/alphabetical</example-url>
|
|
1111
|
+
*/
|
|
1112
|
+
class CngxBucketPaginate {
|
|
1113
|
+
/** The buckets to partition into, in render order. One chip per entry. */
|
|
1114
|
+
buckets = input([], ...(ngDevMode ? [{ debugName: "buckets" }] : /* istanbul ignore next */ []));
|
|
1115
|
+
/** The collection the buckets test against. Drives the derived empty state. */
|
|
1116
|
+
items = input([], ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
|
|
1117
|
+
/**
|
|
1118
|
+
* Active bucket label, or `null` for the unfiltered collection. The two-way
|
|
1119
|
+
* primary value (`[(active)]`); a `model()` because it is the directive's
|
|
1120
|
+
* bindable state, not a derived read.
|
|
1121
|
+
*/
|
|
1122
|
+
active = model(null, ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
|
|
1123
|
+
/**
|
|
1124
|
+
* Labels of every bucket whose predicate matches no bound item. A pure
|
|
1125
|
+
* `computed()` over `items` / `buckets` - the disabled chips read this, so
|
|
1126
|
+
* the empty state is derived, never synced. The explicit set `equal` stops a
|
|
1127
|
+
* fresh-`Set` identity from cascading downstream on every unrelated recompute.
|
|
1128
|
+
*/
|
|
1129
|
+
emptyLabels = computed(() => {
|
|
1130
|
+
const items = this.items();
|
|
1131
|
+
const empties = new Set();
|
|
1132
|
+
for (const bucket of this.buckets()) {
|
|
1133
|
+
if (!items.some((item) => bucket.match(item))) {
|
|
1134
|
+
empties.add(bucket.label);
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
return empties;
|
|
1138
|
+
}, { ...(ngDevMode ? { debugName: "emptyLabels" } : /* istanbul ignore next */ {}), equal: setEquals });
|
|
1139
|
+
/** `true` when no bound item falls into the bucket. */
|
|
1140
|
+
isEmpty(label) {
|
|
1141
|
+
return this.emptyLabels().has(label);
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Select the bucket, or clear the selection when it is already active
|
|
1145
|
+
* (toggle). An empty bucket is a no-op - it never becomes the active filter.
|
|
1146
|
+
*/
|
|
1147
|
+
select(label) {
|
|
1148
|
+
if (this.isEmpty(label)) {
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
this.active.update((current) => (current === label ? null : label));
|
|
1152
|
+
}
|
|
1153
|
+
/** Clear the active bucket - show the unfiltered collection. */
|
|
1154
|
+
clear() {
|
|
1155
|
+
this.active.set(null);
|
|
1156
|
+
}
|
|
1157
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBucketPaginate, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1158
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxBucketPaginate, isStandalone: true, selector: "[cngxBucketPaginate]", inputs: { buckets: { classPropertyName: "buckets", publicName: "buckets", isSignal: true, isRequired: false, transformFunction: null }, items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, active: { classPropertyName: "active", publicName: "active", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { active: "activeChange" }, providers: [{ provide: CNGX_BUCKET_PAGINATE_HOST, useExisting: CngxBucketPaginate }], exportAs: ["cngxBucketPaginate"], ngImport: i0 });
|
|
1159
|
+
}
|
|
1160
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBucketPaginate, decorators: [{
|
|
1161
|
+
type: Directive,
|
|
1162
|
+
args: [{
|
|
1163
|
+
selector: '[cngxBucketPaginate]',
|
|
1164
|
+
exportAs: 'cngxBucketPaginate',
|
|
1165
|
+
standalone: true,
|
|
1166
|
+
providers: [{ provide: CNGX_BUCKET_PAGINATE_HOST, useExisting: CngxBucketPaginate }],
|
|
1167
|
+
}]
|
|
1168
|
+
}], propDecorators: { buckets: [{ type: i0.Input, args: [{ isSignal: true, alias: "buckets", required: false }] }], items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], active: [{ type: i0.Input, args: [{ isSignal: true, alias: "active", required: false }] }, { type: i0.Output, args: ["activeChange"] }] } });
|
|
1169
|
+
|
|
737
1170
|
/**
|
|
738
1171
|
* Minimal CDK `DataSource` that bridges a Signal to the CDK table's
|
|
739
1172
|
* Observable-based data contract.
|
|
@@ -1768,26 +2201,83 @@ class CngxMetric {
|
|
|
1768
2201
|
return u ? `${v} ${u}` : v;
|
|
1769
2202
|
}, ...(ngDevMode ? [{ debugName: "accessibleValue" }] : /* istanbul ignore next */ []));
|
|
1770
2203
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMetric, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1771
|
-
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: `
|
|
2204
|
+
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: `
|
|
1772
2205
|
<span class="cngx-metric__value">{{ formattedValue() }}</span>
|
|
1773
2206
|
@if (unit()) {
|
|
1774
2207
|
<span class="cngx-metric__unit">{{ unit() }}</span>
|
|
1775
2208
|
}
|
|
1776
|
-
`, 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 });
|
|
2209
|
+
`, 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 });
|
|
1777
2210
|
}
|
|
1778
2211
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMetric, decorators: [{
|
|
1779
2212
|
type: Component,
|
|
1780
2213
|
args: [{ selector: 'cngx-metric', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
1781
2214
|
class: 'cngx-metric',
|
|
2215
|
+
// role=img makes the host a single labelled graphic so AT announces the
|
|
2216
|
+
// curated `aria-label` (value + unit) instead of the raw text on an
|
|
2217
|
+
// otherwise role=generic custom element, where aria-label is unreliably
|
|
2218
|
+
// exposed. Mirrors CngxDelta / CngxTrend.
|
|
2219
|
+
role: 'img',
|
|
1782
2220
|
'[attr.aria-label]': 'accessibleValue()',
|
|
1783
2221
|
}, template: `
|
|
1784
2222
|
<span class="cngx-metric__value">{{ formattedValue() }}</span>
|
|
1785
2223
|
@if (unit()) {
|
|
1786
2224
|
<span class="cngx-metric__unit">{{ unit() }}</span>
|
|
1787
2225
|
}
|
|
1788
|
-
`, 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"] }]
|
|
2226
|
+
`, 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"] }]
|
|
1789
2227
|
}], 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 }] }] } });
|
|
1790
2228
|
|
|
2229
|
+
/**
|
|
2230
|
+
* Pure, framework-agnostic helpers that turn a signed delta value into the
|
|
2231
|
+
* three orthogonal signals a KPI atom renders: **direction** (which way the
|
|
2232
|
+
* arrow points), **sentiment** (whether the change is good or bad, which
|
|
2233
|
+
* drives colour and the SR word), and the formatted magnitude.
|
|
2234
|
+
*
|
|
2235
|
+
* Direction and sentiment are deliberately separate. `CngxTrend` colours by
|
|
2236
|
+
* direction (up = green); `CngxDelta` colours by sentiment, so a value that
|
|
2237
|
+
* dropped can still read as an improvement (churn down, latency down). Both
|
|
2238
|
+
* consume these helpers so the direction / glyph / format logic has a single
|
|
2239
|
+
* source of truth (Pillar 1) with no Angular dependency.
|
|
2240
|
+
*/
|
|
2241
|
+
/** `> 0 → up`, `< 0 → down`, `0 → flat`. */
|
|
2242
|
+
function deltaDirection(value) {
|
|
2243
|
+
return value > 0 ? 'up' : value < 0 ? 'down' : 'flat';
|
|
2244
|
+
}
|
|
2245
|
+
/**
|
|
2246
|
+
* Combine movement with the caller's polarity. `flat` or `neutral` polarity
|
|
2247
|
+
* collapse to `neutral`; otherwise up is positive under `higher-is-better`
|
|
2248
|
+
* and negative under `lower-is-better` (and the reverse for down).
|
|
2249
|
+
*/
|
|
2250
|
+
function deltaSentiment(direction, polarity) {
|
|
2251
|
+
if (direction === 'flat' || polarity === 'neutral') {
|
|
2252
|
+
return 'neutral';
|
|
2253
|
+
}
|
|
2254
|
+
const upIsGood = polarity === 'higher-is-better';
|
|
2255
|
+
const isGood = direction === 'up' ? upIsGood : !upIsGood;
|
|
2256
|
+
return isGood ? 'positive' : 'negative';
|
|
2257
|
+
}
|
|
2258
|
+
/** Arrow glyph for the direction: `↑` / `↓` / `→`. */
|
|
2259
|
+
function directionGlyph(direction) {
|
|
2260
|
+
return direction === 'up' ? '↑' : direction === 'down' ? '↓' : '→';
|
|
2261
|
+
}
|
|
2262
|
+
/**
|
|
2263
|
+
* Format the magnitude. The sign is carried by the arrow and colour, not the
|
|
2264
|
+
* digits: a positive value gains a leading `+`, everything else prints its
|
|
2265
|
+
* absolute value unsigned. Percent mode appends a narrow-no-break-space + `%`
|
|
2266
|
+
* and defaults to one fraction digit; absolute mode uses the locale grouping.
|
|
2267
|
+
* A supplied `Intl.NumberFormatOptions` overrides the default digit handling
|
|
2268
|
+
* in both modes.
|
|
2269
|
+
*/
|
|
2270
|
+
function formatDelta(value, mode, locale, format) {
|
|
2271
|
+
const abs = Math.abs(value);
|
|
2272
|
+
const prefix = value > 0 ? '+' : '';
|
|
2273
|
+
if (mode === 'percent') {
|
|
2274
|
+
const num = format ? new Intl.NumberFormat(locale, format).format(abs) : abs.toFixed(1);
|
|
2275
|
+
return `${prefix}${num}\u202f%`;
|
|
2276
|
+
}
|
|
2277
|
+
const num = format ? new Intl.NumberFormat(locale, format).format(abs) : abs.toLocaleString(locale);
|
|
2278
|
+
return `${prefix}${num}`;
|
|
2279
|
+
}
|
|
2280
|
+
|
|
1791
2281
|
/**
|
|
1792
2282
|
* Displays a trend indicator with directional arrow and formatted percentage.
|
|
1793
2283
|
*
|
|
@@ -1826,45 +2316,494 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1826
2316
|
* <example-url>http://localhost:4200/#/common/data/trend/trend-directions</example-url>
|
|
1827
2317
|
*/
|
|
1828
2318
|
class CngxTrend {
|
|
2319
|
+
locale = inject(LOCALE_ID);
|
|
1829
2320
|
/** Trend percentage. Positive = up, negative = down, zero = flat. */
|
|
1830
2321
|
value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
1831
2322
|
/** Consumer-provided SR label override. When set, replaces the generated default. */
|
|
1832
2323
|
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
1833
2324
|
/** @internal */
|
|
1834
|
-
icon = computed(() =>
|
|
2325
|
+
icon = computed(() => directionGlyph(deltaDirection(this.value())), ...(ngDevMode ? [{ debugName: "icon" }] : /* istanbul ignore next */ []));
|
|
1835
2326
|
/** @internal */
|
|
1836
|
-
formattedValue = computed(() => {
|
|
1837
|
-
const v = this.value();
|
|
1838
|
-
const abs = Math.abs(v);
|
|
1839
|
-
return `${v > 0 ? '+' : ''}${abs.toFixed(1)}\u202F%`;
|
|
1840
|
-
}, ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
2327
|
+
formattedValue = computed(() => formatDelta(this.value(), 'percent', this.locale), ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
1841
2328
|
/** @internal */
|
|
1842
2329
|
resolvedLabel = computed(() => {
|
|
1843
2330
|
if (this.label()) {
|
|
1844
2331
|
return this.label();
|
|
1845
2332
|
}
|
|
1846
|
-
const
|
|
2333
|
+
const direction = deltaDirection(this.value());
|
|
2334
|
+
const dir = direction === 'up' ? 'up' : direction === 'down' ? 'down' : 'unchanged';
|
|
1847
2335
|
return `${this.formattedValue()} ${dir}`;
|
|
1848
2336
|
}, ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
|
|
1849
2337
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTrend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1850
|
-
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: `
|
|
2338
|
+
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: `
|
|
1851
2339
|
<span aria-hidden="true">{{ icon() }}</span>
|
|
1852
2340
|
{{ formattedValue() }}
|
|
1853
|
-
`, 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 });
|
|
2341
|
+
`, 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 });
|
|
1854
2342
|
}
|
|
1855
2343
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTrend, decorators: [{
|
|
1856
2344
|
type: Component,
|
|
1857
2345
|
args: [{ selector: 'cngx-trend', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
1858
2346
|
class: 'cngx-trend',
|
|
2347
|
+
// role=img makes the host a single labelled graphic so AT announces the
|
|
2348
|
+
// curated `aria-label` instead of the raw glyph text on an otherwise
|
|
2349
|
+
// role=generic custom element, where aria-label is unreliably exposed.
|
|
2350
|
+
role: 'img',
|
|
1859
2351
|
'[class.cngx-trend--up]': 'value() > 0',
|
|
1860
2352
|
'[class.cngx-trend--down]': 'value() < 0',
|
|
1861
2353
|
'[attr.aria-label]': 'resolvedLabel()',
|
|
1862
2354
|
}, template: `
|
|
1863
2355
|
<span aria-hidden="true">{{ icon() }}</span>
|
|
1864
2356
|
{{ formattedValue() }}
|
|
1865
|
-
`, 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"] }]
|
|
2357
|
+
`, 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"] }]
|
|
1866
2358
|
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }] } });
|
|
1867
2359
|
|
|
2360
|
+
const SENTIMENT_WORD = {
|
|
2361
|
+
positive: 'improved',
|
|
2362
|
+
negative: 'declined',
|
|
2363
|
+
neutral: 'unchanged',
|
|
2364
|
+
};
|
|
2365
|
+
/**
|
|
2366
|
+
* Sentiment-aware delta indicator. Where `CngxTrend` colours strictly by
|
|
2367
|
+
* direction (up = green), `CngxDelta` colours by **sentiment**: a `polarity`
|
|
2368
|
+
* of `lower-is-better` makes a drop read as an improvement (churn, latency,
|
|
2369
|
+
* error rate). The arrow glyph always tracks the raw direction, so colour is
|
|
2370
|
+
* never the only signal - a green value can carry a down arrow, and the SR
|
|
2371
|
+
* label speaks the sentiment word.
|
|
2372
|
+
*
|
|
2373
|
+
* Sentiment, direction, glyph and the formatted magnitude are each a
|
|
2374
|
+
* `computed()` off the single `value`/`polarity` input pair (Pillar 1); the
|
|
2375
|
+
* colour class and the arrow are bound from independent signals so they can
|
|
2376
|
+
* diverge (Pillar 2).
|
|
2377
|
+
*
|
|
2378
|
+
* ### Basic (higher-is-better default)
|
|
2379
|
+
* ```html
|
|
2380
|
+
* <cngx-delta [value]="5.3" />
|
|
2381
|
+
* ```
|
|
2382
|
+
*
|
|
2383
|
+
* ### Lower-is-better (a drop is good)
|
|
2384
|
+
* ```html
|
|
2385
|
+
* <cngx-delta [value]="-2.1" polarity="lower-is-better" />
|
|
2386
|
+
* ```
|
|
2387
|
+
*
|
|
2388
|
+
* ### Absolute magnitude
|
|
2389
|
+
* ```html
|
|
2390
|
+
* <cngx-delta [value]="1240" mode="absolute" [format]="{ maximumFractionDigits: 0 }" />
|
|
2391
|
+
* ```
|
|
2392
|
+
*
|
|
2393
|
+
* @category common/data/metric
|
|
2394
|
+
* @docsKind primary
|
|
2395
|
+
* @wcag AA
|
|
2396
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/display/delta/delta.component.ts
|
|
2397
|
+
* @since 0.1.0
|
|
2398
|
+
* @relatedTo CngxTrend, CngxMetric, CngxStat
|
|
2399
|
+
*
|
|
2400
|
+
* <example-url>http://localhost:4200/#/common/data/delta/sentiment-polarity</example-url>
|
|
2401
|
+
*/
|
|
2402
|
+
class CngxDelta {
|
|
2403
|
+
locale = inject(LOCALE_ID);
|
|
2404
|
+
/** Signed delta. Positive = up, negative = down, zero = flat. */
|
|
2405
|
+
value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
2406
|
+
/**
|
|
2407
|
+
* How to read the sign. `higher-is-better` (default) treats a rise as
|
|
2408
|
+
* positive; `lower-is-better` inverts it; `neutral` disables sentiment
|
|
2409
|
+
* (direction still renders, colour stays neutral).
|
|
2410
|
+
*/
|
|
2411
|
+
polarity = input('higher-is-better', ...(ngDevMode ? [{ debugName: "polarity" }] : /* istanbul ignore next */ []));
|
|
2412
|
+
/** `percent` (default, one fraction digit + `%`) or `absolute`. */
|
|
2413
|
+
mode = input('percent', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
2414
|
+
/** `Intl.NumberFormatOptions` applied to the magnitude in either mode. */
|
|
2415
|
+
format = input(undefined, ...(ngDevMode ? [{ debugName: "format" }] : /* istanbul ignore next */ []));
|
|
2416
|
+
/** Consumer-provided SR label override. Replaces the generated default. */
|
|
2417
|
+
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
2418
|
+
/** @internal Raw movement, independent of polarity. Drives the glyph. */
|
|
2419
|
+
direction = computed(() => deltaDirection(this.value()), ...(ngDevMode ? [{ debugName: "direction" }] : /* istanbul ignore next */ []));
|
|
2420
|
+
/** @internal Good / bad / indifferent. Drives colour and the SR word. */
|
|
2421
|
+
sentiment = computed(() => deltaSentiment(this.direction(), this.polarity()), ...(ngDevMode ? [{ debugName: "sentiment" }] : /* istanbul ignore next */ []));
|
|
2422
|
+
/** @internal Arrow glyph bound from direction only. */
|
|
2423
|
+
glyph = computed(() => directionGlyph(this.direction()), ...(ngDevMode ? [{ debugName: "glyph" }] : /* istanbul ignore next */ []));
|
|
2424
|
+
/** @internal Formatted magnitude. */
|
|
2425
|
+
formattedValue = computed(() => formatDelta(this.value(), this.mode(), this.locale, this.format()), ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
2426
|
+
/** @internal Full SR label: magnitude plus the sentiment word. */
|
|
2427
|
+
resolvedLabel = computed(() => {
|
|
2428
|
+
const override = this.label();
|
|
2429
|
+
if (override) {
|
|
2430
|
+
return override;
|
|
2431
|
+
}
|
|
2432
|
+
return `${this.formattedValue()} ${SENTIMENT_WORD[this.sentiment()]}`;
|
|
2433
|
+
}, ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
|
|
2434
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDelta, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2435
|
+
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: `
|
|
2436
|
+
<span aria-hidden="true">{{ glyph() }}</span>
|
|
2437
|
+
{{ formattedValue() }}
|
|
2438
|
+
`, 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 });
|
|
2439
|
+
}
|
|
2440
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDelta, decorators: [{
|
|
2441
|
+
type: Component,
|
|
2442
|
+
args: [{ selector: 'cngx-delta', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
2443
|
+
class: 'cngx-delta',
|
|
2444
|
+
// role=img makes the host a single labelled graphic so AT announces the
|
|
2445
|
+
// curated `aria-label` (the sentiment word) instead of the raw glyph text
|
|
2446
|
+
// on an otherwise role=generic custom element, where aria-label is
|
|
2447
|
+
// unreliably exposed.
|
|
2448
|
+
role: 'img',
|
|
2449
|
+
'[class.cngx-delta--positive]': "sentiment() === 'positive'",
|
|
2450
|
+
'[class.cngx-delta--negative]': "sentiment() === 'negative'",
|
|
2451
|
+
'[class.cngx-delta--neutral]': "sentiment() === 'neutral'",
|
|
2452
|
+
'[attr.aria-label]': 'resolvedLabel()',
|
|
2453
|
+
}, template: `
|
|
2454
|
+
<span aria-hidden="true">{{ glyph() }}</span>
|
|
2455
|
+
{{ formattedValue() }}
|
|
2456
|
+
`, 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"] }]
|
|
2457
|
+
}], 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 }] }] } });
|
|
2458
|
+
|
|
2459
|
+
/** DI token carrying the {@link CngxStatRegistry} a `CngxStat` provides. */
|
|
2460
|
+
const CNGX_STAT = new InjectionToken('CNGX_STAT');
|
|
2461
|
+
|
|
2462
|
+
/** Fixed reading order for the coordinated slots. */
|
|
2463
|
+
const SLOT_ORDER = ['label', 'value', 'delta', 'caption'];
|
|
2464
|
+
/** Structural equality so an unchanged id set never cascades `labelledBy`. */
|
|
2465
|
+
const idsEqual = (a, b) => a.length === b.length && a.every((id, i) => id === b[i]);
|
|
2466
|
+
/**
|
|
2467
|
+
* Coordination molecule for a KPI stat. Its sole reason to exist is the
|
|
2468
|
+
* screen-reader layer (Pillar 2): hand-assembling a heading, a `<cngx-metric>`
|
|
2469
|
+
* and a `<cngx-delta>` makes a screen reader announce three disconnected
|
|
2470
|
+
* fragments. `CngxStat` projects the label / value / delta / caption slots,
|
|
2471
|
+
* collects the id each slot registers, and derives one `aria-labelledby` that
|
|
2472
|
+
* reads the whole stat as a single accessible name in reading order.
|
|
2473
|
+
*
|
|
2474
|
+
* Composition, never a config bag (Pillar 3): the molecule owns only the id
|
|
2475
|
+
* coordination `computed()` graph; the visuals are whatever atoms the
|
|
2476
|
+
* consumer projects into the slots.
|
|
2477
|
+
*
|
|
2478
|
+
* ```html
|
|
2479
|
+
* <cngx-stat aria-live="polite">
|
|
2480
|
+
* <span cngxStatLabel>Revenue</span>
|
|
2481
|
+
* <cngx-metric cngxStatValue [value]="1.2" unit="M EUR" />
|
|
2482
|
+
* <cngx-delta cngxStatDelta [value]="5.3" />
|
|
2483
|
+
* <span cngxStatCaption>vs. last quarter</span>
|
|
2484
|
+
* </cngx-stat>
|
|
2485
|
+
* ```
|
|
2486
|
+
*
|
|
2487
|
+
* @category common/data/metric
|
|
2488
|
+
* @docsKind primary
|
|
2489
|
+
* @wcag AA
|
|
2490
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/display/stat/stat.component.ts
|
|
2491
|
+
* @since 0.1.0
|
|
2492
|
+
* @relatedTo CngxMetric, CngxDelta, CngxTrend
|
|
2493
|
+
*
|
|
2494
|
+
* <example-url>http://localhost:4200/#/common/data/stat/composed-kpi</example-url>
|
|
2495
|
+
*/
|
|
2496
|
+
class CngxStat {
|
|
2497
|
+
slots = signal(new Map(), ...(ngDevMode ? [{ debugName: "slots" }] : /* istanbul ignore next */ []));
|
|
2498
|
+
/**
|
|
2499
|
+
* Politeness of the live region. `off` (default) for a static stat;
|
|
2500
|
+
* `polite` / `assertive` for a KPI whose value updates in place.
|
|
2501
|
+
*/
|
|
2502
|
+
live = input('off', ...(ngDevMode ? [{ debugName: "live" }] : /* istanbul ignore next */ []));
|
|
2503
|
+
/** {@inheritDoc CngxStatRegistry.register} */
|
|
2504
|
+
register(kind, id) {
|
|
2505
|
+
this.slots.update((prev) => new Map(prev).set(kind, id));
|
|
2506
|
+
}
|
|
2507
|
+
/** {@inheritDoc CngxStatRegistry.unregister} */
|
|
2508
|
+
unregister(kind) {
|
|
2509
|
+
this.slots.update((prev) => {
|
|
2510
|
+
const next = new Map(prev);
|
|
2511
|
+
next.delete(kind);
|
|
2512
|
+
return next;
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
/** @internal Present slot ids in reading order; structurally stable. */
|
|
2516
|
+
orderedIds = computed(() => {
|
|
2517
|
+
const map = this.slots();
|
|
2518
|
+
return SLOT_ORDER.map((kind) => map.get(kind)).filter((id) => id !== undefined);
|
|
2519
|
+
}, { ...(ngDevMode ? { debugName: "orderedIds" } : /* istanbul ignore next */ {}), equal: idsEqual });
|
|
2520
|
+
/** @internal Combined accessible name; `null` when no slot is present. */
|
|
2521
|
+
labelledBy = computed(() => this.orderedIds().join(' ') || null, ...(ngDevMode ? [{ debugName: "labelledBy" }] : /* istanbul ignore next */ []));
|
|
2522
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStat, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2523
|
+
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: `
|
|
2524
|
+
<ng-content select="[cngxStatLabel]" />
|
|
2525
|
+
<div class="cngx-stat__row">
|
|
2526
|
+
<ng-content select="[cngxStatValue]" />
|
|
2527
|
+
<ng-content select="[cngxStatDelta]" />
|
|
2528
|
+
</div>
|
|
2529
|
+
<ng-content select="[cngxStatCaption]" />
|
|
2530
|
+
`, 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 });
|
|
2531
|
+
}
|
|
2532
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStat, decorators: [{
|
|
2533
|
+
type: Component,
|
|
2534
|
+
args: [{ selector: 'cngx-stat', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [{ provide: CNGX_STAT, useExisting: CngxStat }], host: {
|
|
2535
|
+
class: 'cngx-stat',
|
|
2536
|
+
role: 'group',
|
|
2537
|
+
'[attr.aria-labelledby]': 'labelledBy()',
|
|
2538
|
+
'[attr.aria-live]': 'live()',
|
|
2539
|
+
}, template: `
|
|
2540
|
+
<ng-content select="[cngxStatLabel]" />
|
|
2541
|
+
<div class="cngx-stat__row">
|
|
2542
|
+
<ng-content select="[cngxStatValue]" />
|
|
2543
|
+
<ng-content select="[cngxStatDelta]" />
|
|
2544
|
+
</div>
|
|
2545
|
+
<ng-content select="[cngxStatCaption]" />
|
|
2546
|
+
`, 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"] }]
|
|
2547
|
+
}], propDecorators: { live: [{ type: i0.Input, args: [{ isSignal: true, alias: "live", required: false }] }] } });
|
|
2548
|
+
|
|
2549
|
+
/**
|
|
2550
|
+
* Generate a stable id, register it with the enclosing `CngxStat` (if any),
|
|
2551
|
+
* and withdraw it on destroy. Shared by the four slot directives via plain
|
|
2552
|
+
* composition - no base class, no inheritance (Pillar 3).
|
|
2553
|
+
*/
|
|
2554
|
+
function useStatSlot(kind) {
|
|
2555
|
+
const registry = inject(CNGX_STAT, { optional: true });
|
|
2556
|
+
const id = nextUid(`cngx-stat-${kind}`);
|
|
2557
|
+
registry?.register(kind, id);
|
|
2558
|
+
inject(DestroyRef).onDestroy(() => registry?.unregister(kind));
|
|
2559
|
+
return id;
|
|
2560
|
+
}
|
|
2561
|
+
/**
|
|
2562
|
+
* Marks the label element of a {@link CngxStat}. Its generated id leads the
|
|
2563
|
+
* molecule's `aria-labelledby`.
|
|
2564
|
+
*
|
|
2565
|
+
* @category common/data/metric
|
|
2566
|
+
* @since 0.1.0
|
|
2567
|
+
* @relatedTo CngxStat
|
|
2568
|
+
*/
|
|
2569
|
+
class CngxStatLabel {
|
|
2570
|
+
/** Auto-generated id bound to the host `[id]`; consumed by `CngxStat`. */
|
|
2571
|
+
id = useStatSlot('label');
|
|
2572
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2573
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStatLabel, isStandalone: true, selector: "[cngxStatLabel]", host: { properties: { "id": "id" } }, ngImport: i0 });
|
|
2574
|
+
}
|
|
2575
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatLabel, decorators: [{
|
|
2576
|
+
type: Directive,
|
|
2577
|
+
args: [{
|
|
2578
|
+
selector: '[cngxStatLabel]',
|
|
2579
|
+
standalone: true,
|
|
2580
|
+
host: { '[id]': 'id' },
|
|
2581
|
+
}]
|
|
2582
|
+
}] });
|
|
2583
|
+
/**
|
|
2584
|
+
* Marks the primary value element of a {@link CngxStat} (typically a
|
|
2585
|
+
* `<cngx-metric>`).
|
|
2586
|
+
*
|
|
2587
|
+
* @category common/data/metric
|
|
2588
|
+
* @since 0.1.0
|
|
2589
|
+
* @relatedTo CngxStat
|
|
2590
|
+
*/
|
|
2591
|
+
class CngxStatValue {
|
|
2592
|
+
/** Auto-generated id bound to the host `[id]`; consumed by `CngxStat`. */
|
|
2593
|
+
id = useStatSlot('value');
|
|
2594
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatValue, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2595
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStatValue, isStandalone: true, selector: "[cngxStatValue]", host: { properties: { "id": "id" } }, ngImport: i0 });
|
|
2596
|
+
}
|
|
2597
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatValue, decorators: [{
|
|
2598
|
+
type: Directive,
|
|
2599
|
+
args: [{
|
|
2600
|
+
selector: '[cngxStatValue]',
|
|
2601
|
+
standalone: true,
|
|
2602
|
+
host: { '[id]': 'id' },
|
|
2603
|
+
}]
|
|
2604
|
+
}] });
|
|
2605
|
+
/**
|
|
2606
|
+
* Marks the delta element of a {@link CngxStat} (typically a `<cngx-delta>`
|
|
2607
|
+
* or `<cngx-trend>`).
|
|
2608
|
+
*
|
|
2609
|
+
* @category common/data/metric
|
|
2610
|
+
* @since 0.1.0
|
|
2611
|
+
* @relatedTo CngxStat
|
|
2612
|
+
*/
|
|
2613
|
+
class CngxStatDelta {
|
|
2614
|
+
/** Auto-generated id bound to the host `[id]`; consumed by `CngxStat`. */
|
|
2615
|
+
id = useStatSlot('delta');
|
|
2616
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatDelta, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2617
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStatDelta, isStandalone: true, selector: "[cngxStatDelta]", host: { properties: { "id": "id" } }, ngImport: i0 });
|
|
2618
|
+
}
|
|
2619
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatDelta, decorators: [{
|
|
2620
|
+
type: Directive,
|
|
2621
|
+
args: [{
|
|
2622
|
+
selector: '[cngxStatDelta]',
|
|
2623
|
+
standalone: true,
|
|
2624
|
+
host: { '[id]': 'id' },
|
|
2625
|
+
}]
|
|
2626
|
+
}] });
|
|
2627
|
+
/**
|
|
2628
|
+
* Marks the caption element of a {@link CngxStat} - the trailing context
|
|
2629
|
+
* line (e.g. "vs. last quarter").
|
|
2630
|
+
*
|
|
2631
|
+
* @category common/data/metric
|
|
2632
|
+
* @since 0.1.0
|
|
2633
|
+
* @relatedTo CngxStat
|
|
2634
|
+
*/
|
|
2635
|
+
class CngxStatCaption {
|
|
2636
|
+
/** Auto-generated id bound to the host `[id]`; consumed by `CngxStat`. */
|
|
2637
|
+
id = useStatSlot('caption');
|
|
2638
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatCaption, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2639
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStatCaption, isStandalone: true, selector: "[cngxStatCaption]", host: { properties: { "id": "id" } }, ngImport: i0 });
|
|
2640
|
+
}
|
|
2641
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatCaption, decorators: [{
|
|
2642
|
+
type: Directive,
|
|
2643
|
+
args: [{
|
|
2644
|
+
selector: '[cngxStatCaption]',
|
|
2645
|
+
standalone: true,
|
|
2646
|
+
host: { '[id]': 'id' },
|
|
2647
|
+
}]
|
|
2648
|
+
}] });
|
|
2649
|
+
|
|
2650
|
+
/** Tone glyph rendered inside the decorative dot - the non-colour signal. */
|
|
2651
|
+
const TONE_GLYPH = {
|
|
2652
|
+
success: '✓',
|
|
2653
|
+
warning: '!',
|
|
2654
|
+
danger: '✕',
|
|
2655
|
+
info: 'i',
|
|
2656
|
+
neutral: '•',
|
|
2657
|
+
};
|
|
2658
|
+
/**
|
|
2659
|
+
* Semantic health indicator - a decorative tone dot paired with a visible
|
|
2660
|
+
* label. Distinct from `CngxBadge` (count overlay), `CngxChip` (interactive)
|
|
2661
|
+
* and `CngxTag` (labeled token): its single job is to communicate a status
|
|
2662
|
+
* (operational / degraded / down / info).
|
|
2663
|
+
*
|
|
2664
|
+
* Colour is never the only signal (Pillar 2): the tone drives the dot colour
|
|
2665
|
+
* *and* a tone glyph, so a colour-blind reader still distinguishes the states,
|
|
2666
|
+
* and the visible `label` carries the meaning for assistive tech (the dot is
|
|
2667
|
+
* `aria-hidden`). Set `live` for a status that changes in place.
|
|
2668
|
+
*
|
|
2669
|
+
* ### Basic
|
|
2670
|
+
* ```html
|
|
2671
|
+
* <cngx-status tone="success" label="Operational" />
|
|
2672
|
+
* ```
|
|
2673
|
+
*
|
|
2674
|
+
* ### Live-updating
|
|
2675
|
+
* ```html
|
|
2676
|
+
* <cngx-status tone="danger" label="Outage" live="assertive" />
|
|
2677
|
+
* ```
|
|
2678
|
+
*
|
|
2679
|
+
* @category common/data/metric
|
|
2680
|
+
* @docsKind primary
|
|
2681
|
+
* @wcag AA
|
|
2682
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/display/status/status.component.ts
|
|
2683
|
+
* @since 0.1.0
|
|
2684
|
+
* @relatedTo CngxBadge, CngxTag, CngxChip
|
|
2685
|
+
*
|
|
2686
|
+
* <example-url>http://localhost:4200/#/common/data/status/tone-matrix</example-url>
|
|
2687
|
+
*/
|
|
2688
|
+
class CngxStatus {
|
|
2689
|
+
elRef = inject((ElementRef));
|
|
2690
|
+
/** Semantic health. Drives both the dot colour and the tone glyph. */
|
|
2691
|
+
tone = input('neutral', ...(ngDevMode ? [{ debugName: "tone" }] : /* istanbul ignore next */ []));
|
|
2692
|
+
/** Visible status text. Carries the meaning for assistive tech. */
|
|
2693
|
+
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
2694
|
+
/**
|
|
2695
|
+
* Politeness of the live region. `off` (default) for a static status;
|
|
2696
|
+
* `polite` / `assertive` for a status that changes in place.
|
|
2697
|
+
*/
|
|
2698
|
+
live = input('off', ...(ngDevMode ? [{ debugName: "live" }] : /* istanbul ignore next */ []));
|
|
2699
|
+
/** @internal Tone glyph bound into the decorative dot. */
|
|
2700
|
+
glyph = computed(() => TONE_GLYPH[this.tone()], ...(ngDevMode ? [{ debugName: "glyph" }] : /* istanbul ignore next */ []));
|
|
2701
|
+
constructor() {
|
|
2702
|
+
if (isDevMode()) {
|
|
2703
|
+
afterNextRender(() => {
|
|
2704
|
+
const el = this.elRef.nativeElement;
|
|
2705
|
+
if (!this.label() && !el.getAttribute('aria-label') && !el.getAttribute('aria-labelledby')) {
|
|
2706
|
+
console.warn('cngx-status: no `label` and no external `aria-label`/`aria-labelledby`; ' +
|
|
2707
|
+
'the status has no accessible name and reads only as a coloured dot. ' +
|
|
2708
|
+
'Set [label] or an aria-label on the host.');
|
|
2709
|
+
}
|
|
2710
|
+
});
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatus, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2714
|
+
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: `
|
|
2715
|
+
<span class="cngx-status__dot" aria-hidden="true">{{ glyph() }}</span>
|
|
2716
|
+
@if (label()) {
|
|
2717
|
+
<span class="cngx-status__label">{{ label() }}</span>
|
|
2718
|
+
}
|
|
2719
|
+
`, 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 });
|
|
2720
|
+
}
|
|
2721
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatus, decorators: [{
|
|
2722
|
+
type: Component,
|
|
2723
|
+
args: [{ selector: 'cngx-status', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
2724
|
+
class: 'cngx-status',
|
|
2725
|
+
'[class.cngx-status--success]': "tone() === 'success'",
|
|
2726
|
+
'[class.cngx-status--warning]': "tone() === 'warning'",
|
|
2727
|
+
'[class.cngx-status--danger]': "tone() === 'danger'",
|
|
2728
|
+
'[class.cngx-status--info]': "tone() === 'info'",
|
|
2729
|
+
'[class.cngx-status--neutral]': "tone() === 'neutral'",
|
|
2730
|
+
'[attr.aria-live]': 'live()',
|
|
2731
|
+
}, template: `
|
|
2732
|
+
<span class="cngx-status__dot" aria-hidden="true">{{ glyph() }}</span>
|
|
2733
|
+
@if (label()) {
|
|
2734
|
+
<span class="cngx-status__label">{{ label() }}</span>
|
|
2735
|
+
}
|
|
2736
|
+
`, 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"] }]
|
|
2737
|
+
}], 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 }] }] } });
|
|
2738
|
+
|
|
2739
|
+
/**
|
|
2740
|
+
* Determinate attainment bar - a continuous progress toward a target
|
|
2741
|
+
* (quota reached, budget spent, goal met). Named `CngxGoal` because
|
|
2742
|
+
* `cngx-progress` is the indeterminate async loading bar; this is the
|
|
2743
|
+
* finished-fraction indicator, distinct from that and from the discrete
|
|
2744
|
+
* `CngxSegmentedProgress`.
|
|
2745
|
+
*
|
|
2746
|
+
* Mirrors the `CngxSegmentedProgress` a11y shape: `role="progressbar"` with
|
|
2747
|
+
* the whole `aria-value*` set plus `aria-valuetext` living in the `computed()`
|
|
2748
|
+
* graph (Pillar 2). The value is clamped to `[0, max]`; the fill width is a
|
|
2749
|
+
* derived percent bound as a CSS custom property.
|
|
2750
|
+
*
|
|
2751
|
+
* ```html
|
|
2752
|
+
* <cngx-goal [value]="73" [max]="100" />
|
|
2753
|
+
* <cngx-goal [value]="q()" [max]="target()" [valueTextFormat]="quotaText" />
|
|
2754
|
+
* ```
|
|
2755
|
+
*
|
|
2756
|
+
* @category common/data/metric
|
|
2757
|
+
* @docsKind primary
|
|
2758
|
+
* @wcag AA
|
|
2759
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/display/goal/goal.component.ts
|
|
2760
|
+
* @since 0.1.0
|
|
2761
|
+
* @relatedTo CngxSegmentedProgress, CngxMetric
|
|
2762
|
+
*
|
|
2763
|
+
* <example-url>http://localhost:4200/#/common/data/goal/quota-attainment</example-url>
|
|
2764
|
+
*/
|
|
2765
|
+
class CngxGoal {
|
|
2766
|
+
/** Current attainment. Clamped to `[0, max]`. */
|
|
2767
|
+
value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
2768
|
+
/** Target the value works toward. Defaults to `100`. */
|
|
2769
|
+
max = input(100, ...(ngDevMode ? [{ debugName: "max" }] : /* istanbul ignore next */ []));
|
|
2770
|
+
/**
|
|
2771
|
+
* Override the `aria-valuetext` string. Receives `(now, max)` - the clamped
|
|
2772
|
+
* value and the target. The default is `(now, max) => \`${now} of ${max}\``.
|
|
2773
|
+
* Supply a localised closure for richer text (e.g.
|
|
2774
|
+
* `(n, m) => \`${n} of ${m}, ${Math.round((n / m) * 100)}% of quota\``).
|
|
2775
|
+
*/
|
|
2776
|
+
valueTextFormat = input(undefined, ...(ngDevMode ? [{ debugName: "valueTextFormat" }] : /* istanbul ignore next */ []));
|
|
2777
|
+
/** `aria-valuemax` - the target, floored at 0. */
|
|
2778
|
+
maxValue = computed(() => Math.max(0, this.max()), ...(ngDevMode ? [{ debugName: "maxValue" }] : /* istanbul ignore next */ []));
|
|
2779
|
+
/** `aria-valuenow` - value clamped into `[0, max]`. */
|
|
2780
|
+
now = computed(() => Math.max(0, Math.min(this.value(), this.maxValue())), ...(ngDevMode ? [{ debugName: "now" }] : /* istanbul ignore next */ []));
|
|
2781
|
+
/** Fill width as a percent of the target; `0` when the target is `0`. */
|
|
2782
|
+
fillPercent = computed(() => {
|
|
2783
|
+
const max = this.maxValue();
|
|
2784
|
+
return max === 0 ? 0 : (this.now() / max) * 100;
|
|
2785
|
+
}, ...(ngDevMode ? [{ debugName: "fillPercent" }] : /* istanbul ignore next */ []));
|
|
2786
|
+
/** `aria-valuetext` - human-readable attainment via the resolved closure. */
|
|
2787
|
+
valueText = computed(() => {
|
|
2788
|
+
const fmt = this.valueTextFormat() ?? ((now, max) => `${now} of ${max}`);
|
|
2789
|
+
return fmt(this.now(), this.maxValue());
|
|
2790
|
+
}, ...(ngDevMode ? [{ debugName: "valueText" }] : /* istanbul ignore next */ []));
|
|
2791
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxGoal, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2792
|
+
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 });
|
|
2793
|
+
}
|
|
2794
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxGoal, decorators: [{
|
|
2795
|
+
type: Component,
|
|
2796
|
+
args: [{ selector: 'cngx-goal', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
2797
|
+
class: 'cngx-goal',
|
|
2798
|
+
role: 'progressbar',
|
|
2799
|
+
'[attr.aria-valuemin]': '0',
|
|
2800
|
+
'[attr.aria-valuemax]': 'maxValue()',
|
|
2801
|
+
'[attr.aria-valuenow]': 'now()',
|
|
2802
|
+
'[attr.aria-valuetext]': 'valueText()',
|
|
2803
|
+
'[style.--cngx-goal-fill.%]': 'fillPercent()',
|
|
2804
|
+
}, 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"] }]
|
|
2805
|
+
}], 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 }] }] } });
|
|
2806
|
+
|
|
1868
2807
|
const EMPTY_RANGE = {
|
|
1869
2808
|
start: 0,
|
|
1870
2809
|
end: 0,
|
|
@@ -2229,7 +3168,13 @@ function injectRecycler(config) {
|
|
|
2229
3168
|
}
|
|
2230
3169
|
return typeof config.columns === 'function' ? config.columns() : config.columns;
|
|
2231
3170
|
}, ...(ngDevMode ? [{ debugName: "columns" }] : /* istanbul ignore next */ []));
|
|
2232
|
-
|
|
3171
|
+
// A Signal is a zero-arg function but resolves to a uniform height, not a
|
|
3172
|
+
// per-index measurement - it carries no O(n) per-frame cost, so exclude it
|
|
3173
|
+
// from the variable-height warning (a reactive scalar estimate is a
|
|
3174
|
+
// sanctioned pattern; see the resolveSize note below).
|
|
3175
|
+
if (typeof config.estimateSize === 'function' &&
|
|
3176
|
+
!isSignal(config.estimateSize) &&
|
|
3177
|
+
isDevMode()) {
|
|
2233
3178
|
const count = config.totalCount();
|
|
2234
3179
|
if (count > 10_000) {
|
|
2235
3180
|
console.warn(`[CngxRecycler] estimateSize as a function with ${count} items has O(n) ` +
|
|
@@ -3058,5 +4003,5 @@ function createMaterialBidirectionalSync(opts) {
|
|
|
3058
4003
|
* Generated bundle index. Do not edit.
|
|
3059
4004
|
*/
|
|
3060
4005
|
|
|
3061
|
-
export { CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_RECYCLER_I18N, CngxAsync, CngxDataSource, CngxFilter, CngxFilterChip, CngxFilterChips, CngxMeasure, CngxMetric, CngxPaginate, CngxRecyclerAnnouncer, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxTrend, CngxVirtualItem, connectRecyclerToActiveDescendant, connectRecyclerToRoving, createAsyncState, createCommitController, createManualState, createMaterialBidirectionalSync, injectAsyncState, injectDataSource, injectRecycler, injectSmartDataSource, provideRecyclerI18n, resolveAsyncView };
|
|
4006
|
+
export { CNGX_BUCKET_PAGINATE_HOST, CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_RECYCLER_I18N, CNGX_STAT, CngxAsync, CngxBucketPaginate, CngxDataSource, CngxDelta, CngxFilter, CngxFilterChip, CngxFilterChips, CngxGoal, CngxMeasure, CngxMetric, CngxPaginate, CngxPaginateResetOn, CngxPaginateRouting, CngxRecyclerAnnouncer, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxStat, CngxStatCaption, CngxStatDelta, CngxStatLabel, CngxStatValue, CngxStatus, CngxTrend, CngxVirtualItem, connectPaginateEmit, connectPaginateResetOn, connectRecyclerToActiveDescendant, connectRecyclerToRoving, createAsyncState, createCommitController, createManualState, createMaterialBidirectionalSync, createSortHeaderState, fromHttpResource, fromResource, injectAsyncState, injectDataSource, injectRecycler, injectSmartDataSource, provideRecyclerI18n, resolveAsyncView, tapAsyncProgress, tapAsyncState, tapHttpAsyncState };
|
|
3062
4007
|
//# sourceMappingURL=cngx-common-data.mjs.map
|