[Trunk | Library]: Add in tabs, view for small screens:

1. small-tabs.component.ts: File added for small screens - active tab & a fake tab are always visible, while all tabs are shows in a list, toggled by fake tab (connected to switcher 'small-tabs-content').
2. tabs.component.ts: Tabs are connected to switcher 'tabs-content'.
3. tabs.module.ts: Add 'SmallTabsComponent' in declarations & exports.


git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58758 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
konstantina.galouni 2020-05-25 11:27:07 +00:00
parent 7f967dd6a9
commit cd5d412b81
3 changed files with 96 additions and 23 deletions

View File

@ -0,0 +1,89 @@
/**
* The main component that renders single TabComponent
* instances.
*/
import {
Component,
ContentChildren,
QueryList,
AfterContentInit, Output, EventEmitter, ViewChild, ElementRef,
} from '@angular/core';
import { TabComponent } from './tab.component';
declare var UIkit: any;
@Component({
selector: 'my-small-tabs',
template: `
<ul uk-tab class="uk-tab main-tabs uk-margin-remove uk-child-width-expand">
<li *ngFor="let tab of activeTabs" [class]="'uk-active uk-padding-remove '+(tab.statistics ? ' statistics ' : '')">
<a class="uk-width-1-1 uk-height-1-1">
<div class="tab-header">{{tab.title}}</div>
<div *ngIf="tab.num" class="number">{{tab.num | number}}</div>
<div *ngIf="tab.statistics" class="number">
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
<path d="M0 0h24v24H0z" fill="none"></path>
<path d="M10 20h4V4h-4v16zm-6 0h4v-8H4v8zM16 9v11h4V9h-4z"></path>
</svg>
</div>
</a>
</li>
<li class="uk-padding-remove fake_tab">
<a class="uk-text-center uk-width-1-1 uk-height-1-1">...</a>
<div #drop_element uk-drop="mode: click" class="uk-drop">
<div class="uk-card uk-card-body uk-card-default">
<ul class="uk-list uk-list-divider main-small-tabs" uk-switcher="connect: .small-tabs-content">
<li *ngFor="let tab of tabs" (click)="selectTab(tab)" [class]="' uk-height-1-1 uk-width-1-1'+(tab.active ? ' uk-text-bold' : '')">
<a class="uk-display-block uk-height-1-1 uk-width-1-1">{{tab.title}}</a>
</li>
</ul>
</div>
</div>
</li>
</ul>
<div class="uk-switcher small-tabs-content main-tabs-content">
<ng-content></ng-content>
</div>
`
})
export class SmallTabsComponent implements AfterContentInit {
@ViewChild('drop_element') dropElement: ElementRef;
@ContentChildren(TabComponent) tabs: QueryList<TabComponent>;
@Output() public selectedActiveTab: EventEmitter<any> = new EventEmitter();
public activeTabs: TabComponent[] = [];
// contentChildren are set
ngAfterContentInit() {
// get all active tabs
this.activeTabs = this.tabs.filter((tab)=>tab.active);
// if there is no active tab set, activate the first
if(this.tabs.length > 0 && this.activeTabs.length === 0) {
this.selectTab(this.tabs.first);
}
}
selectTab(tab: TabComponent){
console.log("selectTab: "+tab.title);
// deactivate all tabs
this.tabs.toArray().forEach(tab => tab.active = false);
this.activeTabs = [];
this.activeTabs.push(tab);
// activate the tab the user has clicked on.
tab.active = true;
this.selectedActiveTab.emit(tab.tabId);
if(this.dropElement) {
console.log("dropElement: ",this.dropElement);
UIkit.drop(this.dropElement.nativeElement).hide(false);
}
}
}

View File

@ -15,8 +15,7 @@ import { TabComponent } from './tab.component';
@Component({
selector: 'my-tabs',
template: `
<ul uk-tab class="uk-tab main-tabs uk-margin-remove uk-child-width-expand" uk-switcher="connect: .main-tabs-content" uk-height-match="target: .tab-header">
<!-- + (tab.active ? ' uk-active' : '')-->
<ul uk-tab class="uk-tab main-tabs uk-margin-remove uk-child-width-expand" uk-switcher="connect: .tabs-content" uk-height-match="target: .tab-header">
<li *ngFor="let tab of tabs" (click)="selectTab(tab)" [class.active]="tab.active" [class]="'uk-padding-remove '+(tab.statistics ? ' statistics ' : '')">
<a class="uk-width-1-1 uk-height-1-1">
<div class="tab-header">{{tab.title}}</div>
@ -30,26 +29,11 @@ import { TabComponent } from './tab.component';
</a>
</li>
</ul>
<div class="uk-switcher main-tabs-content">
<div class="uk-switcher tabs-content main-tabs-content">
<ng-content></ng-content>
</div>
<!-- <ul class="nav nav-tabs">-->
<!-- <li *ngFor="let tab of tabs" (click)="selectTab(tab)" [class.active]="tab.active">-->
<!-- <a href="#">{{tab.title}}</a>-->
<!-- </li>-->
<!-- </ul>-->
<!-- <ng-content></ng-content>-->
`//,
// styles: [
// `
// .tab-close {
// color: gray;
// text-align: right;
// cursor: pointer;
// }
// `
// ]
`
})
export class TabsComponent implements AfterContentInit {
@ -74,6 +58,5 @@ export class TabsComponent implements AfterContentInit {
// activate the tab the user has clicked on.
tab.active = true;
this.selectedActiveTab.emit(tab.tabId);
}
}

View File

@ -4,16 +4,17 @@ import { FormsModule } from '@angular/forms';
import {TabsComponent} from './tabs.component';
import {TabComponent} from "./tab.component";
import {SmallTabsComponent} from "./small-tabs.component";
@NgModule({
imports: [
CommonModule, FormsModule
],
declarations: [
TabsComponent, TabComponent
TabsComponent, TabComponent, SmallTabsComponent
],
exports: [
TabsComponent, TabComponent
TabsComponent, TabComponent, SmallTabsComponent
]
})
export class TabsModule { }