-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvwc-expansion-panel-list-base.ts
56 lines (45 loc) · 1.37 KB
/
vwc-expansion-panel-list-base.ts
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
import { LitElement, property } from 'lit-element';
import { VWCExpansionPanelBase } from './vwc-expansion-panel-base.js';
export abstract class VWCExpansionPanelListBase extends LitElement {
@property({ type: Boolean, reflect: true })
multi = false;
@property({ type: Boolean, reflect: true })
openAll = false;
private expansionPanels: HTMLCollectionOf<VWCExpansionPanelBase> | undefined = undefined;
constructor() {
super();
this.addEventListener('opened', this.handleOpened);
}
connectedCallback(): void {
super.connectedCallback();
this.expansionPanels = this.children as HTMLCollectionOf<VWCExpansionPanelBase>;
if (this.multi && this.openAll && this.expansionPanels) {
for (const expansionPanel of this.expansionPanels) {
expansionPanel.open = true;
}
}
}
handleOpened(e: Event): any {
if (!this.multi && this.expansionPanels) {
for (const expansionPanel of this.expansionPanels) {
if (expansionPanel !== e.target) expansionPanel.close();
}
}
}
getOpened(): Array<VWCExpansionPanelBase> {
const opened = [];
if (this.expansionPanels) {
for (const expansionPanel of this.expansionPanels) {
if (expansionPanel.open === true) opened.push(expansionPanel);
}
}
return opened;
}
closeAll(): void {
if (this.expansionPanels) {
for (const expansionPanel of this.expansionPanels) {
expansionPanel.close();
}
}
}
}