UNPKG

ng2-bootstrap

Version:
57 lines (56 loc) 2.2 kB
"use strict"; var core_1 = require('@angular/core'); var progress_directive_1 = require('./progress.directive'); // todo: number pipe // todo: use query from progress? var BarComponent = (function () { function BarComponent(progress) { this.percent = 0; this.progress = progress; } Object.defineProperty(BarComponent.prototype, "value", { get: function () { return this._value; }, set: function (v) { if (!v && v !== 0) { return; } this._value = v; this.recalculatePercentage(); }, enumerable: true, configurable: true }); BarComponent.prototype.ngOnInit = function () { this.progress.addBar(this); }; BarComponent.prototype.ngOnDestroy = function () { this.progress.removeBar(this); }; BarComponent.prototype.recalculatePercentage = function () { this.percent = +(100 * this.value / this.progress.max).toFixed(2); var totalPercentage = this.progress.bars.reduce(function (total, bar) { return total + bar.percent; }, 0); if (totalPercentage > 100) { this.percent -= totalPercentage - 100; } }; BarComponent.decorators = [ { type: core_1.Component, args: [{ selector: 'bar', 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" },] }, ]; /** @nocollapse */ BarComponent.ctorParameters = [ { type: progress_directive_1.ProgressDirective, decorators: [{ type: core_1.Host },] }, ]; BarComponent.propDecorators = { 'type': [{ type: core_1.Input },], 'value': [{ type: core_1.Input },], }; return BarComponent; }()); exports.BarComponent = BarComponent;