-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtimeline.ts
More file actions
62 lines (53 loc) · 1.69 KB
/
timeline.ts
File metadata and controls
62 lines (53 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { html, LitElement, type PropertyValues } from 'lit';
import { property } from 'lit/decorators.js';
import { addSlotController, setSlots } from '../common/controllers/slot.js';
import { registerComponent } from '../common/definitions/register.js';
import IgcTimelineItemComponent from './item.js';
import { styles } from './timeline.base.css.js';
/**
* A container component that arranges `igc-timeline-item` elements along a
* vertical or horizontal axis connected by a visual line.
*
* @element igc-timeline
*
* @slot - Renders `igc-timeline-item` elements.
*/
export default class IgcTimelineComponent extends LitElement {
public static readonly tagName = 'igc-timeline';
public static override styles = styles;
/* blazorSuppress */
public static register(): void {
registerComponent(IgcTimelineComponent, IgcTimelineItemComponent);
}
private readonly _slots = addSlotController(this, {
slots: setSlots(),
onChange: this._syncOrientation,
initial: true,
});
@property({ reflect: true })
public orientation: 'vertical' | 'horizontal' = 'vertical';
protected override updated(changed: PropertyValues<this>): void {
if (changed.has('orientation')) {
this._syncOrientation();
}
}
private _syncOrientation(): void {
const items = this._slots.getAssignedElements<IgcTimelineItemComponent>(
'[default]',
{
selector: IgcTimelineItemComponent.tagName,
}
);
for (const item of items) {
item.dataset.orientation = this.orientation;
}
}
protected override render() {
return html`<slot></slot>`;
}
}
declare global {
interface HTMLElementTagNameMap {
'igc-timeline': IgcTimelineComponent;
}
}