forked from ngx-builders/ngx-bulma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement tab component ngx-builders#18 : this is basic version of ta…
…b will add support for allignment,icon,size, style in my next commit.
- Loading branch information
Showing
17 changed files
with
160 additions
and
16 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
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); | ||
} | ||
} |