Skip to content

Commit

Permalink
Implement tab component ngx-builders#18 : this is basic version of ta…
Browse files Browse the repository at this point in the history
…b will add support for allignment,icon,size, style in my next commit.
  • Loading branch information
kedar9444 committed Oct 12, 2019
1 parent 8785255 commit 0d096a2
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 16 deletions.
4 changes: 3 additions & 1 deletion projects/bulma-app/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {ModelComponent} from './model/model.component';
import {IntroductionComponent} from './introduction/introduction.component';
import {GettingstartedComponent} from './gettingstarted/gettingstarted.component';
import { PanelComponent } from './panel/panel.component';
import { TabComponent } from './tab/tab.component';


const routes: Routes = [
Expand All @@ -20,7 +21,8 @@ const routes: Routes = [
{ path: 'message', component: MessageComponent },
{ path: 'card', component: CardComponent },
{ path: 'model', component: ModelComponent },
{ path: 'panel', component: PanelComponent }
{ path: 'panel', component: PanelComponent },
{ path: 'tab', component: TabComponent }
];

@NgModule({
Expand Down
3 changes: 2 additions & 1 deletion projects/bulma-app/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<section class="main-content columns is-fullheight">

<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>
Expand All @@ -49,6 +49,7 @@
<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>

Expand Down
4 changes: 3 additions & 1 deletion projects/bulma-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ModelComponent } from './model/model.component';
import { IntroductionComponent } from './introduction/introduction.component';
import { GettingstartedComponent } from './gettingstarted/gettingstarted.component';
import { PanelComponent } from './panel/panel.component';
import { TabComponent } from './tab/tab.component';


@NgModule({
Expand All @@ -31,7 +32,8 @@ import { PanelComponent } from './panel/panel.component';
ModelComponent,
IntroductionComponent,
GettingstartedComponent,
PanelComponent
PanelComponent,
TabComponent
],
imports: [
BrowserModule,
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions projects/bulma-app/src/app/tab/tab.component.html
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>
25 changes: 25 additions & 0 deletions projects/bulma-app/src/app/tab/tab.component.spec.ts
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();
});
});
8 changes: 8 additions & 0 deletions projects/bulma-app/src/app/tab/tab.component.ts
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 { }
1 change: 1 addition & 0 deletions projects/ngx-bulma/src/lib/tabs/index.ts
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.
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>
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 projects/ngx-bulma/src/lib/tabs/tab-item/tab-item.component.ts
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();
}

}
6 changes: 5 additions & 1 deletion projects/ngx-bulma/src/lib/tabs/tabs.component.html
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>
10 changes: 2 additions & 8 deletions projects/ngx-bulma/src/lib/tabs/tabs.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy } from '@angular/core';
import { Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy, ContentChildren, QueryList } from '@angular/core';

@Component({
selector: 'bu-tabs',
Expand All @@ -7,11 +7,5 @@ import { Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy } from '@
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class BulmaTabsComponent implements OnInit {

constructor() { }

ngOnInit() {
}

export class BulmaTabsComponent {
}
9 changes: 5 additions & 4 deletions projects/ngx-bulma/src/lib/tabs/tabs.module.ts
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 { }
12 changes: 12 additions & 0 deletions projects/ngx-bulma/src/lib/tabs/tabs.service.spec.ts
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();
});
});
19 changes: 19 additions & 0 deletions projects/ngx-bulma/src/lib/tabs/tabs.service.ts
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);
}
}

0 comments on commit 0d096a2

Please sign in to comment.