Project

General

Profile

1 61381 k.triantaf
/**
2
 * The main component that renders single TabComponent
3
 * instances.
4
 */
5
6
import {
7
  Component,
8
  ContentChildren,
9
  QueryList,
10
  AfterContentInit, Output, EventEmitter, ViewChild, ElementRef,
11
} from '@angular/core';
12
13
import { TabComponent } from './tab.component';
14
15
declare var UIkit: any;
16
17
@Component({
18
  selector: 'my-small-tabs',
19
  template: `
20
    <ng-container *ngIf="tabs.toArray().length > 2">
21
      <ul class="uk-hidden@m uk-tab main-tabs uk-margin-remove uk-child-width-expand">
22
  <!--      *ngFor="let activeTab of activeTabs"-->
23
        <li [class]="'uk-active uk-padding-remove '+(activeTab.statistics ? ' statistics ' : '')">
24
          <a class="uk-width-1-1 uk-height-1-1">
25
            <div class="tab-header">{{activeTab.title}}</div>
26
            <div *ngIf="activeTab.num" class="number">{{activeTab.num | number}}</div>
27
            <div *ngIf="activeTab.statistics" class="number">
28
              <svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
29
                <path d="M0 0h24v24H0z" fill="none"></path>
30
                <path d="M10 20h4V4h-4v16zm-6 0h4v-8H4v8zM16 9v11h4V9h-4z"></path>
31
              </svg>
32
            </div>
33
          </a>
34
        </li>
35
        <li class="uk-padding-remove fake-tab" uk-tooltip="title: More tabs">
36
          <a class="uk-text-center uk-width-1-1 uk-height-1-1 uk-icon">
37
            <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" data-svg="more">
38
              <circle cx="3" cy="10" r="2"></circle>
39
              <circle cx="10" cy="10" r="2"></circle>
40
              <circle cx="17" cy="10" r="2"></circle>
41
            </svg>
42
          </a>
43
          <div #drop_element uk-drop="mode: click" class="uk-drop">
44
            <div class="uk-card uk-card-body uk-card-default">
45
              <ul class="uk-list main-small-tabs" uk-switcher="connect: .small-tabs-content">
46
                <ng-container *ngFor="let tab of tabs.toArray()">
47
                  <li (click)="selectTab(tab)"
48
                      [class]="'uk-margin-top uk-margin-bottom uk-height-1-1 uk-width-1-1 ' + (tab == activeTab ? 'uk-hidden' : '')">
49
                    <a class="uk-display-block uk-height-1-1 uk-width-1-1">{{tab.title}}</a>
50
                  </li>
51
                </ng-container>
52
              </ul>
53
            </div>
54
          </div>
55
        </li>
56
      </ul>
57
58
      <div class="uk-hidden@m uk-switcher small-tabs-content main-tabs-content">
59
        <ng-content></ng-content>
60
      </div>
61
    </ng-container>
62
63
  `
64
})
65
export class SmallTabsComponent implements AfterContentInit {
66
  @ViewChild('drop_element') dropElement: ElementRef;
67
68
  @ContentChildren(TabComponent) tabs: QueryList<TabComponent>;
69
  @Output() public selectedActiveTab: EventEmitter<any> = new EventEmitter();
70
  public activeTab: TabComponent = null;
71
72
  // contentChildren are set
73
  ngAfterContentInit() {
74
    // if there is no active tab set, activate the first
75
    if(this.tabs && this.tabs.length > 0) {
76
      this.selectTab(this.tabs.first);
77
    }
78
  }
79
80
  selectTab(tab: TabComponent){
81
    this.activeTab = tab;
82
83
    // activate the tab the user has clicked on.
84
    this.selectedActiveTab.emit(tab.tabId);
85
86
    if(typeof document !== 'undefined' && this.dropElement) {
87
      UIkit.drop(this.dropElement.nativeElement).hide(false);
88
    }
89
  }
90
}