@cngx/ui 0.1.0-rc.5 → 0.1.0-rc.7
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/README.md +112 -0
- package/a11y/README.md +81 -0
- package/context-menu/README.md +98 -0
- package/data-grid-accordion/README.md +27 -0
- package/feedback/README.md +2 -0
- package/fesm2022/cngx-ui-a11y.mjs +320 -0
- package/fesm2022/cngx-ui-a11y.mjs.map +1 -0
- package/fesm2022/cngx-ui-accordion.mjs +19 -8
- package/fesm2022/cngx-ui-accordion.mjs.map +1 -1
- package/fesm2022/cngx-ui-action-button.mjs +5 -2
- package/fesm2022/cngx-ui-action-button.mjs.map +1 -1
- package/fesm2022/cngx-ui-breadcrumb.mjs +11 -6
- package/fesm2022/cngx-ui-breadcrumb.mjs.map +1 -1
- package/fesm2022/cngx-ui-chart-panel.mjs +429 -0
- package/fesm2022/cngx-ui-chart-panel.mjs.map +1 -0
- package/fesm2022/cngx-ui-collection.mjs +15 -6
- package/fesm2022/cngx-ui-collection.mjs.map +1 -1
- package/fesm2022/cngx-ui-command-palette.mjs +1005 -0
- package/fesm2022/cngx-ui-command-palette.mjs.map +1 -0
- package/fesm2022/cngx-ui-context-menu.mjs +742 -0
- package/fesm2022/cngx-ui-context-menu.mjs.map +1 -0
- package/fesm2022/cngx-ui-data-grid-accordion.mjs +90 -20
- package/fesm2022/cngx-ui-data-grid-accordion.mjs.map +1 -1
- package/fesm2022/cngx-ui-feedback.mjs +97 -106
- package/fesm2022/cngx-ui-feedback.mjs.map +1 -1
- package/fesm2022/cngx-ui-layout.mjs +18 -9
- package/fesm2022/cngx-ui-layout.mjs.map +1 -1
- package/fesm2022/cngx-ui-mat-accordion.mjs +9 -9
- package/fesm2022/cngx-ui-mat-accordion.mjs.map +1 -1
- package/fesm2022/cngx-ui-mat-tabs.mjs +64 -70
- package/fesm2022/cngx-ui-mat-tabs.mjs.map +1 -1
- package/fesm2022/cngx-ui-paginator.mjs +18 -8
- package/fesm2022/cngx-ui-paginator.mjs.map +1 -1
- package/fesm2022/cngx-ui-sidenav.mjs +2 -2
- package/fesm2022/cngx-ui-sidenav.mjs.map +1 -1
- package/fesm2022/cngx-ui-skeleton.mjs +20 -7
- package/fesm2022/cngx-ui-skeleton.mjs.map +1 -1
- package/fesm2022/cngx-ui-speak.mjs +2 -2
- package/fesm2022/cngx-ui-speak.mjs.map +1 -1
- package/fesm2022/cngx-ui-stat-card.mjs +618 -0
- package/fesm2022/cngx-ui-stat-card.mjs.map +1 -0
- package/fesm2022/cngx-ui-stepper.mjs +38 -19
- package/fesm2022/cngx-ui-stepper.mjs.map +1 -1
- package/fesm2022/cngx-ui-tabs.mjs +36 -19
- package/fesm2022/cngx-ui-tabs.mjs.map +1 -1
- package/fesm2022/cngx-ui-timeline.mjs +495 -0
- package/fesm2022/cngx-ui-timeline.mjs.map +1 -0
- package/fesm2022/cngx-ui-toc.mjs +704 -0
- package/fesm2022/cngx-ui-toc.mjs.map +1 -0
- package/fesm2022/cngx-ui.mjs +2 -2
- package/fesm2022/cngx-ui.mjs.map +1 -1
- package/mat-accordion/README.md +1 -1
- package/mat-tabs/styles/mat-tabs.css +20 -17
- package/package.json +32 -1
- package/skeleton/README.md +2 -0
- package/stepper/README.md +2 -2
- package/timeline/README.md +350 -0
- package/toc/README.md +183 -0
- package/types/cngx-ui-a11y.d.ts +303 -0
- package/types/cngx-ui-accordion.d.ts +9 -4
- package/types/cngx-ui-action-button.d.ts +3 -0
- package/types/cngx-ui-breadcrumb.d.ts +5 -0
- package/types/cngx-ui-chart-panel.d.ts +278 -0
- package/types/cngx-ui-collection.d.ts +12 -3
- package/types/cngx-ui-command-palette.d.ts +451 -0
- package/types/cngx-ui-context-menu.d.ts +467 -0
- package/types/cngx-ui-data-grid-accordion.d.ts +72 -15
- package/types/cngx-ui-feedback.d.ts +71 -18
- package/types/cngx-ui-layout.d.ts +8 -3
- package/types/cngx-ui-mat-accordion.d.ts +3 -3
- package/types/cngx-ui-mat-tabs.d.ts +11 -9
- package/types/cngx-ui-paginator.d.ts +13 -3
- package/types/cngx-ui-skeleton.d.ts +13 -1
- package/types/cngx-ui-stat-card.d.ts +327 -0
- package/types/cngx-ui-stepper.d.ts +18 -4
- package/types/cngx-ui-tabs.d.ts +20 -4
- package/types/cngx-ui-timeline.d.ts +479 -0
- package/types/cngx-ui-toc.d.ts +514 -0
- package/types/cngx-ui.d.ts +1 -1
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
# CngxTimeline
|
|
2
|
+
|
|
3
|
+
Chronological event feed. Groups a flat list into date bands and switches its
|
|
4
|
+
body on a bound async state.
|
|
5
|
+
|
|
6
|
+
## Import
|
|
7
|
+
|
|
8
|
+
```typescript
|
|
9
|
+
import { CngxTimeline } from '@cngx/ui/timeline';
|
|
10
|
+
import { CngxTimelineItem, CngxTimelineItemTpl, CngxTimelineTime } from '@cngx/common/timeline';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { Component } from '@angular/core';
|
|
17
|
+
import { CngxTimeline } from '@cngx/ui/timeline';
|
|
18
|
+
import { CngxTimelineItem, CngxTimelineItemTpl, CngxTimelineTime } from '@cngx/common/timeline';
|
|
19
|
+
import { CngxTime } from '@cngx/common/display';
|
|
20
|
+
|
|
21
|
+
@Component({
|
|
22
|
+
selector: 'app-example',
|
|
23
|
+
template: `
|
|
24
|
+
<cngx-timeline [state]="feed" [dateAccessor]="at" [idAccessor]="byId" groupBy="day">
|
|
25
|
+
<ng-template [cngxTimelineItem]="feed.data()" let-event let-last="last">
|
|
26
|
+
<cngx-timeline-item [position]="last ? 'last' : 'middle'" status="done">
|
|
27
|
+
<cngx-time cngxTimelineTime [date]="event.at" />
|
|
28
|
+
<p>{{ event.summary }}</p>
|
|
29
|
+
</cngx-timeline-item>
|
|
30
|
+
</ng-template>
|
|
31
|
+
</cngx-timeline>
|
|
32
|
+
`,
|
|
33
|
+
imports: [CngxTimeline, CngxTimelineItem, CngxTimelineItemTpl, CngxTimelineTime, CngxTime],
|
|
34
|
+
})
|
|
35
|
+
export class ExampleComponent {
|
|
36
|
+
// feed is a CngxAsyncState<Event[]> from createAsyncState / injectAsyncState
|
|
37
|
+
protected readonly at = (event: Event) => event.at;
|
|
38
|
+
protected readonly byId = (event: Event) => event.id;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`[items]` takes a plain array when there is no async state to bind. `[state]`
|
|
43
|
+
wins over it.
|
|
44
|
+
|
|
45
|
+
Binding the same array to `[cngxTimelineItem]` is what types `let-event`.
|
|
46
|
+
Angular cannot infer a structural directive's context generic from a sibling
|
|
47
|
+
input on the host, so the slot pins it through an input of its own - the
|
|
48
|
+
`ngForOf` mechanism. The binding is optional and never read at runtime; leave
|
|
49
|
+
it off and the `let-` variables fall back to `unknown`.
|
|
50
|
+
|
|
51
|
+
## Overview
|
|
52
|
+
|
|
53
|
+
The organism owns very little. Bucketing lives in a presenter
|
|
54
|
+
(`createTimelineGrouping`, `@cngx/common/timeline`) fronted by
|
|
55
|
+
`CNGX_TIMELINE_GROUPING_FACTORY`, the row raster lives with `CngxTimelineItem`,
|
|
56
|
+
and latency gating lives in `<cngx-skeleton>` (`@cngx/ui/skeleton`). What the
|
|
57
|
+
component adds is the band-and-row rendering, the ARIA chain, and the body
|
|
58
|
+
switch over `[state]`.
|
|
59
|
+
|
|
60
|
+
The rows are content, not widgets: there is no roving tabindex and no selection.
|
|
61
|
+
Links and buttons a consumer puts *inside* a row are natively tabbable in DOM
|
|
62
|
+
order, which is what a read-only history wants. Timeline is history; guided
|
|
63
|
+
process is `@cngx/common/stepper`.
|
|
64
|
+
|
|
65
|
+
## Grouping
|
|
66
|
+
|
|
67
|
+
`[groupBy]` takes `'day'` (default), `'week'`, `'month'`, `'none'`, or a
|
|
68
|
+
function. The three calendar modes read **local** date fields, so a 23- or
|
|
69
|
+
25-hour DST day still groups as one day. Weeks start Monday and a band is
|
|
70
|
+
anchored on its own Monday rather than on a week number.
|
|
71
|
+
|
|
72
|
+
`[direction]` is `'desc'` (newest first, the activity-feed convention) or
|
|
73
|
+
`'asc'`.
|
|
74
|
+
|
|
75
|
+
Input order is irrelevant - the presenter sorts defensively. Bands whose items
|
|
76
|
+
are the same objects hand back the same band reference, so appending leaves
|
|
77
|
+
every other band's `@for` block untouched.
|
|
78
|
+
|
|
79
|
+
For anything the built-ins do not cover - fiscal quarters, UTC days, "today /
|
|
80
|
+
this week / earlier" - pass a function returning a key and a start instant:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
protected readonly byQuarter = (date: Date) => ({
|
|
84
|
+
key: `${date.getFullYear()}-Q${Math.floor(date.getMonth() / 3) + 1}`,
|
|
85
|
+
start: new Date(date.getFullYear(), Math.floor(date.getMonth() / 3) * 3, 1),
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Swap the whole presenter app-wide through `CNGX_TIMELINE_GROUPING_FACTORY`
|
|
90
|
+
instead of forking the component.
|
|
91
|
+
|
|
92
|
+
## Async state
|
|
93
|
+
|
|
94
|
+
Bind `[state]` and the body follows it: skeleton on first load, error surface
|
|
95
|
+
with a retry, empty surface, and a refreshing tail over content that stays on
|
|
96
|
+
screen. Every branch comes from `resolveAsyncView`, and the show-delay /
|
|
97
|
+
min-dwell gating is the skeleton container's - the timeline holds no latency
|
|
98
|
+
logic, so a load that resolves faster than the delay never flashes a
|
|
99
|
+
placeholder.
|
|
100
|
+
|
|
101
|
+
`[skeletonRowCount]` sizes the placeholder to the usual result length, and
|
|
102
|
+
`*cngxTimelineSkeleton` reshapes the placeholder row itself when your rows are
|
|
103
|
+
taller than a dot and two bars.
|
|
104
|
+
`[emptyReason]` tells the empty slot which empty it is looking at: the organism
|
|
105
|
+
cannot infer whether a filter cleared the list or nothing has ever happened.
|
|
106
|
+
|
|
107
|
+
The bound state is republished through `CNGX_STATEFUL`, so `CngxToastOn` /
|
|
108
|
+
`CngxAlertOn` / `CngxBannerOn` attach on the host with no binding of their own.
|
|
109
|
+
|
|
110
|
+
A single row can carry its own state. `<cngx-timeline-item [state]="rowState">`
|
|
111
|
+
sets `aria-busy` while that row is in flight and repaints marker and rail as
|
|
112
|
+
`rejected` on failure, without discarding the editorial `status` the row goes
|
|
113
|
+
back to once a retry lands.
|
|
114
|
+
|
|
115
|
+
## Modes and skins
|
|
116
|
+
|
|
117
|
+
`[mode]` selects the row raster:
|
|
118
|
+
|
|
119
|
+
- `narrative` (default) - timestamp above the body.
|
|
120
|
+
- `activity` - timestamp trailing the body on one line.
|
|
121
|
+
|
|
122
|
+
`[skin]` is paint only; structure, ARIA and slot behaviour are identical across
|
|
123
|
+
values:
|
|
124
|
+
|
|
125
|
+
- `line` (default) - bare rail, no surface.
|
|
126
|
+
- `card` - each row body lifted onto its own surface.
|
|
127
|
+
- `bands` - alternating group tint for long timelines.
|
|
128
|
+
|
|
129
|
+
## Layout
|
|
130
|
+
|
|
131
|
+
Three inputs, each defaulting to the v1 rendering, each resolving to a
|
|
132
|
+
`[data-*]` attribute the row stylesheet reads. No new DOM, no ARIA change: the
|
|
133
|
+
role chain is byte-identical across every combination, and DOM order stays
|
|
134
|
+
chronological whatever the paint does.
|
|
135
|
+
|
|
136
|
+
|Input|Values|Effect|
|
|
137
|
+
|-|-|-|
|
|
138
|
+
|`[placement]`|`start` (default), `end`, `alternate`|which side of the rail the body sits on|
|
|
139
|
+
|`[rail]`|`segmented` (default), `continuous`|whether the rail breaks between rows|
|
|
140
|
+
|`[orientation]`|`vertical` (default), `horizontal`|which axis the run reads along|
|
|
141
|
+
|
|
142
|
+
```html
|
|
143
|
+
<cngx-timeline [items]="milestones()" [dateAccessor]="at"
|
|
144
|
+
placement="alternate" rail="continuous" groupBy="none">
|
|
145
|
+
<ng-template [cngxTimelineItem]="milestones()" let-milestone let-last="last">
|
|
146
|
+
<cngx-timeline-item [position]="last ? 'last' : 'middle'" status="done">
|
|
147
|
+
<strong cngxTimelineOpposite>{{ milestone.year }}</strong>
|
|
148
|
+
<h3>{{ milestone.title }}</h3>
|
|
149
|
+
</cngx-timeline-item>
|
|
150
|
+
</ng-template>
|
|
151
|
+
</cngx-timeline>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Alternation comes from the loop index**, not from `:nth-child`, so a filtered
|
|
155
|
+
or refetched list alternates by its rendered position rather than by DOM
|
|
156
|
+
structure. The built-in loading placeholder derives its sides the same way, so
|
|
157
|
+
the swap from skeleton to content does not reflow.
|
|
158
|
+
|
|
159
|
+
**`alternate` is not supported with `mode="activity"`.** Alternating a
|
|
160
|
+
scan-feed defeats the scan; those rows render `start` and dev mode warns once.
|
|
161
|
+
|
|
162
|
+
**`alternate` collapses to a single side below `32rem`** of the timeline's own
|
|
163
|
+
width. It is a container query, not a viewport one, so the same timeline
|
|
164
|
+
behaves correctly inside a narrow panel on a wide screen. The threshold is a
|
|
165
|
+
literal because a container-query condition cannot read a custom property.
|
|
166
|
+
|
|
167
|
+
**`continuous` stretches each segment across the row gap**, per segment rather
|
|
168
|
+
than as one line behind the run. That is what keeps a `rejected` stretch red
|
|
169
|
+
and an `upcoming` tail dashed. The last segment of a band never stretches, so
|
|
170
|
+
the gap between groups stays open.
|
|
171
|
+
|
|
172
|
+
### Horizontal
|
|
173
|
+
|
|
174
|
+
`orientation="horizontal"` transposes the whole raster: the rail becomes the
|
|
175
|
+
axis, the cards stack away from it, and grouped bands become labelled columns.
|
|
176
|
+
The run sits behind `overflow-x: auto`, which makes it keyboard-scrollable
|
|
177
|
+
natively.
|
|
178
|
+
|
|
179
|
+
Orientation **composes** with placement rather than replacing it. Under
|
|
180
|
+
`horizontal`, `[placement]` selects which side of the *axis* a row sits on, so
|
|
181
|
+
`alternate` puts cards above and below in turn. The organism derives a side per
|
|
182
|
+
row, never a direction; the stylesheet decides which axis that side lives on.
|
|
183
|
+
|
|
184
|
+
```html
|
|
185
|
+
<cngx-timeline [items]="events()" [dateAccessor]="at"
|
|
186
|
+
orientation="horizontal" placement="alternate" groupBy="none">
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
A horizontal row takes `--cngx-timeline-item-inline-size` (default `12rem`)
|
|
190
|
+
rather than a content-derived width, because flex would otherwise size every
|
|
191
|
+
card to its longest word and the axis would read as a ragged queue.
|
|
192
|
+
|
|
193
|
+
`mode="activity"` has no horizontal variant: a scan-feed is a vertical shape,
|
|
194
|
+
and those rows render the narrative axis.
|
|
195
|
+
|
|
196
|
+
**RTL is free.** In horizontal the run's main axis *is* the inline axis, so
|
|
197
|
+
`dir="rtl"` reverses the whole timeline through the same logical properties
|
|
198
|
+
that carry the block axis in vertical. Neither stylesheet contains a single
|
|
199
|
+
physical property.
|
|
200
|
+
|
|
201
|
+
## Slots
|
|
202
|
+
|
|
203
|
+
Eight template slots, each resolved through the family-standard three-stage
|
|
204
|
+
cascade: per-instance directive, then `CngxTimelineConfig.templates`, then the
|
|
205
|
+
built-in markup.
|
|
206
|
+
|
|
207
|
+
|Directive|Context|
|
|
208
|
+
|-|-|
|
|
209
|
+
|`*cngxTimelineItem`|`$implicit`, `index`, `first`, `last`, `group`|
|
|
210
|
+
|`*cngxTimelineDateHeader`|`$implicit: TimelineGroup<T>`|
|
|
211
|
+
|`*cngxTimelineMarkerTpl`|`$implicit`, `status`|
|
|
212
|
+
|`*cngxTimelineEmpty`|`$implicit: EmptyReason`|
|
|
213
|
+
|`*cngxTimelineError`|`$implicit: unknown`, `retry`|
|
|
214
|
+
|`*cngxTimelineRetryButton`|`$implicit: retry`|
|
|
215
|
+
|`*cngxTimelineLoadingTail`|none|
|
|
216
|
+
|`*cngxTimelineSkeleton`|none|
|
|
217
|
+
|
|
218
|
+
`*cngxTimelineMarkerTpl` applies to every row; a single row overrides it by
|
|
219
|
+
projecting its own `[cngxTimelineMarkerContent]`, which wins.
|
|
220
|
+
|
|
221
|
+
### Content across the rail
|
|
222
|
+
|
|
223
|
+
`[cngxTimelineOpposite]` is a projection slot on the row, not a template slot:
|
|
224
|
+
it carries per-row content, and the config cascade is for surfaces the whole
|
|
225
|
+
timeline shares. Whatever is projected lands on the far side of the rail from
|
|
226
|
+
the body.
|
|
227
|
+
|
|
228
|
+
```html
|
|
229
|
+
<cngx-timeline-item status="done">
|
|
230
|
+
<cngx-time cngxTimelineOpposite [date]="event.at" />
|
|
231
|
+
<p>{{ event.summary }}</p>
|
|
232
|
+
</cngx-timeline-item>
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
The row grows a third grid track only when something is actually projected, so
|
|
236
|
+
markup written before this slot existed keeps its geometry unchanged.
|
|
237
|
+
|
|
238
|
+
Keep the content non-interactive. The slot projects ahead of the body in DOM
|
|
239
|
+
order, which reads correctly for a label but would put a link or button before
|
|
240
|
+
the row it belongs to.
|
|
241
|
+
|
|
242
|
+
### Media inside the marker
|
|
243
|
+
|
|
244
|
+
The dot clips to its circle, so a photo, an avatar or a glyph renders inside it
|
|
245
|
+
with no extra markup. Sizing has two halves and they behave differently:
|
|
246
|
+
|
|
247
|
+
|Content|Sized by|
|
|
248
|
+
|-|-|
|
|
249
|
+
|`img` / `picture`|the marker; fills it edge to edge|
|
|
250
|
+
|`svg`|`--cngx-timeline-marker-glyph-size` (60% of the dot)|
|
|
251
|
+
|`<cngx-avatar>` / `<cngx-icon>`|its own size token, never the marker|
|
|
252
|
+
|
|
253
|
+
Bare media follows `--cngx-timeline-marker-size` on its own. A projected atom
|
|
254
|
+
does not: `CngxAvatar` and `CngxIcon` pin `--cngx-avatar-size` /
|
|
255
|
+
`--cngx-icon-size` on their own host, where nothing inherited from the marker
|
|
256
|
+
reaches them. **Enlarging a marker that holds an atom means setting both.**
|
|
257
|
+
|
|
258
|
+
```html
|
|
259
|
+
<cngx-timeline-item [style.--cngx-timeline-marker-size]="'48px'">
|
|
260
|
+
<cngx-avatar cngxTimelineMarkerContent size="lg" initials="JD" />
|
|
261
|
+
<p>{{ event.summary }}</p>
|
|
262
|
+
</cngx-timeline-item>
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
`--cngx-timeline-rail-inset` derives from the marker size at the row host, so
|
|
266
|
+
the rail meets an enlarged dot's centre with no further wiring.
|
|
267
|
+
|
|
268
|
+
## Configuration
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
provideTimelineConfig(
|
|
272
|
+
withTimelineLabels({ retry: 'Try again', emptyFallback: 'Nothing yet.' }),
|
|
273
|
+
withTimelineTemplates({ empty: myEmptyTemplate }),
|
|
274
|
+
);
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Root, or scoped to a subtree with `provideTimelineConfigAt` in `viewProviders`,
|
|
278
|
+
where features merge onto the parent config rather than replacing it - a region
|
|
279
|
+
can re-phrase one label without resetting the rest. Resolution runs per-instance
|
|
280
|
+
input, then the scoped provider, then root, then the library default. Defaults
|
|
281
|
+
are English; supply your locale through the cascade.
|
|
282
|
+
|
|
283
|
+
The config is deliberately small - text and templates only. There are no
|
|
284
|
+
behavioural switches to configure: bucketing swaps through the factory token,
|
|
285
|
+
everything visual through the slots.
|
|
286
|
+
|
|
287
|
+
## Accessibility
|
|
288
|
+
|
|
289
|
+
Every band is its own list: grouped renders `role="group"` on the container,
|
|
290
|
+
then per band a generic wrapper holding the date header beside a `role="list"`
|
|
291
|
+
that owns only `role="listitem"` rows and is named by that header. A screen
|
|
292
|
+
reader therefore reports an item count per band rather than one across the whole
|
|
293
|
+
timeline. The header sits outside the list on purpose - a list may own nothing
|
|
294
|
+
but list items, and the header is a consumer slot that often carries a heading.
|
|
295
|
+
`groupBy: 'none'` moves `list` up to the container and drops both wrappers to
|
|
296
|
+
`presentation`, shortening the chain to `list -> listitem` without a second code
|
|
297
|
+
path.
|
|
298
|
+
|
|
299
|
+
`aria-busy` sits on the element that owns the content, and is a `computed()`
|
|
300
|
+
over the bound state rather than a one-time setting. A polite live region stays
|
|
301
|
+
in the DOM whether or not there is anything to say - a region created together
|
|
302
|
+
with its message is announced inconsistently or not at all.
|
|
303
|
+
|
|
304
|
+
A row's status line announces what the row paints: a failed row reports
|
|
305
|
+
`rejected` even while it keeps the editorial status it will return to.
|
|
306
|
+
|
|
307
|
+
## Composition
|
|
308
|
+
|
|
309
|
+
Consumers wire filtering, searching, paging and scroll tracking themselves -
|
|
310
|
+
none of them is injected by the timeline, which keeps one filter usable across a
|
|
311
|
+
timeline, a table and a chart at once. Narrow the list in a `computed()` and
|
|
312
|
+
hand the result to `[items]`; see the integration stories for
|
|
313
|
+
`injectDataSource`, filter-before-bind, and `CngxScrollSpy` band navigation.
|
|
314
|
+
|
|
315
|
+
Two swap points cover the rest without a fork. `CNGX_TIMELINE_GROUPING_FACTORY`
|
|
316
|
+
replaces the bucketing; `CNGX_TIMELINE_VIEW_FACTORY` replaces the body-view
|
|
317
|
+
mapping, for when holding rows through every refetch or treating a filtered
|
|
318
|
+
empty differently is a product decision rather than a library one.
|
|
319
|
+
|
|
320
|
+
An ejected skin keeps working: `createTimelineView`, `createTimelineSlots`,
|
|
321
|
+
`createTimelineSlotBinding` and `createTimelineFallbackCopy` are public, so the
|
|
322
|
+
copy imports the brain instead of restating it. The state-forwarding façade it
|
|
323
|
+
also needs, `createForwardedAsyncState`, is not timeline-specific and ships from
|
|
324
|
+
`@cngx/common/data` alongside the rest of the async-state surface.
|
|
325
|
+
|
|
326
|
+
## Material Theme
|
|
327
|
+
|
|
328
|
+
```scss
|
|
329
|
+
@use '@angular/material' as mat;
|
|
330
|
+
@use '@cngx/themes/material/timeline-theme' as timeline;
|
|
331
|
+
|
|
332
|
+
$theme: mat.define-theme((...));
|
|
333
|
+
|
|
334
|
+
html {
|
|
335
|
+
@include mat.all-component-themes($theme);
|
|
336
|
+
@include timeline.theme($theme);
|
|
337
|
+
}
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Without the bridge the family uses the cngx foundation `--cngx-color-*` tokens
|
|
341
|
+
(light/dark aware) with a native look; the bridge maps text, rail, surface and
|
|
342
|
+
the status colours onto `--mat-sys-*`.
|
|
343
|
+
|
|
344
|
+
## See Also
|
|
345
|
+
|
|
346
|
+
- [CngxTimelineItem](../../common/timeline/) - the row molecule, usable standalone
|
|
347
|
+
- [CngxAsyncState](../../core/utils/) - async state contract
|
|
348
|
+
- [CngxSkeleton](../skeleton/) - the loading body
|
|
349
|
+
- [API on compodocx](https://cngxjs.github.io/cngx/)
|
|
350
|
+
- Tests: `projects/ui/timeline/timeline.component.spec.ts`, `timeline-async.spec.ts`
|
package/toc/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# CngxToc
|
|
2
|
+
|
|
3
|
+
"On this page" navigation rail. Renders a labeled `<nav>` of anchor links from
|
|
4
|
+
a tree of items, tracks the most-visible section as you scroll, and reflects it
|
|
5
|
+
on `aria-current`. Composition over an unused atom: the active-section
|
|
6
|
+
detection is `CngxScrollSpy`, bound inside the organism's own template, so the
|
|
7
|
+
component ships zero `IntersectionObserver` code.
|
|
8
|
+
|
|
9
|
+
## Import
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { CngxToc, CngxTocItemSlot, CngxTocRouterSync, type CngxTocItem } from '@cngx/ui/toc';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Component } from '@angular/core';
|
|
19
|
+
import { CngxToc, type CngxTocItem } from '@cngx/ui/toc';
|
|
20
|
+
|
|
21
|
+
@Component({
|
|
22
|
+
selector: 'app-example',
|
|
23
|
+
template: `
|
|
24
|
+
<cngx-toc [items]="toc" contentRoot="#article"></cngx-toc>
|
|
25
|
+
<article id="article">
|
|
26
|
+
<section id="intro">...</section>
|
|
27
|
+
<section id="usage">...</section>
|
|
28
|
+
</article>
|
|
29
|
+
`,
|
|
30
|
+
imports: [CngxToc],
|
|
31
|
+
})
|
|
32
|
+
export class ExampleComponent {
|
|
33
|
+
protected readonly toc: CngxTocItem[] = [
|
|
34
|
+
{ id: 'intro', label: 'Introduction' },
|
|
35
|
+
{ id: 'usage', label: 'Usage', children: [{ id: 'usage-cli', label: 'CLI' }] },
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`[items]` is the outline; each `id` targets a section element the link scrolls
|
|
41
|
+
to. `contentRoot` is the scroll container's CSS selector - leave it off to
|
|
42
|
+
observe the viewport. `[rootMargin]` and `[threshold]` pass straight through to
|
|
43
|
+
the internal spy.
|
|
44
|
+
|
|
45
|
+
## Heading auto-discovery
|
|
46
|
+
|
|
47
|
+
Set `autoDiscover` and the outline is derived from the headings under
|
|
48
|
+
`contentRoot` instead of a hand-maintained `[items]` array:
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<cngx-toc autoDiscover contentRoot="#article"></cngx-toc>
|
|
52
|
+
<article id="article">
|
|
53
|
+
<h2>Overview</h2>
|
|
54
|
+
<h2>Installation</h2>
|
|
55
|
+
<h3>Using npm</h3>
|
|
56
|
+
</article>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Headings nest by their level (`h2 > h3`); `[headingSelector]` controls which
|
|
60
|
+
headings are collected (default `'h2, h3'`). A heading with no `id` gets a
|
|
61
|
+
slugified one written onto it so its link has a target (collisions get a `-N`
|
|
62
|
+
suffix); an author-set `id` is kept verbatim. Writing that `id` mutates
|
|
63
|
+
consumer DOM, so like the focus contract it is a documented, guarded mutation.
|
|
64
|
+
|
|
65
|
+
The scan runs **once** after the first render - it is not a live observer.
|
|
66
|
+
After you inject or remove sections at runtime, call `refresh()`:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
@ViewChild(CngxToc) toc!: CngxToc;
|
|
70
|
+
loadMoreSections() {
|
|
71
|
+
// ...append sections to the DOM...
|
|
72
|
+
this.toc.refresh();
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Off the browser (SSR) the scan is inert - the rail renders empty and never
|
|
77
|
+
touches `document`.
|
|
78
|
+
|
|
79
|
+
## Overview
|
|
80
|
+
|
|
81
|
+
The organism owns very little. Active-section detection is `CngxScrollSpy`
|
|
82
|
+
(`@cngx/common/layout`), bound on the rail's own `<nav>` and read back through a
|
|
83
|
+
`viewChild`. The flat id list the spy observes and the ancestor `data-active-trail`
|
|
84
|
+
chain are both `computed()` from `[items]`, each with a shared element-wise
|
|
85
|
+
`equal` so a scroll tick never re-allocates the arrays.
|
|
86
|
+
|
|
87
|
+
Exactly one link carries `aria-current` at a time. Ancestor links of the active
|
|
88
|
+
leaf get a `data-active-trail` attribute (a styling hook, no ARIA).
|
|
89
|
+
|
|
90
|
+
## Nav of links, not a tree
|
|
91
|
+
|
|
92
|
+
A table of contents is a **navigation landmark containing links**. Nesting is
|
|
93
|
+
communicated structurally - nested `<ul>` and indentation - so native tab order,
|
|
94
|
+
Enter-to-navigate, middle-click and screen-reader link lists all keep working.
|
|
95
|
+
The APG treeview pattern (composite widget, one tab stop, active-descendant) is
|
|
96
|
+
deliberately **not** applied: it would break link semantics.
|
|
97
|
+
|
|
98
|
+
Reach for `CngxSidenav` instead when you need a collapsible primary-navigation
|
|
99
|
+
rail with a selection model. `CngxToc` is a passive reflection of scroll
|
|
100
|
+
position, not a navigation state machine.
|
|
101
|
+
|
|
102
|
+
## Activation, reduced motion and focus
|
|
103
|
+
|
|
104
|
+
Clicking (or pressing Enter on) a link takes over the native anchor jump,
|
|
105
|
+
scrolls the section into view, and moves focus to it so a screen reader reads
|
|
106
|
+
from the new position - a visual-only jump is a silent state change. The scroll
|
|
107
|
+
behaviour is the configured `scrollBehavior` (`'smooth'` by default), swapped to
|
|
108
|
+
`'auto'` (instant) whenever `prefers-reduced-motion: reduce` matches.
|
|
109
|
+
|
|
110
|
+
**Focus contract.** The section elements are consumer-owned DOM. To make an
|
|
111
|
+
arbitrary section programmatically focusable, `CngxToc` sets `tabindex="-1"` on
|
|
112
|
+
the target **only** when it is not focusable by default and carries no
|
|
113
|
+
author-set `tabindex`; an author value is never overwritten. This is a
|
|
114
|
+
documented, persistent mutation of borrowed DOM.
|
|
115
|
+
|
|
116
|
+
## Item slot
|
|
117
|
+
|
|
118
|
+
Project an `<ng-template cngxTocItem>` to replace the built-in label. The
|
|
119
|
+
context exposes the item, its `active` state and its `depth`:
|
|
120
|
+
|
|
121
|
+
```html
|
|
122
|
+
<cngx-toc [items]="toc" contentRoot="#article">
|
|
123
|
+
<ng-template cngxTocItem let-item let-active="active">
|
|
124
|
+
<span [style.font-weight]="active ? 600 : 400">{{ item.label }}</span>
|
|
125
|
+
</ng-template>
|
|
126
|
+
</cngx-toc>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Resolution is three-stage: the per-instance slot, then
|
|
130
|
+
`CNGX_TOC_CONFIG.templates.item`, then the built-in plain label.
|
|
131
|
+
|
|
132
|
+
## Router fragment sync
|
|
133
|
+
|
|
134
|
+
`[cngxTocRouterSync]` on the same host deep-links the active section into the
|
|
135
|
+
URL fragment. Activating a link writes `#<section-id>` (replacing the history
|
|
136
|
+
entry, so a scroll-driven rail never floods the back stack); a deep link like
|
|
137
|
+
`/guide#pricing` scrolls to that section once on load. The directive reaches the
|
|
138
|
+
rail through the `CNGX_TOC` contract token, never the concrete class, and its
|
|
139
|
+
activation subscription is torn down with the directive. Without
|
|
140
|
+
`@angular/router` it dev-warns once and no-ops.
|
|
141
|
+
|
|
142
|
+
```html
|
|
143
|
+
<cngx-toc cngxTocRouterSync [items]="toc" contentRoot="#article"></cngx-toc>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Configuration
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
provideTocConfig(
|
|
150
|
+
withTocAriaLabels({ nav: 'On this page' }),
|
|
151
|
+
withTocScrollBehavior('smooth'),
|
|
152
|
+
withTocSpy({ rootMargin: '-80px 0px 0px 0px' }),
|
|
153
|
+
withTocTemplates({ item: myItemTemplate }),
|
|
154
|
+
);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Root, or scoped to a subtree with `provideTocConfigAt` in `viewProviders`, where
|
|
158
|
+
features merge onto the parent config rather than replacing it. Resolution runs
|
|
159
|
+
per-instance input, then the scoped provider, then root, then the library
|
|
160
|
+
default. Defaults are English; supply your locale through the cascade.
|
|
161
|
+
|
|
162
|
+
## Material Theme
|
|
163
|
+
|
|
164
|
+
```scss
|
|
165
|
+
@use '@angular/material' as mat;
|
|
166
|
+
@use '@cngx/themes/material/toc-theme' as toc;
|
|
167
|
+
|
|
168
|
+
html {
|
|
169
|
+
@include toc.theme($theme);
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Without the bridge the rail uses the cngx foundation `--cngx-color-*` tokens
|
|
174
|
+
(light/dark aware) with a native look; the bridge maps the link, active and
|
|
175
|
+
focus-ring colours onto `--mat-sys-*`. Spacing stays on `--cngx-space-*` so
|
|
176
|
+
density tracking keeps working.
|
|
177
|
+
|
|
178
|
+
## See Also
|
|
179
|
+
|
|
180
|
+
- [CngxScrollSpy](../../common/layout/) - the detection atom the rail composes
|
|
181
|
+
- [CngxSidenav](../sidenav/) - collapsible primary-navigation rail
|
|
182
|
+
- [API on compodocx](https://cngxjs.github.io/cngx/)
|
|
183
|
+
- Tests: `projects/ui/toc/toc.component.spec.ts`, `toc-router-sync.directive.spec.ts`
|