-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kit):
Tabs
add vertical option (#2862)
- Loading branch information
Showing
14 changed files
with
313 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
projects/demo/src/modules/components/tabs/examples/8/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<section class="content"> | ||
<nav | ||
tuiTabs | ||
vertical="left" | ||
class="left" | ||
> | ||
<button tuiTab>Item 1</button> | ||
<button tuiTab>Item 2</button> | ||
<button tuiTab>Item 3 with name so long it spans multiple lines</button> | ||
</nav> | ||
<div> | ||
<p> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce nec ultricies enim, vel molestie orci. In | ||
finibus diam ac nulla accumsan, vel condimentum lorem ultricies. In feugiat mauris sem, ac ultricies metus | ||
aliquet nec. Ut a iaculis metus, id vestibulum justo. Nulla id ante semper, aliquam augue vitae, | ||
sollicitudin massa. Sed congue nisi sed ullamcorper mollis. Vivamus volutpat non est a vestibulum. Sed in | ||
elementum odio. Proin a lectus ac quam vulputate ornare nec id mi. Maecenas pharetra ultricies efficitur. | ||
Etiam sit amet vulputate elit. Donec ut dapibus nunc. Nullam vestibulum diam eros, ac euismod velit porta | ||
ac. Ut ut auctor velit. Nulla ac lobortis erat, ut tempor neque. | ||
</p> | ||
<p> | ||
Donec quis lacus leo. Mauris quis vestibulum mauris. Sed hendrerit odio id blandit iaculis. Nulla ac gravida | ||
ligula, tristique tempus eros. Mauris efficitur risus quis arcu pharetra, eu semper ex rutrum. Aenean justo | ||
felis, imperdiet non justo vel, fringilla maximus nibh. Vestibulum ut imperdiet ex, vel varius odio. Nunc | ||
nec lorem non odio mollis porta. In gravida accumsan lacus, vitae egestas lectus aliquet sed. Morbi justo | ||
orci, fringilla sit amet consectetur vel, consectetur a nibh. Sed eu porttitor ante. Morbi imperdiet ligula | ||
id velit dignissim malesuada. Vestibulum blandit posuere sem. | ||
</p> | ||
</div> | ||
</section> | ||
|
||
<section class="content"> | ||
<div> | ||
<p> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce nec ultricies enim, vel molestie orci. In | ||
finibus diam ac nulla accumsan, vel condimentum lorem ultricies. In feugiat mauris sem, ac ultricies metus | ||
aliquet nec. Ut a iaculis metus, id vestibulum justo. Nulla id ante semper, aliquam augue vitae, | ||
sollicitudin massa. Sed congue nisi sed ullamcorper mollis. Vivamus volutpat non est a vestibulum. Sed in | ||
elementum odio. Proin a lectus ac quam vulputate ornare nec id mi. Maecenas pharetra ultricies efficitur. | ||
Etiam sit amet vulputate elit. Donec ut dapibus nunc. Nullam vestibulum diam eros, ac euismod velit porta | ||
ac. Ut ut auctor velit. Nulla ac lobortis erat, ut tempor neque. | ||
</p> | ||
<p> | ||
Donec quis lacus leo. Mauris quis vestibulum mauris. Sed hendrerit odio id blandit iaculis. Nulla ac gravida | ||
ligula, tristique tempus eros. Mauris efficitur risus quis arcu pharetra, eu semper ex rutrum. Aenean justo | ||
felis, imperdiet non justo vel, fringilla maximus nibh. Vestibulum ut imperdiet ex, vel varius odio. Nunc | ||
nec lorem non odio mollis porta. In gravida accumsan lacus, vitae egestas lectus aliquet sed. Morbi justo | ||
orci, fringilla sit amet consectetur vel, consectetur a nibh. Sed eu porttitor ante. Morbi imperdiet ligula | ||
id velit dignissim malesuada. Vestibulum blandit posuere sem. | ||
</p> | ||
</div> | ||
<tui-tabs | ||
vertical="right" | ||
class="right" | ||
> | ||
<a | ||
tuiTab | ||
routerLink="/components/button" | ||
routerLinkActive | ||
> | ||
Button | ||
</a> | ||
<a | ||
tuiTab | ||
routerLink="/navigation/tabs" | ||
routerLinkActive | ||
> | ||
Tabs | ||
</a> | ||
<a | ||
tuiTab | ||
routerLink="/components/input" | ||
routerLinkActive | ||
> | ||
Input | ||
</a> | ||
</tui-tabs> | ||
</section> |
16 changes: 16 additions & 0 deletions
16
projects/demo/src/modules/components/tabs/examples/8/index.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.content { | ||
display: flex; | ||
margin: 2rem 0; | ||
} | ||
|
||
.left { | ||
margin-right: 2rem; | ||
min-width: 10rem; | ||
width: 10rem; | ||
} | ||
|
||
.right { | ||
margin-left: 2rem; | ||
min-width: 10rem; | ||
width: 10rem; | ||
} |
12 changes: 12 additions & 0 deletions
12
projects/demo/src/modules/components/tabs/examples/8/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {Component} from '@angular/core'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
|
||
@Component({ | ||
selector: `tui-tabs-example-8`, | ||
templateUrl: `./index.html`, | ||
styleUrls: [`./index.less`], | ||
changeDetection, | ||
encapsulation, | ||
}) | ||
export class TuiTabsExample8 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
export * from './tab/tab.component'; | ||
export * from './tab/tab.providers'; | ||
export * from './tabs.directive'; | ||
export * from './tabs.module'; | ||
export * from './tabs/tabs.component'; | ||
export * from './tabs-options'; | ||
export * from './tabs-vertical/tabs-vertical.component'; | ||
export * from './tabs-with-more/tabs-with-more.component'; | ||
export * from './tabs-with-more/tabs-with-more.providers'; | ||
export * from './underline/underline.component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
projects/kit/components/tabs/tabs-vertical/tabs-vertical.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
HostBinding, | ||
HostListener, | ||
Inject, | ||
Input, | ||
} from '@angular/core'; | ||
import {tuiDefaultProp} from '@taiga-ui/cdk'; | ||
import {TuiHorizontalDirection} from '@taiga-ui/core'; | ||
|
||
import {TuiTabsDirective} from '../tabs.directive'; | ||
|
||
@Component({ | ||
selector: `tui-tabs[vertical], nav[tuiTabs][vertical]`, | ||
template: ` | ||
<ng-content></ng-content> | ||
`, | ||
styleUrls: [`./tabs-vertical.style.less`], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class TuiTabsVerticalComponent { | ||
@Input() | ||
@HostBinding(`attr.data-vertical`) | ||
@tuiDefaultProp() | ||
vertical: TuiHorizontalDirection = `left`; | ||
|
||
constructor(@Inject(TuiTabsDirective) private readonly tabs: TuiTabsDirective) {} | ||
|
||
@HostListener(`keydown.arrowDown.prevent`, [`$event.target`, `1`]) | ||
@HostListener(`keydown.arrowUp.prevent`, [`$event.target`, `-1`]) | ||
onKeyDownArrow(current: HTMLElement, step: number): void { | ||
this.tabs.moveFocus(current, step); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
projects/kit/components/tabs/tabs-vertical/tabs-vertical.style.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@import 'taiga-ui-local'; | ||
|
||
:host { | ||
display: flex; | ||
flex-direction: column; | ||
font: var(--tui-font-text-m); | ||
color: var(--tui-text-02); | ||
box-shadow: inset -1px 0 var(--tui-base-03); | ||
|
||
&[data-vertical='right'] { | ||
box-shadow: inset 1px 0 var(--tui-base-03); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
AfterViewChecked, | ||
Directive, | ||
ElementRef, | ||
EventEmitter, | ||
HostListener, | ||
Inject, | ||
Input, | ||
Output, | ||
} from '@angular/core'; | ||
import {tuiDefaultProp, tuiMoveFocus} from '@taiga-ui/cdk'; | ||
|
||
import {TUI_TAB_ACTIVATE} from './tab/tab.providers'; | ||
|
||
@Directive({ | ||
selector: `tui-tabs, nav[tuiTabs]`, | ||
}) | ||
export class TuiTabsDirective implements AfterViewChecked { | ||
@Input() | ||
@tuiDefaultProp() | ||
activeItemIndex = 0; | ||
|
||
@Output() | ||
readonly activeItemIndexChange = new EventEmitter<number>(); | ||
|
||
constructor( | ||
@Inject(ElementRef) private readonly elementRef: ElementRef<HTMLElement>, | ||
) {} | ||
|
||
get tabs(): readonly HTMLElement[] { | ||
return Array.from( | ||
this.elementRef.nativeElement.querySelectorAll<HTMLElement>(`[tuiTab]`), | ||
); | ||
} | ||
|
||
get activeElement(): HTMLElement | null { | ||
return this.tabs[this.activeItemIndex] || null; | ||
} | ||
|
||
@HostListener(`${TUI_TAB_ACTIVATE}.stop`, [`$event.target`]) | ||
onActivate(element: HTMLElement): void { | ||
const index = this.tabs.findIndex(tab => tab === element); | ||
|
||
if (index === this.activeItemIndex) { | ||
return; | ||
} | ||
|
||
this.activeItemIndexChange.emit(index); | ||
this.activeItemIndex = index; | ||
} | ||
|
||
moveFocus(current: HTMLElement, step: number): void { | ||
const {tabs} = this; | ||
|
||
tuiMoveFocus(tabs.indexOf(current), tabs, step); | ||
} | ||
|
||
ngAfterViewChecked(): void { | ||
const {tabs, activeElement} = this; | ||
|
||
tabs.forEach(nativeElement => { | ||
const active = nativeElement === activeElement; | ||
|
||
nativeElement.classList.toggle(`_active`, active); | ||
nativeElement.setAttribute(`tabIndex`, active ? `0` : `-1`); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.