Added action change animation

This commit is contained in:
NejcZdovc
2016-11-19 11:01:56 +01:00
committed by József Farkas
parent 02db20e6c3
commit d42e3093f2
2 changed files with 26 additions and 6 deletions
@@ -1,4 +1,6 @@
<svg:rect [id]="id" [attr.rx]="rx" [attr.ry]="ry" <svg:rect [@change]="animation"
(@change.done)="animationDone()"
[id]="id" [attr.rx]="rx" [attr.ry]="ry"
[attr.height]="height" [attr.width]="width" [attr.height]="height" [attr.width]="width"
[attr.fill]="fill" [attr.fill]="fill"
/> />

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

@@ -1,4 +1,7 @@
import {Component, Input, OnChanges, OnDestroy, OnInit, SimpleChange } from '@angular/core'; import {
Component, Input, OnChanges, OnDestroy, OnInit, SimpleChange,
animate, group, style, transition, trigger
} from '@angular/core';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
@@ -33,6 +36,18 @@ enum LabelTypes {
} }
@Component({ @Component({
animations: [
trigger('change', [
transition('inactive => active', [
style({fill: '#fff'}),
group([
animate('1s ease-out', style({
fill: '#333'
}))
])
])
])
],
selector: 'g[svg-keyboard-key]', selector: 'g[svg-keyboard-key]',
template: require('./svg-keyboard-key.component.html'), template: require('./svg-keyboard-key.component.html'),
styles: [require('./svg-keyboard-key.component.scss')] styles: [require('./svg-keyboard-key.component.scss')]
@@ -45,15 +60,13 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
@Input() width: number; @Input() width: number;
@Input() keyAction: KeyAction; @Input() keyAction: KeyAction;
/* tslint:disable:no-unused-variable */ enumLabelTypes = LabelTypes;
/* It is used in the template */
private enumLabelTypes = LabelTypes;
/* tslint:enable:no-unused-variable */
private labelSource: any; private labelSource: any;
private labelType: LabelTypes; private labelType: LabelTypes;
private macros: Macro[]; private macros: Macro[];
private subscription: Subscription; private subscription: Subscription;
private animation: string = 'inactive';
constructor(private mapperService: MapperService, private store: Store<AppState>) { constructor(private mapperService: MapperService, private store: Store<AppState>) {
this.subscription = store.let(getMacroEntities()) this.subscription = store.let(getMacroEntities())
@@ -68,6 +81,7 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
/* tslint:disable:no-string-literal */ /* tslint:disable:no-string-literal */
if (changes['keyAction']) { if (changes['keyAction']) {
this.setLabels(); this.setLabels();
this.animation = 'active';
} }
/* tslint:enable:no-string-literal */ /* tslint:enable:no-string-literal */
} }
@@ -76,6 +90,10 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
this.subscription.unsubscribe(); this.subscription.unsubscribe();
} }
animationDone() {
this.animation = 'inactive';
}
private setLabels(): void { private setLabels(): void {
if (!this.keyAction) { if (!this.keyAction) {
this.labelSource = undefined; this.labelSource = undefined;