mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
85 lines
1.9 KiB
JavaScript
85 lines
1.9 KiB
JavaScript
import {Component, onInit} from 'angular2/src/core/annotations_impl/annotations';
|
|
import {View} from 'angular2/src/core/annotations_impl/view';
|
|
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
|
|
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
|
|
import {Injector} from 'angular2/di';
|
|
import {NgFor} from 'angular2/angular2';
|
|
|
|
import {IonicComponent} from '../../config/component';
|
|
import {Tab} from './tab';
|
|
import {TabButton} from './tab-button';
|
|
|
|
|
|
@Component({
|
|
selector: 'ion-tabs',
|
|
properties: [
|
|
'tabBarPlacement',
|
|
'tabBarIcons'
|
|
],
|
|
lifecycle: [onInit]
|
|
})
|
|
@View({
|
|
template: `
|
|
<nav class="navbar-container tab-bar-container">
|
|
<div class="tab-bar">
|
|
<button *ng-for="#t of tabs" [tab]="t" class="tab-button" role="tab">
|
|
<icon [class-name]="'tab-button-icon ' + t.tabIcon"></icon>
|
|
<span class="tab-button-text">{{t.tabTitle}}</span>
|
|
</button>
|
|
</div>
|
|
</nav>
|
|
<section class="content-container">
|
|
<content></content>
|
|
</section>
|
|
`,
|
|
directives: [NgFor, TabButton]
|
|
})
|
|
export class Tabs {
|
|
constructor(elementRef: ElementRef, loader: DynamicComponentLoader, injector: Injector) {
|
|
this.domElement = elementRef.domElement;
|
|
this.config = Tabs.config.invoke(this);
|
|
this.tabs = [];
|
|
}
|
|
|
|
onInit() {
|
|
if (this.tabs.length > 0) {
|
|
this.selectTab(this.tabs[0]);
|
|
}
|
|
}
|
|
|
|
addTab(tab) {
|
|
this.tabs.push(tab);
|
|
}
|
|
|
|
selectTab(tab) {
|
|
if (!tab || this._selected === tab) return;
|
|
|
|
this.tabs.forEach(otherTab => {
|
|
otherTab.select(false);
|
|
});
|
|
|
|
tab.select(true);
|
|
this._selected = tab;
|
|
}
|
|
|
|
}
|
|
|
|
new IonicComponent(Tabs, {
|
|
properties: {
|
|
tabBarPlacement: {
|
|
defaults: {
|
|
ios: 'bottom',
|
|
android: 'top',
|
|
core: 'bottom'
|
|
}
|
|
},
|
|
tabBarIcons: {
|
|
defaults: {
|
|
ios: 'top',
|
|
android: 'top',
|
|
core: 'top'
|
|
}
|
|
}
|
|
}
|
|
});
|