-
Notifications
You must be signed in to change notification settings - Fork 11
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 #28 from angular-way/master
Implement tab component #18
- Loading branch information
Showing
17 changed files
with
223 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,84 @@ | ||
<html> | ||
|
||
<body> | ||
<div id="app"> | ||
|
||
<nav class="nav has-shadow"> | ||
<div class="container"> | ||
<div class="nav-left"> | ||
<bu-nav> | ||
<bu-nav-brand> | ||
<a class="navbar-item" href="https://bulma.io"> | ||
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28"> | ||
</a> | ||
</bu-nav-brand> | ||
<bu-nav-item> | ||
<a class="navbar-item"> | ||
Home | ||
</a> | ||
<a class="navbar-item"> | ||
Documentation | ||
</a> | ||
</bu-nav-item> | ||
</bu-nav> | ||
</div> | ||
<label for="menu-toggle" class="nav-toggle"> | ||
<span></span> | ||
<span></span> | ||
<span></span> | ||
</label> | ||
<input type="checkbox" id="menu-toggle" class="is-hidden" /> | ||
<div class="nav-right nav-menu"> | ||
|
||
|
||
</div> | ||
</div> | ||
</nav> | ||
<nav class="nav has-shadow"> | ||
<div class="container"> | ||
<div class="nav-left"> | ||
<bu-nav> | ||
<bu-nav-brand> | ||
<a class="navbar-item" href="https://bulma.io"> | ||
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28"> | ||
</a> | ||
</bu-nav-brand> | ||
<bu-nav-item> | ||
<a class="navbar-item"> | ||
Home | ||
</a> | ||
<a class="navbar-item"> | ||
Documentation | ||
</a> | ||
</bu-nav-item> | ||
</bu-nav> | ||
</div> | ||
<label for="menu-toggle" class="nav-toggle"> | ||
<span></span> | ||
<span></span> | ||
<span></span> | ||
</label> | ||
<input type="checkbox" id="menu-toggle" class="is-hidden"/> | ||
<div class="nav-right nav-menu"> | ||
|
||
|
||
</div> | ||
</div> | ||
</nav> | ||
|
||
<section class="main-content columns is-fullheight"> | ||
<section class="main-content columns is-fullheight"> | ||
|
||
<aside class="column is-2 is-narrow-mobile is-fullheight section is-hidden-mobile"> | ||
<aside class="column is-2 is-narrow-mobile is-fullheight section is-hidden-mobile"> | ||
|
||
<ul class="menu-list"> | ||
<li><a [routerLink]="['']" routerLinkActive="router-link-active">Introduction</a></li> | ||
<li><a [routerLink]="['/gettingstarted']" routerLinkActive="router-link-active">Getting Started</a></li> | ||
<ul class="menu-list"> | ||
<li><a [routerLink]="['']" routerLinkActive="router-link-active" >Introduction</a></li> | ||
<li><a [routerLink]="['/gettingstarted']" routerLinkActive="router-link-active">Getting Started</a></li> | ||
|
||
<li><a [routerLink]="['/home']" routerLinkActive="router-link-active">Home</a></li> | ||
<li><a [routerLink]="['/menu']" routerLinkActive="router-link-active">Menu</a></li> | ||
<li><a [routerLink]="['/navbar']" routerLinkActive="router-link-active">NavBar</a></li> | ||
<li><a [routerLink]="['/message']" routerLinkActive="router-link-active">message</a></li> | ||
<li><a [routerLink]="['/card']" routerLinkActive="router-link-active">card</a></li> | ||
<li><a [routerLink]="['/model']" routerLinkActive="router-link-active">model</a></li> | ||
<li><a [routerLink]="['/panel']" routerLinkActive="router-link-active">panel</a></li> | ||
</ul> | ||
</aside> | ||
<li><a [routerLink]="['/home']" routerLinkActive="router-link-active" >Home</a></li> | ||
<li><a [routerLink]="['/menu']" routerLinkActive="router-link-active" >Menu</a></li> | ||
<li><a [routerLink]="['/navbar']" routerLinkActive="router-link-active" >NavBar</a></li> | ||
<li><a [routerLink]="['/message']" routerLinkActive="router-link-active" >message</a></li> | ||
<li><a [routerLink]="['/card']" routerLinkActive="router-link-active" >card</a></li> | ||
<li><a [routerLink]="['/model']" routerLinkActive="router-link-active" >model</a></li> | ||
<li><a [routerLink]="['/panel']" routerLinkActive="router-link-active" >panel</a></li> | ||
<li><a [routerLink]="['/tab']" routerLinkActive="router-link-active" >Tab</a></li> | ||
</ul> | ||
</aside> | ||
|
||
<div class="container column is-10"> | ||
<div class="section"> | ||
<div class="container column is-10"> | ||
<div class="section"> | ||
|
||
<div class="card"> | ||
<div class="card-content"> | ||
<div class="content"> | ||
<router-outlet></router-outlet> | ||
</div> | ||
</div> | ||
</div> | ||
<br /> | ||
<div class="card"> | ||
<div class="card-content"><div class="content"> | ||
<router-outlet></router-outlet> | ||
</div> | ||
</div> | ||
</div> | ||
<br /> | ||
|
||
|
||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</section> | ||
</section> | ||
|
||
<footer class="footer"> | ||
<div class="container"> | ||
<div class="content has-text-centered"> | ||
<a href="https://www.netlify.com"> | ||
<img src="https://www.netlify.com/img/global/badges/netlify-color-accent.svg" /> | ||
</a> | ||
</div> | ||
</div> | ||
</footer> | ||
<footer class="footer is-hidden"> | ||
<div class="container"> | ||
<div class="content has-text-centered"> | ||
<p>Hello</p> | ||
</div> | ||
</div> | ||
</footer> | ||
|
||
</div> | ||
</body> | ||
|
||
</html> |
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
Empty file.
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,6 @@ | ||
<bu-tabs> | ||
<bu-tab-item title="Home" > | ||
</bu-tab-item> | ||
<bu-tab-item title="Dashboard"> | ||
</bu-tab-item> | ||
</bu-tabs> |
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,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { TabComponent } from './tab.component'; | ||
|
||
describe('TabComponent', () => { | ||
let component: TabComponent; | ||
let fixture: ComponentFixture<TabComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ TabComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TabComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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,8 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-tab', | ||
templateUrl: './tab.component.html', | ||
styleUrls: ['./tab.component.css'] | ||
}) | ||
export class TabComponent { } |
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,2 +1,3 @@ | ||
export * from './tabs.component'; | ||
export * from './tab-item/tab-item.component'; | ||
export * from './tabs.module'; |
Empty file.
6 changes: 6 additions & 0 deletions
6
projects/ngx-bulma/src/lib/tabs/tab-item/tab-item.component.html
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,6 @@ | ||
<li [class.is-active]="id === 'bu-tab-item-'+ selectedId"> | ||
<a [id]="id" | ||
href (click)="select($event, id)" role="tab"> | ||
{{title}} | ||
</a> | ||
</li> |
25 changes: 25 additions & 0 deletions
25
projects/ngx-bulma/src/lib/tabs/tab-item/tab-item.component.spec.ts
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,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { TabItemComponent } from './tab-item.component'; | ||
|
||
describe('TabItemComponent', () => { | ||
let component: TabItemComponent; | ||
let fixture: ComponentFixture<TabItemComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ TabItemComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TabItemComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
projects/ngx-bulma/src/lib/tabs/tab-item/tab-item.component.ts
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,38 @@ | ||
import { Component, ViewEncapsulation, ChangeDetectionStrategy, Input, ChangeDetectorRef, AfterContentChecked } from '@angular/core'; | ||
import { TabsService } from '../tabs.service'; | ||
|
||
@Component({ | ||
selector: 'bu-tab-item', | ||
templateUrl: './tab-item.component.html', | ||
styleUrls: ['./tab-item.component.css'], | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
|
||
export class TabItemComponent implements AfterContentChecked { | ||
|
||
@Input() title: string; | ||
public id = `bu-tab-item-${this.tabsService.getid()}`; | ||
public selectedId: number; | ||
|
||
constructor(private tabsService: TabsService, private ref: ChangeDetectorRef) { | ||
this.tabsService.selectedId.subscribe(data => { | ||
this.selectedId = data; | ||
}); | ||
} | ||
|
||
select(event, id) { | ||
event.preventDefault(); | ||
const idSeparated = id.split('-'); | ||
this.tabsService.setSelectedId(this.getSelectedId(idSeparated)); | ||
} | ||
|
||
getSelectedId(idSeparated) { | ||
return idSeparated[idSeparated.length - 1]; | ||
} | ||
|
||
ngAfterContentChecked() { | ||
this.ref.detectChanges(); | ||
} | ||
|
||
} |
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 +1,5 @@ | ||
<p>bulma-tabs works!</p> | ||
<div class="tabs"> | ||
<ul> | ||
<ng-content select="bu-tab-item"></ng-content> | ||
</ul> | ||
</div> |
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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { BulmaTabsComponent } from './tabs.component'; | ||
|
||
|
||
import { TabItemComponent } from './tab-item/tab-item.component'; | ||
import { TabsService } from './tabs.service'; | ||
|
||
@NgModule({ | ||
declarations: [BulmaTabsComponent], | ||
declarations: [BulmaTabsComponent, TabItemComponent], | ||
imports: [ | ||
CommonModule | ||
], | ||
exports: [BulmaTabsComponent] | ||
exports: [BulmaTabsComponent, TabItemComponent], | ||
providers: [TabsService] | ||
}) | ||
export class BulmaTabsModule { } |
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,12 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { TabsService } from './tabs.service'; | ||
|
||
describe('TabsService', () => { | ||
beforeEach(() => TestBed.configureTestingModule({})); | ||
|
||
it('should be created', () => { | ||
const service: TabsService = TestBed.get(TabsService); | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
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,19 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class TabsService { | ||
public nextid = 1; | ||
public selectedId = new BehaviorSubject<number>(null); | ||
constructor() { } | ||
|
||
getid() { | ||
return this.nextid++; | ||
} | ||
|
||
setSelectedId(id) { | ||
this.selectedId.next(id); | ||
} | ||
} |