Skip to content

Commit 93f29ce

Browse files
author
mmart1n
committed
feat(stepper): different horizontal and vertical animation settings
1 parent ce3cf09 commit 93f29ce

File tree

2 files changed

+74
-22
lines changed

2 files changed

+74
-22
lines changed

projects/igniteui-angular/src/lib/stepper/igx-stepper.component.ts

+38-19
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import { AnimationBuilder } from '@angular/animations';
22
import { CommonModule } from '@angular/common';
33
import {
44
AfterViewInit, Component, HostBinding, OnDestroy, OnInit,
5-
Input, Output, EventEmitter, ContentChildren, QueryList, ElementRef, NgModule, ChangeDetectorRef
5+
Input, Output, EventEmitter, ContentChildren, QueryList, ElementRef, NgModule
66
} from '@angular/core';
77
import { IgxCarouselComponentBase } from 'igniteui-angular';
88
import { Subject } from 'rxjs';
99
import { takeUntil } from 'rxjs/operators';
1010
import { growVerIn, growVerOut } from '../animations/grow';
11-
import { slideInLeft, slideOutRight } from '../animations/slide';
1211
import { ToggleAnimationSettings } from '../expansion-panel/toggle-animation-component';
1312
import { IgxStepperOrienatation, IGX_STEPPER_COMPONENT, IStepToggledEventArgs, IStepTogglingEventArgs } from './common';
1413
import {
@@ -40,11 +39,11 @@ export class IgxStepperComponent extends IgxCarouselComponentBase implements OnI
4039
return this.orientation === IgxStepperOrienatation.Horizontal;
4140
}
4241

43-
/** Get/Set the animation settings that branches should use when expanding/collpasing.
42+
/** Get/Set the animation settings that should be used when the active step is changed in vertical orientation mode.
4443
*
4544
* ```html
46-
* <igx-tree [animationSettings]="customAnimationSettings">
47-
* </igx-tree>
45+
* <igx-stepper [verticalAnimationSettings]="customAnimationSettings">
46+
* </igx-stepper>
4847
* ```
4948
*
5049
* ```typescript
@@ -53,15 +52,45 @@ export class IgxStepperComponent extends IgxCarouselComponentBase implements OnI
5352
* closeAnimation: growVerOut
5453
* };
5554
*
56-
* this.tree.animationSettings = animationSettings;
55+
* this.stepper.verticalAnimationSettings = animationSettings;
5756
* ```
5857
*/
5958
@Input()
60-
public animationSettings: ToggleAnimationSettings = {
59+
public verticalAnimationSettings: ToggleAnimationSettings = {
6160
openAnimation: growVerIn,
62-
closeAnimation: growVerOut
61+
closeAnimation: growVerOut,
6362
};
6463

64+
/**
65+
* Gets/sets the animation type of the stepper when the orientation direction is horizontal.
66+
* Default value is `slide`. Another possible values are `none` and `fade`.
67+
* ```html
68+
* <igx-stepper animationType='none'>
69+
* <igx-stepper>
70+
* ```
71+
*
72+
* @memberOf IgxSlideComponent
73+
*/
74+
@Input()
75+
public get horizontalAnimationType(): string {
76+
return this.animationType;
77+
}
78+
79+
public set horizontalAnimationType(value: string) {
80+
// TODO: activeChange event is not emitted for the collapsing steps
81+
this.stepperService.collapsingSteps.clear();
82+
this.animationType = value;
83+
}
84+
85+
@Input()
86+
public get horizontalAnimationDuration(): number {
87+
return this.animationDuration;
88+
}
89+
90+
public set horizontalAnimationDuration(value: number) {
91+
this.animationDuration = value;
92+
}
93+
6594
/**
6695
* Get/Set whether the stepper is linear.
6796
* Only if the active step is valid the user is able to move forward.
@@ -89,17 +118,7 @@ export class IgxStepperComponent extends IgxCarouselComponentBase implements OnI
89118
if (this._orientation === value) {
90119
return;
91120
}
92-
if (value === IgxStepperOrienatation.Horizontal) {
93-
this.animationSettings = {
94-
openAnimation: slideInLeft,
95-
closeAnimation: slideOutRight
96-
};
97-
} else {
98-
this.animationSettings = {
99-
openAnimation: growVerIn,
100-
closeAnimation: growVerOut
101-
};
102-
}
121+
103122
// TODO: activeChange event is not emitted for the collapsing steps
104123
this.stepperService.collapsingSteps.clear();
105124
this._orientation = value;

projects/igniteui-angular/src/lib/stepper/step/igx-step.component.ts

+36-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class IgxStepComponent extends ToggleAnimationPlayer implements OnInit, A
4545

4646
/** @hidden @internal */
4747
public get animationSettings(): ToggleAnimationSettings {
48-
return this.stepper.animationSettings;
48+
return this.stepper.verticalAnimationSettings;
4949
}
5050

5151
/**
@@ -288,7 +288,9 @@ export class IgxStepComponent extends ToggleAnimationPlayer implements OnInit, A
288288
public ngOnInit() {
289289
this.openAnimationDone.pipe(takeUntil(this.destroy$)).subscribe(
290290
() => {
291-
this.stepper.activeStepChanged.emit({ owner: this.stepper, activeStep: this });
291+
if (this.stepperService.activeStep === this) {
292+
this.stepper.activeStepChanged.emit({ owner: this.stepper, activeStep: this });
293+
}
292294
}
293295
);
294296
this.closeAnimationDone.pipe(takeUntil(this.destroy$)).subscribe(() => {
@@ -352,11 +354,42 @@ export class IgxStepComponent extends ToggleAnimationPlayer implements OnInit, A
352354
*/
353355
public onPointerDown(event) {
354356
event.stopPropagation();
355-
this.stepperService.expand(this);
357+
if (this.isHorizontal) {
358+
this.changeHorizontalActiveStep();
359+
} else {
360+
this.changeVerticalActiveStep();
361+
}
356362
}
357363

358364
public ngOnDestroy() {
359365
super.ngOnDestroy();
360366
}
361367

368+
private changeHorizontalActiveStep(): void {
369+
// pointer events none on active step and remove this.stepperService.activeStep !== this on the next line
370+
if (this.stepper.animationType === 'none' && this.stepperService.activeStep !== this) {
371+
this.active = true;
372+
this.stepper.activeStepChanged.emit({ owner: this.stepper, activeStep: this });
373+
return;
374+
}
375+
this.stepperService.expand(this);
376+
if (this.stepper.animationType === 'fade') {
377+
if (this.stepperService.collapsingSteps.has(this.stepperService.previousActiveStep)) {
378+
this.stepperService.previousActiveStep.active = false;
379+
}
380+
}
381+
}
382+
383+
private changeVerticalActiveStep(): void {
384+
this.stepperService.expand(this);
385+
386+
if (!this.animationSettings.closeAnimation) {
387+
this.stepperService.previousActiveStep.openAnimationPlayer?.finish();
388+
}
389+
390+
if (!this.animationSettings.openAnimation) {
391+
this.stepperService.activeStep.closeAnimationPlayer?.finish();
392+
}
393+
}
394+
362395
}

0 commit comments

Comments
 (0)