ngx-bootstrap-progressbar.umd.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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 = 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, core, utils, common) { 'use strict';
  6. /**
  7. * @fileoverview added by tsickle
  8. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  9. */
  10. var ProgressbarConfig = /** @class */ (function () {
  11. function ProgressbarConfig() {
  12. /**
  13. * if `true` changing value of progress bar will be animated
  14. */
  15. this.animate = false;
  16. /**
  17. * maximum total value of progress element
  18. */
  19. this.max = 100;
  20. }
  21. ProgressbarConfig.decorators = [
  22. { type: core.Injectable }
  23. ];
  24. return ProgressbarConfig;
  25. }());
  26. /**
  27. * @fileoverview added by tsickle
  28. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  29. */
  30. var ProgressbarComponent = /** @class */ (function () {
  31. function ProgressbarComponent(config) {
  32. this.isStacked = false;
  33. this.addClass = true;
  34. /* tslint:disable-next-line:no-any */
  35. this.bars = [];
  36. this._max = 100;
  37. Object.assign(this, config);
  38. }
  39. Object.defineProperty(ProgressbarComponent.prototype, "animate", {
  40. /** if `true` changing value of progress bar will be animated */
  41. set: /**
  42. * if `true` changing value of progress bar will be animated
  43. * @param {?} value
  44. * @return {?}
  45. */
  46. function (value) {
  47. this._animate = value;
  48. this.bars.forEach((/**
  49. * @param {?} b
  50. * @return {?}
  51. */
  52. function (b) {
  53. b.animate = value;
  54. }));
  55. },
  56. enumerable: true,
  57. configurable: true
  58. });
  59. Object.defineProperty(ProgressbarComponent.prototype, "striped", {
  60. /** If `true`, striped classes are applied */
  61. set: /**
  62. * If `true`, striped classes are applied
  63. * @param {?} value
  64. * @return {?}
  65. */
  66. function (value) {
  67. this._striped = value;
  68. this.bars.forEach((/**
  69. * @param {?} b
  70. * @return {?}
  71. */
  72. function (b) {
  73. b.striped = value;
  74. }));
  75. },
  76. enumerable: true,
  77. configurable: true
  78. });
  79. Object.defineProperty(ProgressbarComponent.prototype, "value", {
  80. /** current value of progress bar. Could be a number or array of objects
  81. * like {"value":15,"type":"info","label":"15 %"}
  82. */
  83. set: /**
  84. * current value of progress bar. Could be a number or array of objects
  85. * like {"value":15,"type":"info","label":"15 %"}
  86. * @param {?} value
  87. * @return {?}
  88. */
  89. function (value) {
  90. this.isStacked = Array.isArray(value);
  91. this._value = value;
  92. },
  93. enumerable: true,
  94. configurable: true
  95. });
  96. Object.defineProperty(ProgressbarComponent.prototype, "isBs3", {
  97. get: /**
  98. * @return {?}
  99. */
  100. function () {
  101. return utils.isBs3();
  102. },
  103. enumerable: true,
  104. configurable: true
  105. });
  106. Object.defineProperty(ProgressbarComponent.prototype, "max", {
  107. /** maximum total value of progress element */
  108. get: /**
  109. * maximum total value of progress element
  110. * @return {?}
  111. */
  112. function () {
  113. return this._max;
  114. },
  115. set: /**
  116. * @param {?} v
  117. * @return {?}
  118. */
  119. function (v) {
  120. this._max = v;
  121. this.bars.forEach((/**
  122. * @param {?} bar
  123. * @return {?}
  124. */
  125. function (bar) {
  126. bar.recalculatePercentage();
  127. }));
  128. },
  129. enumerable: true,
  130. configurable: true
  131. });
  132. /**
  133. * @param {?} bar
  134. * @return {?}
  135. */
  136. ProgressbarComponent.prototype.addBar = /**
  137. * @param {?} bar
  138. * @return {?}
  139. */
  140. function (bar) {
  141. bar.animate = this._animate;
  142. bar.striped = this._striped;
  143. this.bars.push(bar);
  144. };
  145. /**
  146. * @param {?} bar
  147. * @return {?}
  148. */
  149. ProgressbarComponent.prototype.removeBar = /**
  150. * @param {?} bar
  151. * @return {?}
  152. */
  153. function (bar) {
  154. this.bars.splice(this.bars.indexOf(bar), 1);
  155. };
  156. ProgressbarComponent.decorators = [
  157. { type: core.Component, args: [{
  158. selector: 'progressbar',
  159. template: "<bar [type]=\"type\" [value]=\"_value\" *ngIf=\"!isStacked\">\n <ng-content></ng-content>\n</bar>\n<ng-template [ngIf]=\"isStacked\">\n <bar *ngFor=\"let item of _value\" [type]=\"item.type\" [value]=\"item.value\">{{ item.label }}</bar>\n</ng-template>\n",
  160. styles: ["\n :host {\n width: 100%;\n display: flex;\n }\n "]
  161. }] }
  162. ];
  163. /** @nocollapse */
  164. ProgressbarComponent.ctorParameters = function () { return [
  165. { type: ProgressbarConfig }
  166. ]; };
  167. ProgressbarComponent.propDecorators = {
  168. animate: [{ type: core.Input }],
  169. striped: [{ type: core.Input }],
  170. type: [{ type: core.Input }],
  171. value: [{ type: core.Input }],
  172. max: [{ type: core.HostBinding, args: ['attr.max',] }, { type: core.Input }],
  173. addClass: [{ type: core.HostBinding, args: ['class.progress',] }]
  174. };
  175. return ProgressbarComponent;
  176. }());
  177. /**
  178. * @fileoverview added by tsickle
  179. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  180. */
  181. // todo: number pipe
  182. // todo: use query from progress?
  183. var BarComponent = /** @class */ (function () {
  184. function BarComponent(el, progress, renderer) {
  185. this.el = el;
  186. this.renderer = renderer;
  187. this.addClass = true;
  188. this.percent = 0;
  189. this.progress = progress;
  190. }
  191. Object.defineProperty(BarComponent.prototype, "type", {
  192. /** provide one of the four supported contextual classes: `success`, `info`, `warning`, `danger` */
  193. get: /**
  194. * provide one of the four supported contextual classes: `success`, `info`, `warning`, `danger`
  195. * @return {?}
  196. */
  197. function () {
  198. return this._type;
  199. },
  200. set: /**
  201. * @param {?} v
  202. * @return {?}
  203. */
  204. function (v) {
  205. this._type = v;
  206. this.applyTypeClasses();
  207. },
  208. enumerable: true,
  209. configurable: true
  210. });
  211. Object.defineProperty(BarComponent.prototype, "value", {
  212. /** current value of progress bar */
  213. get: /**
  214. * current value of progress bar
  215. * @return {?}
  216. */
  217. function () {
  218. return this._value;
  219. },
  220. set: /**
  221. * @param {?} v
  222. * @return {?}
  223. */
  224. function (v) {
  225. if (!v && v !== 0) {
  226. return;
  227. }
  228. this._value = v;
  229. this.recalculatePercentage();
  230. },
  231. enumerable: true,
  232. configurable: true
  233. });
  234. Object.defineProperty(BarComponent.prototype, "setBarWidth", {
  235. get: /**
  236. * @return {?}
  237. */
  238. function () {
  239. this.recalculatePercentage();
  240. return this.percent;
  241. },
  242. enumerable: true,
  243. configurable: true
  244. });
  245. Object.defineProperty(BarComponent.prototype, "isBs3", {
  246. get: /**
  247. * @return {?}
  248. */
  249. function () {
  250. return utils.isBs3();
  251. },
  252. enumerable: true,
  253. configurable: true
  254. });
  255. /**
  256. * @return {?}
  257. */
  258. BarComponent.prototype.ngOnInit = /**
  259. * @return {?}
  260. */
  261. function () {
  262. this.progress.addBar(this);
  263. };
  264. /**
  265. * @return {?}
  266. */
  267. BarComponent.prototype.ngOnDestroy = /**
  268. * @return {?}
  269. */
  270. function () {
  271. this.progress.removeBar(this);
  272. };
  273. /**
  274. * @return {?}
  275. */
  276. BarComponent.prototype.recalculatePercentage = /**
  277. * @return {?}
  278. */
  279. function () {
  280. this.percent = +(this.value / this.progress.max * 100).toFixed(2);
  281. /** @type {?} */
  282. var totalPercentage = this.progress.bars
  283. .reduce((/**
  284. * @param {?} total
  285. * @param {?} bar
  286. * @return {?}
  287. */
  288. function (total, bar) {
  289. return total + bar.percent;
  290. }), 0);
  291. if (totalPercentage > 100) {
  292. this.percent -= totalPercentage - 100;
  293. }
  294. };
  295. /**
  296. * @private
  297. * @return {?}
  298. */
  299. BarComponent.prototype.applyTypeClasses = /**
  300. * @private
  301. * @return {?}
  302. */
  303. function () {
  304. if (this._prevType) {
  305. /** @type {?} */
  306. var barTypeClass = "progress-bar-" + this._prevType;
  307. /** @type {?} */
  308. var bgClass = "bg-" + this._prevType;
  309. this.renderer.removeClass(this.el.nativeElement, barTypeClass);
  310. this.renderer.removeClass(this.el.nativeElement, bgClass);
  311. this._prevType = null;
  312. }
  313. if (this._type) {
  314. /** @type {?} */
  315. var barTypeClass = "progress-bar-" + this._type;
  316. /** @type {?} */
  317. var bgClass = "bg-" + this._type;
  318. this.renderer.addClass(this.el.nativeElement, barTypeClass);
  319. this.renderer.addClass(this.el.nativeElement, bgClass);
  320. this._prevType = this._type;
  321. }
  322. };
  323. BarComponent.decorators = [
  324. { type: core.Component, args: [{
  325. selector: 'bar',
  326. template: "<ng-content></ng-content>\n",
  327. host: {
  328. role: 'progressbar',
  329. 'aria-valuemin': '0',
  330. '[class.progress-bar-animated]': '!isBs3 && animate',
  331. '[class.progress-bar-striped]': 'striped',
  332. '[class.active]': 'isBs3 && animate',
  333. '[attr.aria-valuenow]': 'value',
  334. '[attr.aria-valuetext]': 'percent ? percent.toFixed(0) + "%" : ""',
  335. '[attr.aria-valuemax]': 'max',
  336. '[style.height.%]': '"100"'
  337. }
  338. }] }
  339. ];
  340. /** @nocollapse */
  341. BarComponent.ctorParameters = function () { return [
  342. { type: core.ElementRef },
  343. { type: ProgressbarComponent, decorators: [{ type: core.Host }] },
  344. { type: core.Renderer2 }
  345. ]; };
  346. BarComponent.propDecorators = {
  347. type: [{ type: core.Input }],
  348. value: [{ type: core.Input }],
  349. setBarWidth: [{ type: core.HostBinding, args: ['style.width.%',] }],
  350. addClass: [{ type: core.HostBinding, args: ['class.progress-bar',] }]
  351. };
  352. return BarComponent;
  353. }());
  354. /**
  355. * @fileoverview added by tsickle
  356. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  357. */
  358. var ProgressbarModule = /** @class */ (function () {
  359. function ProgressbarModule() {
  360. }
  361. /**
  362. * @return {?}
  363. */
  364. ProgressbarModule.forRoot = /**
  365. * @return {?}
  366. */
  367. function () {
  368. return { ngModule: ProgressbarModule, providers: [ProgressbarConfig] };
  369. };
  370. ProgressbarModule.decorators = [
  371. { type: core.NgModule, args: [{
  372. imports: [common.CommonModule],
  373. declarations: [BarComponent, ProgressbarComponent],
  374. exports: [BarComponent, ProgressbarComponent]
  375. },] }
  376. ];
  377. return ProgressbarModule;
  378. }());
  379. exports.BarComponent = BarComponent;
  380. exports.ProgressbarComponent = ProgressbarComponent;
  381. exports.ProgressbarConfig = ProgressbarConfig;
  382. exports.ProgressbarModule = ProgressbarModule;
  383. Object.defineProperty(exports, '__esModule', { value: true });
  384. }));
  385. //# sourceMappingURL=ngx-bootstrap-progressbar.umd.js.map