File

my-lib/tabs/tabs.ts

Implements

OnInit AfterContentInit OnDestroy

Metadata

encapsulation ViewEncapsulation.None
selector tabs
styleUrls tabs.less,
patch.less
templateUrl ./tabs.html

Index

Properties
Methods
Inputs
HostBindings
Accessors

Constructor

constructor()

Inputs

activeIndex

Type: number

Default value: 0

animated

Type: boolean

prefixCls

Type: string

Default value: prefixCls

tabBarPosition
tabDirection

HostBindings

class
class:

Methods

ngAfterContentInit
ngAfterContentInit()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

_barUnderlineClass
_barUnderlineClass: Object
Type : Object
Default value : {}
_tabsBarWrap
_tabsBarWrap: Object
Type : Object
Default value : {}
_tabsClass
_tabsClass: Object
Type : Object
Default value : {}
_tabsContentWrapClass
_tabsContentWrapClass: Object
Type : Object
Default value : {}
_tabsDefaultBar
_tabsDefaultBar: Object
Type : Object
Default value : {}
bars
bars: QueryList<TabItemComponent>
Type : QueryList<TabItemComponent>
Decorators : ContentChildren
page
page: TabPanelComponent
Type : TabPanelComponent
panels
panels: QueryList<TabPanelComponent>
Type : QueryList<TabPanelComponent>
Decorators : ContentChildren
sub$
sub$: any
Type : any

Accessors

tabsBarWrapClass
gettabsBarWrapClass()
tabbsDefaultBar
gettabbsDefaultBar()
barUnderlineClass
getbarUnderlineClass()
tabsContentWrapClass
gettabsContentWrapClass()
tabDirection
settabDirection(val: )
tabBarPosition
settabBarPosition(val: )
animated
setanimated(val: boolean)
import {
    Component, OnInit, Input,
    Output, EventEmitter, HostBinding,
    ViewEncapsulation, ContentChildren, QueryList,
    Injectable, AfterContentInit, OnDestroy
} from '@angular/core';
import { prefixCls, tabsDefaultBarPrefixCls } from './var';
import { ansycClassObj, merge, setClassObj } from 'meepo-utils';
import { TabItemComponent } from './tab-item/tab-item';
import { TabPanelComponent } from './tab-panel/tab-panel';

@Component({
    selector: 'tabs',
    templateUrl: './tabs.html',
    styleUrls: ['./tabs.less', './patch.less'],
    encapsulation: ViewEncapsulation.None
})
export class TabsComponent implements OnInit, AfterContentInit, OnDestroy {
    @Input() prefixCls: string = prefixCls;
    @ContentChildren(TabItemComponent) bars: QueryList<TabItemComponent>;
    @ContentChildren(TabPanelComponent) panels: QueryList<TabPanelComponent>;

    // tabs
    _tabsClass: Object = {};
    _tabsBarWrap: Object = {};
    _tabsDefaultBar: Object = {};
    _barUnderlineClass: Object = {};
    _tabsContentWrapClass: Object = {};

    @HostBinding(`class`)
    get tabsClass() {
        return ansycClassObj(this._tabsClass);
    }

    get tabsBarWrapClass() {
        return ansycClassObj(this._tabsBarWrap);
    }

    get tabbsDefaultBar() {
        return ansycClassObj(this._tabsDefaultBar);
    }

    get barUnderlineClass() {
        return ansycClassObj(this._barUnderlineClass);
    }

    get tabsContentWrapClass() {
        return ansycClassObj(this._tabsContentWrapClass);
    }

    @Input()
    set tabDirection(val: 'horizontal' | 'vertical') {
        this._tabsClass = setClassObj('horizontal,vertical', this._tabsClass, val, prefixCls);
    }
    @Input()
    set tabBarPosition(val: 'left' | 'right' | 'top' | 'bottom') {
        this._tabsClass = setClassObj('left,right,top,bottom', this._tabsClass, val, prefixCls);
        this._tabsDefaultBar = setClassObj('left,right,top,bottom', this._tabsDefaultBar, val, tabsDefaultBarPrefixCls);
    }

    @Input()
    set animated(val: boolean) {
        this._tabsDefaultBar[`${tabsDefaultBarPrefixCls}-animated`] = val;
        this._tabsContentWrapClass[`${prefixCls}-content-wrap-animated`] = val;
    }

    @Input() activeIndex: number = 0;

    sub$: any;
    page: TabPanelComponent;

    constructor() {
        this._tabsClass[`${prefixCls}`] = true;
        this._tabsClass[`${prefixCls}-top`] = true;
        this._tabsClass[`${prefixCls}-horizontal`] = true;

        // tabs bar wrap
        this._tabsBarWrap[`${prefixCls}-bar-wrap`] = true;
        // tabs default bar 
        this._tabsDefaultBar[`${tabsDefaultBarPrefixCls}`] = true;

        this._barUnderlineClass[`${tabsDefaultBarPrefixCls}-underline`] = true;
        this._tabsDefaultBar[`${tabsDefaultBarPrefixCls}-animated`] = true;
        this._tabsDefaultBar[`${tabsDefaultBarPrefixCls}-top`] = true;

        this._tabsContentWrapClass[`${prefixCls}-content-wrap`] = true;
        this._tabsContentWrapClass[`${prefixCls}-content-wrap-animated`] = true;
    }

    ngOnInit() { }
    ngOnDestroy() {
        this.sub$.unsubscribe();
    }
    ngAfterContentInit() {
        const subs: any[] = [];
        const panels: any[] = [];
        this.bars.map((bar: TabItemComponent, index: number) => {
            subs.push(bar.onClick);
            panels[index] = bar.panel;
        });
        this.panels.reset(panels);
        this.sub$ = merge(...subs)
            .startWith(this.activeIndex)
            .map(res => Number(res))
            .subscribe((res: number) => {
                // 处理激活状态
                this.bars.map((bar, index) => {
                    bar.setActive(res === index);
                });
                this.activeIndex = res;
                this.page = this.panels.find((item, index, panels) => {
                    return res === index;
                });
            })
    }
}
<div [class]="tabsBarWrapClass">
    <div [class]="tabbsDefaultBar">
        <div [class]="prefixCls + '-default-bar-content'">
            <ng-container *ngFor="let bar of bars;index as i;">
                <ng-container *ngTemplateOutlet="bar.tpl;context:{$implicit:i}"></ng-container>
            </ng-container>
            <div [class]="barUnderlineClass" [style.left.%]="(activeIndex/bars.length) * 100" [style.width.%]="(1/bars.length) * 100"></div>
        </div>
    </div>
</div>
<div [class]="tabsContentWrapClass">
    <ng-container *ngTemplateOutlet="page?.tpl"></ng-container>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""