Skip to content

Commit

Permalink
feat(tab): new tab component
Browse files Browse the repository at this point in the history
  • Loading branch information
marcjulian committed Apr 28, 2020
1 parent 96ae30e commit 36f4b5a
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 22 deletions.
8 changes: 8 additions & 0 deletions projects/components/src/lib/tab/tab.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="flex justify-center items-center xs:flex-1 md:flex md:h-24 md:flex-none" [ngClass]="'logo'"
[class.xs:hidden]="tab.hideOnMobile" [class.md:hidden]="tab.hideOnDesktop">
<a class="flex flex-col items-center hover:text-blue" [class.hover:text-color]="tab.logo" [routerLink]="tab.url"
[routerLinkActive]="tab.routeActive ? 'active-tab' : ''">
<niz-inline-svg class="h-8 w-8" [svgSource]="tab.image"></niz-inline-svg>
<span *ngIf="tab.text" class="mt-1 text-lg font-semibold tracking-tight">{{tab.text}}</span>
</a>
</div>
3 changes: 3 additions & 0 deletions projects/components/src/lib/tab/tab.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.active-tab {
color: var(--blue);
}
25 changes: 25 additions & 0 deletions projects/components/src/lib/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();
});
});
15 changes: 15 additions & 0 deletions projects/components/src/lib/tab/tab.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit, Input } from '@angular/core';
import { Tab } from '../utils/symbols';

@Component({
selector: 'niz-tab',
templateUrl: './tab.component.html',
styleUrls: ['./tab.component.scss'],
})
export class NizTab implements OnInit {
@Input() tab: Tab;

constructor() {}

ngOnInit(): void {}
}
12 changes: 12 additions & 0 deletions projects/components/src/lib/tab/tab.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NizTab } from './tab.component';
import { NizInlineSvgModule } from '../inline-svg/inline-svg.module';
import { RouterModule } from '@angular/router';

@NgModule({
declarations: [NizTab],
imports: [CommonModule, RouterModule, NizInlineSvgModule],
exports: [NizTab],
})
export class NizTabModule {}
7 changes: 1 addition & 6 deletions projects/components/src/lib/tabs/tabs.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<nav
class="fixed flex bg-tabs z-10 xs:flex-row xs:bottom-0 xs:h-20 xs:w-screen md:flex-col md:top-0 md:h-screen md:w-20">
<div *ngFor="let tab of tabs" class="flex justify-center items-center xs:flex-1 md:flex md:h-20 md:flex-none"
[class.xs:hidden]="tab.hideOnMobile" [class.md:hidden]="tab.hideOnDesktop">
<a class="h-8 w-8 hover:text-blue" [routerLink]="tab.url" [routerLinkActive]="tab.routeActive ? 'active-tab' : ''">
<niz-inline-svg [svgSource]="tab.image"></niz-inline-svg>
</a>
</div>
<niz-tab *ngFor="let tab of tabs" [tab]="tab"></niz-tab>
</nav>
<div class="w-full min-h-screen xs:pb-20 md:pl-20 ">
<ng-content></ng-content>
Expand Down
4 changes: 1 addition & 3 deletions projects/components/src/lib/tabs/tabs.component.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
.active-tab {
color: var(--blue);
}

12 changes: 2 additions & 10 deletions projects/components/src/lib/tabs/tabs.component.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { Component, OnInit, Input } from '@angular/core';

export interface Tab{
url: string;
routeActive: boolean;
image: string;
hideOnMobile?: boolean;
hideOnDesktop?: boolean;
}
import { Tab } from '../utils/symbols';

@Component({
selector: 'niz-tabs',
templateUrl: './tabs.component.html',
styleUrls: ['./tabs.component.scss']
styleUrls: ['./tabs.component.scss'],
})
export class NizTabs implements OnInit {

@Input() tabs: Tab[];

constructor() {}
Expand Down
5 changes: 2 additions & 3 deletions projects/components/src/lib/tabs/tabs.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NizTabs } from './tabs.component';
import { RouterModule } from '@angular/router';
import { NizInlineSvgModule } from '../inline-svg/inline-svg.module';
import { NizTabModule } from '../tab/tab.module';

@NgModule({
declarations: [NizTabs],
imports: [CommonModule, RouterModule, NizInlineSvgModule],
imports: [CommonModule, NizTabModule],
exports: [NizTabs],
})
export class NizTabsModule {}
9 changes: 9 additions & 0 deletions projects/components/src/lib/utils/symbols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface Tab {
url: string;
logo?: boolean;
text?: string;
routeActive: boolean;
image: string;
hideOnMobile?: boolean;
hideOnDesktop?: boolean;
}
4 changes: 4 additions & 0 deletions projects/components/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ export * from './lib/footer/footer.module';
export * from './lib/footer/footer.component';
export * from './lib/inline-svg/inline-svg.module';
export * from './lib/inline-svg/inline-svg.component';
export * from './lib/tab/tab.module';
export * from './lib/tab/tab.component';
export * from './lib/tabs/tabs.module';
export * from './lib/tabs/tabs.component';
export * from './lib/toolbar/toolbar.module';
export * from './lib/toolbar/toolbar.component';

export * from './lib/utils/symbols';
3 changes: 3 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ export class AppComponent {
tabs: Tab[] = [
{
url: '/',
logo: true,
text: 'notiz',
image: 'assets/img/notiz.svg',
routeActive: false,
hideOnMobile: true,
},
{
url: '/search/',
text: 'search',
image: 'assets/img/search.svg',
routeActive: true,
},
Expand Down

0 comments on commit 36f4b5a

Please sign in to comment.