Skip to content

Commit 34b4d95

Browse files
committed
style: fix tabs ts errors
1 parent be75575 commit 34b4d95

File tree

4 files changed

+41
-103
lines changed

4 files changed

+41
-103
lines changed

library/angular-admin-lte/src/lib/tabs/tabs.component.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33
<li *ngFor="let tab of tabs" [class.active]="tab.isActive" [mkColor]="tab.tabColor || tabsColor" mkColorProperty="border-top-color">
44
<a *ngIf="!tab.isDisabled" [mkTabToggle]="tab" href="#">
55
{{tab.header}}
6-
<ng-template *ngIf="!tab.header" [ngTemplateOutlet]="tab.tabHeaderComponent.templateRef"></ng-template>
6+
<ng-template *ngIf="!tab.header && tab.tabHeaderComponent" [ngTemplateOutlet]="tab.tabHeaderComponent.templateRef"></ng-template>
77
</a>
88
<ng-template [ngIf]="tab.isDisabled">
99
{{tab.header}}
10-
<ng-template *ngIf="!tab.header" [ngTemplateOutlet]="tab.tabHeaderComponent.templateRef"></ng-template>
10+
<ng-template *ngIf="!tab.header && tab.tabHeaderComponent" [ngTemplateOutlet]="tab.tabHeaderComponent.templateRef"></ng-template>
1111
</ng-template>
1212
</li>
1313
<li *ngIf="tabsHeaderComponent || header" [ngClass]="headerStyleClass">
1414
{{header}}
15-
<ng-template *ngIf="!header" [ngTemplateOutlet]="tabsHeaderComponent.templateRef"></ng-template>
15+
<ng-template *ngIf="tabsHeaderComponent" [ngTemplateOutlet]="tabsHeaderComponent.templateRef"></ng-template>
1616
</li>
1717
</ul>
1818
<div [ngClass]="contentStyleClass">
1919
<div *ngFor="let tab of tabs" class="tab-pane" [class.active]="tab.isActive">
20-
<ng-template [ngTemplateOutlet]="tab.contentTemplateRef"></ng-template>
20+
<ng-template *ngIf="!tab.tabContentComponent" [ngTemplateOutlet]="tab.templateRef"></ng-template>
21+
<ng-template *ngIf="tab.tabContentComponent" [ngTemplateOutlet]="tab.tabContentComponent.templateRef"></ng-template>
2122
</div>
2223
</div>
2324
</div>

library/angular-admin-lte/src/lib/tabs/tabs.component.ts

Lines changed: 35 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,14 @@ import {
1717
ViewChild,
1818
ViewChildren
1919
} from '@angular/core';
20-
2120
import type { TemplateRef, QueryList } from '@angular/core';
2221

23-
import { TabToggleDirective } from './tabs.directive';
22+
import { Subscription } from 'rxjs';
2423

24+
import { TabToggleDirective } from './tabs.directive';
2525
import { removeListeners, removeSubscriptions } from '../helpers';
26-
import { Subscription } from 'rxjs';
2726

28-
// @TODO Vertical tabs
2927

