@engie-group/fluid-design-system-angular
Version:
Fluid Design System Angular
100 lines (86 loc) • 2.14 kB
text/typescript
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, Input, ViewEncapsulation } from '@angular/core';
import { ProgressAnimation } from './progress.animation';
export class ProgressComponent {
/**
* @ignore
*/
private readonly progressClassName = 'nj-progress';
/**
* Label of the progressbar
*/
label: string;
/**
* Progress value
*/
value = 0;
/**
* Whether progress description is shown on the right/bottom or hidden
*/
descriptionPosition: 'right' | 'bottom' | 'none' = 'none';
/**
* Progress min
*/
min = 0;
/**
* Progress max
*/
max = 100;
/**
* Whether progress is animated at first render
*/
isAnimated = true;
/**
* Whether progress has css transitions for progress width
*/
hasTransition = false;
/**
* Decimal precision of the description text
*/
decimalPrecision = 0;
constructor() {}
/**
* @ignore
*/
getTransitionClass(): string {
return this.hasTransition ? `${this.progressClassName}--has-transition` : '';
}
/**
* @ignore
*/
getDescriptionPositionClass(): string {
return this.descriptionPosition === 'right' ? `${this.progressClassName}--has-right-description` : '';
}
/**
* @ignore
*/
getFormattedValue(): number {
if (this.value > this.max) {
return this.max;
} else if (this.value < this.min) {
return this.min;
} else {
return this.value;
}
}
/**
* @ignore
*/
getFormattedPercentage(): string {
if (this.value < this.min) {
return '0';
} else if (this.value > this.max) {
return '100';
}
return Number(((this.getFormattedValue() - this.min) / (this.max - this.min)) * 100).toFixed(this.decimalPrecision);
}
}