2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import { Component, ContentChildren, QueryList, AfterContentInit, Input, Output, EventEmitter } from '@angular/core';
22 import { Tab } from './tab/tab.component';
23 import { ViewEncapsulation } from '@angular/core';
24 import { trigger, state, style, transition, animate, keyframes } from '@angular/core';
30 templateUrl: './tabs.component.html',
31 styleUrls: ['./tabs.component.less'],
32 encapsulation: ViewEncapsulation.None,
34 trigger('indicatorAnimation', [
35 transition(':enter', [style({ transform: 'translateY(-50%)', opacity: 0 }), animate('250ms', style({ transform: 'translateY(0)', opacity: 1 })) ]),
36 transition(':leave', [style({ opacity: 1 }), animate('500ms', style({ opacity: 0 })) ])
40 export class Tabs implements AfterContentInit {
42 @Input() tabStyle: string;
43 @Input() hideIndicationOnTabChange?: boolean = false;
44 @ContentChildren(Tab) tabs: QueryList<Tab>;
45 @Output() tabChanged: EventEmitter<Tab> = new EventEmitter<Tab>();
48 ngAfterContentInit() {
49 //after contentChildren are set, determine active tab. If no active tab set, activate the first one
50 let activeTabs = this.tabs.filter((tab) => tab.active);
52 if (activeTabs.length === 0) {
53 this.selectTab(this.tabs.first);
58 //activate the tab the user clicked.
59 this.tabs.toArray().forEach(tab => {
61 if (this.hideIndicationOnTabChange && tab.indication) {
62 tab.indication = null;
66 this.tabChanged.emit(tab);
69 triggerTabChange(tabTitle) {
70 this.tabs.toArray().forEach(tab => {
71 tab.active = (tab.title == tabTitle) ? true : false;
75 setTabIndication(tabTitle:string, indication?:number) {
76 let selectedTab: Tab = this.tabs.toArray().find(tab => tab.title == tabTitle);
77 selectedTab.indication = indication || null;