-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added a simple tabs example (no routing)
- Loading branch information
Showing
4 changed files
with
96 additions
and
68 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,74 @@ | ||
import {MaterializeDirective} from "../../src/index"; | ||
import {Component,OnDestroy} from "angular2/core" | ||
import {Subscription} from "rxjs/subscription"; | ||
import {Router, RouteConfig, Location, ROUTER_DIRECTIVES} from "angular2/router"; | ||
|
||
@Component({selector: "tabs-test1",template: `<div id="test1" class="col s12">Test 1</div>`}) | ||
class TabsTest1 {} | ||
@Component({selector: "tabs-test2",template: `<div id="test2" class="col s12">Test 2</div>`}) | ||
class TabsTest2 {} | ||
@Component({selector: "tabs-test3",template: `<div id="test3" class="col s12">Test 3</div>`}) | ||
class TabsTest3 {} | ||
@Component({selector: "tabs-test4",template: `<div id="test4" class="col s12">Test 4</div>`}) | ||
class TabsTest4 {} | ||
|
||
@Component({ | ||
selector: "tabs-routing", | ||
directives: [ROUTER_DIRECTIVES,MaterializeDirective,TabsTest1,TabsTest2,TabsTest3,TabsTest4], | ||
template: ` | ||
<div class="row"> | ||
<div class="col s12"> | ||
<ul materialize="tabs" [materializeParams]="tabSelectionParams" class="tabs"> | ||
<li class="tab col s3" [class.disabled]="tab.disabled" *ngFor="#tab of tabs"> | ||
<a [href]="'#'+tab.route" (click)="$event.preventDefault();routeTo(tab.route)">{{tab.name}}</a> | ||
</li> | ||
</ul> | ||
</div> | ||
<br/> | ||
<router-outlet></router-outlet> | ||
</div> | ||
` | ||
}) | ||
@RouteConfig([ | ||
{path: "/test1", component: TabsTest1, name: "TabsTest1", useAsDefault:true}, | ||
{path: "/test2", component: TabsTest2, name: "TabsTest2"}, | ||
{path: "/test3", component: TabsTest3, name: "TabsTest3"}, | ||
{path: "/test4", component: TabsTest4, name: "TabsTest4"} | ||
]) | ||
export class TabsRouting implements OnDestroy { | ||
|
||
private tabs = [ | ||
{name:"Test 1",href:"/tabs/test1",route:"TabsTest1"}, | ||
{name:"Test 2",href:"/tabs/test2",route:"TabsTest2"}, | ||
{name:"Test 3",href:"/tabs/test3",route:"TabsTest3", disabled:true}, | ||
{name:"Test 4",href:"/tabs/test4",route:"TabsTest4"} | ||
]; | ||
private routerSubscription:Subscription; | ||
private tabSelectionParams = null; | ||
|
||
constructor(private router:Router, private location:Location) { | ||
this.routerSubscription = <Subscription>router.parent.subscribe(() => { | ||
this.updateSelectionParams(router); | ||
}); | ||
} | ||
|
||
routeTo(route) { | ||
this.router.navigate([route]); | ||
} | ||
|
||
updateSelectionParams(router) { | ||
for (var i=0; i<this.tabs.length; i++) { | ||
const tab = this.tabs[i]; | ||
if (location.href.lastIndexOf(tab.href)==location.href.length-tab.href.length) { | ||
if (!this.tabSelectionParams || this.tabSelectionParams[0]!=tab.route) { | ||
// switch the view to select that tab | ||
this.tabSelectionParams = ['select_tab',tab.route]; | ||
} | ||
} | ||
}; | ||
} | ||
|
||
ngOnDestroy() { | ||
this.routerSubscription.unsubscribe(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,74 +1,26 @@ | ||
import {MaterializeDirective} from "../../src/index"; | ||
import {Component,OnDestroy} from "angular2/core" | ||
import {Subscription} from "rxjs/subscription"; | ||
import {Router, RouteConfig, Location, ROUTER_DIRECTIVES} from "angular2/router"; | ||
|
||
@Component({selector: "tabs-test1",template: `<div id="test1" class="col s12">Test 1</div>`}) | ||
class TabsTest1 {} | ||
@Component({selector: "tabs-test2",template: `<div id="test2" class="col s12">Test 2</div>`}) | ||
class TabsTest2 {} | ||
@Component({selector: "tabs-test3",template: `<div id="test3" class="col s12">Test 3</div>`}) | ||
class TabsTest3 {} | ||
@Component({selector: "tabs-test4",template: `<div id="test4" class="col s12">Test 4</div>`}) | ||
class TabsTest4 {} | ||
import {Component} from "angular2/core" | ||
|
||
@Component({ | ||
selector: "tabs", | ||
directives: [ROUTER_DIRECTIVES,MaterializeDirective,TabsTest1,TabsTest2,TabsTest3,TabsTest4], | ||
directives: [MaterializeDirective], | ||
template: ` | ||
<div class="row"> | ||
<div class="col s12"> | ||
<ul materialize="tabs" [materializeParams]="tabSelectionParams" class="tabs"> | ||
<li class="tab col s3" [class.disabled]="tab.disabled" *ngFor="#tab of tabs"> | ||
<a [href]="'#'+tab.route" (click)="$event.preventDefault();routeTo(tab.route)">{{tab.name}}</a> | ||
</li> | ||
</ul> | ||
</div> | ||
<br/> | ||
<router-outlet></router-outlet> | ||
</div> | ||
<div class="row"> | ||
<div class="col s12"> | ||
<ul class="tabs" materialize="tabs"> | ||
<li class="tab col s3"><a href="#test1">Test 1</a></li> | ||
<li class="tab col s3"><a class="active" href="#test2">Test 2</a></li> | ||
<li class="tab col s3 disabled"><a href="#test3">Disabled Tab</a></li> | ||
<li class="tab col s3"><a href="#test4">Test 4</a></li> | ||
</ul> | ||
</div> | ||
<div id="test1" class="col s12">Test 1</div> | ||
<div id="test2" class="col s12">Test 2</div> | ||
<div id="test3" class="col s12">Test 3</div> | ||
<div id="test4" class="col s12">Test 4</div> | ||
</div> | ||
` | ||
}) | ||
@RouteConfig([ | ||
{path: "/test1", component: TabsTest1, name: "TabsTest1", useAsDefault:true}, | ||
{path: "/test2", component: TabsTest2, name: "TabsTest2"}, | ||
{path: "/test3", component: TabsTest3, name: "TabsTest3"}, | ||
{path: "/test4", component: TabsTest4, name: "TabsTest4"} | ||
]) | ||
export class Tabs implements OnDestroy { | ||
|
||
private tabs = [ | ||
{name:"Test 1",href:"/tabs/test1",route:"TabsTest1"}, | ||
{name:"Test 2",href:"/tabs/test2",route:"TabsTest2"}, | ||
{name:"Test 3",href:"/tabs/test3",route:"TabsTest3", disabled:true}, | ||
{name:"Test 4",href:"/tabs/test4",route:"TabsTest4"} | ||
]; | ||
private routerSubscription:Subscription; | ||
private tabSelectionParams = null; | ||
|
||
constructor(private router:Router, private location:Location) { | ||
this.routerSubscription = <Subscription>router.parent.subscribe(() => { | ||
this.updateSelectionParams(router); | ||
}); | ||
} | ||
|
||
routeTo(route) { | ||
this.router.navigate([route]); | ||
} | ||
|
||
updateSelectionParams(router) { | ||
for (var i=0; i<this.tabs.length; i++) { | ||
const tab = this.tabs[i]; | ||
if (location.href.lastIndexOf(tab.href)==location.href.length-tab.href.length) { | ||
if (!this.tabSelectionParams || this.tabSelectionParams[0]!=tab.route) { | ||
// switch the view to select that tab | ||
this.tabSelectionParams = ['select_tab',tab.route]; | ||
} | ||
} | ||
}; | ||
} | ||
export class Tabs { | ||
|
||
ngOnDestroy() { | ||
this.routerSubscription.unsubscribe(); | ||
} | ||
} |