UNPKG

8.66 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('ngx-bootstrap/utils'), require('@angular/common')) :
3 typeof define === 'function' && define.amd ? define('ngx-bootstrap/progressbar', ['exports', '@angular/core', 'ngx-bootstrap/utils', '@angular/common'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].progressbar = {}), global.ng.core, global.utils, global.ng.common));
5}(this, (function (exports, i0, utils, common) { 'use strict';
6
7 var BarComponent = /** @class */ (function () {
8 function BarComponent(el, renderer) {
9 this.el = el;
10 this.renderer = renderer;
11 /** maximum total value of progress element */
12 this.max = 100;
13 /** current value of progress bar */
14 this.value = 0;
15 /** if `true` changing value of progress bar will be animated */
16 this.animate = false;
17 /** If `true`, striped classes are applied */
18 this.striped = false;
19 /** provide one of the four supported contextual classes: `success`, `info`, `warning`, `danger` */
20 this.type = 'info';
21 this.percent = 100;
22 }
23 Object.defineProperty(BarComponent.prototype, "isBs3", {
24 get: function () {
25 return utils.isBs3();
26 },
27 enumerable: false,
28 configurable: true
29 });
30 BarComponent.prototype.ngOnChanges = function (changes) {
31 var _a;
32 if (changes.value || changes.max) {
33 this.percent = 100 * (Number(changes.value.currentValue || 0)
34 / Number((((_a = changes.max) === null || _a === void 0 ? void 0 : _a.currentValue) || this.max) || 100));
35 }
36 if (changes.type) {
37 this.applyTypeClasses();
38 }
39 };
40 BarComponent.prototype.applyTypeClasses = function () {
41 if (this._prevType) {
42 var barTypeClass = "progress-bar-" + this._prevType;
43 var bgClass = "bg-" + this._prevType;
44 this.renderer.removeClass(this.el.nativeElement, barTypeClass);
45 this.renderer.removeClass(this.el.nativeElement, bgClass);
46 this._prevType = void 0;
47 }
48 if (this.type) {
49 var barTypeClass = "progress-bar-" + this.type;
50 var bgClass = "bg-" + this.type;
51 this.renderer.addClass(this.el.nativeElement, barTypeClass);
52 this.renderer.addClass(this.el.nativeElement, bgClass);
53 this._prevType = this.type;
54 }
55 };
56 return BarComponent;
57 }());
58 BarComponent.decorators = [
59 { type: i0.Component, args: [{
60 selector: 'bar',
61 template: "<ng-content></ng-content>\n",
62 changeDetection: i0.ChangeDetectionStrategy.OnPush,
63 // eslint-disable-next-line @angular-eslint/no-host-metadata-property
64 host: {
65 role: 'progressbar',
66 'aria-valuemin': '0',
67 '[class.progress-bar]': 'true',
68 '[class.progress-bar-animated]': '!isBs3 && animate',
69 '[class.progress-bar-striped]': 'striped',
70 '[class.active]': 'isBs3 && animate',
71 '[attr.aria-valuenow]': 'value',
72 '[attr.aria-valuetext]': 'percent ? percent.toFixed(0) + "%" : ""',
73 '[attr.aria-valuemax]': 'max',
74 '[style.height.%]': '"100"',
75 '[style.width.%]': 'percent'
76 }
77 },] }
78 ];
79 BarComponent.ctorParameters = function () { return [
80 { type: i0.ElementRef },
81 { type: i0.Renderer2 }
82 ]; };
83 BarComponent.propDecorators = {
84 max: [{ type: i0.Input }],
85 value: [{ type: i0.Input }],
86 animate: [{ type: i0.Input }],
87 striped: [{ type: i0.Input }],
88 type: [{ type: i0.Input }]
89 };
90
91 var ProgressbarConfig = /** @class */ (function () {
92 function ProgressbarConfig() {
93 /** if `true` changing value of progress bar will be animated */
94 this.animate = false;
95 /** maximum total value of progress element */
96 this.max = 100;
97 }
98 return ProgressbarConfig;
99 }());
100 ProgressbarConfig.ɵprov = i0.ɵɵdefineInjectable({ factory: function ProgressbarConfig_Factory() { return new ProgressbarConfig(); }, token: ProgressbarConfig, providedIn: "root" });
101 ProgressbarConfig.decorators = [
102 { type: i0.Injectable, args: [{
103 providedIn: 'root'
104 },] }
105 ];
106
107 var ProgressbarComponent = /** @class */ (function () {
108 function ProgressbarComponent(config) {
109 /** maximum total value of progress element */
110 this.max = 100;
111 /** if `true` changing value of progress bar will be animated */
112 this.animate = false;
113 /** If `true`, striped classes are applied */
114 this.striped = false;
115 this.isStacked = false;
116 this._value = 0;
117 Object.assign(this, config);
118 }
119 Object.defineProperty(ProgressbarComponent.prototype, "value", {
120 /** current value of progress bar. Could be a number or array of objects
121 * like {"value":15,"type":"info","label":"15 %"}
122 */
123 set: function (value) {
124 this.isStacked = Array.isArray(value);
125 if (typeof value === 'number') {
126 this._value = value;
127 this._values = void 0;
128 }
129 else {
130 this._value = void 0;
131 this._values = value;
132 }
133 },
134 enumerable: false,
135 configurable: true
136 });
137 return ProgressbarComponent;
138 }());
139 ProgressbarComponent.decorators = [
140 { type: i0.Component, args: [{
141 selector: 'progressbar',
142 template: "<ng-container *ngIf=\"!isStacked then NotStacked else Stacked\"></ng-container>\n\n<ng-template #NotStacked>\n <bar [type]=\"type\" [value]=\"_value\" [max]=\"max\" [animate]=\"animate\" [striped]=\"striped\">\n <ng-content></ng-content>\n </bar>\n</ng-template>\n\n<ng-template #Stacked>\n <bar *ngFor=\"let item of _values\"\n [type]=\"item.type\" [value]=\"item.value\" [max]=\"item.max\" [animate]=\"animate\" [striped]=\"striped\">{{ item.label }}</bar>\n</ng-template>\n",
143 changeDetection: i0.ChangeDetectionStrategy.OnPush,
144 // eslint-disable-next-line @angular-eslint/no-host-metadata-property
145 host: {
146 '[class.progress]': 'true',
147 '[attr.max]': 'max'
148 },
149 styles: ["\n :host {\n width: 100%;\n display: flex;\n } "]
150 },] }
151 ];
152 ProgressbarComponent.ctorParameters = function () { return [
153 { type: ProgressbarConfig }
154 ]; };
155 ProgressbarComponent.propDecorators = {
156 max: [{ type: i0.Input }],
157 animate: [{ type: i0.Input }],
158 striped: [{ type: i0.Input }],
159 type: [{ type: i0.Input }],
160 value: [{ type: i0.Input }]
161 };
162
163 var ProgressbarModule = /** @class */ (function () {
164 function ProgressbarModule() {
165 }
166 ProgressbarModule.forRoot = function () {
167 return { ngModule: ProgressbarModule, providers: [] };
168 };
169 return ProgressbarModule;
170 }());
171 ProgressbarModule.decorators = [
172 { type: i0.NgModule, args: [{
173 imports: [common.CommonModule],
174 declarations: [BarComponent, ProgressbarComponent],
175 exports: [BarComponent, ProgressbarComponent]
176 },] }
177 ];
178
179 /**
180 * Generated bundle index. Do not edit.
181 */
182
183 exports.BarComponent = BarComponent;
184 exports.ProgressbarComponent = ProgressbarComponent;
185 exports.ProgressbarConfig = ProgressbarConfig;
186 exports.ProgressbarModule = ProgressbarModule;
187
188 Object.defineProperty(exports, '__esModule', { value: true });
189
190})));
191//# sourceMappingURL=ngx-bootstrap-progressbar.umd.js.map