Skip to content

refactor(progress-bar): use color mixin #9473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions src/lib/progress-bar/progress-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Component, ChangeDetectionStrategy, Input, ViewEncapsulation} from '@angular/core';
import {
Component,
ChangeDetectionStrategy,
ElementRef,
Input,
ViewEncapsulation
} from '@angular/core';
import {CanColor, mixinColor} from '@angular/material/core';

// TODO(josephperrott): Benchpress tests.
// TODO(josephperrott): Add ARIA attributes for progressbar "for".
// TODO(josephperrott): Add ARIA attributes for progress bar "for".

// Boilerplate for applying mixins to MatProgressBar.
/** @docs-private */
export class MatProgressBarBase {
constructor(public _elementRef: ElementRef) { }
}

export const _MatProgressBarMixinBase = mixinColor(MatProgressBarBase, 'primary');


/**
Expand All @@ -25,34 +40,32 @@ import {Component, ChangeDetectionStrategy, Input, ViewEncapsulation} from '@ang
'aria-valuemax': '100',
'[attr.aria-valuenow]': 'value',
'[attr.mode]': 'mode',
'[class.mat-primary]': 'color == "primary"',
'[class.mat-accent]': 'color == "accent"',
'[class.mat-warn]': 'color == "warn"',
'class': 'mat-progress-bar',
},
inputs: ['color'],
templateUrl: 'progress-bar.html',
styleUrls: ['progress-bar.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also have to add inputs: ['color'] to the metadata.

preserveWhitespaces: false,
})
export class MatProgressBar {
/** Color of the progress bar. */
@Input() color: 'primary' | 'accent' | 'warn' = 'primary';
export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor {

private _value: number = 0;
constructor(public _elementRef: ElementRef) {
super(_elementRef);
}

/** Value of the progressbar. Defaults to zero. Mirrored to aria-valuenow. */
/** Value of the progress bar. Defaults to zero. Mirrored to aria-valuenow. */
@Input()
get value() { return this._value; }
get value(): number { return this._value; }
set value(v: number) { this._value = clamp(v || 0); }

private _bufferValue: number = 0;
private _value: number = 0;

/** Buffer value of the progress bar. Defaults to zero. */
@Input()
get bufferValue() { return this._bufferValue; }
get bufferValue(): number { return this._bufferValue; }
set bufferValue(v: number) { this._bufferValue = clamp(v || 0); }
private _bufferValue: number = 0;

/**
* Mode of the progress bar.
Expand All @@ -65,17 +78,17 @@ export class MatProgressBar {

/** Gets the current transform value for the progress bar's primary indicator. */
_primaryTransform() {
let scale = this.value / 100;
const scale = this.value / 100;
return {transform: `scaleX(${scale})`};
}

/**
* Gets the current transform value for the progress bar's buffer indicator. Only used if the
* Gets the current transform value for the progress bar's buffer indicator. Only used if the
* progress mode is set to buffer, otherwise returns an undefined, causing no transformation.
*/
_bufferTransform() {
if (this.mode == 'buffer') {
let scale = this.bufferValue / 100;
if (this.mode === 'buffer') {
const scale = this.bufferValue / 100;
return {transform: `scaleX(${scale})`};
}
}
Expand Down