forked from madoar/angular-archwizard-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom-navigation-mode.ts
36 lines (30 loc) · 1.09 KB
/
custom-navigation-mode.ts
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
import {SemiStrictNavigationMode} from 'angular-archwizard';
/**
* A custom NavigationMode
*
* Allows to navigate backward to any step (like `StrictNavigationMode`)
* and forward to steps the user has already visited before.
*
* Next and Previous buttons work as in `StrictNavigationMode`.
*/
export class CustomNavigationMode extends SemiStrictNavigationMode {
canTransitionToStep(destinationIndex: number) {
// Works as in strict mode
return this.wizardState.wizardSteps
.filter((step, index) => index < destinationIndex && index !== this.wizardState.currentStepIndex)
.every(step => step.completed || step.optional);
}
// @override
isNavigable(destinationIndex: number): boolean {
// allow returning to previous steps
if (destinationIndex < this.wizardState.currentStepIndex) {
return true;
}
// allow returning to any previously visited ("completed" steps)
const step = this.wizardState.wizardSteps[destinationIndex];
if (step && step.completed) {
return true;
}
return false;
}
}