Skip to content

Commit 8137030

Browse files
musienkoyuriyvalorkin
authored andcommitted
feat(tabs): added config
1 parent d78d8df commit 8137030

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

src/spec/tabset.component.spec.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component } from '@angular/core';
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
3+
import { TabsetConfig } from '../tabs/tabset.config';
34

45
import { TabsModule } from '../tabs/tabs.module';
56

@@ -18,15 +19,15 @@ const html = `
1819
</tabset>
1920
`;
2021

21-
function getTabTitles(nativeEl:HTMLElement):NodeListOf<Element> {
22+
function getTabTitles(nativeEl: HTMLElement): NodeListOf<Element> {
2223
return nativeEl.querySelectorAll('.nav-link');
2324
}
2425

25-
function getTabContent(nativeEl:HTMLElement):NodeListOf<Element> {
26+
function getTabContent(nativeEl: HTMLElement): NodeListOf<Element> {
2627
return nativeEl.querySelectorAll('.tab-content .tab-pane');
2728
}
2829

29-
function expectActiveTabs(nativeEl:HTMLElement, active:boolean[]):void {
30+
function expectActiveTabs(nativeEl: HTMLElement, active: boolean[]): void {
3031
const tabTitles = getTabTitles(nativeEl);
3132
const tabContent = getTabContent(nativeEl);
3233

@@ -67,7 +68,7 @@ describe('Component: Tabs', () => {
6768
beforeEach(() => {
6869
TestBed.configureTestingModule({
6970
declarations: [TestTabsetComponent],
70-
imports: [TabsModule]
71+
imports: [TabsModule.forRoot()]
7172
});
7273
TestBed.overrideComponent(TestTabsetComponent, {set: {template: html}});
7374
fixture = TestBed.createComponent(TestTabsetComponent);
@@ -190,15 +191,19 @@ class TestTabsetComponent {
190191
{title: 'tab3', content: 'tab3 content', removable: true}
191192
];
192193

193-
public _select(e:TabsModule):TabsModule {
194+
public constructor(config: TabsetConfig) {
195+
Object.assign(this, config);
196+
}
197+
198+
public _select(e: TabsModule): TabsModule {
194199
return e;
195200
}
196201

197-
public _deselect(e:TabsModule):TabsModule {
202+
public _deselect(e: TabsModule): TabsModule {
198203
return e;
199204
}
200205

201-
public _removed(e:TabsModule):TabsModule {
206+
public _removed(e: TabsModule): TabsModule {
202207
return e;
203208
}
204209
}

src/tabs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export { TabsetComponent } from './tabset.component';
33
export { TabDirective } from './tab.directive';
44
export { TabsModule } from './tabs.module';
55
export { NgTranscludeDirective } from './ng-transclude.directive';
6+
export { TabsetConfig } from './tabset.config';

src/tabs/tabs.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { NgTranscludeDirective } from './ng-transclude.directive';
55
import { TabHeadingDirective } from './tab-heading.directive';
66
import { TabDirective } from './tab.directive';
77
import { TabsetComponent } from './tabset.component';
8+
import { TabsetConfig } from './tabset.config';
89

910
@NgModule({
1011
imports: [CommonModule],
@@ -15,7 +16,7 @@ export class TabsModule {
1516
public static forRoot(): ModuleWithProviders {
1617
return {
1718
ngModule: TabsModule,
18-
providers: []
19+
providers: [TabsetConfig]
1920
};
2021
}
2122
}

src/tabs/tabset.component.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Component, HostBinding, Input, OnDestroy, OnInit } from '@angular/core';
1+
import { Component, HostBinding, Input, OnDestroy } from '@angular/core';
22

33
import { TabDirective } from './tab.directive';
4+
import { TabsetConfig } from './tabset.config';
45
// todo: add active event to tab
56
// todo: fix? mixing static and dynamic tabs position tabs in order of creation
67
@Component({
@@ -24,7 +25,7 @@ import { TabDirective } from './tab.directive';
2425
</div>
2526
`
2627
})
27-
export class TabsetComponent implements OnInit, OnDestroy {
28+
export class TabsetComponent implements OnDestroy {
2829
@Input()
2930
public get vertical():boolean {
3031
return this._vertical;
@@ -62,8 +63,8 @@ export class TabsetComponent implements OnInit, OnDestroy {
6263
protected _justified:boolean;
6364
protected _type:string;
6465

65-
public ngOnInit():void {
66-
this.type = this.type !== 'undefined' ? this.type : 'tabs';
66+
public constructor(config: TabsetConfig) {
67+
Object.assign(this, config);
6768
}
6869

6970
public ngOnDestroy():void {
@@ -127,7 +128,7 @@ export class TabsetComponent implements OnInit, OnDestroy {
127128
this.classMap = {
128129
'nav-stacked': this.vertical,
129130
'nav-justified': this.justified,
130-
['nav-' + (this.type || 'tabs')]: true
131+
[`nav-${this.type}`]: true
131132
};
132133
}
133134
}

src/tabs/tabset.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Injectable } from '@angular/core';
2+
3+
@Injectable()
4+
export class TabsetConfig {
5+
public type: string = 'tabs';
6+
}

0 commit comments

Comments
 (0)