@cngx/common 0.1.0-rc.2 → 0.1.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/data/README.md +10 -3
  2. package/display/README.md +1 -0
  3. package/fesm2022/cngx-common-a11y.mjs +123 -3
  4. package/fesm2022/cngx-common-a11y.mjs.map +1 -1
  5. package/fesm2022/cngx-common-card.mjs +8 -8
  6. package/fesm2022/cngx-common-card.mjs.map +1 -1
  7. package/fesm2022/cngx-common-data.mjs +999 -54
  8. package/fesm2022/cngx-common-data.mjs.map +1 -1
  9. package/fesm2022/cngx-common-display.mjs +320 -8
  10. package/fesm2022/cngx-common-display.mjs.map +1 -1
  11. package/fesm2022/cngx-common-interactive.mjs +1603 -75
  12. package/fesm2022/cngx-common-interactive.mjs.map +1 -1
  13. package/fesm2022/cngx-common-layout.mjs +187 -3
  14. package/fesm2022/cngx-common-layout.mjs.map +1 -1
  15. package/fesm2022/cngx-common-popover.mjs +63 -8
  16. package/fesm2022/cngx-common-popover.mjs.map +1 -1
  17. package/fesm2022/cngx-common.mjs +1 -1
  18. package/interactive/README.md +101 -0
  19. package/layout/README.md +39 -1
  20. package/package.json +1 -1
  21. package/theming/components/cngx-accordion.css +147 -0
  22. package/theming/components/cngx-badge.css +6 -0
  23. package/theming/components/cngx-bottom-sheet.css +8 -1
  24. package/theming/components/cngx-breadcrumb.css +108 -0
  25. package/theming/components/cngx-button-toggle.css +6 -0
  26. package/theming/components/cngx-data-grid.css +154 -0
  27. package/theming/components/cngx-dialog.css +4 -0
  28. package/theming/components/cngx-divider.css +4 -0
  29. package/theming/components/cngx-listbox.css +6 -0
  30. package/theming/components/cngx-menu.css +7 -0
  31. package/theming/components/cngx-slider.css +237 -0
  32. package/theming/components/cngx-tooltip.css +6 -0
  33. package/types/cngx-common-a11y.d.ts +67 -2
  34. package/types/cngx-common-data.d.ts +837 -23
  35. package/types/cngx-common-display.d.ts +189 -1
  36. package/types/cngx-common-interactive.d.ts +1014 -31
  37. package/types/cngx-common-layout.d.ts +88 -3
  38. package/types/cngx-common-popover.d.ts +25 -4
package/data/README.md CHANGED
@@ -778,7 +778,10 @@ readonly dataSource = injectSmartDataSource(this.residents);
778
778
  </table>
779
779
  }
780
780
 
781
- <cngx-mat-paginator [cngxPaginateRef]="pg" />
781
+ <mat-paginator
782
+ [length]="pg.total()" [pageIndex]="pg.pageIndex()" [pageSize]="pg.pageSize()"
783
+ (page)="pg.setPageSize($event.pageSize, false); pg.setPage($event.pageIndex)"
784
+ ></mat-paginator>
782
785
  </div>
783
786
  ```
784
787
 
@@ -814,12 +817,16 @@ The paginator accepts `[state]` and blocks navigation while busy:
814
817
  <div cngxPaginate #pg="cngxPaginate"
815
818
  [total]="dataSource.filteredCount()" [state]="residents">
816
819
  <!-- table -->
817
- <cngx-mat-paginator [cngxPaginateRef]="pg" />
820
+ <mat-paginator
821
+ [length]="pg.total()" [pageIndex]="pg.pageIndex()" [pageSize]="pg.pageSize()"
822
+ [disabled]="pg.isBusy()"
823
+ (page)="pg.setPageSize($event.pageSize, false); pg.setPage($event.pageIndex)"
824
+ ></mat-paginator>
818
825
  </div>
819
826
  ```
820
827
 
821
828
  - `setPage()`, `next()`, `previous()`, `setPageSize()` are no-ops while `isBusy`
822
- - `CngxMatPaginator` auto-disables via `[disabled]="ref().isBusy()"`
829
+ - bind `[disabled]="pg.isBusy()"` so the rendered controls reflect busy state
823
830
  - No manual disabled management needed
824
831
 
825
832
 
package/display/README.md CHANGED
@@ -7,6 +7,7 @@ Display-only atoms. Icons, avatars, badges, chips, tags, indicators, dividers -
7
7
  You need a primitive visual piece that other components compose:
8
8
 
