UNPKG

@angular-mdc/web

Version:
22 lines (20 loc) 9.66 kB
/** * @license * Copyright (c) Dominic Carretto * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/trimox/angular-mdc-web/blob/master/LICENSE */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular-mdc/web/tab-indicator"),require("@angular-mdc/web/tab"),require("@angular-mdc/web/tab-scroller"),require("@angular/cdk/coercion"),require("@angular/cdk/platform"),require("rxjs"),require("rxjs/operators"),require("@angular-mdc/web/base"),require("@material/tab-bar")):"function"==typeof define&&define.amd?define("@angular-mdc/web/tab-bar",["exports","@angular/core","@angular-mdc/web/tab-indicator","@angular-mdc/web/tab","@angular-mdc/web/tab-scroller","@angular/cdk/coercion","@angular/cdk/platform","rxjs","rxjs/operators","@angular-mdc/web/base","@material/tab-bar"],e):e(((t=t||self).ng=t.ng||{},t.ng.web=t.ng.web||{},t.ng.web.tabBar={}),t.ng.core,t.ng.web.tabIndicator,t.ng.web.tab,t.ng.web.tabScroller,t.ng.cdk.coercion,t.ng.cdk.platform,t.rxjs,t.rxjs.operators,t.ng.web.base,t.mdc.tabBar)}(this,(function(t,e,n,o,r,i,a,c,s,u,b){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */var d=function(t,e){return(d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};var l=function(t,e,n){this.source=t,this.index=e,this.tab=n},f=function(t){function n(n,o,r){var i=t.call(this,r)||this;return i._platform=n,i._changeDetectorRef=o,i.elementRef=r,i._destroy=new c.Subject,i._fade=!1,i._stacked=!1,i._fixed=!1,i._align=null,i._iconIndicator=null,i._useAutomaticActivation=!0,i._activeTabIndex=0,i._focusOnActivate=!0,i.activated=new e.EventEmitter,i._changeSubscription=null,i._tabInteractionSubscription=null,i}return function(t,e){function n(){this.constructor=t}d(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(n,t),Object.defineProperty(n.prototype,"fade",{get:function(){return this._fade},set:function(t){this._fade=i.coerceBooleanProperty(t),this._syncTabs()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"stacked",{get:function(){return this._stacked},set:function(t){this._stacked=i.coerceBooleanProperty(t),this._syncTabs()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"fixed",{get:function(){return this._fixed},set:function(t){this._fixed=i.coerceBooleanProperty(t),this._syncTabs()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"align",{get:function(){return this._align},set:function(t){this._align=t||"start",this.tabScroller.align=this.align},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"iconIndicator",{get:function(){return this._iconIndicator},set:function(t){this._iconIndicator=t,this._syncTabs()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"useAutomaticActivation",{get:function(){return this._useAutomaticActivation},set:function(t){this._useAutomaticActivation=i.coerceBooleanProperty(t),this._foundation.setUseAutomaticActivation(this._useAutomaticActivation)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"activeTabIndex",{get:function(){return this._activeTabIndex},set:function(t){this.activeTabIndex!==t&&(this._activeTabIndex=t,this.activateTab(this.activeTabIndex))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"focusOnActivate",{get:function(){return this._focusOnActivate},set:function(t){this._focusOnActivate=i.coerceBooleanProperty(t),this._syncTabs()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"tabInteractions",{get:function(){return c.merge.apply(void 0,this.tabs.map((function(t){return t.interacted})))},enumerable:!0,configurable:!0}),n.prototype.getDefaultFoundation=function(){var t=this,e={scrollTo:function(e){return t.tabScroller.scrollTo(e)},incrementScroll:function(e){return t.tabScroller.incrementScroll(e)},getScrollPosition:function(){return t.tabScroller.getScrollPosition()},getScrollContentWidth:function(){return t.tabScroller.getScrollContentWidth()},getOffsetWidth:function(){return t._getHostElement().offsetWidth},isRTL:function(){return!!t._platform.isBrowser&&"rtl"===window.getComputedStyle(t._getHostElement()).getPropertyValue("direction")},setActiveTab:function(e){return t.activateTab(e)},activateTabAtIndex:function(e,n){t._indexIsInRange(e)&&t.tabs.toArray()[e].activate(n)},deactivateTabAtIndex:function(e){t._indexIsInRange(e)&&t.tabs.toArray()[e].deactivate()},focusTabAtIndex:function(e){return t.tabs.toArray()[e].focus()},getTabIndicatorClientRectAtIndex:function(e){return t._platform.isBrowser?(t._indexIsInRange(e)||(e=t.activeTabIndex),t.tabs.toArray()[e].computeIndicatorClientRect()):{height:0,width:0,bottom:0,top:0,left:0,right:0}},getTabDimensionsAtIndex:function(e){return t.tabs.toArray()[e].computeDimensions()},getPreviousActiveTabIndex:function(){return t.tabs.toArray().findIndex((function(t){return t.active}))},getFocusedTabIndex:function(){return t._platform.isBrowser?t.tabs.toArray().findIndex((function(t){return t.elementRef.nativeElement===document.activeElement})):-1},getIndexOfTabById:function(e){return t.tabs.toArray().findIndex((function(t){return e===t.id}))},getTabListLength:function(){return t.tabs.length},notifyTabActivated:function(e){return t.activated.emit({source:t,index:e,tab:t.tabs.toArray()[e]})}};return new b.MDCTabBarFoundation(e)},n.prototype.ngAfterContentInit=function(){var t=this;this._foundation.init(),this._changeSubscription=this.tabs.changes.pipe(s.startWith(null)).subscribe((function(){Promise.resolve().then((function(){t.tabs.length&&(t._syncTabs(),t.activateTab(t.activeTabIndex),t._resetTabSubscriptions())}))}))},n.prototype.ngOnDestroy=function(){this._destroy.next(),this._destroy.complete(),this._changeSubscription&&this._changeSubscription.unsubscribe(),this._dropSubscriptions()},n.prototype._syncTabs=function(){var t=this;this.tabs&&this.tabs.forEach((function(e){e.stacked=t._stacked,e.fixed=t._fixed,e.tabIndicator.fade=t._fade,e.tabIndicator.icon=t._iconIndicator,e.focusOnActivate=t._focusOnActivate}))},n.prototype._resetTabSubscriptions=function(){this._dropSubscriptions(),this._listenToTabInteraction()},n.prototype._dropSubscriptions=function(){this._tabInteractionSubscription&&(this._tabInteractionSubscription.unsubscribe(),this._tabInteractionSubscription=null)},n.prototype._listenToTabInteraction=function(){var t=this;this._tabInteractionSubscription=this.tabInteractions.subscribe((function(e){var n=t.getActiveTab();n&&(n.tabIndicator.active=!1),e.detail.tab.tabIndicator.active=!0,t._foundation.handleTabInteraction(e)}))},n.prototype.activateTab=function(t){this.tabs&&(this.activeTabIndex=t,this._platform.isBrowser&&this._foundation.activateTab(t),this._changeDetectorRef.markForCheck())},n.prototype.scrollIntoView=function(t){this._foundation.scrollIntoView(t)},n.prototype.getActiveTabIndex=function(){return this.tabs.toArray().findIndex((function(t){return t.active}))},n.prototype.getActiveTab=function(){return this.tabs.toArray().find((function(t){return t.active}))},n.prototype.getTabIndex=function(t){return this.tabs.toArray().indexOf(t)},n.prototype.disableTab=function(t,e){this.tabs&&(this.tabs.toArray()[t].disabled=i.coerceBooleanProperty(e))},n.prototype._onKeydown=function(t){this._foundation.handleKeyDown(t)},n.prototype._indexIsInRange=function(t){return t>=0&&t<this.tabs.length},n.prototype._getHostElement=function(){return this.elementRef.nativeElement},n.decorators=[{type:e.Component,args:[{selector:"[mdcTabBar], mdc-tab-bar",exportAs:"mdcTabBar",host:{role:"tablist",class:"mdc-tab-bar","(keydown)":"_onKeydown($event)"},template:"<ng-content></ng-content>",changeDetection:e.ChangeDetectionStrategy.OnPush,encapsulation:e.ViewEncapsulation.None,providers:[{provide:o.MDC_TAB_BAR_PARENT_COMPONENT,useExisting:n}]}]}],n.ctorParameters=function(){return[{type:a.Platform},{type:e.ChangeDetectorRef},{type:e.ElementRef}]},n.propDecorators={fade:[{type:e.Input}],stacked:[{type:e.Input}],fixed:[{type:e.Input}],align:[{type:e.Input}],iconIndicator:[{type:e.Input}],useAutomaticActivation:[{type:e.Input}],activeTabIndex:[{type:e.Input}],focusOnActivate:[{type:e.Input}],activated:[{type:e.Output}],tabScroller:[{type:e.ContentChild,args:[r.MdcTabScroller,{static:!0}]}],tabs:[{type:e.ContentChildren,args:[o.MdcTab,{descendants:!0}]}]},n}(u.MDCComponent),p=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{imports:[n.MdcTabIndicatorModule,o.MdcTabModule,r.MdcTabScrollerModule],exports:[f,n.MdcTabIndicatorModule,o.MdcTabModule,r.MdcTabScrollerModule],declarations:[f]}]}],t}();t.MdcTabActivatedEvent=l,t.MdcTabBar=f,t.MdcTabBarModule=p,Object.defineProperty(t,"__esModule",{value:!0})}));