Skip to content

Commit 0d096a2

Browse files
committed
Implement tab component ngx-builders#18 : this is basic version of tab will add support for allignment,icon,size, style in my next commit.
1 parent 8785255 commit 0d096a2

17 files changed

+160
-16
lines changed

projects/bulma-app/src/app/app-routing.module.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {ModelComponent} from './model/model.component';
99
import {IntroductionComponent} from './introduction/introduction.component';
1010
import {GettingstartedComponent} from './gettingstarted/gettingstarted.component';
1111
import { PanelComponent } from './panel/panel.component';
12+
import { TabComponent } from './tab/tab.component';
1213

1314

1415
const routes: Routes = [
@@ -20,7 +21,8 @@ const routes: Routes = [
2021
{ path: 'message', component: MessageComponent },
2122
{ path: 'card', component: CardComponent },
2223
{ path: 'model', component: ModelComponent },
23-
{ path: 'panel', component: PanelComponent }
24+
{ path: 'panel', component: PanelComponent },
25+
{ path: 'tab', component: TabComponent }
2426
];
2527

2628
@NgModule({

projects/bulma-app/src/app/app.component.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<section class="main-content columns is-fullheight">
3838

3939
<aside class="column is-2 is-narrow-mobile is-fullheight section is-hidden-mobile">
40-
40+
4141
<ul class="menu-list">
4242
<li><a [routerLink]="['']" routerLinkActive="router-link-active" >Introduction</a></li>
4343
<li><a [routerLink]="['/gettingstarted']" routerLinkActive="router-link-active">Getting Started</a></li>
@@ -49,6 +49,7 @@
4949
<li><a [routerLink]="['/card']" routerLinkActive="router-link-active" >card</a></li>
5050
<li><a [routerLink]="['/model']" routerLinkActive="router-link-active" >model</a></li>
5151
<li><a [routerLink]="['/panel']" routerLinkActive="router-link-active" >panel</a></li>
52+
<li><a [routerLink]="['/tab']" routerLinkActive="router-link-active" >Tab</a></li>
5253
</ul>
5354
</aside>
5455

projects/bulma-app/src/app/app.module.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ModelComponent } from './model/model.component';
1818
import { IntroductionComponent } from './introduction/introduction.component';
1919
import { GettingstartedComponent } from './gettingstarted/gettingstarted.component';
2020
import { PanelComponent } from './panel/panel.component';
21+
import { TabComponent } from './tab/tab.component';
2122

2223

2324
@NgModule({
@@ -31,7 +32,8 @@ import { PanelComponent } from './panel/panel.component';
3132
ModelComponent,
3233
IntroductionComponent,
3334
GettingstartedComponent,
34-
PanelComponent
35+
PanelComponent,
36+
TabComponent
3537
],
3638
imports: [
3739
BrowserModule,

projects/bulma-app/src/app/tab/tab.component.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<bu-tabs>
2+
<bu-tab-item title="Home" >
3+
</bu-tab-item>
4+
<bu-tab-item title="Dashboard">
5+
</bu-tab-item>
6+
</bu-tabs>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { TabComponent } from './tab.component';
4+
5+
describe('TabComponent', () => {
6+
let component: TabComponent;
7+
let fixture: ComponentFixture<TabComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ TabComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(TabComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-tab',
5+
templateUrl: './tab.component.html',
6+
styleUrls: ['./tab.component.css']
7+
})
8+
export class TabComponent { }
+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './tabs.component';
2+
export * from './tab-item/tab-item.component';
23
export * from './tabs.module';

projects/ngx-bulma/src/lib/tabs/tab-item/tab-item.component.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<li [class.is-active]="id === 'bu-tab-item-'+ selectedId">
2+
<a [id]="id"
3+
href (click)="select($event, id)" role="tab">
4+
{{title}}
5+
</a>
6+
</li>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { TabItemComponent } from './tab-item.component';
4+
5+
describe('TabItemComponent', () => {
6+
let component: TabItemComponent;
7+
let fixture: ComponentFixture<TabItemComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ TabItemComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(TabItemComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Component, ViewEncapsulation, ChangeDetectionStrategy, Input, ChangeDetectorRef, AfterContentChecked } from '@angular/core';
2+
import { TabsService } from '../tabs.service';
3+
4+
@Component({
5+
selector: 'bu-tab-item',
6+
templateUrl: './tab-item.component.html',
7+
styleUrls: ['./tab-item.component.css'],
8+
encapsulation: ViewEncapsulation.None,
9+
changeDetection: ChangeDetectionStrategy.OnPush
10+
})
11+
12+
export class TabItemComponent implements AfterContentChecked {
13+
14+
@Input() title: string;
15+
public id = `bu-tab-item-${this.tabsService.getid()}`;
16+
public selectedId: number;
17+
18+
constructor(private tabsService: TabsService, private ref: ChangeDetectorRef) {
19+
this.tabsService.selectedId.subscribe(data => {
20+
this.selectedId = data;
21+
});
22+
}
23+
24+
select(event, id) {
25+
event.preventDefault();
26+
const idSeparated = id.split('-');
27+
this.tabsService.setSelectedId(this.getSelectedId(idSeparated));
28+
}
29+
30+
getSelectedId(idSeparated) {
31+
return idSeparated[idSeparated.length - 1];
32+
}
33+
34+
ngAfterContentChecked() {
35+
this.ref.detectChanges();
36+
}
37+
38+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
<p>bulma-tabs works!</p>
1+
<div class="tabs">
2+
<ul>
3+
<ng-content select="bu-tab-item"></ng-content>
4+
</ul>
5+
</div>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy } from '@angular/core';
1+
import { Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy, ContentChildren, QueryList } from '@angular/core';
22

33
@Component({
44
selector: 'bu-tabs',
@@ -7,11 +7,5 @@ import { Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy } from '@
77
encapsulation: ViewEncapsulation.None,
88
changeDetection: ChangeDetectionStrategy.OnPush
99
})
10-
export class BulmaTabsComponent implements OnInit {
11-
12-
constructor() { }
13-
14-
ngOnInit() {
15-
}
16-
10+
export class BulmaTabsComponent {
1711
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { BulmaTabsComponent } from './tabs.component';
4-
5-
4+
import { TabItemComponent } from './tab-item/tab-item.component';
5+
import { TabsService } from './tabs.service';
66

77
@NgModule({
8-
declarations: [BulmaTabsComponent],
8+
declarations: [BulmaTabsComponent, TabItemComponent],
99
imports: [
1010
CommonModule
1111
],
12-
exports: [BulmaTabsComponent]
12+
exports: [BulmaTabsComponent, TabItemComponent],
13+
providers: [TabsService]
1314
})
1415
export class BulmaTabsModule { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { TabsService } from './tabs.service';
4+
5+
describe('TabsService', () => {
6+
beforeEach(() => TestBed.configureTestingModule({}));
7+
8+
it('should be created', () => {
9+
const service: TabsService = TestBed.get(TabsService);
10+
expect(service).toBeTruthy();
11+
});
12+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Injectable } from '@angular/core';
2+
import { BehaviorSubject } from 'rxjs';
3+
4+
@Injectable({
5+
providedIn: 'root'
6+
})
7+
export class TabsService {
8+
public nextid = 1;
9+
public selectedId = new BehaviorSubject<number>(null);
10+
constructor() { }
11+
12+
getid() {
13+
return this.nextid++;
14+
}
15+
16+
setSelectedId(id) {
17+
this.selectedId.next(id);
18+
}
19+
}

0 commit comments

Comments
 (0)