9
9
  - An avatar that gracefully degrades from photo URL → initials → fallback.
10
+ - A stacked `CngxAvatarGroup` that overlaps avatars and collapses the extras past `[max]` into a `+N` overflow pill, with an `aria-label` summarising the hidden count.
10
11
  - A chip the user can remove (used internally by multi-select, combobox, tag-input, filter-chips - and available to you for the same purpose).
11
12
  - A tag pill that conveys status, category, or count - non-removable, theme-aware.
12
13
  - A checkbox or radio glyph for a custom row design where you want the cngx look but own the selection logic yourself.
@@ -1,6 +1,6 @@
1
1
  import * as i0 from '@angular/core';
2
- import { input, Directive, inject, ElementRef, Injector, DestroyRef, afterNextRender, effect, signal, computed, model, contentChildren, InjectionToken, output } from '@angular/core';
3
- import { DOCUMENT } from '@angular/common';
2
+ import { input, Directive, inject, PLATFORM_ID, Injectable, ElementRef, Injector, DestroyRef, afterNextRender, effect, signal, computed, model, contentChildren, InjectionToken, output } from '@angular/core';
3
+ import { DOCUMENT, isPlatformBrowser } from '@angular/common';
4
4
  import { FocusTrapFactory } from '@angular/cdk/a11y';
5
5
 
6
6
  /**
@@ -132,6 +132,102 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
132
132
  }]
133
133
  }], propDecorators: { politeness: [{ type: i0.Input, args: [{ isSignal: true, alias: "politeness", required: false }] }], atomic: [{ type: i0.Input, args: [{ isSignal: true, alias: "atomic", required: false }] }], relevant: [{ type: i0.Input, args: [{ isSignal: true, alias: "relevant", required: false }] }] } });
134
134
 
135
+ /**
136
+ * Imperative, reusable polite/assertive live-region announcer.
137
+ *
138
+ * The imperative counterpart to {@link CngxLiveRegion}: where the directive
139
+ * decorates an element you render (the content IS the announcement), this
140
+ * service owns a single visually-hidden `aria-live` element appended to
141
+ * `document.body` and exposes an `announce(message)` call for template-less
142
+ * directives and event handlers (e.g. `CngxCopyValue` copy success,
143
+ * `CngxOtpInput` completion).
144
+ *
145
+ * One root element is created lazily on the first announcement and reused for
146
+ * every subsequent call. The text is cleared and re-set on the next macrotask
147
+ * so an identical consecutive message is still re-read by the screen reader.
148
+ *
149
+ * SSR-safe: all DOM access is guarded by `isPlatformBrowser`; on the server
150
+ * `announce()` is a no-op and no element is created.
151
+ *
152
+ * ```typescript
153
+ * const announcer = inject(CngxLiveAnnouncer);
154
+ * announcer.announce('Copied');
155
+ * announcer.announce('Save failed', 'assertive');
156
+ * ```
157
+ *
158
+ * @category common/a11y
159
+ * @docsKind primary
160
+ * @wcag AA
161
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/live-announcer.ts
162
+ * @since 0.1.0
163
+ * @relatedTo CngxLiveRegion
164
+ */
165
+ class CngxLiveAnnouncer {
166
+ doc = inject(DOCUMENT);
167
+ isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
168
+ region = null;
169
+ pending = null;
170
+ /**
171
+ * Announces `message` through the shared live region.
172
+ *
173
+ * @param message Text read by the screen reader.
174
+ * @param politeness `'polite'` (default) queues after the current
175
+ * utterance; `'assertive'` interrupts immediately.
176
+ */
177
+ announce(message, politeness = 'polite') {
178
+ if (!this.isBrowser) {
179
+ return;
180
+ }
181
+ const region = this.ensureRegion();
182
+ region.setAttribute('aria-live', politeness);
183
+ // Clear first, then write on the next macrotask so repeating the same
184
+ // string still registers as a content change for the SR.
185
+ region.textContent = '';
186
+ if (this.pending !== null) {
187
+ clearTimeout(this.pending);
188
+ }
189
+ this.pending = setTimeout(() => {
190
+ region.textContent = message;
191
+ this.pending = null;
192
+ });
193
+ }
194
+ ngOnDestroy() {
195
+ if (this.pending !== null) {
196
+ clearTimeout(this.pending);
197
+ this.pending = null;
198
+ }
199
+ this.region?.remove();
200
+ this.region = null;
201
+ }
202
+ ensureRegion() {
203
+ if (this.region) {
204
+ return this.region;
205
+ }
206
+ const span = this.doc.createElement('span');
207
+ span.setAttribute('aria-live', 'polite');
208
+ span.setAttribute('aria-atomic', 'true');
209
+ span.className = 'cngx-sr-only';
210
+ span.style.position = 'absolute';
211
+ span.style.width = '1px';
212
+ span.style.height = '1px';
213
+ span.style.padding = '0';
214
+ span.style.margin = '-1px';
215
+ span.style.overflow = 'hidden';
216
+ span.style.clip = 'rect(0, 0, 0, 0)';
217
+ span.style.whiteSpace = 'nowrap';
218
+ span.style.border = '0';
219
+ this.doc.body.appendChild(span);
220
+ this.region = span;
221
+ return span;
222
+ }
223
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxLiveAnnouncer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
224
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxLiveAnnouncer, providedIn: 'root' });
225
+ }
226
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxLiveAnnouncer, decorators: [{
227
+ type: Injectable,
228
+ args: [{ providedIn: 'root' }]
229
+ }] });
230
+
135
231
  /**
136
232
  * Reactive autofocus for dynamically inserted elements.
137
233
  *
@@ -631,6 +727,13 @@ class CngxRovingTabindex {
631
727
  /** Host element for `data-cngx-recycle-index` queries in virtual mode. */
632
728
  hostEl = inject((ElementRef));
633
729
  pendingFocusState = signal(null, ...(ngDevMode ? [{ debugName: "pendingFocusState" }] : /* istanbul ignore next */ []));
730
+ /**
731
+ * Set true just before a navigation key (arrow / Home / End) moves focus to a
732
+ * new item, cleared by {@link consumeNavigationKey}. Transient handshake, not
733
+ * reactive state: consumer groups read it synchronously from the
734
+ * newly-focused leaf's `(focus)` handler.
735
+ */
736
+ navigationKeyInFlight = false;
634
737
  /**
635
738
  * Index of the item that should receive focus but is not currently in the DOM.
636
739
  * Non-null when virtual navigation targets an out-of-range item.
@@ -668,6 +771,19 @@ class CngxRovingTabindex {
668
771
  clearPendingFocus() {
669
772
  this.pendingFocusState.set(null);
670
773
  }
774
+ /**
775
+ * Whether the last focus move was driven by a navigation key, consuming the
776
+ * flag so it reads `true` exactly once. Consumer groups (radio,
777
+ * button-toggle) call this from the newly-focused leaf's `(focus)` handler to
778
+ * decide whether to auto-select. The flag is set before `.focus()`, so it is
779
+ * already `true` when focus lands - this closes the one-press-behind race
780
+ * that a group's own `(keydown)` binding suffered (#135).
781
+ */
782
+ consumeNavigationKey() {
783
+ const inFlight = this.navigationKeyInFlight;
784
+ this.navigationKeyInFlight = false;
785
+ return inFlight;
786
+ }
671
787
  /**
672
788
  * Handles arrow-key, Home, and End navigation within the group.
673
789
  * Prevents default scrolling on arrow keys.
@@ -706,6 +822,10 @@ class CngxRovingTabindex {
706
822
  if (nextIndex !== null && nextIndex !== currentActive) {
707
823
  event.preventDefault();
708
824
  this.activeIndex.set(nextIndex);
825
+ // Expose the navigation intent before focus moves, so the newly-focused
826
+ // leaf's (focus) handler reads an already-set fact instead of racing the
827
+ // group's own late (keydown) binding (#135).
828
+ this.navigationKeyInFlight = true;
709
829
  if (isVirtual) {
710
830
  this.focusVirtualItem(nextIndex);
711
831
  }
@@ -1369,5 +1489,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1369
1489
  * Generated bundle index. Do not edit.
1370
1490
  */
1371
1491
 
1372
- export { CNGX_AD_ITEM, CNGX_FOCUSABLE_SELECTOR, CngxActiveDescendant, CngxAriaExpanded, CngxAutofocus, CngxFocusRestore, CngxFocusTrap, CngxFocusVisible, CngxLiveRegion, CngxReducedMotion, CngxRovingItem, CngxRovingTabindex };
1492
+ export { CNGX_AD_ITEM, CNGX_FOCUSABLE_SELECTOR, CngxActiveDescendant, CngxAriaExpanded, CngxAutofocus, CngxFocusRestore, CngxFocusTrap, CngxFocusVisible, CngxLiveAnnouncer, CngxLiveRegion, CngxReducedMotion, CngxRovingItem, CngxRovingTabindex };
1373
1493
  //# sourceMappingURL=cngx-common-a11y.mjs.map