-
Notifications
You must be signed in to change notification settings - Fork 4
/
accordion.component.ts
62 lines (52 loc) · 1.59 KB
/
accordion.component.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
57
58
59
60
61
62
import { Component, Input, ContentChildren, AfterContentInit, QueryList } from '@angular/core';
import { AccordionPanelComponent } from './accordion-panel.component';
@Component({
selector: 'lsu-accordion',
template: `
<div class="ui styled accordion" [ngClass]="getCls()">
<ng-content select="lsu-accordionPanel"></ng-content>
</div>
`
})
export class AccordionComponent implements AfterContentInit {
@ContentChildren(AccordionPanelComponent)
public accordions: QueryList<AccordionPanelComponent>;
@Input()
option: any = {};
_accordions: Array<AccordionPanelComponent> = [];
constructor() {
}
getCls(): any {
let cls = {
"styled": this.option.styled == undefined ? true : this.option.styled,
"fluid": this.option.fluid == undefined ? true : this.option.fluid,
"inverted": this.option.inverted == undefined ? false : this.option.inverted
};
return cls;
}
setAccordion(accordion: AccordionPanelComponent): void {
let isActive = accordion.active;
if (!this.option.allowMultiple) {
this._accordions.forEach(a => a.active = false);
}
accordion.active = !isActive;
}
ngAfterContentInit(): void {
this._accordions = this.accordions.toArray();
this._accordions.forEach(a => {
a.onChange(this);
});
if (!this.option.allowMultiple) {
let finded: any = {};
(this._accordions || []).forEach(item => {
if (item.active) {
item.active = false;
finded = item;
}
});
if (finded.active !== undefined) {
finded.active = true;
}
}
}
}