ngx-bootstrap-progressbar.js 12 KB

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