@hilux/ngx-motion 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hilux/ngx-motion",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "A library for Angular motion directives",
5
5
  "main": "bundles/ngx-motion.umd.js",
6
6
  "module": "fesm5/ngx-motion.js",
@@ -6,6 +6,8 @@ import {
6
6
  Output,
7
7
  EventEmitter,
8
8
  AfterViewInit,
9
+ OnChanges,
10
+ SimpleChanges
9
11
  } from "@angular/core";
10
12
  import {
11
13
  AnimationBuilder,
@@ -19,7 +21,7 @@ import { MotionHostDirective} from "./ngx-motion-container.directive";
19
21
  selector: "[motion]",
20
22
  standalone: true,
21
23
  })
22
- export class MotionDirective implements OnDestroy, AfterViewInit {
24
+ export class MotionDirective implements OnDestroy, AfterViewInit, OnChanges {
23
25
  @Input() initial: any = {};
24
26
  @Input() animate: any = {};
25
27
  @Input() exit: any = {};
@@ -36,8 +38,11 @@ export class MotionDirective implements OnDestroy, AfterViewInit {
36
38
  constructor(private builder: AnimationBuilder, private el: ElementRef) {}
37
39
 
38
40
  ngAfterViewInit() {
39
- this.applyInitialStyles();
40
- if (!this.variant) {
41
+ if (this.variant) {
42
+ const initialState = this.variant === 'animate' ? this.animate : this.initial;
43
+ Object.assign(this.el.nativeElement.style, initialState);
44
+ } else {
45
+ this.applyInitialStyles();
41
46
  this.runAnimation(this.animate);
42
47
  }
43
48
  this.setupHoverAnimations();
@@ -47,6 +52,27 @@ export class MotionDirective implements OnDestroy, AfterViewInit {
47
52
  this.runExitAnimation();
48
53
  }
49
54
 
55
+ ngOnChanges(changes: SimpleChanges) {
56
+ if (changes['variant'] && !changes['variant'].firstChange) {
57
+ const targetState = this.variant === 'animate' ? this.animate :
58
+ this.variant === 'exit' ? this.exit :
59
+ this.initial;
60
+
61
+ const startState = this.variant === 'exit' ? this.animate : this.initial;
62
+
63
+ const animation = this.builder.build([
64
+ style(startState),
65
+ animate(`${this.duration} ${this.easing}`, style(targetState))
66
+ ]);
67
+
68
+ if (this.player) {
69
+ this.player.destroy();
70
+ }
71
+ this.player = animation.create(this.el.nativeElement);
72
+ this.player.play();
73
+ }
74
+ }
75
+
50
76
  registerPresence(presence: MotionHostDirective) {
51
77
  this.presence = presence;
52
78
  }
@@ -58,7 +84,7 @@ export class MotionDirective implements OnDestroy, AfterViewInit {
58
84
  this.variant === 'exit' ? this.exit : styles;
59
85
 
60
86
  animationMetadata = [
61
- style(this.variant === 'initial' ? {} : this.initial),
87
+ style(this.variant === 'exit' ? this.animate : this.initial),
62
88
  animate(`${this.duration} ${this.easing}`, style(currentStyles))
63
89
  ];
64
90