ngx-bootstrap-tabs.umd.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) :
  3. typeof define === 'function' && define.amd ? define('ngx-bootstrap/tabs', ['exports', '@angular/core', '@angular/common'], factory) :
  4. (global = global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].tabs = {}), global.ng.core, global.ng.common));
  5. }(this, function (exports, core, common) { 'use strict';
  6. /**
  7. * @fileoverview added by tsickle
  8. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  9. */
  10. var NgTranscludeDirective = /** @class */ (function () {
  11. function NgTranscludeDirective(viewRef) {
  12. this.viewRef = viewRef;
  13. }
  14. Object.defineProperty(NgTranscludeDirective.prototype, "ngTransclude", {
  15. /* tslint:disable-next-line:no-any */
  16. get: /* tslint:disable-next-line:no-any */
  17. /**
  18. * @return {?}
  19. */
  20. function () {
  21. return this._ngTransclude;
  22. },
  23. set: /**
  24. * @param {?} templateRef
  25. * @return {?}
  26. */
  27. function (templateRef) {
  28. this._ngTransclude = templateRef;
  29. if (templateRef) {
  30. this.viewRef.createEmbeddedView(templateRef);
  31. }
  32. },
  33. enumerable: true,
  34. configurable: true
  35. });
  36. NgTranscludeDirective.decorators = [
  37. { type: core.Directive, args: [{
  38. selector: '[ngTransclude]'
  39. },] }
  40. ];
  41. /** @nocollapse */
  42. NgTranscludeDirective.ctorParameters = function () { return [
  43. { type: core.ViewContainerRef }
  44. ]; };
  45. NgTranscludeDirective.propDecorators = {
  46. ngTransclude: [{ type: core.Input }]
  47. };
  48. return NgTranscludeDirective;
  49. }());
  50. /**
  51. * @fileoverview added by tsickle
  52. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  53. */
  54. var TabsetConfig = /** @class */ (function () {
  55. function TabsetConfig() {
  56. /**
  57. * provides default navigation context class: 'tabs' or 'pills'
  58. */
  59. this.type = 'tabs';
  60. }
  61. TabsetConfig.decorators = [
  62. { type: core.Injectable }
  63. ];
  64. return TabsetConfig;
  65. }());
  66. /**
  67. * @fileoverview added by tsickle
  68. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  69. */
  70. // todo: add active event to tab
  71. // todo: fix? mixing static and dynamic tabs position tabs in order of creation
  72. var TabsetComponent = /** @class */ (function () {
  73. function TabsetComponent(config, renderer, elementRef) {
  74. this.renderer = renderer;
  75. this.elementRef = elementRef;
  76. this.clazz = true;
  77. this.tabs = [];
  78. this.classMap = {};
  79. Object.assign(this, config);
  80. }
  81. Object.defineProperty(TabsetComponent.prototype, "vertical", {
  82. /** if true tabs will be placed vertically */
  83. get: /**
  84. * if true tabs will be placed vertically
  85. * @return {?}
  86. */
  87. function () {
  88. return this._vertical;
  89. },
  90. set: /**
  91. * @param {?} value
  92. * @return {?}
  93. */
  94. function (value) {
  95. this._vertical = value;
  96. this.setClassMap();
  97. },
  98. enumerable: true,
  99. configurable: true
  100. });
  101. Object.defineProperty(TabsetComponent.prototype, "justified", {
  102. /** if true tabs fill the container and have a consistent width */
  103. get: /**
  104. * if true tabs fill the container and have a consistent width
  105. * @return {?}
  106. */
  107. function () {
  108. return this._justified;
  109. },
  110. set: /**
  111. * @param {?} value
  112. * @return {?}
  113. */
  114. function (value) {
  115. this._justified = value;
  116. this.setClassMap();
  117. },
  118. enumerable: true,
  119. configurable: true
  120. });
  121. Object.defineProperty(TabsetComponent.prototype, "type", {
  122. /** navigation context class: 'tabs' or 'pills' */
  123. get: /**
  124. * navigation context class: 'tabs' or 'pills'
  125. * @return {?}
  126. */
  127. function () {
  128. return this._type;
  129. },
  130. set: /**
  131. * @param {?} value
  132. * @return {?}
  133. */
  134. function (value) {
  135. this._type = value;
  136. this.setClassMap();
  137. },
  138. enumerable: true,
  139. configurable: true
  140. });
  141. /**
  142. * @return {?}
  143. */
  144. TabsetComponent.prototype.ngOnDestroy = /**
  145. * @return {?}
  146. */
  147. function () {
  148. this.isDestroyed = true;
  149. };
  150. /**
  151. * @param {?} tab
  152. * @return {?}
  153. */
  154. TabsetComponent.prototype.addTab = /**
  155. * @param {?} tab
  156. * @return {?}
  157. */
  158. function (tab) {
  159. this.tabs.push(tab);
  160. tab.active = this.tabs.length === 1 && typeof tab.active === 'undefined';
  161. };
  162. /**
  163. * @param {?} tab
  164. * @param {?=} options
  165. * @return {?}
  166. */
  167. TabsetComponent.prototype.removeTab = /**
  168. * @param {?} tab
  169. * @param {?=} options
  170. * @return {?}
  171. */
  172. function (tab, options) {
  173. if (options === void 0) { options = { reselect: true, emit: true }; }
  174. /** @type {?} */
  175. var index = this.tabs.indexOf(tab);
  176. if (index === -1 || this.isDestroyed) {
  177. return;
  178. }
  179. // Select a new tab if the tab to be removed is selected and not destroyed
  180. if (options.reselect && tab.active && this.hasAvailableTabs(index)) {
  181. /** @type {?} */
  182. var newActiveIndex = this.getClosestTabIndex(index);
  183. this.tabs[newActiveIndex].active = true;
  184. }
  185. if (options.emit) {
  186. tab.removed.emit(tab);
  187. }
  188. this.tabs.splice(index, 1);
  189. if (tab.elementRef.nativeElement.parentNode) {
  190. this.renderer.removeChild(tab.elementRef.nativeElement.parentNode, tab.elementRef.nativeElement);
  191. }
  192. };
  193. /* tslint:disable-next-line: cyclomatic-complexity */
  194. /* tslint:disable-next-line: cyclomatic-complexity */
  195. /**
  196. * @param {?} event
  197. * @param {?} index
  198. * @return {?}
  199. */
  200. TabsetComponent.prototype.keyNavActions = /* tslint:disable-next-line: cyclomatic-complexity */
  201. /**
  202. * @param {?} event
  203. * @param {?} index
  204. * @return {?}
  205. */
  206. function (event, index) {
  207. /** @type {?} */
  208. var list = Array.from(this.elementRef.nativeElement.querySelectorAll('.nav-link'));
  209. // const activeElList = list.filter((el: HTMLElement) => !el.classList.contains('disabled'));
  210. // tslint:disable-next-line:deprecation
  211. if (event.keyCode === 13 || event.key === 'Enter' || event.keyCode === 32 || event.key === 'Space') {
  212. event.preventDefault();
  213. /** @type {?} */
  214. var currentTab = list[(index) % list.length];
  215. currentTab.click();
  216. return;
  217. }
  218. // tslint:disable-next-line:deprecation
  219. if (event.keyCode === 39 || event.key === 'RightArrow') {
  220. /** @type {?} */
  221. var nextTab = void 0;
  222. /** @type {?} */
  223. var shift = 1;
  224. do {
  225. nextTab = list[(index + shift) % list.length];
  226. shift++;
  227. } while (nextTab.classList.contains('disabled'));
  228. nextTab.focus();
  229. return;
  230. }
  231. // tslint:disable-next-line:deprecation
  232. if (event.keyCode === 37 || event.key === 'LeftArrow') {
  233. /** @type {?} */
  234. var previousTab = void 0;
  235. /** @type {?} */
  236. var shift = 1;
  237. /** @type {?} */
  238. var i = index;
  239. do {
  240. if ((i - shift) < 0) {
  241. i = list.length - 1;
  242. previousTab = list[i];
  243. shift = 0;
  244. }
  245. else {
  246. previousTab = list[i - shift];
  247. }
  248. shift++;
  249. } while (previousTab.classList.contains('disabled'));
  250. previousTab.focus();
  251. return;
  252. }
  253. // tslint:disable-next-line:deprecation
  254. if (event.keyCode === 36 || event.key === 'Home') {
  255. event.preventDefault();
  256. /** @type {?} */
  257. var firstTab = void 0;
  258. /** @type {?} */
  259. var shift = 0;
  260. do {
  261. firstTab = list[shift % list.length];
  262. shift++;
  263. } while (firstTab.classList.contains('disabled'));
  264. firstTab.focus();
  265. return;
  266. }
  267. // tslint:disable-next-line:deprecation
  268. if (event.keyCode === 35 || event.key === 'End') {
  269. event.preventDefault();
  270. /** @type {?} */
  271. var lastTab = void 0;
  272. /** @type {?} */
  273. var shift = 1;
  274. /** @type {?} */
  275. var i = index;
  276. do {
  277. if ((i - shift) < 0) {
  278. i = list.length - 1;
  279. lastTab = list[i];
  280. shift = 0;
  281. }
  282. else {
  283. lastTab = list[i - shift];
  284. }
  285. shift++;
  286. } while (lastTab.classList.contains('disabled'));
  287. lastTab.focus();
  288. return;
  289. }
  290. // tslint:disable-next-line:deprecation
  291. if (event.keyCode === 46 || event.key === 'Delete') {
  292. if (this.tabs[index].removable) {
  293. this.removeTab(this.tabs[index]);
  294. if (list[index + 1]) {
  295. list[(index + 1) % list.length].focus();
  296. return;
  297. }
  298. if (list[list.length - 1]) {
  299. list[0].focus();
  300. }
  301. }
  302. }
  303. };
  304. /**
  305. * @protected
  306. * @param {?} index
  307. * @return {?}
  308. */
  309. TabsetComponent.prototype.getClosestTabIndex = /**
  310. * @protected
  311. * @param {?} index
  312. * @return {?}
  313. */
  314. function (index) {
  315. /** @type {?} */
  316. var tabsLength = this.tabs.length;
  317. if (!tabsLength) {
  318. return -1;
  319. }
  320. for (var step = 1; step <= tabsLength; step += 1) {
  321. /** @type {?} */
  322. var prevIndex = index - step;
  323. /** @type {?} */
  324. var nextIndex = index + step;
  325. if (this.tabs[prevIndex] && !this.tabs[prevIndex].disabled) {
  326. return prevIndex;
  327. }
  328. if (this.tabs[nextIndex] && !this.tabs[nextIndex].disabled) {
  329. return nextIndex;
  330. }
  331. }
  332. return -1;
  333. };
  334. /**
  335. * @protected
  336. * @param {?} index
  337. * @return {?}
  338. */
  339. TabsetComponent.prototype.hasAvailableTabs = /**
  340. * @protected
  341. * @param {?} index
  342. * @return {?}
  343. */
  344. function (index) {
  345. /** @type {?} */
  346. var tabsLength = this.tabs.length;
  347. if (!tabsLength) {
  348. return false;
  349. }
  350. for (var i = 0; i < tabsLength; i += 1) {
  351. if (!this.tabs[i].disabled && i !== index) {
  352. return true;
  353. }
  354. }
  355. return false;
  356. };
  357. /**
  358. * @protected
  359. * @return {?}
  360. */
  361. TabsetComponent.prototype.setClassMap = /**
  362. * @protected
  363. * @return {?}
  364. */
  365. function () {
  366. var _a;
  367. this.classMap = (_a = {
  368. 'nav-stacked': this.vertical,
  369. 'flex-column': this.vertical,
  370. 'nav-justified': this.justified
  371. },
  372. _a["nav-" + this.type] = true,
  373. _a);
  374. };
  375. TabsetComponent.decorators = [
  376. { type: core.Component, args: [{
  377. selector: 'tabset',
  378. template: "<ul class=\"nav\" [ngClass]=\"classMap\" (click)=\"$event.preventDefault()\">\n <li *ngFor=\"let tabz of tabs; let i = index\" [ngClass]=\"['nav-item', tabz.customClass || '']\"\n [class.active]=\"tabz.active\" [class.disabled]=\"tabz.disabled\" (keydown)=\"keyNavActions($event, i)\">\n <a href=\"javascript:void(0);\" class=\"nav-link\"\n [attr.id]=\"tabz.id ? tabz.id + '-link' : ''\"\n [class.active]=\"tabz.active\" [class.disabled]=\"tabz.disabled\"\n (click)=\"tabz.active = true\">\n <span [ngTransclude]=\"tabz.headingRef\">{{ tabz.heading }}</span>\n <span *ngIf=\"tabz.removable\" (click)=\"$event.preventDefault(); removeTab(tabz);\" class=\"bs-remove-tab\"> &#10060;</span>\n </a>\n </li>\n</ul>\n<div class=\"tab-content\">\n <ng-content></ng-content>\n</div>\n",
  379. styles: [":host .nav-tabs .nav-item.disabled a.disabled{cursor:default}"]
  380. }] }
  381. ];
  382. /** @nocollapse */
  383. TabsetComponent.ctorParameters = function () { return [
  384. { type: TabsetConfig },
  385. { type: core.Renderer2 },
  386. { type: core.ElementRef }
  387. ]; };
  388. TabsetComponent.propDecorators = {
  389. vertical: [{ type: core.Input }],
  390. justified: [{ type: core.Input }],
  391. type: [{ type: core.Input }],
  392. clazz: [{ type: core.HostBinding, args: ['class.tab-container',] }]
  393. };
  394. return TabsetComponent;
  395. }());
  396. /**
  397. * @fileoverview added by tsickle
  398. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  399. */
  400. var TabDirective = /** @class */ (function () {
  401. function TabDirective(tabset, elementRef, renderer) {
  402. this.elementRef = elementRef;
  403. this.renderer = renderer;
  404. /**
  405. * fired when tab became active, $event:Tab equals to selected instance of Tab component
  406. */
  407. this.selectTab = new core.EventEmitter();
  408. /**
  409. * fired when tab became inactive, $event:Tab equals to deselected instance of Tab component
  410. */
  411. this.deselect = new core.EventEmitter();
  412. /**
  413. * fired before tab will be removed, $event:Tab equals to instance of removed tab
  414. */
  415. this.removed = new core.EventEmitter();
  416. this.addClass = true;
  417. this.tabset = tabset;
  418. this.tabset.addTab(this);
  419. }
  420. Object.defineProperty(TabDirective.prototype, "customClass", {
  421. /** if set, will be added to the tab's class attribute. Multiple classes are supported. */
  422. get: /**
  423. * if set, will be added to the tab's class attribute. Multiple classes are supported.
  424. * @return {?}
  425. */
  426. function () {
  427. return this._customClass;
  428. },
  429. set: /**
  430. * @param {?} customClass
  431. * @return {?}
  432. */
  433. function (customClass) {
  434. var _this = this;
  435. if (this.customClass) {
  436. this.customClass.split(' ').forEach((/**
  437. * @param {?} cssClass
  438. * @return {?}
  439. */
  440. function (cssClass) {
  441. _this.renderer.removeClass(_this.elementRef.nativeElement, cssClass);
  442. }));
  443. }
  444. this._customClass = customClass ? customClass.trim() : null;
  445. if (this.customClass) {
  446. this.customClass.split(' ').forEach((/**
  447. * @param {?} cssClass
  448. * @return {?}
  449. */
  450. function (cssClass) {
  451. _this.renderer.addClass(_this.elementRef.nativeElement, cssClass);
  452. }));
  453. }
  454. },
  455. enumerable: true,
  456. configurable: true
  457. });
  458. Object.defineProperty(TabDirective.prototype, "active", {
  459. /** tab active state toggle */
  460. get: /**
  461. * tab active state toggle
  462. * @return {?}
  463. */
  464. function () {
  465. return this._active;
  466. },
  467. set: /**
  468. * @param {?} active
  469. * @return {?}
  470. */
  471. function (active) {
  472. var _this = this;
  473. if (this._active === active) {
  474. return;
  475. }
  476. if ((this.disabled && active) || !active) {
  477. if (this._active && !active) {
  478. this.deselect.emit(this);
  479. this._active = active;
  480. }
  481. return;
  482. }
  483. this._active = active;
  484. this.selectTab.emit(this);
  485. this.tabset.tabs.forEach((/**
  486. * @param {?} tab
  487. * @return {?}
  488. */
  489. function (tab) {
  490. if (tab !== _this) {
  491. tab.active = false;
  492. }
  493. }));
  494. },
  495. enumerable: true,
  496. configurable: true
  497. });
  498. /**
  499. * @return {?}
  500. */
  501. TabDirective.prototype.ngOnInit = /**
  502. * @return {?}
  503. */
  504. function () {
  505. this.removable = this.removable;
  506. };
  507. /**
  508. * @return {?}
  509. */
  510. TabDirective.prototype.ngOnDestroy = /**
  511. * @return {?}
  512. */
  513. function () {
  514. this.tabset.removeTab(this, { reselect: false, emit: false });
  515. };
  516. TabDirective.decorators = [
  517. { type: core.Directive, args: [{ selector: 'tab, [tab]' },] }
  518. ];
  519. /** @nocollapse */
  520. TabDirective.ctorParameters = function () { return [
  521. { type: TabsetComponent },
  522. { type: core.ElementRef },
  523. { type: core.Renderer2 }
  524. ]; };
  525. TabDirective.propDecorators = {
  526. heading: [{ type: core.Input }],
  527. id: [{ type: core.HostBinding, args: ['attr.id',] }, { type: core.Input }],
  528. disabled: [{ type: core.Input }],
  529. removable: [{ type: core.Input }],
  530. customClass: [{ type: core.Input }],
  531. active: [{ type: core.HostBinding, args: ['class.active',] }, { type: core.Input }],
  532. selectTab: [{ type: core.Output }],
  533. deselect: [{ type: core.Output }],
  534. removed: [{ type: core.Output }],
  535. addClass: [{ type: core.HostBinding, args: ['class.tab-pane',] }]
  536. };
  537. return TabDirective;
  538. }());
  539. /**
  540. * @fileoverview added by tsickle
  541. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  542. */
  543. /**
  544. * Should be used to mark <ng-template> element as a template for tab heading
  545. */
  546. var TabHeadingDirective = /** @class */ (function () {
  547. /* tslint:disable-next-line:no-any */
  548. function TabHeadingDirective(templateRef, tab) {
  549. tab.headingRef = templateRef;
  550. }
  551. TabHeadingDirective.decorators = [
  552. { type: core.Directive, args: [{ selector: '[tabHeading]' },] }
  553. ];
  554. /** @nocollapse */
  555. TabHeadingDirective.ctorParameters = function () { return [
  556. { type: core.TemplateRef },
  557. { type: TabDirective }
  558. ]; };
  559. return TabHeadingDirective;
  560. }());
  561. /**
  562. * @fileoverview added by tsickle
  563. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  564. */
  565. var TabsModule = /** @class */ (function () {
  566. function TabsModule() {
  567. }
  568. /**
  569. * @return {?}
  570. */
  571. TabsModule.forRoot = /**
  572. * @return {?}
  573. */
  574. function () {
  575. return {
  576. ngModule: TabsModule,
  577. providers: [TabsetConfig]
  578. };
  579. };
  580. TabsModule.decorators = [
  581. { type: core.NgModule, args: [{
  582. imports: [common.CommonModule],
  583. declarations: [
  584. NgTranscludeDirective,
  585. TabDirective,
  586. TabsetComponent,
  587. TabHeadingDirective
  588. ],
  589. exports: [
  590. TabDirective,
  591. TabsetComponent,
  592. TabHeadingDirective,
  593. NgTranscludeDirective
  594. ]
  595. },] }
  596. ];
  597. return TabsModule;
  598. }());
  599. exports.NgTranscludeDirective = NgTranscludeDirective;
  600. exports.TabDirective = TabDirective;
  601. exports.TabHeadingDirective = TabHeadingDirective;
  602. exports.TabsModule = TabsModule;
  603. exports.TabsetComponent = TabsetComponent;
  604. exports.TabsetConfig = TabsetConfig;
  605. Object.defineProperty(exports, '__esModule', { value: true });
  606. }));
  607. //# sourceMappingURL=ngx-bootstrap-tabs.umd.js.map