30-
/*
31-
*
32-
*/
3328
@Component({
3429
selector: 'mk-tab-header',
3530
template: '<ng-template #templateRef><ng-content></ng-content></ng-template>',
@@ -40,9 +35,6 @@ export class TabHeaderComponent {
4035
}
4136

4237

43-
/*
44-
*
45-
*/
4638
@Component({
4739
selector: 'mk-tab-content',
4840
template: '<ng-template #templateRef><ng-content></ng-content></ng-template>',
@@ -52,44 +44,27 @@ export class TabContentComponent {
5244
@ViewChild('templateRef', { static: true }) public templateRef!: TemplateRef<ElementRef>;
5345
}
5446

55-
/*
56-
*
57-
*/
47+
5848
@Component({
5949
selector: 'mk-tab',
6050
template: '<ng-template #templateRef><ng-content></ng-content></ng-template>',
6151
changeDetection: ChangeDetectionStrategy.OnPush
6252
})
63-
export class TabComponent implements AfterContentInit {
64-
public index!: number;
65-
public isActive = false;
66-
67-
public contentTemplateRef!: TemplateRef<ElementRef>;
68-
53+
export class TabComponent {
6954
@Input() public header?: string;
7055
@Input() public isDisabled = false;
7156
@Input() public tabColor?: string;
7257

7358
@ViewChild('templateRef', { static: true }) public templateRef!: TemplateRef<ElementRef>;
7459

75-
@ContentChild(TabHeaderComponent) public tabHeaderComponent!: TabHeaderComponent;
60+
@ContentChild(TabHeaderComponent) public tabHeaderComponent?: TabHeaderComponent;
7661
@ContentChild(TabContentComponent) public tabContentComponent?: TabContentComponent;
7762

78-
/**
79-
* @method ngAfterContentInit
80-
*/
81-
ngAfterContentInit(): void {
82-
if (this.tabContentComponent) {
83-
this.contentTemplateRef = this.tabContentComponent.templateRef;
84-
} else {
85-
this.contentTemplateRef = this.templateRef;
86-
}
87-
}
63+
public index!: number;
64+
public isActive = false;
8865
}
8966

90-
/*
91-
*
92-
*/
67+
9368
@Component({
9469
selector: 'mk-tabs-header',
9570
template: '<ng-template #templateRef><ng-content></ng-content></ng-template>',
@@ -99,20 +74,14 @@ export class TabsHeaderComponent {
9974
@ViewChild('templateRef', { static: true }) public templateRef!: TemplateRef<ElementRef>;
10075
}
10176

102-
/*
103-
*
104-
*/
77+
10578
@Component({
10679
selector: 'mk-tabs',
10780
templateUrl: './tabs.component.html',
10881
styleUrls: ['./tabs.component.css'],
10982
changeDetection: ChangeDetectionStrategy.OnPush
11083
})
11184
export class TabsComponent implements AfterContentInit, AfterViewInit, OnChanges, OnDestroy {
112-
private activatedTabIndex?: number;
113-
private listeners: (() => void)[] = [];
114-
private subscriptions: Subscription[] = [];
115-
11685
@Input() public set activeTabIndex(index: number) {
11786
this.activatedTabIndex = index;
11887
this.changeDetectorRef.detectChanges();
@@ -127,43 +96,37 @@ export class TabsComponent implements AfterContentInit, AfterViewInit, OnChanges
12796
@Output() public closeTab = new EventEmitter();
12897
@Output() public openTab = new EventEmitter();
12998

130-
@ContentChild(TabsHeaderComponent, { static: true }) public tabsHeaderComponent!: TabsHeaderComponent;
99+
@ContentChild(TabsHeaderComponent) public tabsHeaderComponent?: TabsHeaderComponent;
131100

132-
@ContentChildren(TabComponent) public tabs!: QueryList<TabComponent>;
101+
@ContentChildren(TabComponent) public tabs?: QueryList<TabComponent>;
133102

134103
@ViewChildren(TabToggleDirective) public tabToggleDirectives?: QueryList<TabToggleDirective>;
135104

136-
/**
137-
* @method constructor
138-
* @param changeDetectorRef [description]
139-
* @param ngZone [description]
140-
* @param renderer2 [description]
141-
*/
105+
private activatedTabIndex?: number;
106+
private listeners: (() => void)[] = [];
107+
private subscriptions: Subscription[] = [];
108+
142109
constructor(
143110
private changeDetectorRef: ChangeDetectorRef,
144111
private ngZone: NgZone,
145112
private renderer2: Renderer2
146113
) {}
147114

148-
/**
149-
* @method ngAfterViewInit
150-
*/
151115
ngAfterContentInit(): void {
152116
// Set tab index on load.
153117
this.setTabIndex();
154118

155119
// Update tab index if tabs is updated.
156-
this.subscriptions.push(this.tabs.changes.subscribe(() => {
157-
this.setTabIndex();
158-
}));
120+
if (this.tabs) {
121+
this.subscriptions.push(this.tabs.changes.subscribe(() => {
122+
this.setTabIndex();
123+
}));
124+
}
159125

160126
// Open tab on load.
161127
this.openTabIndex();
162128
}
163129

164-
/**
165-
* @method ngAfterViewInit
166-
*/
167130
ngAfterViewInit(): void {
168131
// Set tab toggles on load.
169132
this.setTabsToggle();
@@ -176,28 +139,17 @@ export class TabsComponent implements AfterContentInit, AfterViewInit, OnChanges
176139
}
177140
}
178141

179-
/**
180-
* @method ngOnChanges
181-
* @param changes [description]
182-
*/
183142
ngOnChanges(changes: {[propKey: string]: SimpleChange}): void {
184143
if (changes.activeTabIndex) {
185144
this.openTabIndex();
186145
}
187146
}
188147

189-
/**
190-
* @method ngOnDestroy
191-
*/
192148
ngOnDestroy(): void {
193149
removeListeners(this.listeners);
194150
removeSubscriptions(this.subscriptions);
195151
}
196152

197-
/**
198-
* [toggleTab description]
199-
* @method toggleTab
200-
*/
201153
public openTabIndex(): void {
202154
if (this.tabs) {
203155
this.tabs.forEach((tab: TabComponent) => {
@@ -214,39 +166,31 @@ export class TabsComponent implements AfterContentInit, AfterViewInit, OnChanges
214166
}
215167
}
216168

217-
/**
218-
* [openTab description]
219-
* @method openTab
220-
* @param event [description]
221-
* @param tabToOpen [description]
222-
*/
223169
public onOpenTab(event: Event, tabToOpen: TabComponent): void {
224170
event.preventDefault();
225171
tabToOpen.isActive = true;
226172
this.openTab.emit({event, index: tabToOpen.index});
227-
this.tabs.forEach((tab: TabComponent) => {
228-
if (tab.isActive && tabToOpen !== tab) {
229-
tab.isActive = false;
230-
this.closeTab.emit({event, index: tab.index});
231-
}
232-
});
173+
174+
if (this.tabs) {
175+
this.tabs.forEach((tab: TabComponent) => {
176+
if (tab.isActive && tabToOpen !== tab) {
177+
tab.isActive = false;
178+
this.closeTab.emit({event, index: tab.index});
179+
}
180+
});
181+
}
233182
}
234183

235-
/**
236-
* [setTabIndex description]
237-
* @method setTabIndex
238-
*/
239184
private setTabIndex(): void {
240-
this.tabs.forEach((tab: TabComponent, index: number) => {
241-
tab.index = index;
242-
});
185+
if (this.tabs) {
186+
this.tabs.forEach((tab: TabComponent, index: number) => {
187+
tab.index = index;
188+
});
189+
}
190+
243191
this.changeDetectorRef.detectChanges();
244192
}
245193

246-
/**
247-
* [setTabsToggle description]
248-
* @method setTabsToggle
249-
*/
250194
private setTabsToggle(): void {
251195
this.listeners = removeListeners(this.listeners);
252196
this.ngZone.runOutsideAngular(() => {

library/angular-admin-lte/src/lib/tabs/tabs.directive.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
import { Directive, Input, ElementRef } from '@angular/core';
22
import { TabComponent } from './tabs.component';
33

4-
/*
5-
*
6-
*/
4+
75
@Directive({
86
selector: '[mkTabToggle]'
97
})
108
export class TabToggleDirective {
119
// TODO: Add @Required decorator
1210
@Input('mkTabToggle') tabComponent!: TabComponent;
1311

14-
/**
15-
* @method constructor
16-
* @param elementRef [description]
17-
*/
1812
constructor(
1913
public elementRef: ElementRef
2014
) {}

library/angular-admin-lte/src/lib/tabs/tabs.module.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33

44
import { ColorModule } from '../color/color.module';
5-
65
import { TabToggleDirective } from './tabs.directive';
76
import { TabsComponent, TabsHeaderComponent, TabComponent, TabHeaderComponent, TabContentComponent } from './tabs.component';
87

0 commit comments

Comments
 (0)