summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/customModal/directives/ripple-click.animation.directive.ts
blob: d343d5dc2d09dc6f0d3903918a102f0b9ebf5d53 (plain)
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
import { Directive, Input, HostBinding, HostListener } from "@angular/core";

export enum RippleAnimationAction {
  CLICK = 0,
  MOUSE_ENTER = 1
}

@Directive({
  selector: `[customRippleClickAnimation]`
})
export class CustomRippleClickAnimationDirective {
  private animated: boolean;

  @Input() rippleClickDisabled: boolean;
  @Input() rippleOnAction:RippleAnimationAction = RippleAnimationAction.CLICK;

  @HostBinding('class.sdc-ripple-click__animated') animationClass: string;

  @HostListener('click') onClick() {
    if(this.rippleOnAction === RippleAnimationAction.CLICK){
      this.animateStart();
    }
  }

  @HostListener('mouseenter') onMouseEnter() {
    //console.log("Mouseenter!", this.rippleOnAction);
    if(this.rippleOnAction === RippleAnimationAction.MOUSE_ENTER){
      this.animateStart();
    }
  }

  private animateStart():void{
    if (!this.rippleClickDisabled) {
      this.animated = true;
      this.animationClass = 'sdc-ripple-click__animated';
    }
  }
  @HostListener('animationend') onAnimationComplete() {
    this.animated = false;
    this.animationClass = '';
  }

  constructor() {
    this.rippleClickDisabled = false;
    this.animated = false;
  }
}