66 * found in the LICENSE file at https://angular.io/license
77 */
88
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' ;
1017
1118// 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' ) ;
1328
1429
1530/**
@@ -25,34 +40,32 @@ import {Component, ChangeDetectionStrategy, Input, ViewEncapsulation} from '@ang
2540 'aria-valuemax' : '100' ,
2641 '[attr.aria-valuenow]' : 'value' ,
2742 '[attr.mode]' : 'mode' ,
28- '[class.mat-primary]' : 'color == "primary"' ,
29- '[class.mat-accent]' : 'color == "accent"' ,
30- '[class.mat-warn]' : 'color == "warn"' ,
3143 'class' : 'mat-progress-bar' ,
3244 } ,
45+ inputs : [ 'color' ] ,
3346 templateUrl : 'progress-bar.html' ,
3447 styleUrls : [ 'progress-bar.css' ] ,
3548 changeDetection : ChangeDetectionStrategy . OnPush ,
3649 encapsulation : ViewEncapsulation . None ,
3750 preserveWhitespaces : false ,
3851} )
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 {
4253
43- private _value : number = 0 ;
54+ constructor ( public _elementRef : ElementRef ) {
55+ super ( _elementRef ) ;
56+ }
4457
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. */
4659 @Input ( )
4760 get value ( ) : number { return this . _value ; }
4861 set value ( v : number ) { this . _value = clamp ( v || 0 ) ; }
49-
50- private _bufferValue : number = 0 ;
62+ private _value : number = 0 ;
5163
5264 /** Buffer value of the progress bar. Defaults to zero. */
5365 @Input ( )
5466 get bufferValue ( ) : number { return this . _bufferValue ; }
5567 set bufferValue ( v : number ) { this . _bufferValue = clamp ( v || 0 ) ; }
68+ private _bufferValue : number = 0 ;
5669
5770 /**
5871 * Mode of the progress bar.
@@ -65,17 +78,17 @@ export class MatProgressBar {
6578
6679 /** Gets the current transform value for the progress bar's primary indicator. */
6780 _primaryTransform ( ) {
68- let scale = this . value / 100 ;
81+ const scale = this . value / 100 ;
6982 return { transform : `scaleX(${ scale } )` } ;
7083 }
7184
7285 /**
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
7487 * progress mode is set to buffer, otherwise returns an undefined, causing no transformation.
7588 */
7689 _bufferTransform ( ) {
77- if ( this . mode == 'buffer' ) {
78- let scale = this . bufferValue / 100 ;
90+ if ( this . mode === 'buffer' ) {
91+ const scale = this . bufferValue / 100 ;
7992 return { transform : `scaleX(${ scale } )` } ;
8093 }
8194 }
0 commit comments