ngx-fizz
Version:
Rich Animated icon set for AngularIO operated by animeJS engine
62 lines (53 loc) • 1.89 kB
text/typescript
import {
Component,
ElementRef,
Input,
OnInit,
ViewChild,
} from '@angular/core';
import {
ShowHideIcon,
ShowHideState,
} from '../../core';
export class FizCodeComponent extends ShowHideIcon implements OnInit {
public leftTri: ElementRef;
public rightTri: ElementRef;
public centerBar: ElementRef;
public barColor: string;
constructor() {
super();
}
public ngOnInit() {
}
protected _show(duration) {
const { _anime, leftTri, rightTri, centerBar } = this;
const nextTimeline = this.initNextTimeline(ShowHideState.SHOW, duration);
/* Manually set isHide false since anime.js has bug which on begin is not called when duration is very short. */
this.isHide = false;
nextTimeline.add({
targets: [leftTri.nativeElement, rightTri.nativeElement],
strokeDashoffset: [_anime.setDashoffset, 0],
}).add({
targets: centerBar.nativeElement,
strokeDashoffset: [_anime.setDashoffset, 0],
});
return this.endAnimation(ShowHideState.SHOW, nextTimeline);
}
protected _hide(duration) {
const { _anime, leftTri, rightTri, centerBar } = this;
const nextTimeline = this.initNextTimeline(ShowHideState.HIDE, duration);
nextTimeline.add({
targets: centerBar.nativeElement,
strokeDashoffset: [0, _anime.setDashoffset],
}).add({
targets: [leftTri.nativeElement, rightTri.nativeElement],
strokeDashoffset: [0, _anime.setDashoffset],
});
return this.endAnimation(ShowHideState.HIDE, nextTimeline);
}
}