1 | import { Component, Host, Input } from '@angular/core';
|
2 | import { ProgressDirective } from './progress.directive';
|
3 |
|
4 |
|
5 | export var BarComponent = (function () {
|
6 | function BarComponent(progress) {
|
7 | this.percent = 0;
|
8 | this.progress = progress;
|
9 | }
|
10 | Object.defineProperty(BarComponent.prototype, "value", {
|
11 |
|
12 | get: function () {
|
13 | return this._value;
|
14 | },
|
15 | set: function (v) {
|
16 | if (!v && v !== 0) {
|
17 | return;
|
18 | }
|
19 | this._value = v;
|
20 | this.recalculatePercentage();
|
21 | },
|
22 | enumerable: true,
|
23 | configurable: true
|
24 | });
|
25 | BarComponent.prototype.ngOnInit = function () {
|
26 | this.progress.addBar(this);
|
27 | };
|
28 | BarComponent.prototype.ngOnDestroy = function () {
|
29 | this.progress.removeBar(this);
|
30 | };
|
31 | BarComponent.prototype.recalculatePercentage = function () {
|
32 | this.percent = +(100 * this.value / this.progress.max).toFixed(2);
|
33 | var totalPercentage = this.progress.bars.reduce(function (total, bar) {
|
34 | return total + bar.percent;
|
35 | }, 0);
|
36 | if (totalPercentage > 100) {
|
37 | this.percent -= totalPercentage - 100;
|
38 | }
|
39 | };
|
40 | BarComponent.decorators = [
|
41 | { type: Component, args: [{
|
42 | selector: 'bar',
|
43 | template: "\n <div class=\"progress-bar\"\n style=\"min-width: 0;\"\n role=\"progressbar\"\n [ngClass]=\"type && 'progress-bar-' + type\"\n [ngStyle]=\"{width: (percent < 100 ? percent : 100) + '%', transition: transition}\"\n aria-valuemin=\"0\"\n [attr.aria-valuenow]=\"value\"\n [attr.aria-valuetext]=\"percent.toFixed(0) + '%'\"\n [attr.aria-valuemax]=\"max\"><ng-content></ng-content></div>\n"
|
44 | },] },
|
45 | ];
|
46 |
|
47 | BarComponent.ctorParameters = function () { return [
|
48 | { type: ProgressDirective, decorators: [{ type: Host },] },
|
49 | ]; };
|
50 | BarComponent.propDecorators = {
|
51 | 'type': [{ type: Input },],
|
52 | 'value': [{ type: Input },],
|
53 | };
|
54 | return BarComponent;
|
55 | }());
|
56 |
|
\ | No newline at end of file |