2020-05-18 14:37:52 +02:00
|
|
|
/**
|
|
|
|
* The main component that renders single TabComponent
|
|
|
|
* instances.
|
|
|
|
*/
|
2022-04-06 16:01:25 +02:00
|
|
|
import {
|
|
|
|
AfterContentInit,
|
|
|
|
Component,
|
|
|
|
ContentChildren,
|
|
|
|
EventEmitter,
|
2022-04-08 17:26:27 +02:00
|
|
|
HostListener, Input,
|
2022-04-06 16:01:25 +02:00
|
|
|
Output,
|
|
|
|
QueryList,
|
|
|
|
} from '@angular/core';
|
2022-02-22 23:37:18 +01:00
|
|
|
import {TabComponent} from './tab.component';
|
2020-05-18 14:37:52 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-tabs',
|
2022-04-06 16:01:25 +02:00
|
|
|
template: `
|
2022-04-08 17:26:27 +02:00
|
|
|
<div id="mytabs" class="uk-grid uk-margin-remove-left">
|
2022-04-06 17:27:55 +02:00
|
|
|
<div class="uk-margin-medium-right uk-padding-small uk-width-expand uk-padding-remove-bottom" >
|
2022-04-06 16:01:25 +02:00
|
|
|
<div class=" uk-width-1-1" uk-slider="finite: true">
|
|
|
|
<div class="uk-position-relative " >
|
|
|
|
<div class="uk-slider-container ">
|
|
|
|
<ul class=" uk-slider-items " style="flex-wrap: nowrap !important;" >
|
|
|
|
<ng-container *ngFor="let tab of tabs.toArray(); let i=index">
|
|
|
|
<ng-container *ngIf="!tab.customClass">
|
|
|
|
<li [ngClass]="tab.customClass" (click)="selectTab(tab)" >
|
|
|
|
<ul class="uk-tab">
|
2022-04-06 17:02:15 +02:00
|
|
|
<li [class.uk-active]="tab.active" [class.uk-disabled]="tab.disabled">
|
2022-04-06 16:01:25 +02:00
|
|
|
<a class="uk-width-1-1 uk-height-1-1 uk-flex uk-flex-center" [ngClass]="tab.tabIcon ? 'uk-flex-column' : ''">
|
|
|
|
<icon *ngIf="tab.tabIcon" [svg]="tab.tabIcon.svg" [ratio]="tab.tabIcon.ratio?tab.tabIcon.ratio:1" class="uk-margin-small-bottom"
|
|
|
|
[ngClass]="(selected === tab.tabId)?tab.tabIcon.active:null"></icon>
|
|
|
|
<div>{{tab.title}}</div>
|
2022-04-06 17:02:15 +02:00
|
|
|
<div *ngIf="tab.num && !tab.disabled" class="">({{tab.num | number}})</div>
|
|
|
|
<div *ngIf="tab.disabled" class="">(-)</div>
|
2022-04-06 16:01:25 +02:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ng-container>
|
|
|
|
</ng-container>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="">
|
|
|
|
<a class="uk-position-center-left-out" uk-slider-item="previous"><span uk-icon="chevron-left"></span></a>
|
|
|
|
<a class="uk-position-center-right-out" uk-slider-item="next"><span uk-icon="chevron-right"></span></a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-06 17:02:15 +02:00
|
|
|
<ng-container *ngFor="let tab of tabs.toArray(); let i=index">
|
|
|
|
<ng-container *ngIf="tab.customClass">
|
2022-04-06 17:27:55 +02:00
|
|
|
<div class="uk-width-small uk-padding-small uk-padding-remove-bottom">
|
2022-04-06 17:02:15 +02:00
|
|
|
<ul class="uk-tab">
|
2022-04-06 16:01:25 +02:00
|
|
|
<li [ngClass]="tab.customClass" (click)="selectTab(tab)" [class.uk-active]="tab.active" >
|
2022-04-08 17:26:27 +02:00
|
|
|
<a class="uk-width-1-1 uk-height-1-1 uk-flex uk-flex-center featuredTab" [ngClass]="tab.tabIcon ? 'uk-flex-column' : ''">
|
|
|
|
<!--<icon *ngIf="tab.tabIcon" [svg]="tab.tabIcon.svg" [ratio]="tab.tabIcon.ratio?tab.tabIcon.ratio:1" class="uk-margin-small-bottom"
|
|
|
|
[ngClass]="(selected === tab.tabId)?tab.tabIcon.active:null"></icon>-->
|
|
|
|
<span *ngIf="tab.tabId=='statistics'" class="material-icons">bar_chart</span>
|
2022-04-06 17:02:15 +02:00
|
|
|
<div>{{tab.title}}</div>
|
2022-04-06 16:01:25 +02:00
|
|
|
<div *ngIf="tab.num" class="number">{{tab.num | number}}</div>
|
|
|
|
</a>
|
|
|
|
</li>
|
2022-04-06 17:02:15 +02:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</ng-container>
|
|
|
|
</ng-container>
|
2020-05-18 14:37:52 +02:00
|
|
|
</div>
|
2022-04-06 16:01:25 +02:00
|
|
|
|
2022-04-08 17:26:27 +02:00
|
|
|
`,
|
|
|
|
styles: [
|
|
|
|
`
|
|
|
|
#mytabs .uk-tab::before {
|
|
|
|
border-bottom: none;
|
|
|
|
}
|
|
|
|
#mytabs::before {
|
|
|
|
content: "";
|
|
|
|
position: absolute;
|
|
|
|
bottom: 0;
|
|
|
|
left: 20px;
|
|
|
|
right: 0;
|
|
|
|
border-bottom: 2px solid #eaeaea;
|
|
|
|
}
|
|
|
|
.featuredTab, .uk-active a.featuredTab{
|
|
|
|
color:#E96439 !important;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
]
|
2020-05-18 14:37:52 +02:00
|
|
|
})
|
2022-03-10 18:45:44 +01:00
|
|
|
export class TabsComponent implements AfterContentInit {
|
2022-04-06 16:01:25 +02:00
|
|
|
|
2022-02-22 23:37:18 +01:00
|
|
|
public customClass: string;
|
2020-05-18 14:37:52 +02:00
|
|
|
@ContentChildren(TabComponent) tabs: QueryList<TabComponent>;
|
|
|
|
@Output() public selectedActiveTab: EventEmitter<any> = new EventEmitter();
|
2022-04-08 17:26:27 +02:00
|
|
|
@Input() isSticky:boolean;
|
|
|
|
@Output() isStickyChange :EventEmitter<boolean> = new EventEmitter();
|
2022-03-10 18:45:44 +01:00
|
|
|
public selected: string;
|
2022-04-06 16:01:25 +02:00
|
|
|
disableScroll = false;
|
|
|
|
@HostListener("window:scroll", [])
|
|
|
|
onWindowScroll() {
|
|
|
|
this.scroll();
|
|
|
|
}
|
2022-03-10 18:45:44 +01:00
|
|
|
ngAfterContentInit() {
|
|
|
|
if(this.tabs.length > 0) {
|
|
|
|
this.selected = this.tabs.get(0).tabId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-06 16:01:25 +02:00
|
|
|
selectTab(tab: TabComponent, scroll=true){
|
|
|
|
console.log("Select tab ",tab.tabId);
|
|
|
|
this.unSelectTab(this.selected, tab.tabId);
|
|
|
|
tab.active = true;
|
2022-03-10 18:45:44 +01:00
|
|
|
this.selected = tab.tabId;
|
2020-05-26 22:12:37 +02:00
|
|
|
this.selectedActiveTab.emit(tab.tabId);
|
2022-04-06 16:01:25 +02:00
|
|
|
if(scroll) {
|
|
|
|
this.disableScroll = true;
|
|
|
|
setTimeout(() => {
|
|
|
|
window.scrollTo({
|
|
|
|
top: document.getElementById(tab.tabId) ? document.getElementById(tab.tabId).offsetTop - 180 : 250,
|
|
|
|
behavior: 'smooth'
|
|
|
|
});
|
|
|
|
setTimeout(() => {
|
|
|
|
this.disableScroll = false;
|
|
|
|
}, 600);
|
|
|
|
console.log(window.scrollY, tab.tabId, document.getElementById(tab.tabId))
|
|
|
|
}, 200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scroll(){
|
2022-04-08 17:26:27 +02:00
|
|
|
let tabDistanceFromCurrentViewTop = document.getElementById("main-tabs-div") ? document.getElementById("main-tabs-div").getBoundingClientRect().top : null;
|
|
|
|
if((tabDistanceFromCurrentViewTop <= 0)){
|
|
|
|
this.isStickyChange.emit(true);
|
|
|
|
this.isSticky =true;
|
|
|
|
}else if(!(tabDistanceFromCurrentViewTop <= 0)){
|
|
|
|
this.isStickyChange.emit(false);
|
|
|
|
this.isSticky =false;
|
|
|
|
}
|
2022-04-06 16:01:25 +02:00
|
|
|
if(this.disableScroll){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// console.log(window.scrollY)
|
|
|
|
let currentTabView = null;
|
|
|
|
let windowInnerHeight = window && window.innerHeight ? window.innerHeight : 300;
|
|
|
|
// console.log("find CT", windowInnerHeight)
|
|
|
|
for (let tab of this.tabs) {
|
|
|
|
|
|
|
|
let distanceFromCurrentViewTop = document.getElementById(tab.tabId) ? document.getElementById(tab.tabId).getBoundingClientRect().top : null;
|
|
|
|
// console.log(pos, distanceFromCurrentViewTop, windowInnerHeight/2);
|
|
|
|
if (distanceFromCurrentViewTop != null && distanceFromCurrentViewTop <= windowInnerHeight / 2) {
|
|
|
|
currentTabView = tab;
|
|
|
|
|
|
|
|
} else if (distanceFromCurrentViewTop != null && distanceFromCurrentViewTop > windowInnerHeight) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// console.log("current currentTabView", currentTabView.tabId)
|
|
|
|
if (currentTabView && this.selected != currentTabView.tabId) {
|
|
|
|
this.selectTab(currentTabView, false);
|
|
|
|
this.disableScroll =true;
|
|
|
|
setTimeout(() => {
|
|
|
|
this.disableScroll = false;
|
|
|
|
}, 600);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unSelectTab(oldTabId, newTabId){
|
|
|
|
for (let tab of this.tabs) {
|
|
|
|
if(tab.tabId == oldTabId){
|
|
|
|
tab.active = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.selected = newTabId;
|
2020-05-26 22:12:37 +02:00
|
|
|
}
|
2020-05-18 14:37:52 +02:00
|
|
|
}
|