@cngx/common 0.1.0-rc.3 → 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/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 +691 -52
- 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 +444 -22
- 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,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { input, signal, computed, output, Directive, inject, TemplateRef, model, contentChild,
|
|
2
|
+
import { input, signal, afterNextRender, computed, output, Directive, inject, TemplateRef, model, contentChild, DestroyRef, ChangeDetectionStrategy, Component, effect, untracked, InjectionToken, Injector, ViewContainerRef, LOCALE_ID, ViewEncapsulation, ElementRef, isDevMode, isSignal, runInInjectionContext } from '@angular/core';
|
|
3
3
|
import { NgTemplateOutlet, DOCUMENT } from '@angular/common';
|
|
4
4
|
import { CngxChip } from '@cngx/common/display';
|
|
5
5
|
import { CngxMultiChipGroup, CngxChipInGroup, CngxSearch } from '@cngx/common/interactive';
|
|
@@ -7,7 +7,7 @@ import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
|
|
|
7
7
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
8
8
|
import { DataSource } from '@angular/cdk/collections';
|
|
9
9
|
import { arrayEqual } from '@cngx/utils';
|
|
10
|
-
import { buildAsyncStateView, createTransitionTracker } from '@cngx/core/utils';
|
|
10
|
+
import { buildAsyncStateView, nextUid, createTransitionTracker } from '@cngx/core/utils';
|
|
11
11
|
import { isObservable, firstValueFrom, defer, tap, filter, map } from 'rxjs';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -18,6 +18,11 @@ import { isObservable, firstValueFrom, defer, tap, filter, map } from 'rxjs';
|
|
|
18
18
|
* precedence over the internal state - pair with `sortChange` to keep them
|
|
19
19
|
* in sync.
|
|
20
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
|
+
*
|
|
21
26
|
* When `multiSort` is `true`, holding **Shift** while clicking a sort header
|
|
22
27
|
* adds it as a secondary (tertiary, …) sort key instead of replacing the
|
|
23
28
|
* primary one. Shift-clicking an active column cycles it asc → desc → removed.
|
|
@@ -36,9 +41,6 @@ import { isObservable, firstValueFrom, defer, tap, filter, map } from 'rxjs';
|
|
|
36
41
|
* <example-url>http://localhost:4200/#/common/data/sort/multi-sort</example-url>
|
|
37
42
|
* <example-url>http://localhost:4200/#/common/data/sort/controlled</example-url>
|
|
38
43
|
* <example-url>http://localhost:4200/#/common/data/sort/aria-and-keyboard</example-url>
|
|
39
|
-
// * <example-url>http://localhost:4200/#/common/data/smart-data-source/auto-wired</example-url>
|
|
40
|
-
// * <example-url>http://localhost:4200/#/common/data/smart-data-source/how-it-works-hostdirectives-inject</example-url>
|
|
41
|
-
// * <example-url>http://localhost:4200/#/common/data/smart-data-source/smartdatasource-cngxpaginate-hostdirective</example-url>
|
|
42
44
|
*/
|
|
43
45
|
class CngxSort {
|
|
44
46
|
/** Controlled active column. When bound, takes precedence over internal state (single-sort only). */
|
|
@@ -50,7 +52,25 @@ class CngxSort {
|
|
|
50
52
|
* replacing the current sort.
|
|
51
53
|
*/
|
|
52
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' });
|
|
53
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
|
+
}
|
|
54
74
|
/** The active sort column of the primary entry (controlled takes precedence in single-sort mode). */
|
|
55
75
|
active = computed(() => this.activeInput() ?? this.sortsState()[0]?.active, ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
|
|
56
76
|
/** The active sort direction of the primary entry (controlled takes precedence in single-sort mode). */
|
|
@@ -78,7 +98,7 @@ class CngxSort {
|
|
|
78
98
|
* Sets or toggles the sort for `field`.
|
|
79
99
|
*
|
|
80
100
|
* **`additive = false`** (default, plain click):
|
|
81
|
-
* - Same field →
|
|
101
|
+
* - Same field → cycle `asc` → `desc` → cleared (a third click removes the sort)
|
|
82
102
|
* - Different field → replace stack with `{ field, asc }`
|
|
83
103
|
*
|
|
84
104
|
* **`additive = true`** (Shift+click when `multiSort` is enabled on the header):
|
|
@@ -106,11 +126,19 @@ class CngxSort {
|
|
|
106
126
|
}
|
|
107
127
|
else {
|
|
108
128
|
const current = this.sortsState();
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
+
}
|
|
114
142
|
}
|
|
115
143
|
}
|
|
116
144
|
/** Clears all active sorts. Emits both `sortChange(undefined)` and `sortsChange([])`. */
|
|
@@ -120,7 +148,7 @@ class CngxSort {
|
|
|
120
148
|
this.sortsChange.emit([]);
|
|
121
149
|
}
|
|
122
150
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSort, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
123
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxSort, isStandalone: true, selector: "[cngxSort]", inputs: { activeInput: { classPropertyName: "activeInput", publicName: "cngxSortActive", isSignal: true, isRequired: false, transformFunction: null }, directionInput: { classPropertyName: "directionInput", publicName: "cngxSortDirection", isSignal: true, isRequired: false, transformFunction: null }, multiSort: { classPropertyName: "multiSort", publicName: "multiSort", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { sortChange: "sortChange", sortsChange: "sortsChange" }, exportAs: ["cngxSort"], ngImport: i0 });
|
|
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 });
|
|
124
152
|
}
|
|
125
153
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSort, decorators: [{
|
|
126
154
|
type: Directive,
|
|
@@ -129,7 +157,44 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
129
157
|
exportAs: 'cngxSort',
|
|
130
158
|
standalone: true,
|
|
131
159
|
}]
|
|
132
|
-
}], propDecorators: { activeInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxSortActive", required: false }] }], directionInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxSortDirection", required: false }] }], multiSort: [{ type: i0.Input, args: [{ isSignal: true, alias: "multiSort", required: false }] }], sortChange: [{ type: i0.Output, args: ["sortChange"] }], sortsChange: [{ type: i0.Output, args: ["sortsChange"] }] } });
|
|
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
|
+
}
|
|
133
198
|
|
|
134
199
|
/**
|
|
135
200
|
* Molecule directive for sort-header elements.
|
|
@@ -170,36 +235,28 @@ class CngxSortHeader {
|
|
|
170
235
|
field = input.required({ ...(ngDevMode ? { debugName: "field" } : /* istanbul ignore next */ {}), alias: 'cngxSortHeader' });
|
|
171
236
|
/** Explicit reference to the owning `CngxSort`. */
|
|
172
237
|
cngxSortRef = input.required(...(ngDevMode ? [{ debugName: "cngxSortRef" }] : /* istanbul ignore next */ []));
|
|
173
|
-
|
|
174
|
-
.sorts()
|
|
175
|
-
.find((s) => s.active === this.field()), ...(ngDevMode ? [{ debugName: "entry" }] : /* istanbul ignore next */ []));
|
|
238
|
+
state = createSortHeaderState(this.cngxSortRef, this.field);
|
|
176
239
|
/** `true` when this column is part of the active sort (primary or secondary). */
|
|
177
|
-
isActive =
|
|
240
|
+
isActive = this.state.isActive;
|
|
178
241
|
/** `true` when this column is active and sorted ascending. */
|
|
179
|
-
isAsc =
|
|
242
|
+
isAsc = this.state.isAsc;
|
|
180
243
|
/** `true` when this column is active and sorted descending. */
|
|
181
|
-
isDesc =
|
|
244
|
+
isDesc = this.state.isDesc;
|
|
182
245
|
/**
|
|
183
246
|
* 1-based position of this column in the sort stack.
|
|
184
247
|
* Returns `0` when the column is not part of the active sort.
|
|
185
248
|
* Only meaningful when `multiSort` is enabled on the owning `CngxSort`.
|
|
186
249
|
*/
|
|
187
|
-
priority =
|
|
188
|
-
const idx = this.cngxSortRef()
|
|
189
|
-
.sorts()
|
|
190
|
-
.findIndex((s) => s.active === this.field());
|
|
191
|
-
return idx === -1 ? 0 : idx + 1;
|
|
192
|
-
}, ...(ngDevMode ? [{ debugName: "priority" }] : /* istanbul ignore next */ []));
|
|
250
|
+
priority = this.state.priority;
|
|
193
251
|
/** The `aria-sort` attribute value for the host element. */
|
|
194
252
|
ariaSort = computed(() => {
|
|
195
|
-
if (!this.isActive()) {
|
|
253
|
+
if (!this.state.isActive()) {
|
|
196
254
|
return null;
|
|
197
255
|
}
|
|
198
|
-
return this.isAsc() ? 'ascending' : 'descending';
|
|
256
|
+
return this.state.isAsc() ? 'ascending' : 'descending';
|
|
199
257
|
}, ...(ngDevMode ? [{ debugName: "ariaSort" }] : /* istanbul ignore next */ []));
|
|
200
258
|
handleSort(event) {
|
|
201
|
-
|
|
202
|
-
this.cngxSortRef().setSort(this.field(), additive);
|
|
259
|
+
this.state.toggle(event?.shiftKey ?? false);
|
|
203
260
|
}
|
|
204
261
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSortHeader, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
205
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 });
|
|
@@ -603,14 +660,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
603
660
|
/**
|
|
604
661
|
* Atom directive that tracks pagination state (current page index and page size).
|
|
605
662
|
*
|
|
606
|
-
* Supports both **uncontrolled** (internal state) and **controlled** modes.
|
|
663
|
+
* Supports both **uncontrolled** (internal state) and **controlled** modes. \
|
|
607
664
|
* In controlled mode the `cngxPageIndex` / `cngxPageSize` inputs take precedence
|
|
608
|
-
* over internal state - pair with
|
|
665
|
+
* over internal state - pair with \
|
|
666
|
+
* `pageChange` / `pageSizeChange` to keep them
|
|
609
667
|
* in sync.
|
|
610
668
|
*
|
|
611
669
|
* Consumer connects this to a list or table via `range()` - nothing is injected
|
|
612
670
|
* automatically.
|
|
613
671
|
*
|
|
672
|
+
* ```
|
|
614
673
|
* // Headless: read range() from a template ref
|
|
615
674
|
* <div cngxPaginate #pg="cngxPaginate" [total]="items.length">
|
|
616
675
|
* @for (item of items.slice(pg.range()[0], pg.range()[1]); track item.id) { ... }
|
|
@@ -620,7 +679,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
620
679
|
* <mat-paginator
|
|
621
680
|
* [length]="pg.total()" [pageIndex]="pg.pageIndex()" [pageSize]="pg.pageSize()"
|
|
622
681
|
* (page)="pg.setPageSize($event.pageSize, false); pg.setPage($event.pageIndex)" />
|
|
623
|
-
*
|
|
682
|
+
* ```
|
|
624
683
|
* @category common/data/paginate
|
|
625
684
|
* @docsKind primary
|
|
626
685
|
* @wcag AA
|
|
@@ -629,8 +688,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
629
688
|
* @relatedTo CngxSort, CngxFilter, CngxSmartDataSource
|
|
630
689
|
*
|
|
631
690
|
* <example-url>http://localhost:4200/#/common/data/data-source/datasource-cngxpaginate-manual-pipeline</example-url>
|
|
632
|
-
* <example-url>http://localhost:4200/#/common/data/paginate-list/bridge-announce-page-changes</example-url>
|
|
633
|
-
* <example-url>http://localhost:4200/#/common/data/paginate-list/instrumentation-bridge-cngxmatpaginator</example-url>
|
|
634
691
|
* <example-url>http://localhost:4200/#/common/data/paginate-list/paginated-list-cngxpaginate-cngxmatpaginator</example-url>
|
|
635
692
|
* <example-url>http://localhost:4200/#/common/data/paginate-list/uncontrolled-mode-zero-class-boilerplate</example-url>
|
|
636
693
|
* <example-url>http://localhost:4200/#/common/data/smart-data-source/smartdatasource-cngxpaginate-hostdirective</example-url>
|
|
@@ -776,8 +833,8 @@ function connectPaginateResetOn(paginate, key) {
|
|
|
776
833
|
}
|
|
777
834
|
/**
|
|
778
835
|
* Resets a `cngxPaginate` host to the first page whenever the bound key
|
|
779
|
-
* changes - the composable form of {@link connectPaginateResetOn}.
|
|
780
|
-
* the same element as `cngxPaginate` (or a `CngxPaginator` / `CngxMatPaginator`,
|
|
836
|
+
* changes - the composable form of {@link connectPaginateResetOn}. \
|
|
837
|
+
* Drop it on the same element as `cngxPaginate` (or a `CngxPaginator` / `CngxMatPaginator`,
|
|
781
838
|
* which provide the brain), and bind the sort / filter / search value a result
|
|
782
839
|
* set depends on, so a narrowed result never strands the user on a now-empty
|
|
783
840
|
* page.
|
|
@@ -788,9 +845,11 @@ function connectPaginateResetOn(paginate, key) {
|
|
|
788
845
|
* ```html
|
|
789
846
|
* <table cngxPaginate [cngxPaginateResetOn]="filter()"><!-- ... --></table>
|
|
790
847
|
* ```
|
|
848
|
+
* <example-url>http://localhost:4200/#/ui/paginator/paginator-behaviors/reset-on-filter</example-url>
|
|
791
849
|
*
|
|
792
850
|
* @category common/data/paginate
|
|
793
851
|
* @docsKind primary
|
|
852
|
+
* @wcag AA
|
|
794
853
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/paginate/paginate-reset.directive.ts
|
|
795
854
|
* @since 0.1.0
|
|
796
855
|
* @relatedTo CngxPaginate, CngxPaginator, CngxMatPaginator
|
|
@@ -814,6 +873,74 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
814
873
|
}]
|
|
815
874
|
}], ctorParameters: () => [], propDecorators: { key: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPaginateResetOn", required: false }] }] } });
|
|
816
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
|
+
|
|
817
944
|
/**
|
|
818
945
|
* Persists a `cngxPaginate` host's page / size in the URL query string, so a
|
|
819
946
|
* paginated view is deep-linkable and survives reload / back / forward.
|
|
@@ -827,7 +954,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
827
954
|
* ```
|
|
828
955
|
*
|
|
829
956
|
* Two paginators on one route must take distinct param names via
|
|
830
|
-
* `[cngxPaginatePageParam]` / `[cngxPaginateSizeParam]` to avoid a collision.
|
|
957
|
+
* `[cngxPaginatePageParam]` / `[cngxPaginateSizeParam]` to avoid a collision. \
|
|
831
958
|
* Requires `@angular/router` (`provideRouter`); without it the directive is an
|
|
832
959
|
* inert no-op (a dev-mode warning is logged). Framework-agnostic of any UI - it
|
|
833
960
|
* needs only the brain and the router.
|
|
@@ -2074,26 +2201,83 @@ class CngxMetric {
|
|
|
2074
2201
|
return u ? `${v} ${u}` : v;
|
|
2075
2202
|
}, ...(ngDevMode ? [{ debugName: "accessibleValue" }] : /* istanbul ignore next */ []));
|
|
2076
2203
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMetric, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2077
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxMetric, isStandalone: true, selector: "cngx-metric", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, unit: { classPropertyName: "unit", publicName: "unit", isSignal: true, isRequired: false, transformFunction: null }, format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.aria-label": "accessibleValue()" }, classAttribute: "cngx-metric" }, ngImport: i0, template: `
|
|
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: `
|
|
2078
2205
|
<span class="cngx-metric__value">{{ formattedValue() }}</span>
|
|
2079
2206
|
@if (unit()) {
|
|
2080
2207
|
<span class="cngx-metric__unit">{{ unit() }}</span>
|
|
2081
2208
|
}
|
|
2082
|
-
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-metric-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-metric-value-size{syntax: \"*\"; inherits: true; initial-value: 1.75rem;}@property --cngx-metric-value-weight{syntax: \"<number>\"; inherits: true; initial-value: 600;}@property --cngx-metric-value-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.2 .01 290);}@property --cngx-metric-unit-size{syntax: \"*\"; inherits: true; initial-value: .875rem;}@property --cngx-metric-unit-weight{syntax: \"<number>\"; inherits: true; initial-value: 400;}@property --cngx-metric-unit-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}}[data-color-scheme=dark],.dark{--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}[data-color-scheme=light],.light{--cngx-metric-value-color: oklch(.2 .01 290);--cngx-metric-unit-color: oklch(.36 .02 290)}}@layer cngx.components{@scope(.cngx-metric){:scope{display:inline-flex;align-items:baseline;gap:var(--cngx-metric-gap, 2px)}.cngx-metric__value{font-size:var(--cngx-metric-value-size, 1.75rem);font-weight:var(--cngx-metric-value-weight, 600);color:var(--cngx-metric-value-color, var(--cngx-color-text, oklch(.2 .01 290)));line-height:1.2}.cngx-metric__unit{font-size:var(--cngx-metric-unit-size, .875rem);font-weight:var(--cngx-metric-unit-weight, 400);color:var(--cngx-metric-unit-color, oklch(.36 .02 290))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
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 });
|
|
2083
2210
|
}
|
|
2084
2211
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMetric, decorators: [{
|
|
2085
2212
|
type: Component,
|
|
2086
2213
|
args: [{ selector: 'cngx-metric', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
2087
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',
|
|
2088
2220
|
'[attr.aria-label]': 'accessibleValue()',
|
|
2089
2221
|
}, template: `
|
|
2090
2222
|
<span class="cngx-metric__value">{{ formattedValue() }}</span>
|
|
2091
2223
|
@if (unit()) {
|
|
2092
2224
|
<span class="cngx-metric__unit">{{ unit() }}</span>
|
|
2093
2225
|
}
|
|
2094
|
-
`, styles: ["@layer cngx.tokens{@property --cngx-metric-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-metric-value-size{syntax: \"*\"; inherits: true; initial-value: 1.75rem;}@property --cngx-metric-value-weight{syntax: \"<number>\"; inherits: true; initial-value: 600;}@property --cngx-metric-value-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.2 .01 290);}@property --cngx-metric-unit-size{syntax: \"*\"; inherits: true; initial-value: .875rem;}@property --cngx-metric-unit-weight{syntax: \"<number>\"; inherits: true; initial-value: 400;}@property --cngx-metric-unit-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}}[data-color-scheme=dark],.dark{--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}[data-color-scheme=light],.light{--cngx-metric-value-color: oklch(.2 .01 290);--cngx-metric-unit-color: oklch(.36 .02 290)}}@layer cngx.components{@scope(.cngx-metric){:scope{display:inline-flex;align-items:baseline;gap:var(--cngx-metric-gap, 2px)}.cngx-metric__value{font-size:var(--cngx-metric-value-size, 1.75rem);font-weight:var(--cngx-metric-value-weight, 600);color:var(--cngx-metric-value-color, var(--cngx-color-text, oklch(.2 .01 290)));line-height:1.2}.cngx-metric__unit{font-size:var(--cngx-metric-unit-size, .875rem);font-weight:var(--cngx-metric-unit-weight, 400);color:var(--cngx-metric-unit-color, oklch(.36 .02 290))}}}\n"] }]
|
|
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"] }]
|
|
2095
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 }] }] } });
|
|
2096
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
|
+
|
|
2097
2281
|
/**
|
|
2098
2282
|
* Displays a trend indicator with directional arrow and formatted percentage.
|
|
2099
2283
|
*
|
|
@@ -2132,45 +2316,494 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2132
2316
|
* <example-url>http://localhost:4200/#/common/data/trend/trend-directions</example-url>
|
|
2133
2317
|
*/
|
|
2134
2318
|
class CngxTrend {
|
|
2319
|
+
locale = inject(LOCALE_ID);
|
|
2135
2320
|
/** Trend percentage. Positive = up, negative = down, zero = flat. */
|
|
2136
2321
|
value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
2137
2322
|
/** Consumer-provided SR label override. When set, replaces the generated default. */
|
|
2138
2323
|
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
2139
2324
|
/** @internal */
|
|
2140
|
-
icon = computed(() =>
|
|
2325
|
+
icon = computed(() => directionGlyph(deltaDirection(this.value())), ...(ngDevMode ? [{ debugName: "icon" }] : /* istanbul ignore next */ []));
|
|
2141
2326
|
/** @internal */
|
|
2142
|
-
formattedValue = computed(() => {
|
|
2143
|
-
const v = this.value();
|
|
2144
|
-
const abs = Math.abs(v);
|
|
2145
|
-
return `${v > 0 ? '+' : ''}${abs.toFixed(1)}\u202F%`;
|
|
2146
|
-
}, ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
2327
|
+
formattedValue = computed(() => formatDelta(this.value(), 'percent', this.locale), ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
2147
2328
|
/** @internal */
|
|
2148
2329
|
resolvedLabel = computed(() => {
|
|
2149
2330
|
if (this.label()) {
|
|
2150
2331
|
return this.label();
|
|
2151
2332
|
}
|
|
2152
|
-
const
|
|
2333
|
+
const direction = deltaDirection(this.value());
|
|
2334
|
+
const dir = direction === 'up' ? 'up' : direction === 'down' ? 'down' : 'unchanged';
|
|
2153
2335
|
return `${this.formattedValue()} ${dir}`;
|
|
2154
2336
|
}, ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
|
|
2155
2337
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTrend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2156
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxTrend, isStandalone: true, selector: "cngx-trend", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-trend--up": "value() > 0", "class.cngx-trend--down": "value() < 0", "attr.aria-label": "resolvedLabel()" }, classAttribute: "cngx-trend" }, ngImport: i0, template: `
|
|
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: `
|
|
2157
2339
|
<span aria-hidden="true">{{ icon() }}</span>
|
|
2158
2340
|
{{ formattedValue() }}
|
|
2159
|
-
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-trend-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-trend-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-trend-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-trend-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-trend-up-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-trend-down-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-trend-color: oklch(.36 .02 290);--cngx-trend-up-color: oklch(.65 .18 145);--cngx-trend-down-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-trend){:scope{display:inline-flex;align-items:center;gap:var(--cngx-trend-gap, 2px);font-size:var(--cngx-trend-size, .8125rem);font-weight:var(--cngx-trend-weight, 500);color:var(--cngx-trend-color, oklch(.36 .02 290))}:scope.cngx-trend--up{color:var(--cngx-trend-up-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-trend--down{color:var(--cngx-trend-down-color, var(--cngx-color-danger, oklch(.65 .22 25)))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
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 });
|
|
2160
2342
|
}
|
|
2161
2343
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTrend, decorators: [{
|
|
2162
2344
|
type: Component,
|
|
2163
2345
|
args: [{ selector: 'cngx-trend', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
2164
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',
|
|
2165
2351
|
'[class.cngx-trend--up]': 'value() > 0',
|
|
2166
2352
|
'[class.cngx-trend--down]': 'value() < 0',
|
|
2167
2353
|
'[attr.aria-label]': 'resolvedLabel()',
|
|
2168
2354
|
}, template: `
|
|
2169
2355
|
<span aria-hidden="true">{{ icon() }}</span>
|
|
2170
2356
|
{{ formattedValue() }}
|
|
2171
|
-
`, styles: ["@layer cngx.tokens{@property --cngx-trend-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-trend-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-trend-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-trend-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-trend-up-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-trend-down-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-trend-color: oklch(.36 .02 290);--cngx-trend-up-color: oklch(.65 .18 145);--cngx-trend-down-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-trend){:scope{display:inline-flex;align-items:center;gap:var(--cngx-trend-gap, 2px);font-size:var(--cngx-trend-size, .8125rem);font-weight:var(--cngx-trend-weight, 500);color:var(--cngx-trend-color, oklch(.36 .02 290))}:scope.cngx-trend--up{color:var(--cngx-trend-up-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-trend--down{color:var(--cngx-trend-down-color, var(--cngx-color-danger, oklch(.65 .22 25)))}}}\n"] }]
|
|
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"] }]
|
|
2172
2358
|
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }] } });
|
|
2173
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
|
+
|
|
2174
2807
|
const EMPTY_RANGE = {
|
|
2175
2808
|
start: 0,
|
|
2176
2809
|
end: 0,
|
|
@@ -2535,7 +3168,13 @@ function injectRecycler(config) {
|
|
|
2535
3168
|
}
|
|
2536
3169
|
return typeof config.columns === 'function' ? config.columns() : config.columns;
|
|
2537
3170
|
}, ...(ngDevMode ? [{ debugName: "columns" }] : /* istanbul ignore next */ []));
|
|
2538
|
-
|
|
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()) {
|
|
2539
3178
|
const count = config.totalCount();
|
|
2540
3179
|
if (count > 10_000) {
|
|
2541
3180
|
console.warn(`[CngxRecycler] estimateSize as a function with ${count} items has O(n) ` +
|
|
@@ -3364,5 +4003,5 @@ function createMaterialBidirectionalSync(opts) {
|
|
|
3364
4003
|
* Generated bundle index. Do not edit.
|
|
3365
4004
|
*/
|
|
3366
4005
|
|
|
3367
|
-
export { CNGX_BUCKET_PAGINATE_HOST, CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_RECYCLER_I18N, CngxAsync, CngxBucketPaginate, CngxDataSource, CngxFilter, CngxFilterChip, CngxFilterChips, CngxMeasure, CngxMetric, CngxPaginate, CngxPaginateResetOn, CngxPaginateRouting, CngxRecyclerAnnouncer, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxTrend, CngxVirtualItem, connectPaginateResetOn, connectRecyclerToActiveDescendant, connectRecyclerToRoving, createAsyncState, createCommitController, createManualState, createMaterialBidirectionalSync, fromHttpResource, fromResource, injectAsyncState, injectDataSource, injectRecycler, injectSmartDataSource, provideRecyclerI18n, resolveAsyncView, tapAsyncProgress, tapAsyncState, tapHttpAsyncState };
|
|
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 };
|
|
3368
4007
|
//# sourceMappingURL=cngx-common-data.mjs.map
|