File
Metadata
| changeDetection |
ChangeDetectionStrategy.OnPush |
| selector |
cx-checkout-progress |
| templateUrl |
./checkout-progress.component.html |
Index
Properties
|
|
|
Methods
|
|
|
Accessors
|
|
|
Methods
|
getTabIndex
|
getTabIndex(stepIndex: number)
|
|
|
Parameters :
| Name |
Type |
Optional |
| stepIndex |
number
|
No
|
|
|
isActive
|
isActive(index: number)
|
|
|
Parameters :
| Name |
Type |
Optional |
| index |
number
|
No
|
|
|
isDisabled
|
isDisabled(index: number)
|
|
|
Parameters :
| Name |
Type |
Optional |
| index |
number
|
No
|
|
|
activeStepIndex$
|
Type : Observable<number>
|
Default value : this.checkoutStepService.activeStepIndex$.pipe(
tap((index) => (this.activeStepIndex = index))
)
|
|
|
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { CheckoutStep } from '@spartacus/checkout/root';
import { BehaviorSubject, Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { CheckoutStepService } from '../../services/checkout-step.service';
@Component({
selector: 'cx-checkout-progress',
templateUrl: './checkout-progress.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CheckoutProgressComponent {
private _steps$: BehaviorSubject<CheckoutStep[]> =
this.checkoutStepService.steps$;
constructor(protected checkoutStepService: CheckoutStepService) {}
activeStepIndex: number;
activeStepIndex$: Observable<number> =
this.checkoutStepService.activeStepIndex$.pipe(
tap((index) => (this.activeStepIndex = index))
);
get steps$(): Observable<CheckoutStep[]> {
return this._steps$.asObservable();
}
getTabIndex(stepIndex: number): number {
return !this.isActive(stepIndex) && !this.isDisabled(stepIndex) ? 0 : -1;
}
isActive(index: number): boolean {
return index === this.activeStepIndex;
}
isDisabled(index: number): boolean {
return index > this.activeStepIndex;
}
}
<section *ngIf="(activeStepIndex$ | async) !== undefined">
<div class="cx-nav d-none d-lg-block d-xl-block">
<ul class="cx-list">
<ng-container *ngFor="let step of steps$ | async; let i = index">
<li
class="cx-item"
[class.active]="isActive(i)"
[class.disabled]="isDisabled(i)"
>
<a
[routerLink]="{ cxRoute: step.routeName } | cxUrl"
class="cx-link"
[class.active]="isActive(i)"
[class.disabled]="isDisabled(i)"
[tabindex]="getTabIndex(i)"
[innerHTML]="step.name | cxTranslate | cxMultiLine"
>
</a>
</li>
</ng-container>
</ul>
</div>
</section>
Legend
Html element with directive