-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaccordion_panel.ts
64 lines (57 loc) · 1.42 KB
/
accordion_panel.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
63
64
import { Component, Input, EventEmitter } from '@angular/core';
import { trigger, state, style, transition, animate } from '@angular/animations';
@Component({
selector: 'lsu-accordionPanel',
template: `
<div class="title" [ngClass]="{'active': active}" (click)="setAccordion()">
<i class="dropdown icon"></i>
{{ title }}
</div>
<div class="content active" [@accordionPanelState]="panelState">
<ng-content></ng-content>
</div>
`,
animations: [
trigger('accordionPanelState', [
state('inactive', style({
padding: '0 1em',
overflow: 'hidden',
height: 0
})),
state('active', style({
padding: '.5em 1em 1.5em',
overflow: 'initial',
height: '*'
})),
transition('inactive => active', animate('150ms ease-in')),
transition('active => inactive', animate('150ms ease-out'))
])
]
})
export class AccordionPanelComponent {
@Input()
public title: string = "";
@Input()
get active(): boolean {
return this._active;
}
set active(v: boolean) {
this._active = !!v;
if (this._active) {
this.panelState = 'active';
} else {
this.panelState = 'inactive';
}
}
_active: boolean = false;
panelState: string = 'inactive';
parent: any;
constructor() {
}
onChange(parent: any): void {
this.parent = parent;
}
setAccordion(): void {
this.parent.setAccordion(this);
}
}