4.0.0 • Published 2 years ago

@terminus/ui-tabs v4.0.0

Weekly downloads
21
License
MIT
Repository
github
Last release
2 years ago

CI/CD Status Codecov MIT License
NPM version Library size

Table of Contents

Installation

Use the ng add command to quickly install all the needed dependencies:

ng add @terminus/ui-tabs

CSS imports

In your top-level stylesheet, add these imports:

@import '~@terminus/design-tokens/css/library-design-tokens.css';
@import '~@terminus/ui-styles/terminus-ui.css';

CSS resources

Load the needed font families by adding this link to the <head> of your application:

<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,500;0,700;1,400&display=swap" rel="stylesheet">

Usage

In its most simple form this must consist of a collection with at least one tab:

<ts-tab-collection>
  <ts-tab label="First">Content 1</ts-tab>
</ts-tab-collection>

Label alignment

There are four horizontal layout options for tab labels.

PositionDescription
startAlign tab labels to the left (default)
centerCenter tab labels to content
endAlign tab labels to the right
stretchForce tab labels to fill all available space
<ts-tab-collection headerPosition="stretch">
  ...
</ts-tab-collection>

Header position

The collection of tab labels are positioned above the tab content by default. This can be inverted so the labels appear below the tab content:

<ts-tab-collection headerPosition="below">
  ...
</ts-tab-collection>

Dynamically insert a tab

Tabs can be dynamically added and removed by using a loop to generate the tabs:

<ts-tab-collection>
  <ts-tab *ngFor="let tab of myTabs; let index = index" [label]="tab">
    Content for {{ tab }} tab
  </ts-tab>
</ts-tab-collection>

Or by showing and hiding via ngIf:

<ts-tab-collection>
  <ts-tab label="First">
    Content 1
  </ts-tab>

  <ts-tab label="Second" *ngIf="shouldIncludeTab">
    Content 2
  </ts-tab>
</ts-tab-collection>

Custom label template

If label customization is needed a template can be defined to contain custom label markup by using the tsTabLabel directive on an ng-template tag:

<ts-tab-collection>
  <ts-tab>
    <ng-template tsTabLabel>
      <ts-icon>home</ts-icon>
      First
    </ng-template>

    Content 1
  </ts-tab>
</ts-tab-collection>

Lazy load tab content

By default tab content is eagerly loaded. Tab content can be lazily loaded by using the tsTabContent directive on an ng-template tag:

<ts-tab-collection>
  <ts-tab label="First">
    <ng-template tsTabContent>
      Content 1
    </ng-template>
  </ts-tab>
</ts-tab-collection>

Events

EventDescriptionPayload
animationFinishedFired when the tab animation is finishedvoid
focusChangeFired when the tab labels focus changesTsTabChangeEvent
selectedIndexChangeFired when the index of the selected tab changesnumber
selectedTabChangeFired when the selected tab changesTsTabChangeEvent
<ts-tab-collection (selectedTabChange)="whenTabChanges($event)">
  ...
</ts-tab-collection>

The TsTabChangeEvent structure:

class TsTabChangeEvent {
  constructor(
    // The tab's current index
    public index: number,
    // The tab
    public tab: TsTabComponent,
  ) {}
}
4.0.1

2 years ago

4.0.0

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.13

4 years ago

2.0.12

4 years ago

2.0.11

4 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago