This repository has been archived by the owner on Dec 21, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from eddiepantoja/master
Legend/Layers in tabs
- Loading branch information
Showing
4 changed files
with
74 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Component, Input } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'tab', | ||
template: | ||
` | ||
<div [hidden]="!active" class="pane"> | ||
<ng-content></ng-content> | ||
</div> | ||
` | ||
}) | ||
export class TabComponent { | ||
@Input('tabTitle') title: string; | ||
@Input() active = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Component, ContentChildren, QueryList, AfterContentInit } from '@angular/core'; | ||
import { TabComponent } from './tab.component'; | ||
|
||
@Component({ | ||
selector: 'tabs', | ||
template: | ||
` | ||
<ul class="nav nav-tabs" style="float: right; width:100%; margin-bottom:20px;"> | ||
<li *ngFor="#tab of tabs" (click)="selectTab(tab)" [class.active]="tab.active"> | ||
<a href="#"> | ||
{{ tab.title }} | ||
</a> | ||
</li> | ||
</ul> | ||
<ng-content></ng-content> | ||
` | ||
}) | ||
export class TabsComponent implements AfterContentInit { | ||
|
||
@ContentChildren(TabComponent) tabs: QueryList<TabComponent>; | ||
|
||
ngAfterContentInit() { | ||
// get all active tabs | ||
let activeTabs = this.tabs.filter((tab)=>tab.active); | ||
|
||
// if there is no active tab set, activate the first | ||
if(activeTabs.length === 0) { | ||
this.selectTab(this.tabs.first); | ||
} | ||
} | ||
|
||
selectTab(tab: TabComponent){ | ||
// deactivate all tabs | ||
this.tabs.toArray().forEach(tab => tab.active = false); | ||
|
||
// activate current tab | ||
tab.active = true; | ||
} | ||
|
||
} |