6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { Component , ChangeDetectionStrategy , Input , ViewEncapsulation } from '@angular/core' ;
9
+ import {
10
+ Component ,
11
+ ChangeDetectionStrategy ,
12
+ ElementRef ,
13
+ Input ,
14
+ ViewEncapsulation
15
+ } from '@angular/core' ;
16
+ import { CanColor , mixinColor } from '@angular/material/core' ;
10
17
11
18
// TODO(josephperrott): Benchpress tests.
12
- // TODO(josephperrott): Add ARIA attributes for progressbar "for".
19
+ // TODO(josephperrott): Add ARIA attributes for progress bar "for".
20
+
21
+ // Boilerplate for applying mixins to MatProgressBar.
22
+ /** @docs -private */
23
+ export class MatProgressBarBase {
24
+ constructor ( public _elementRef : ElementRef ) { }
25
+ }
26
+
27
+ export const _MatProgressBarMixinBase = mixinColor ( MatProgressBarBase , 'primary' ) ;
13
28
14
29
15
30
/**
@@ -25,34 +40,32 @@ import {Component, ChangeDetectionStrategy, Input, ViewEncapsulation} from '@ang
25
40
'aria-valuemax' : '100' ,
26
41
'[attr.aria-valuenow]' : 'value' ,
27
42
'[attr.mode]' : 'mode' ,
28
- '[class.mat-primary]' : 'color == "primary"' ,
29
- '[class.mat-accent]' : 'color == "accent"' ,
30
- '[class.mat-warn]' : 'color == "warn"' ,
31
43
'class' : 'mat-progress-bar' ,
32
44
} ,
45
+ inputs : [ 'color' ] ,
33
46
templateUrl : 'progress-bar.html' ,
34
47
styleUrls : [ 'progress-bar.css' ] ,
35
48
changeDetection : ChangeDetectionStrategy . OnPush ,
36
49
encapsulation : ViewEncapsulation . None ,
37
50
preserveWhitespaces : false ,
38
51
} )
39
- export class MatProgressBar {
40
- /** Color of the progress bar. */
41
- @Input ( ) color : 'primary' | 'accent' | 'warn' = 'primary' ;
52
+ export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor {
42
53
43
- private _value : number = 0 ;
54
+ constructor ( public _elementRef : ElementRef ) {
55
+ super ( _elementRef ) ;
56
+ }
44
57
45
- /** Value of the progressbar . Defaults to zero. Mirrored to aria-valuenow. */
58
+ /** Value of the progress bar . Defaults to zero. Mirrored to aria-valuenow. */
46
59
@Input ( )
47
60
get value ( ) : number { return this . _value ; }
48
61
set value ( v : number ) { this . _value = clamp ( v || 0 ) ; }
49
-
50
- private _bufferValue : number = 0 ;
62
+ private _value : number = 0 ;
51
63
52
64
/** Buffer value of the progress bar. Defaults to zero. */
53
65
@Input ( )
54
66
get bufferValue ( ) : number { return this . _bufferValue ; }
55
67
set bufferValue ( v : number ) { this . _bufferValue = clamp ( v || 0 ) ; }
68
+ private _bufferValue : number = 0 ;
56
69
57
70
/**
58
71
* Mode of the progress bar.
@@ -65,17 +78,17 @@ export class MatProgressBar {
65
78
66
79
/** Gets the current transform value for the progress bar's primary indicator. */
67
80
_primaryTransform ( ) {
68
- let scale = this . value / 100 ;
81
+ const scale = this . value / 100 ;
69
82
return { transform : `scaleX(${ scale } )` } ;
70
83
}
71
84
72
85
/**
73
- * Gets the current transform value for the progress bar's buffer indicator. Only used if the
86
+ * Gets the current transform value for the progress bar's buffer indicator. Only used if the
74
87
* progress mode is set to buffer, otherwise returns an undefined, causing no transformation.
75
88
*/
76
89
_bufferTransform ( ) {
77
- if ( this . mode == 'buffer' ) {
78
- let scale = this . bufferValue / 100 ;
90
+ if ( this . mode === 'buffer' ) {
91
+ const scale = this . bufferValue / 100 ;
79
92
return { transform : `scaleX(${ scale } )` } ;
80
93
}
81
94
}
0 commit comments