@cngx/ui 0.1.0-rc.2 → 0.1.0-rc.3

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.
@@ -0,0 +1,131 @@
1
+ # @cngx/ui/paginator
2
+
3
+ Default-theme, skinnable, framework-neutral pagination organism. A declarative
4
+ `<cngx-paginator>` shell over the `CngxPaginate` brain from `@cngx/common/data`,
5
+ assembled from projected segment parts in DOM order - no `show*` config inputs.
6
+
7
+ ## When you reach for it
8
+
9
+ You want a paginator that:
10
+
11
+ - Composes from child parts (`cngx-pgn-prev`, `cngx-pgn-pages`,
12
+ `cngx-pgn-page-size`, `cngx-pgn-range`, `cngx-pgn-goto`, ...) instead of a pile
13
+ of boolean inputs.
14
+ - Repaints across seven skins via a single `[skin]` attribute, with identical
15
+ DOM, ARIA, and keyboard behaviour across all of them.
16
+ - Carries async-aware navigation gating, a roving-keyboard page row, and
17
+ live-region announcements out of the box.
18
+ - Ships no Material runtime.
19
+
20
+ If you already render a Material `<mat-paginator>`, reach for `[cngxMatPaginator]`
21
+ in `@cngx/ui/mat-paginator` instead. The `CngxPaginate` brain is shared.
22
+
23
+ ## Usage
24
+
25
+ The shell exposes only `total`, `[(pageIndex)]`, `[(pageSize)]`, `[state]`,
26
+ `skin`, `density`, and `resetOn`. Everything else is a projected segment in DOM
27
+ order. The brain owns no data: bind `[total]`, read the active page back through
28
+ the two-way bindings, and slice your own array.
29
+
30
+ ```html
31
+ <cngx-paginator skin="numbered" [total]="items().length" [(pageIndex)]="pageIndex">
32
+ <cngx-pgn-prev />
33
+ <cngx-pgn-pages />
34
+ <cngx-pgn-next />
35
+ <cngx-pgn-range />
36
+ </cngx-paginator>
37
+ ```
38
+
39
+ ```ts
40
+ protected readonly pageIndex = signal(0);
41
+ protected readonly pageSize = signal(10);
42
+ protected readonly pageItems = computed(() => {
43
+ const start = this.pageIndex() * this.pageSize();
44
+ return this.items().slice(start, start + this.pageSize());
45
+ });
46
+ ```
47
+
48
+ ## Segments
49
+
50
+ Each part injects `CNGX_PAGINATOR_HOST` and self-wires; drop in only what the
51
+ context needs.
52
+
53
+ |Segment|Selector|Role|
54
+ |-|-|-|
55
+ |First / last|`cngx-pgn-first` / `cngx-pgn-last`|Jump to the boundaries; `aria-disabled` at the bound|
56
+ |Previous / next|`cngx-pgn-prev` / `cngx-pgn-next`|Step one page; `aria-disabled` at the bound|
57
+ |Pages|`cngx-pgn-pages`|Roving numbered row with ellipsis overflow menu, `aria-current` on the active page|
58
+ |Range|`cngx-pgn-range`|`start-end of total` readout (format from config)|
59
+ |Page size|`cngx-pgn-page-size`|`CngxListbox` select; `[options]` is data; resets to the first page|
60
+ |Page of pages|`cngx-pgn-page-of-pages`|`current / total` jump dropdown|
61
+ |Go to|`cngx-pgn-goto`|Native number input; Enter or blur navigates|
62
+ |Dots|`cngx-pgn-dots`|One dot per page (organism-internal), for the `dots` skin|
63
+
64
+ ## Skins
65
+
66
+ `numbered`, `minimal`, `pill`, `segmented`, `rail`, `dots`, `bar`. Set via
67
+ `[skin]` -> `[data-skin]`. Skin is paint-only: DOM, ARIA, and keyboard behaviour
68
+ are identical across all seven. `density` (`compact` / `default` / `comfortable`)
69
+ is orthogonal.
70
+
71
+ ## Reset and deep-linking
72
+
73
+ `[resetOn]` jumps to the first page whenever its bound value changes - bind the
74
+ sort / filter / search value the result set depends on so a narrowed result never
75
+ strands the user on a now-empty page. Mounting does not reset; bind a primitive
76
+ or a `computed`, never an inline literal.
77
+
78
+ ```html
79
+ <cngx-paginator [total]="filtered().length" [resetOn]="search()">…</cngx-paginator>
80
+ ```
81
+
82
+ For deep-linkable, back-button-safe URLs add the brain-level
83
+ `[cngxPaginateRouting]` directive (from `@cngx/common/data`) on the same host - it
84
+ persists the page / size in the query string and needs `@angular/router`.
85
+
86
+ ```html
87
+ <cngx-paginator cngxPaginateRouting [total]="items().length">…</cngx-paginator>
88
+ ```
89
+
90
+ ## Async
91
+
92
+ `CngxPaginator` is an async-state consumer. Bind `[state]` and, while busy, it
93
+ gates navigation, renders an indeterminate `cngx-progress` bar, flips
94
+ `aria-busy`, and announces the transition.
95
+
96
+ ```html
97
+ <cngx-paginator [total]="total()" [state]="loading">…</cngx-paginator>
98
+ ```
99
+
100
+ ## Configuration
101
+
102
+ All accessible-name strings, announcement phrasing, and the range format cascade
103
+ through `CNGX_PAGINATOR_CONFIG` (English defaults). Override at the app root with
104
+ `provideCngxPaginatorConfig(...)`, or per region with
105
+ `provideCngxPaginatorConfigAt(...)` in `viewProviders`.
106
+
107
+ ```ts
108
+ provideCngxPaginatorConfig(
109
+ withPaginatorAriaLabels({ next: 'Nächste Seite', pageOfPages: 'Seite wählen' }),
110
+ withPaginatorAnnouncements({ pageChange: (p, t) => `Seite ${p} von ${t}` }),
111
+ withPaginatorRangeFormat((start, end, total) => `${start}-${end} von ${total}`),
112
+ );
113
+ ```
114
+
115
+ `withPaginatorRangeFormat` localises the `cngx-pgn-range` text (including the
116
+ `of` connector); `ariaLabels.pageOfPages` is the dedicated label for the
117
+ page-of-pages selector.
118
+
119
+ The live-region announcer is swappable. `CNGX_PAGINATOR_ANNOUNCER_FACTORY`
120
+ defaults to `createPaginatorAnnouncer`; override it to wrap the busy / settle /
121
+ page-change derivation (telemetry tap, politeness escalation, custom branching)
122
+ without forking the shell. It mirrors the select family's
123
+ `CNGX_COMMIT_ERROR_ANNOUNCER_FACTORY`.
124
+
125
+ ## Accessibility
126
+
127
+ `role="navigation"` landmark with a configurable `aria-label`; a single
128
+ roving tab stop on the page row (arrows / Home / End); `aria-current="page"` on
129
+ the active page; a single computed `aria-busy` owner; live-region page-change,
130
+ clamp, and async announcements. A `total`-shrink clamp is never silent - the
131
+ clamped page is both emitted back to the consumer and announced.
@@ -0,0 +1,108 @@
1
+ import * as _angular_core from '@angular/core';
2
+ import * as i1 from '@cngx/common/data';
3
+ import { CngxPaginate } from '@cngx/common/data';
4
+ export { CngxPaginateResetOn, CngxPaginateRouting } from '@cngx/common/data';
5
+
6
+ /**
7
+ * Context handed to {@link CngxMatPaginator.announceLabel} to build the
8
+ * screen-reader announcement after each page / page-size change.
9
+ *
10
+ * @category ui/mat-paginator
11
+ */
12
+ interface CngxMatPaginatorAnnounceContext {
13
+ /** 1-based current page. */
14
+ readonly page: number;
15
+ /** Total page count (minimum 1). */
16
+ readonly totalPages: number;
17
+ /** 1-based index of the first item on the page. */
18
+ readonly start: number;
19
+ /** 1-based index of the last item on the page, capped at `total`. */
20
+ readonly end: number;
21
+ /** Total item count before pagination. */
22
+ readonly total: number;
23
+ }
24
+ /**
25
+ * The in-place adoption half of the Material paginator instrumentation: add
26
+ * `cngxMatPaginator` to an existing `<mat-paginator>` and the signal-native
27
+ * {@link CngxPaginate} brain takes over its state with no DOM rewrite, mirroring
28
+ * `[cngxMatStepper]` / `[cngxMatTabs]`.
29
+ *
30
+ * The bridge composes the untouched brain via `hostDirectives`, injects the
31
+ * consumer's own `MatPaginator` with `{ self: true }`, and syncs the four
32
+ * Material properties (`length` / `pageIndex` / `pageSize` / `disabled`) plus
33
+ * `pageSizeOptions` against the brain's `computed()` graph, forwarding `(page)`
34
+ * back into the brain.
35
+ *
36
+ * Beyond plain `<mat-paginator>`, the bridge adds:
37
+ * - `[resetOn]` - jump to the first page whenever a bound key (a sort / filter /
38
+ * search value) changes, so a filtered result set never strands the user on a
39
+ * now-empty page. Pass a primitive (or a `computed` string key); an inline
40
+ * array literal recomputes every change-detection pass and would reset on each.
41
+ * - `[announce]` - mount a visually-hidden `aria-live` region that speaks the new
42
+ * page + visible range after every change; `<mat-paginator>` only relabels its
43
+ * own range text, which AT does not announce. Localise via `[announceLabel]`.
44
+ * - `[cngxPaginateRouting]` (generic companion directive from `@cngx/common/data`)
45
+ * - persist the page / size in the URL query string for deep-linkable,
46
+ * back-button-safe pagination.
47
+ *
48
+ * ```html
49
+ * <mat-paginator
50
+ * cngxMatPaginator
51
+ * #pg="cngxMatPaginator"
52
+ * [total]="items.length"
53
+ * [pageSizeOptions]="[5, 10, 25]"
54
+ * />
55
+ * <ul>
56
+ * @for (item of items.slice(pg.paginate.range()[0], pg.paginate.range()[1]); track item.id) {
57
+ * <li>{{ item.label }}</li>
58
+ * }
59
+ * </ul>
60
+ * ```
61
+ *
62
+ * @category ui/mat-paginator
63
+ * @docsKind primary
64
+ * @wcag AA
65
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/ui/mat-paginator/mat-paginator-bridge.directive.ts
66
+ * @since 0.1.0
67
+ * @relatedTo CngxPaginate, CngxMatStepper, CngxPaginator
68
+ * <example-url>http://localhost:4200/#/common/data/data-source/datasource-cngxpaginate-manual-pipeline</example-url>
69
+ * <example-url>http://localhost:4200/#/common/data/paginate-list/bridge-announce-page-changes</example-url>
70
+ * <example-url>http://localhost:4200/#/common/data/paginate-list/instrumentation-bridge-cngxmatpaginator</example-url>
71
+ * <example-url>http://localhost:4200/#/common/data/paginate-list/paginated-list-cngxpaginate-cngxmatpaginator</example-url>
72
+ * <example-url>http://localhost:4200/#/common/data/paginate-list/uncontrolled-mode-zero-class-boilerplate</example-url>
73
+ */
74
+ declare class CngxMatPaginator {
75
+ private readonly matPaginator;
76
+ /**
77
+ * The composed {@link CngxPaginate} brain. Public so a sibling list or table
78
+ * outside the `<mat-paginator>` reads `range()` via `#ref="cngxMatPaginator"`.
79
+ */
80
+ readonly paginate: CngxPaginate;
81
+ /** Options for the page-size selector. A Material-render concern, owned here. */
82
+ readonly pageSizeOptions: _angular_core.InputSignal<number[]>;
83
+ /**
84
+ * Reset key. When its value changes (after the initial render) the brain jumps
85
+ * to the first page. Bind the sort / filter / search value a result set
86
+ * depends on. Pass a primitive or a `computed` - an inline array / object
87
+ * literal recomputes every change-detection pass and would reset every time.
88
+ */
89
+ readonly resetOn: _angular_core.InputSignal<unknown>;
90
+ /** Speak page changes through a visually-hidden `aria-live` region when `true`. */
91
+ readonly announce: _angular_core.InputSignal<boolean>;
92
+ /** Builds the announcement string. Defaults to an English template. */
93
+ readonly announceLabel: _angular_core.InputSignal<(context: CngxMatPaginatorAnnounceContext) => string>;
94
+ private readonly elementRef;
95
+ private readonly renderer;
96
+ private readonly destroyRef;
97
+ /** The live-region message - derived, so it never drifts from brain state. */
98
+ private readonly announceMessage;
99
+ private liveRegion;
100
+ constructor();
101
+ /** A visually-hidden polite live region appended to the host paginator. */
102
+ private createLiveRegion;
103
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<CngxMatPaginator, never>;
104
+ static ɵdir: _angular_core.ɵɵDirectiveDeclaration<CngxMatPaginator, "[cngxMatPaginator]", ["cngxMatPaginator"], { "pageSizeOptions": { "alias": "pageSizeOptions"; "required": false; "isSignal": true; }; "resetOn": { "alias": "resetOn"; "required": false; "isSignal": true; }; "announce": { "alias": "announce"; "required": false; "isSignal": true; }; "announceLabel": { "alias": "announceLabel"; "required": false; "isSignal": true; }; }, {}, never, never, true, [{ directive: typeof i1.CngxPaginate; inputs: { "cngxPageIndex": "cngxPageIndex"; "cngxPageSize": "cngxPageSize"; "total": "total"; "state": "state"; }; outputs: { "pageChange": "pageChange"; "pageSizeChange": "pageSizeChange"; }; }]>;
105
+ }
106
+
107
+ export { CngxMatPaginator };
108
+ export type { CngxMatPaginatorAnnounceContext };