ngx-bootstrap
Version:
Native Angular Bootstrap Components
2 lines • 5.99 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/common"),require("@angular/core")):"function"==typeof define&&define.amd?define("ngx-bootstrap/tabs",["exports","@angular/common","@angular/core"],e):e((t["ngx-bootstrap"]=t["ngx-bootstrap"]||{},t["ngx-bootstrap"].tabs={}),t.ng.common,t.ng.core)}(this,function(t,e,s){"use strict";var n=function(){function t(t){this.viewRef=t}return Object.defineProperty(t.prototype,"ngTransclude",{get:function(){return this._ngTransclude},set:function(t){(this._ngTransclude=t)&&this.viewRef.createEmbeddedView(t)},enumerable:!0,configurable:!0}),t.decorators=[{type:s.Directive,args:[{selector:"[ngTransclude]"}]}],t.ctorParameters=function(){return[{type:s.ViewContainerRef}]},t.propDecorators={ngTransclude:[{type:s.Input}]},t}(),i=function(){function t(){this.type="tabs"}return t.decorators=[{type:s.Injectable}],t}(),a=function(){function t(t,e){this.renderer=e,this.clazz=!0,this.tabs=[],this.classMap={},Object.assign(this,t)}return Object.defineProperty(t.prototype,"vertical",{get:function(){return this._vertical},set:function(t){this._vertical=t,this.setClassMap()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"justified",{get:function(){return this._justified},set:function(t){this._justified=t,this.setClassMap()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"type",{get:function(){return this._type},set:function(t){this._type=t,this.setClassMap()},enumerable:!0,configurable:!0}),t.prototype.ngOnDestroy=function(){this.isDestroyed=!0},t.prototype.addTab=function(t){this.tabs.push(t),t.active=1===this.tabs.length&&"undefined"==typeof t.active},t.prototype.removeTab=function(t,e){void 0===e&&(e={reselect:!0,emit:!0});var n=this.tabs.indexOf(t);if(-1!==n&&!this.isDestroyed){if(e.reselect&&t.active&&this.hasAvailableTabs(n)){var s=this.getClosestTabIndex(n);this.tabs[s].active=!0}e.emit&&t.removed.emit(t),this.tabs.splice(n,1),t.elementRef.nativeElement.parentNode&&this.renderer.removeChild(t.elementRef.nativeElement.parentNode,t.elementRef.nativeElement)}},t.prototype.getClosestTabIndex=function(t){var e=this.tabs.length;if(!e)return-1;for(var n=1;n<=e;n+=1){var s=t-n,i=t+n;if(this.tabs[s]&&!this.tabs[s].disabled)return s;if(this.tabs[i]&&!this.tabs[i].disabled)return i}return-1},t.prototype.hasAvailableTabs=function(t){var e=this.tabs.length;if(!e)return!1;for(var n=0;n<e;n+=1)if(!this.tabs[n].disabled&&n!==t)return!0;return!1},t.prototype.setClassMap=function(){var t;this.classMap=((t={"nav-stacked":this.vertical,"flex-column":this.vertical,"nav-justified":this.justified})["nav-"+this.type]=!0,t)},t.decorators=[{type:s.Component,args:[{selector:"tabset",template:'<ul class="nav" [ngClass]="classMap" (click)="$event.preventDefault()">\n <li *ngFor="let tabz of tabs" [ngClass]="[\'nav-item\', tabz.customClass || \'\']"\n [class.active]="tabz.active" [class.disabled]="tabz.disabled">\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"> ❌</span>\n </a>\n </li>\n</ul>\n<div class="tab-content">\n <ng-content></ng-content>\n</div>\n'}]}],t.ctorParameters=function(){return[{type:i},{type:s.Renderer2}]},t.propDecorators={vertical:[{type:s.Input}],justified:[{type:s.Input}],type:[{type:s.Input}],clazz:[{type:s.HostBinding,args:["class.tab-container"]}]},t}(),r=function(){function t(t,e,n){this.elementRef=e,this.renderer=n,this.selectTab=new s.EventEmitter,this.deselect=new s.EventEmitter,this.removed=new s.EventEmitter,this.addClass=!0,this.tabset=t,this.tabset.addTab(this)}return Object.defineProperty(t.prototype,"customClass",{get:function(){return this._customClass},set:function(t){var e=this;this.customClass&&this.customClass.split(" ").forEach(function(t){e.renderer.removeClass(e.elementRef.nativeElement,t)}),this._customClass=t?t.trim():null,this.customClass&&this.customClass.split(" ").forEach(function(t){e.renderer.addClass(e.elementRef.nativeElement,t)})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"active",{get:function(){return this._active},set:function(t){var e=this;this._active!==t&&(this.disabled&&t||!t?this._active&&!t&&(this.deselect.emit(this),this._active=t):(this._active=t,this.selectTab.emit(this),this.tabset.tabs.forEach(function(t){t!==e&&(t.active=!1)})))},enumerable:!0,configurable:!0}),t.prototype.ngOnInit=function(){this.removable=this.removable},t.prototype.ngOnDestroy=function(){this.tabset.removeTab(this,{reselect:!1,emit:!1})},t.decorators=[{type:s.Directive,args:[{selector:"tab, [tab]"}]}],t.ctorParameters=function(){return[{type:a},{type:s.ElementRef},{type:s.Renderer2}]},t.propDecorators={heading:[{type:s.Input}],id:[{type:s.HostBinding,args:["attr.id"]},{type:s.Input}],disabled:[{type:s.Input}],removable:[{type:s.Input}],customClass:[{type:s.Input}],active:[{type:s.HostBinding,args:["class.active"]},{type:s.Input}],selectTab:[{type:s.Output}],deselect:[{type:s.Output}],removed:[{type:s.Output}],addClass:[{type:s.HostBinding,args:["class.tab-pane"]}]},t}(),o=function(){function t(t,e){e.headingRef=t}return t.decorators=[{type:s.Directive,args:[{selector:"[tabHeading]"}]}],t.ctorParameters=function(){return[{type:s.TemplateRef},{type:r}]},t}(),c=function(){function t(){}return t.forRoot=function(){return{ngModule:t,providers:[i]}},t.decorators=[{type:s.NgModule,args:[{imports:[e.CommonModule],declarations:[n,r,a,o],exports:[r,a,o,n]}]}],t}();t.NgTranscludeDirective=n,t.TabDirective=r,t.TabHeadingDirective=o,t.TabsetComponent=a,t.TabsetConfig=i,t.TabsModule=c,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-bootstrap-tabs.umd.min.js.map