2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2020-04-07 15:43:43 -04:00
|
|
|
import {animate, AUTO_STYLE, state, style, transition, trigger} from '@angular/animations';
|
2017-03-01 20:13:06 -05:00
|
|
|
import {Component} from '@angular/core';
|
2016-12-16 20:52:17 -05:00
|
|
|
|
2016-05-31 12:15:17 -04:00
|
|
|
@Component({
|
2016-06-08 19:38:52 -04:00
|
|
|
selector: 'animate-cmp',
|
|
|
|
animations: [trigger(
|
|
|
|
'openClose',
|
|
|
|
[
|
|
|
|
state('*', style({height: AUTO_STYLE, color: 'black', borderColor: 'black'})),
|
|
|
|
state('closed, void', style({height: '0px', color: 'maroon', borderColor: 'maroon'})),
|
|
|
|
state('open', style({height: AUTO_STYLE, borderColor: 'green', color: 'green'})),
|
2017-03-01 20:13:06 -05:00
|
|
|
transition('* => *', animate('1s'))
|
2016-06-08 19:38:52 -04:00
|
|
|
])],
|
2016-05-31 12:15:17 -04:00
|
|
|
template: `
|
|
|
|
<button (click)="setAsOpen()">Open</button>
|
|
|
|
<button (click)="setAsClosed()">Closed</button>
|
2016-06-03 20:52:33 -04:00
|
|
|
<button (click)="setAsSomethingElse()">Something Else</button>
|
2016-05-31 12:15:17 -04:00
|
|
|
<hr />
|
2016-07-07 15:13:52 -04:00
|
|
|
<div [@openClose]="stateExpression">
|
2016-05-31 12:15:17 -04:00
|
|
|
Look at this box
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class AnimateCmp {
|
2016-06-08 19:38:52 -04:00
|
|
|
stateExpression: string;
|
2020-04-07 15:43:43 -04:00
|
|
|
constructor() {
|
|
|
|
this.setAsClosed();
|
|
|
|
}
|
|
|
|
setAsSomethingElse() {
|
|
|
|
this.stateExpression = 'something';
|
|
|
|
}
|
|
|
|
setAsOpen() {
|
|
|
|
this.stateExpression = 'open';
|
|
|
|
}
|
|
|
|
setAsClosed() {
|
|
|
|
this.stateExpression = 'closed';
|
|
|
|
}
|
2016-05-31 12:15:17 -04:00
|
|
|
}
|