Revision 58710
Added by Konstantina Galouni about 4 years ago
modules/uoa-services-library/trunk/ng-openaire-library/src/app/utils/tabs/tabs.component.ts | ||
---|---|---|
1 |
/** |
|
2 |
* The main component that renders single TabComponent |
|
3 |
* instances. |
|
4 |
*/ |
|
5 |
|
|
6 |
import { |
|
7 |
Component, |
|
8 |
ContentChildren, |
|
9 |
QueryList, |
|
10 |
AfterContentInit, Output, EventEmitter, |
|
11 |
} from '@angular/core'; |
|
12 |
|
|
13 |
import { TabComponent } from './tab.component'; |
|
14 |
|
|
15 |
@Component({ |
|
16 |
selector: 'my-tabs', |
|
17 |
template: ` |
|
18 |
<ul uk-tab class="uk-tab uk-text-truncate main-tabs uk-margin-remove uk-child-width-expand uk-width-3-4" uk-switcher="connect: .main-tabs-content"> |
|
19 |
<!-- + (tab.active ? ' uk-active' : '')--> |
|
20 |
<li *ngFor="let tab of tabs" (click)="selectTab(tab)" [class.active]="tab.active" [class]="'uk-padding-remove '+(tab.statistics ? ' statistics ' : '')"> |
|
21 |
<a class="uk-width-1-1 uk-height-1-1"> |
|
22 |
<div class="tab-header">{{tab.title}}</div> |
|
23 |
<div *ngIf="tab.num" class="number">{{tab.num | number}}</div> |
|
24 |
<div *ngIf="tab.statistics" class="number"> |
|
25 |
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"> |
|
26 |
<path d="M0 0h24v24H0z" fill="none"></path> |
|
27 |
<path d="M10 20h4V4h-4v16zm-6 0h4v-8H4v8zM16 9v11h4V9h-4z"></path> |
|
28 |
</svg> |
|
29 |
</div> |
|
30 |
</a> |
|
31 |
</li> |
|
32 |
</ul> |
|
33 |
<div class="uk-switcher main-tabs-content"> |
|
34 |
<ng-content></ng-content> |
|
35 |
</div> |
|
36 |
|
|
37 |
<!-- <ul class="nav nav-tabs">--> |
|
38 |
<!-- <li *ngFor="let tab of tabs" (click)="selectTab(tab)" [class.active]="tab.active">--> |
|
39 |
<!-- <a href="#">{{tab.title}}</a>--> |
|
40 |
<!-- </li>--> |
|
41 |
<!-- </ul>--> |
|
42 |
<!-- <ng-content></ng-content>--> |
|
43 |
`//, |
|
44 |
// styles: [ |
|
45 |
// ` |
|
46 |
// .tab-close { |
|
47 |
// color: gray; |
|
48 |
// text-align: right; |
|
49 |
// cursor: pointer; |
|
50 |
// } |
|
51 |
// ` |
|
52 |
// ] |
|
53 |
}) |
|
54 |
export class TabsComponent implements AfterContentInit { |
|
55 |
|
|
56 |
@ContentChildren(TabComponent) tabs: QueryList<TabComponent>; |
|
57 |
@Output() public selectedActiveTab: EventEmitter<any> = new EventEmitter(); |
|
58 |
|
|
59 |
// contentChildren are set |
|
60 |
ngAfterContentInit() { |
|
61 |
// get all active tabs |
|
62 |
let activeTabs = this.tabs.filter((tab)=>tab.active); |
|
63 |
console.log("ACTIVE TABS: "+activeTabs.length); |
|
64 |
// if there is no active tab set, activate the first |
|
65 |
if(activeTabs.length === 0) { |
|
66 |
this.selectTab(this.tabs.first); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
selectTab(tab: TabComponent){ |
|
71 |
// deactivate all tabs |
|
72 |
this.tabs.toArray().forEach(tab => tab.active = false); |
|
73 |
|
|
74 |
// activate the tab the user has clicked on. |
|
75 |
tab.active = true; |
|
76 |
console.log("ACTIVE TAB SET TO: "+tab.title); |
|
77 |
this.selectedActiveTab.emit(tab.tabId); |
|
78 |
|
|
79 |
} |
|
80 |
} |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/utils/tabs/tabs.module.ts | ||
---|---|---|
1 |
import { NgModule } from '@angular/core'; |
|
2 |
import { CommonModule } from '@angular/common'; |
|
3 |
import { FormsModule } from '@angular/forms'; |
|
4 |
|
|
5 |
import {TabsComponent} from './tabs.component'; |
|
6 |
import {TabComponent} from "./tab.component"; |
|
7 |
|
|
8 |
@NgModule({ |
|
9 |
imports: [ |
|
10 |
CommonModule, FormsModule |
|
11 |
], |
|
12 |
declarations: [ |
|
13 |
TabsComponent, TabComponent |
|
14 |
], |
|
15 |
exports: [ |
|
16 |
TabsComponent, TabComponent |
|
17 |
] |
|
18 |
}) |
|
19 |
export class TabsModule { } |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/utils/tabs/tab.component.ts | ||
---|---|---|
1 |
/** |
|
2 |
* A single tab page. It renders the passed template |
|
3 |
* via the @Input properties by using the ngTemplateOutlet |
|
4 |
* and ngTemplateOutletContext directives. |
|
5 |
*/ |
|
6 |
|
|
7 |
import { Component, Input } from '@angular/core'; |
|
8 |
|
|
9 |
@Component({ |
|
10 |
selector: 'my-tab', |
|
11 |
// styles: [ |
|
12 |
// ` |
|
13 |
// .pane{ |
|
14 |
// padding: 1em; |
|
15 |
// } |
|
16 |
// ` |
|
17 |
// ], |
|
18 |
template: ` |
|
19 |
<!-- [class]="active ? 'uk-active' : ''" [hidden]="!active"--> |
|
20 |
<!-- <div [class]="active ? 'uk-active' : ''" [hidden]="!active">--> |
|
21 |
<div [hidden]="!active" class="pane"> |
|
22 |
<ng-content></ng-content> |
|
23 |
</div> |
|
24 |
|
|
25 |
<!-- <div [hidden]="!active" class="pane">--> |
|
26 |
<!-- <ng-content></ng-content>--> |
|
27 |
<!-- </div>--> |
|
28 |
` |
|
29 |
}) |
|
30 |
export class TabComponent { |
|
31 |
@Input('tabTitle') title: string; |
|
32 |
@Input('tabNumber') num: number; |
|
33 |
@Input('statistics') statistics: boolean = false; |
|
34 |
@Input('tabId') tabId: string; |
|
35 |
@Input() active = false; |
|
36 |
} |
Also available in: Unified diff
[Trunk | Library]: [NEW] tab.component & tabs.component & tabs.module added in /utils folder - skeleton structure for tabs used in landing pages and community home page.