Skip to content

Commit

Permalink
Merge pull request #28 from angular-way/master
Browse files Browse the repository at this point in the history
Implement tab component #18
  • Loading branch information
santoshyadavdev authored Oct 25, 2019
2 parents 580b381 + d55fdb7 commit e5acf97
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 84 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
134 changes: 65 additions & 69 deletions projects/bulma-app/src/app/app.component.html
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>
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 e5acf97

Please sign in to comment.