|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google Inc. All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | + |
| 9 | +import {Directive, Input} from '@angular/core'; |
| 10 | +import {CdkStep, CdkStepper} from './stepper'; |
| 11 | +import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion'; |
| 12 | + |
| 13 | +@Directive({ |
| 14 | + selector: 'cdkStepHeader', |
| 15 | + host: { |
| 16 | + 'role': 'tab', |
| 17 | + '[attr.id]': 'labelId', |
| 18 | + '[attr.aria-controls]': 'contentId', |
| 19 | + '[attr.aria-selected]': 'selected' |
| 20 | + } |
| 21 | +}) |
| 22 | +export class CdkStepHeader { |
| 23 | + /** Whether the orientation of stepper is horizontal. */ |
| 24 | + @Input() |
| 25 | + get horizontal() { return this._horizontal; } |
| 26 | + set horizontal(value: any) { |
| 27 | + this._horizontal = coerceBooleanProperty(value); |
| 28 | + } |
| 29 | + private _horizontal: boolean; |
| 30 | + |
| 31 | + /** Unique label ID of step header. */ |
| 32 | + @Input() |
| 33 | + labelId: string; |
| 34 | + |
| 35 | + /** Unique content ID of step content. */ |
| 36 | + @Input() |
| 37 | + contentId: string; |
| 38 | + |
| 39 | + /** Index of the given step. */ |
| 40 | + @Input() |
| 41 | + get index() { return this._index; } |
| 42 | + set index(value: any) { |
| 43 | + this._index = coerceNumberProperty(value); |
| 44 | + } |
| 45 | + private _index: number; |
| 46 | + |
| 47 | + /** Whether the given step is selected. */ |
| 48 | + @Input() |
| 49 | + get selected() { return this._selected; } |
| 50 | + set selected(value: any) { |
| 51 | + this._selected = coerceBooleanProperty(value); |
| 52 | + } |
| 53 | + private _selected: boolean; |
| 54 | + |
| 55 | + |
| 56 | + /** Returns the step at the index position in stepper. */ |
| 57 | + get step(): CdkStep { |
| 58 | + return this._stepper._steps.toArray()[this._index]; |
| 59 | + } |
| 60 | + |
| 61 | + constructor(private _stepper: CdkStepper) { } |
| 62 | + |
| 63 | + /** Returns the type of icon to be displayed. */ |
| 64 | + _getIndicatorType(): 'number' | 'edit' | 'done' { |
| 65 | + if (!this.step.completed || this._selected) { |
| 66 | + return 'number'; |
| 67 | + } else { |
| 68 | + return this.step.editable ? 'edit' : 'done'; |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments