@molecule/app-timeline-angular 0.0.0-stage → 1.1.0
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/LICENSE +202 -0
- package/README.md +614 -2
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/slot-dom.d.ts +57 -0
- package/dist/slot-dom.d.ts.map +1 -0
- package/dist/slot-dom.js +100 -0
- package/dist/slot-dom.js.map +1 -0
- package/dist/timeline-date.component.d.ts +30 -0
- package/dist/timeline-date.component.d.ts.map +1 -0
- package/dist/timeline-date.component.js +63 -0
- package/dist/timeline-date.component.js.map +1 -0
- package/dist/timeline-event.component.d.ts +71 -0
- package/dist/timeline-event.component.d.ts.map +1 -0
- package/dist/timeline-event.component.js +180 -0
- package/dist/timeline-event.component.js.map +1 -0
- package/dist/timeline-rail.component.d.ts +63 -0
- package/dist/timeline-rail.component.d.ts.map +1 -0
- package/dist/timeline-rail.component.js +148 -0
- package/dist/timeline-rail.component.js.map +1 -0
- package/dist/timeline.component.d.ts +101 -0
- package/dist/timeline.component.d.ts.map +1 -0
- package/dist/timeline.component.js +227 -0
- package/dist/timeline.component.js.map +1 -0
- package/dist/types.d.ts +82 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +69 -4
package/README.md
CHANGED
|
@@ -1,3 +1,615 @@
|
|
|
1
|
-
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-11-21T12:47:37.522Z
|
|
7
|
+
-->
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
# @molecule/app-timeline-angular
|
|
10
|
+
|
|
11
|
+
Angular chronological timeline primitives.
|
|
12
|
+
|
|
13
|
+
Exports:
|
|
14
|
+
|
|
15
|
+
- `<mol-timeline>` / `Timeline` — vertical list of events with optional date separators.
|
|
16
|
+
- `<div mol-timeline-event>` / `TimelineEvent` — one event row with rail (marker + connector) + content.
|
|
17
|
+
- `<div mol-timeline-rail>` / `TimelineRail` — standalone rail (marker + connector) for custom rows.
|
|
18
|
+
- `<div mol-timeline-date>` / `TimelineDate` — date separator rendered between groups.
|
|
19
|
+
- `TimelineEventData` type for event records.
|
|
20
|
+
|
|
21
|
+
Use for activity chronologies, deal timelines, order tracking, audit logs.
|
|
22
|
+
It is the Angular counterpart of `@molecule/app-timeline-react`: the same
|
|
23
|
+
props (React names) and the same DOM for the same input, so switching
|
|
24
|
+
framework is changing the package name in the imports.
|
|
25
|
+
|
|
26
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
27
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
28
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { Component } from '@angular/core'
|
|
34
|
+
import { Timeline, TimelineDate } from '@molecule/app-timeline-angular'
|
|
35
|
+
|
|
36
|
+
@Component({
|
|
37
|
+
selector: 'app-activity',
|
|
38
|
+
standalone: true,
|
|
39
|
+
imports: [Timeline, TimelineDate],
|
|
40
|
+
template: `
|
|
41
|
+
<mol-timeline [events]="events">
|
|
42
|
+
<p slot="emptyState">No activity yet.</p>
|
|
43
|
+
</mol-timeline>
|
|
44
|
+
`,
|
|
45
|
+
})
|
|
46
|
+
export class Activity {
|
|
47
|
+
events = [
|
|
48
|
+
{ id: '1', timestamp: '2 hours ago', title: 'Order placed' },
|
|
49
|
+
{ id: '2', timestamp: 'Yesterday', title: 'Payment confirmed', body: 'Visa ending 4242' },
|
|
50
|
+
{ id: '3', timestamp: 'Mar 12', title: 'Item shipped' },
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Type
|
|
56
|
+
|
|
57
|
+
`feature`
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm install @molecule/app-timeline-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API
|
|
66
|
+
|
|
67
|
+
### Interfaces
|
|
68
|
+
|
|
69
|
+
#### `TimelineEventData`
|
|
70
|
+
|
|
71
|
+
One entry of a `<Timeline>`. Node fields are `ng-template` references (a
|
|
72
|
+
projected node) or plain text, since an input cannot carry a DOM node.
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
interface TimelineEventData {
|
|
76
|
+
/** Stable identifier for this event (the row is tracked by it, like React's key). */
|
|
77
|
+
id: string
|
|
78
|
+
/** Marker icon / dot — defaults to a small dot. */
|
|
79
|
+
marker?: string | number | TemplateRef<unknown>
|
|
80
|
+
/** Display timestamp (ISO, relative, etc.). */
|
|
81
|
+
timestamp: string | number | TemplateRef<unknown>
|
|
82
|
+
/** Headline of the event. */
|
|
83
|
+
title: string | number | TemplateRef<unknown>
|
|
84
|
+
/** Optional body content. */
|
|
85
|
+
body?: string | number | TemplateRef<unknown>
|
|
86
|
+
/**
|
|
87
|
+
* Optional accent color hint. Currently INERT — no component consumes it,
|
|
88
|
+
* so setting it changes nothing; pass a custom `marker` node to color a row.
|
|
89
|
+
*/
|
|
90
|
+
accent?: 'primary' | 'success' | 'warning' | 'error' | 'info' | 'neutral'
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### `TimelineProps`
|
|
95
|
+
|
|
96
|
+
Props accepted by {@link Timeline} — the same props
|
|
97
|
+
`@molecule/app-timeline-react` accepts. `emptyState` is a template reference
|
|
98
|
+
passed as an input (or projected content in a host template); the callback
|
|
99
|
+
prop `renderDateSeparator` is a template reference whose context carries the
|
|
100
|
+
event as `$implicit` / `a0` and its predecessor as `a1`.
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
interface TimelineProps {
|
|
104
|
+
/** Events in display order. */
|
|
105
|
+
events: TimelineEventData[]
|
|
106
|
+
/** Optional renderer for date separators between consecutive events. */
|
|
107
|
+
renderDateSeparator?: TemplateRef<unknown>
|
|
108
|
+
/** Rendered when there are no events. */
|
|
109
|
+
emptyState?: string | number | TemplateRef<unknown>
|
|
110
|
+
/** Extra classes on the outer wrapper. */
|
|
111
|
+
className?: string
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### `TimelineEventProps`
|
|
116
|
+
|
|
117
|
+
Props accepted by {@link TimelineEvent} — the same props
|
|
118
|
+
`@molecule/app-timeline-react` accepts.
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
interface TimelineEventProps {
|
|
122
|
+
/** The event to render. */
|
|
123
|
+
event: TimelineEventData
|
|
124
|
+
/** Whether this is the last event in the list (suppresses the connector). */
|
|
125
|
+
isLast?: boolean
|
|
126
|
+
/** Extra classes. */
|
|
127
|
+
className?: string
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### `TimelineRailProps`
|
|
132
|
+
|
|
133
|
+
Props accepted by {@link TimelineRail} — the same props
|
|
134
|
+
`@molecule/app-timeline-react` accepts.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
interface TimelineRailProps {
|
|
138
|
+
/** Marker for this row — typically a dot or icon. */
|
|
139
|
+
marker?: string | number | TemplateRef<unknown>
|
|
140
|
+
/** Whether to render the vertical connector below the marker. Defaults to `true`. */
|
|
141
|
+
connector?: boolean
|
|
142
|
+
/** Extra classes on the outer wrapper. */
|
|
143
|
+
className?: string
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### `TimelineDateProps`
|
|
148
|
+
|
|
149
|
+
Props accepted by {@link TimelineDate} — the same props
|
|
150
|
+
`@molecule/app-timeline-react` accepts. `children` is projected content in
|
|
151
|
+
Angular (an input cannot carry a node), so it is typed `unknown`: pass it in
|
|
152
|
+
the host template, not as a value.
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
interface TimelineDateProps {
|
|
156
|
+
/** Date label ("Today", "Yesterday", "March 12, 2025"), as projected content. */
|
|
157
|
+
children?: unknown
|
|
158
|
+
/** Extra classes. */
|
|
159
|
+
className?: string
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Classes
|
|
164
|
+
|
|
165
|
+
#### `TimelineDate`
|
|
166
|
+
|
|
167
|
+
TimelineDate component.
|
|
168
|
+
|
|
169
|
+
Date separator rendered between timeline groups. The host IS the
|
|
170
|
+
separator's outer `<div>` (`div[mol-timeline-date]`), matching React's root
|
|
171
|
+
exactly, and the label is projected content (the default `<ng-content>`).
|
|
172
|
+
|
|
173
|
+
This is the Angular counterpart of `@molecule/app-timeline-react`'s
|
|
174
|
+
`TimelineDate`: the same props (React names), the same ClassMap tokens, and
|
|
175
|
+
the same DOM for the same input.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
@Component({
|
|
179
|
+
selector: 'div[mol-timeline-date]',
|
|
180
|
+
standalone: true,
|
|
181
|
+
inputs: ['className'],
|
|
182
|
+
host: {
|
|
183
|
+
'[class]': 'classes()',
|
|
184
|
+
},
|
|
185
|
+
template: `<span [class]="cm().cn(cm().flex1)"><ng-content></ng-content></span>`,
|
|
186
|
+
})
|
|
187
|
+
export class TimelineDate {
|
|
188
|
+
/** Extra classes. */
|
|
189
|
+
className?: string
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The current class map.
|
|
193
|
+
* @returns The UIClassMap.
|
|
194
|
+
*/
|
|
195
|
+
cm(): UIClassMap {
|
|
196
|
+
return getClassMap()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Computes the separator's class list.
|
|
201
|
+
* @returns The class string.
|
|
202
|
+
*/
|
|
203
|
+
classes(): string {
|
|
204
|
+
return this.cm().cn(
|
|
205
|
+
this.cm().flex({ align: 'center', gap: 'sm' }),
|
|
206
|
+
this.cm().sp('py', 2),
|
|
207
|
+
this.cm().textSize('xs'),
|
|
208
|
+
this.cm().fontWeight('semibold'),
|
|
209
|
+
this.className,
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
#### `TimelineEvent`
|
|
216
|
+
|
|
217
|
+
TimelineEvent component.
|
|
218
|
+
|
|
219
|
+
One row of a `<Timeline>`: [rail (marker + connector)] [timestamp / title /
|
|
220
|
+
body]. The host IS the row's outer `<div>` (`div[mol-timeline-event]`),
|
|
221
|
+
matching React's root exactly. The event's node-valued fields are
|
|
222
|
+
`ng-template` references rendered through `NgTemplateOutlet`; string / number
|
|
223
|
+
fields render as text.
|
|
224
|
+
|
|
225
|
+
This is the Angular counterpart of `@molecule/app-timeline-react`'s
|
|
226
|
+
`TimelineEvent`: the same props (React names), the same ClassMap tokens, and
|
|
227
|
+
the same DOM for the same input.
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
@Component({
|
|
231
|
+
selector: 'div[mol-timeline-event]',
|
|
232
|
+
standalone: true,
|
|
233
|
+
imports: [NgTemplateOutlet, TimelineRail],
|
|
234
|
+
inputs: ['event', 'isLast', 'className'],
|
|
235
|
+
host: {
|
|
236
|
+
'[class]': 'classes()',
|
|
237
|
+
},
|
|
238
|
+
// prettier-ignore
|
|
239
|
+
template: `<div mol-timeline-rail [marker]="event.marker" [connector]="!isLast"></div><div [class]="contentClasses()"><div [class]="timestampClasses()">@if (isNode(event.timestamp)) {<ng-container [ngTemplateOutlet]="templateOf(event.timestamp)" />}@else {{{ textOf(event.timestamp) }}}</div><div [class]="titleClasses()">@if (isNode(event.title)) {<ng-container [ngTemplateOutlet]="templateOf(event.title)" />}@else {{{ textOf(event.title) }}}</div>@if (event.body) {<div [class]="cm().textSize('sm')">@if (isNode(event.body)) {<ng-container [ngTemplateOutlet]="templateOf(event.body)" />}@else {{{ textOf(event.body) }}}</div>}</div>`,
|
|
240
|
+
})
|
|
241
|
+
export class TimelineEvent {
|
|
242
|
+
/** The event to render. */
|
|
243
|
+
event!: TimelineEventData
|
|
244
|
+
/** Whether this is the last event in the list (suppresses the connector). */
|
|
245
|
+
isLast?: boolean
|
|
246
|
+
/** Extra classes. */
|
|
247
|
+
className?: string
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The current class map.
|
|
251
|
+
* @returns The UIClassMap.
|
|
252
|
+
*/
|
|
253
|
+
cm(): UIClassMap {
|
|
254
|
+
return getClassMap()
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Computes the row's class list.
|
|
259
|
+
* @returns The class string.
|
|
260
|
+
*/
|
|
261
|
+
classes(): string {
|
|
262
|
+
return this.cm().cn(this.cm().flex({ align: 'stretch', gap: 'sm' }), this.className)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Computes the content column's class list.
|
|
267
|
+
* @returns The class string.
|
|
268
|
+
*/
|
|
269
|
+
contentClasses(): string {
|
|
270
|
+
return this.cm().cn(this.cm().flex1, this.cm().stack(1), this.cm().sp('pb', 4))
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Computes the timestamp line's class list.
|
|
275
|
+
* @returns The class string.
|
|
276
|
+
*/
|
|
277
|
+
timestampClasses(): string {
|
|
278
|
+
return this.cm().cn(this.cm().textSize('xs'), this.cm().fontWeight('medium'))
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Computes the title line's class list.
|
|
283
|
+
* @returns The class string.
|
|
284
|
+
*/
|
|
285
|
+
titleClasses(): string {
|
|
286
|
+
return this.cm().cn(this.cm().textSize('sm'), this.cm().fontWeight('semibold'))
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Whether a field holds a node (an `ng-template` reference) rather than text.
|
|
291
|
+
* @param value - The event field.
|
|
292
|
+
* @returns True when it renders through a template outlet.
|
|
293
|
+
*/
|
|
294
|
+
isNode(value: unknown): value is TemplateRef<unknown> {
|
|
295
|
+
return value instanceof TemplateRef
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Narrows a value to an embedded template.
|
|
300
|
+
* @param value - The event field.
|
|
301
|
+
* @returns The template, or null.
|
|
302
|
+
*/
|
|
303
|
+
templateOf(value: unknown): TemplateRef<unknown> | null {
|
|
304
|
+
return value instanceof TemplateRef ? value : null
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* The text a field renders (React renders strings and numbers as text).
|
|
309
|
+
* @param value - The event field.
|
|
310
|
+
* @returns The text, or `''` for a node field.
|
|
311
|
+
*/
|
|
312
|
+
textOf(value: unknown): string {
|
|
313
|
+
return typeof value === 'string' || typeof value === 'number' ? String(value) : ''
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
#### `TimelineRail`
|
|
319
|
+
|
|
320
|
+
TimelineRail component.
|
|
321
|
+
|
|
322
|
+
Left-hand rail of a timeline row — renders the marker (a default dot when
|
|
323
|
+
none is given) and an optional vertical connector extending downward. The
|
|
324
|
+
host IS the rail's outer `<div>` (`div[mol-timeline-rail]`), matching React's
|
|
325
|
+
root exactly. A node-valued marker is an `ng-template` reference rendered
|
|
326
|
+
through `NgTemplateOutlet`; the connector's inline style is applied the way
|
|
327
|
+
React applies it (through the CSSOM), so the serialized attribute matches.
|
|
328
|
+
|
|
329
|
+
This is the Angular counterpart of `@molecule/app-timeline-react`'s
|
|
330
|
+
`TimelineRail`: the same props (React names), the same ClassMap tokens, and
|
|
331
|
+
the same DOM for the same input.
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
@Component({
|
|
335
|
+
selector: 'div[mol-timeline-rail]',
|
|
336
|
+
standalone: true,
|
|
337
|
+
imports: [NgTemplateOutlet],
|
|
338
|
+
inputs: ['marker', 'connector', 'className'],
|
|
339
|
+
host: {
|
|
340
|
+
'[class]': 'classes()',
|
|
341
|
+
},
|
|
342
|
+
template: `<div>
|
|
343
|
+
@if (markerTemplate(); as marker) {
|
|
344
|
+
<ng-container [ngTemplateOutlet]="marker" />
|
|
345
|
+
} @else if (markerText() !== null) {
|
|
346
|
+
{{ markerText() }}
|
|
347
|
+
} @else {
|
|
348
|
+
<span aria-hidden="true">•</span>
|
|
349
|
+
}
|
|
350
|
+
</div>
|
|
351
|
+
@if (hasConnector()) {
|
|
352
|
+
<div [class]="connectorClasses()" [style]="connectorStyle()"></div>
|
|
353
|
+
}`,
|
|
354
|
+
})
|
|
355
|
+
export class TimelineRail {
|
|
356
|
+
/** Marker for this row, as a template reference or plain text. */
|
|
357
|
+
marker?: string | number | TemplateRef<unknown>
|
|
358
|
+
/** Whether to render the vertical connector below the marker (defaults to `true`). */
|
|
359
|
+
connector?: boolean
|
|
360
|
+
/** Extra classes on the outer wrapper. */
|
|
361
|
+
className?: string
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* The current class map.
|
|
365
|
+
* @returns The UIClassMap.
|
|
366
|
+
*/
|
|
367
|
+
cm(): UIClassMap {
|
|
368
|
+
return getClassMap()
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Computes the outer rail class list.
|
|
373
|
+
* @returns The class string.
|
|
374
|
+
*/
|
|
375
|
+
classes(): string {
|
|
376
|
+
return this.cm().cn(
|
|
377
|
+
this.cm().flex({ direction: 'col', align: 'center' }),
|
|
378
|
+
this.cm().shrink0,
|
|
379
|
+
this.className,
|
|
380
|
+
)
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* React's `connector = true` default: an absent input keeps the connector.
|
|
385
|
+
* @returns Whether the connector renders.
|
|
386
|
+
*/
|
|
387
|
+
hasConnector(): boolean {
|
|
388
|
+
return this.connector ?? true
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Whether the marker holds a node (an `ng-template` reference) rather than text.
|
|
393
|
+
* @returns True when it renders through a template outlet.
|
|
394
|
+
*/
|
|
395
|
+
markerTemplate(): TemplateRef<unknown> | null {
|
|
396
|
+
return this.marker instanceof TemplateRef ? this.marker : null
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* The text a marker renders (React renders strings and numbers as text).
|
|
401
|
+
* @returns The text, or null when the marker is a node or absent.
|
|
402
|
+
*/
|
|
403
|
+
markerText(): string | null {
|
|
404
|
+
if (typeof this.marker === 'string') return this.marker
|
|
405
|
+
if (typeof this.marker === 'number') return String(this.marker)
|
|
406
|
+
return null
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Computes the connector's class list (`cm.w(0)` + `cm.h('full')`).
|
|
411
|
+
* @returns The class string.
|
|
412
|
+
*/
|
|
413
|
+
connectorClasses(): string {
|
|
414
|
+
return this.cm().cn(this.cm().w(0), this.cm().h('full'))
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* The connector's inline style, exactly React's object.
|
|
419
|
+
* @returns The style declarations.
|
|
420
|
+
*/
|
|
421
|
+
connectorStyle(): Record<string, string> {
|
|
422
|
+
return { 'border-left': '1px solid currentColor', opacity: '0.2', 'min-height': '24px' }
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
#### `Timeline`
|
|
428
|
+
|
|
429
|
+
Timeline component.
|
|
430
|
+
|
|
431
|
+
Vertical chronological list of events, each rendered with a marker +
|
|
432
|
+
connector on the left (`<div mol-timeline-event>`). Optional date separators
|
|
433
|
+
come from `renderDateSeparator`, a template reference whose context carries
|
|
434
|
+
the event as `$implicit` / `a0` and its predecessor as `a1`.
|
|
435
|
+
|
|
436
|
+
React's root is the wrapper `<div>` — or, with no events and an empty state,
|
|
437
|
+
that empty state alone (a fragment). A host element always exists in Angular,
|
|
438
|
+
so this component's host is transparent (`mol-timeline`, `display: contents`,
|
|
439
|
+
unwrapped by the conformance normalizer) and the template renders whichever
|
|
440
|
+
root React would. The empty state is projected content
|
|
441
|
+
(`[slot=emptyState]`) or a template reference passed as an input, reconciled
|
|
442
|
+
against React's branch by {@link Timeline.ngAfterViewInit} /
|
|
443
|
+
{@link Timeline.ngAfterViewChecked} / {@link Timeline.ngDoCheck}. Rows are
|
|
444
|
+
tracked by the event's `id` value (`@for (…; track event.id)`), like React's
|
|
445
|
+
per-item keys.
|
|
446
|
+
|
|
447
|
+
This is the Angular counterpart of `@molecule/app-timeline-react`'s
|
|
448
|
+
`Timeline`: the same props (React names), the same ClassMap tokens, and the
|
|
449
|
+
same DOM for the same input.
|
|
450
|
+
|
|
451
|
+
```typescript
|
|
452
|
+
@Component({
|
|
453
|
+
selector: 'mol-timeline',
|
|
454
|
+
standalone: true,
|
|
455
|
+
imports: [NgTemplateOutlet, TimelineEvent],
|
|
456
|
+
inputs: ['events', 'renderDateSeparator', 'emptyState', 'className'],
|
|
457
|
+
host: {
|
|
458
|
+
'data-parity-unwrap': '',
|
|
459
|
+
style: 'display: contents',
|
|
460
|
+
},
|
|
461
|
+
// prettier-ignore
|
|
462
|
+
template: `<span #empty data-parity-unwrap style="display: contents">@if (emptyText(); as text) {{{ text }}}@if (emptyTemplate(); as empty) {<ng-container [ngTemplateOutlet]="empty"></ng-container>}<ng-content select="[slot=emptyState]"></ng-content></span><div #list [class]="classes()">@for (event of events; track event.id; let i = $index) {<div>@if (separatorTemplate(); as separator) {<ng-container [ngTemplateOutlet]="separator" [ngTemplateOutletContext]="separatorContext(event, i)"></ng-container>}<div mol-timeline-event [event]="event" [isLast]="i === events.length - 1"></div></div>}</div>`,
|
|
463
|
+
})
|
|
464
|
+
export class Timeline implements AfterViewInit, AfterViewChecked, DoCheck {
|
|
465
|
+
/** Events in display order. */
|
|
466
|
+
events: TimelineEventData[] = []
|
|
467
|
+
/** Optional renderer for date separators: a template reference with the event in its context. */
|
|
468
|
+
renderDateSeparator?: TemplateRef<unknown>
|
|
469
|
+
/** Rendered when there are no events: a template reference, plain text, or `[slot=emptyState]`. */
|
|
470
|
+
emptyState?: unknown
|
|
471
|
+
/** Extra classes on the outer wrapper. */
|
|
472
|
+
className?: string
|
|
473
|
+
|
|
474
|
+
/** The projected empty-state capture point (unwrapped, so React's bare slot). */
|
|
475
|
+
@ViewChild('empty') private empty?: ElementRef<HTMLElement>
|
|
476
|
+
|
|
477
|
+
/** The wrapper `<div>` (detached when the empty state renders instead). */
|
|
478
|
+
@ViewChild('list') private list?: ElementRef<HTMLElement>
|
|
479
|
+
|
|
480
|
+
private readonly guard = new SlotGuard(inject(ElementRef), inject(Renderer2))
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* The current class map.
|
|
484
|
+
* @returns The UIClassMap.
|
|
485
|
+
*/
|
|
486
|
+
cm(): UIClassMap {
|
|
487
|
+
return getClassMap()
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Computes the outer wrapper's class list (`cm.stack(0)` + `className`).
|
|
492
|
+
* @returns The class string.
|
|
493
|
+
*/
|
|
494
|
+
classes(): string {
|
|
495
|
+
return this.cm().cn(this.cm().stack(0), this.className)
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* React's branch: with no events, the empty state renders bare (its
|
|
500
|
+
* template when it is a node).
|
|
501
|
+
* @returns The empty-state template, or null.
|
|
502
|
+
*/
|
|
503
|
+
emptyTemplate(): TemplateRef<unknown> | null {
|
|
504
|
+
if (this.events.length !== 0 || !this.emptyState) return null
|
|
505
|
+
return this.emptyState instanceof TemplateRef ? this.emptyState : null
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* React's branch: with no events, a text empty state renders bare.
|
|
510
|
+
* @returns The empty-state text, or null when the wrapper renders instead.
|
|
511
|
+
*/
|
|
512
|
+
emptyText(): string | null {
|
|
513
|
+
if (this.events.length !== 0 || !this.emptyState) return null
|
|
514
|
+
if (this.emptyState instanceof TemplateRef) return null
|
|
515
|
+
return String(this.emptyState)
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* The date-separator template, when the caller supplied one.
|
|
520
|
+
* @returns The template, or null.
|
|
521
|
+
*/
|
|
522
|
+
separatorTemplate(): TemplateRef<unknown> | null {
|
|
523
|
+
return this.renderDateSeparator instanceof TemplateRef ? this.renderDateSeparator : null
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* The separator template's context: React's `renderDateSeparator(event, prev)`
|
|
528
|
+
* arguments as `$implicit` / `a0` (the event) and `a1` (its predecessor).
|
|
529
|
+
* @param event - The event the separator precedes.
|
|
530
|
+
* @param index - The event's index in the list.
|
|
531
|
+
* @returns The template context.
|
|
532
|
+
*/
|
|
533
|
+
separatorContext(event: TimelineEventData, index: number): Record<string, unknown> {
|
|
534
|
+
const prev = index > 0 ? this.events[index - 1] : undefined
|
|
535
|
+
return { $implicit: event, a0: event, a1: prev, a2: undefined }
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Reconciles the projected empty state and the wrapper against React's
|
|
540
|
+
* branch once the view queries resolve.
|
|
541
|
+
*/
|
|
542
|
+
ngAfterViewInit(): void {
|
|
543
|
+
this.reconcile()
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Re-reconciles on later passes, so a props step that empties or refills the
|
|
548
|
+
* list swaps the branch the way React does.
|
|
549
|
+
*/
|
|
550
|
+
ngDoCheck(): void {
|
|
551
|
+
this.reconcile()
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Re-reconciles after each view update: a node-valued empty state that arrives
|
|
556
|
+
* through an input renders into its outlet only during the update, so the
|
|
557
|
+
* branch decision must be read afterwards.
|
|
558
|
+
*/
|
|
559
|
+
ngAfterViewChecked(): void {
|
|
560
|
+
this.reconcile()
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Applies React's condition: with no events and an empty state, the empty
|
|
565
|
+
* state renders bare and the wrapper disappears; otherwise the wrapper
|
|
566
|
+
* renders and the empty state is dropped.
|
|
567
|
+
*/
|
|
568
|
+
private reconcile(): void {
|
|
569
|
+
const empty = this.empty?.nativeElement
|
|
570
|
+
const list = this.list?.nativeElement
|
|
571
|
+
const hasEmpty = (this.events?.length ?? 0) === 0 && hasNodes(empty)
|
|
572
|
+
this.guard.toggle(empty, hasEmpty)
|
|
573
|
+
this.guard.toggle(list, !hasEmpty)
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
## Injection Notes
|
|
579
|
+
|
|
580
|
+
### Requirements
|
|
581
|
+
|
|
582
|
+
Peer dependencies:
|
|
583
|
+
|
|
584
|
+
- `@angular/common` ^22.0.0
|
|
585
|
+
- `@angular/core` ^22.0.0
|
|
586
|
+
- `@angular/platform-browser` ^22.0.0
|
|
587
|
+
- `@molecule/app-angular` ^3.5.0
|
|
588
|
+
- `@molecule/app-ui` ^1.0.1
|
|
589
|
+
- `@molecule/app-ui-angular` ^1.1.0
|
|
590
|
+
|
|
591
|
+
### Runtime Dependencies
|
|
592
|
+
|
|
593
|
+
- `@angular/common`
|
|
594
|
+
- `@angular/core`
|
|
595
|
+
- `@angular/platform-browser`
|
|
596
|
+
- `@molecule/app-angular`
|
|
597
|
+
- `@molecule/app-ui`
|
|
598
|
+
- `@molecule/app-ui-angular`
|
|
599
|
+
|
|
600
|
+
This is NOT the Angular binding for `@molecule/app-timeline` (the headless
|
|
601
|
+
provider core wired via `setProvider`) — it is standalone presentational
|
|
602
|
+
markup with no provider. For domain-specific rows see the sibling
|
|
603
|
+
`@molecule/app-{activity,order,status,stage,day}-timeline-angular` packages.
|
|
604
|
+
|
|
605
|
+
`TimelineEventData.accent` is currently INERT — no component reads it, so
|
|
606
|
+
setting it changes nothing; color a row by passing a custom `marker` node
|
|
607
|
+
instead. `timestamp` is a display node — format/translate it before
|
|
608
|
+
passing. Node-valued props are `ng-template` references; `Timeline`'s root is
|
|
609
|
+
a fragment in its empty branch, so its host is `display: contents`, and rows
|
|
610
|
+
are tracked by the event's `id`, like React's keys. The prop surface
|
|
611
|
+
(documented on the exported `TimelineProps`, `TimelineEventProps`,
|
|
612
|
+
`TimelineRailProps` and `TimelineDateProps` interfaces):
|
|
613
|
+
Timeline(events, renderDateSeparator, emptyState, className),
|
|
614
|
+
TimelineEvent(event, isLast, className), TimelineRail(marker, connector,
|
|
615
|
+
className), TimelineDate(children, className).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Angular chronological timeline primitives.
|
|
3
|
+
*
|
|
4
|
+
* Exports:
|
|
5
|
+
* - `<mol-timeline>` / `Timeline` — vertical list of events with optional date separators.
|
|
6
|
+
* - `<div mol-timeline-event>` / `TimelineEvent` — one event row with rail (marker + connector) + content.
|
|
7
|
+
* - `<div mol-timeline-rail>` / `TimelineRail` — standalone rail (marker + connector) for custom rows.
|
|
8
|
+
* - `<div mol-timeline-date>` / `TimelineDate` — date separator rendered between groups.
|
|
9
|
+
* - `TimelineEventData` type for event records.
|
|
10
|
+
*
|
|
11
|
+
* Use for activity chronologies, deal timelines, order tracking, audit logs.
|
|
12
|
+
* It is the Angular counterpart of `@molecule/app-timeline-react`: the same
|
|
13
|
+
* props (React names) and the same DOM for the same input, so switching
|
|
14
|
+
* framework is changing the package name in the imports.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { Component } from '@angular/core'
|
|
19
|
+
* import { Timeline, TimelineDate } from '@molecule/app-timeline-angular'
|
|
20
|
+
*
|
|
21
|
+
* @Component({
|
|
22
|
+
* selector: 'app-activity',
|
|
23
|
+
* standalone: true,
|
|
24
|
+
* imports: [Timeline, TimelineDate],
|
|
25
|
+
* template: `
|
|
26
|
+
* <mol-timeline [events]="events">
|
|
27
|
+
* <p slot="emptyState">No activity yet.</p>
|
|
28
|
+
* </mol-timeline>
|
|
29
|
+
* `,
|
|
30
|
+
* })
|
|
31
|
+
* export class Activity {
|
|
32
|
+
* events = [
|
|
33
|
+
* { id: '1', timestamp: '2 hours ago', title: 'Order placed' },
|
|
34
|
+
* { id: '2', timestamp: 'Yesterday', title: 'Payment confirmed', body: 'Visa ending 4242' },
|
|
35
|
+
* { id: '3', timestamp: 'Mar 12', title: 'Item shipped' },
|
|
36
|
+
* ]
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* This is NOT the Angular binding for `@molecule/app-timeline` (the headless
|
|
42
|
+
* provider core wired via `setProvider`) — it is standalone presentational
|
|
43
|
+
* markup with no provider. For domain-specific rows see the sibling
|
|
44
|
+
* `@molecule/app-{activity,order,status,stage,day}-timeline-angular` packages.
|
|
45
|
+
*
|
|
46
|
+
* `TimelineEventData.accent` is currently INERT — no component reads it, so
|
|
47
|
+
* setting it changes nothing; color a row by passing a custom `marker` node
|
|
48
|
+
* instead. `timestamp` is a display node — format/translate it before
|
|
49
|
+
* passing. Node-valued props are `ng-template` references; `Timeline`'s root is
|
|
50
|
+
* a fragment in its empty branch, so its host is `display: contents`, and rows
|
|
51
|
+
* are tracked by the event's `id`, like React's keys. The prop surface
|
|
52
|
+
* (documented on the exported `TimelineProps`, `TimelineEventProps`,
|
|
53
|
+
* `TimelineRailProps` and `TimelineDateProps` interfaces):
|
|
54
|
+
* Timeline(events, renderDateSeparator, emptyState, className),
|
|
55
|
+
* TimelineEvent(event, isLast, className), TimelineRail(marker, connector,
|
|
56
|
+
* className), TimelineDate(children, className).
|
|
57
|
+
*
|
|
58
|
+
* @module
|
|
59
|
+
*/
|
|
60
|
+
export * from './timeline.component.js';
|
|
61
|
+
export * from './timeline-date.component.js';
|
|
62
|
+
export * from './timeline-event.component.js';
|
|
63
|
+
export * from './timeline-rail.component.js';
|
|
64
|
+
export * from './types.js';
|
|
65
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,cAAc,yBAAyB,CAAA;AACvC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,YAAY,CAAA"}
|