2016-06-03 17:52:33 -07:00
|
|
|
import {AUTO_STYLE, Component, trigger, state, animate, transition, style} from '@angular/core';
|
2016-05-31 09:15:17 -07:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "animate-cmp",
|
|
|
|
animations: [
|
|
|
|
trigger('openClose', [
|
2016-06-03 17:52:33 -07:00
|
|
|
state("*", style({ height: AUTO_STYLE, color: 'black', borderColor: 'black' })),
|
2016-05-31 09:15:17 -07:00
|
|
|
state('closed, void',
|
|
|
|
style({ height:"0px", color: "maroon", borderColor: "maroon" })),
|
|
|
|
state('open',
|
2016-06-03 17:52:33 -07:00
|
|
|
style({ height: AUTO_STYLE, borderColor:"green", color:"green" })),
|
2016-05-31 09:15:17 -07:00
|
|
|
transition("* => *", animate(500))
|
|
|
|
])
|
|
|
|
],
|
|
|
|
template: `
|
|
|
|
<button (click)="setAsOpen()">Open</button>
|
|
|
|
<button (click)="setAsClosed()">Closed</button>
|
2016-06-03 17:52:33 -07:00
|
|
|
<button (click)="setAsSomethingElse()">Something Else</button>
|
2016-05-31 09:15:17 -07:00
|
|
|
<hr />
|
|
|
|
<div @openClose="stateExpression">
|
|
|
|
Look at this box
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class AnimateCmp {
|
|
|
|
stateExpression:string;
|
|
|
|
constructor() {
|
|
|
|
this.setAsClosed();
|
|
|
|
}
|
2016-06-03 17:52:33 -07:00
|
|
|
setAsSomethingElse() {
|
|
|
|
this.stateExpression = 'something';
|
|
|
|
}
|
2016-05-31 09:15:17 -07:00
|
|
|
setAsOpen() {
|
|
|
|
this.stateExpression = 'open';
|
|
|
|
}
|
|
|
|
setAsClosed() {
|
|
|
|
this.stateExpression = 'closed';
|
|
|
|
}
|
|
|
|
}
|