Skip to content

Instantly share code, notes, and snippets.

@JaimeStill
Created June 15, 2021 18:53
Show Gist options
  • Save JaimeStill/7737a4d4ca7260c29f083e2c42f50101 to your computer and use it in GitHub Desktop.
Save JaimeStill/7737a4d4ca7260c29f083e2c42f50101 to your computer and use it in GitHub Desktop.
Vertical Tab Component Infrastructure
export interface Tab {
link: string;
label: string;
hide?: boolean;
}
import {
Component,
Input
} from '@angular/core';
import { Tab } from '../../models';
@Component({
selector: 'vertical-nav',
templateUrl: 'vertical-nav.component.html',
styles: [
'.tab { text-align: center; }'
]
})
export class VerticalNavComponent {
@Input() heading: string;
@Input() headingStyle = 'mat-subheading-2 bold m4';
@Input() size = 180;
@Input() collapsedSize = 50;
@Input() expanded = true;
@Input() tabs: Array<Tab>;
@Input() tabAlignment = 'start stretch';
@Input() tabStyle = 'mat-subheading-2 p8 m0';
@Input() activeStyle = 'el-4 clip-right background-stacked';
calculateWidth = () => this.expanded
? this.size
: this.collapsedSize;
toggleExpanded = () => this.expanded = !this.expanded;
getTabs = () => this.tabs?.filter(tab => !tab.hide);
}
<section fxLayout="row"
fxLayoutAlign="start stretch"
fxFill>
<section fxLayout="column"
[fxLayoutAlign]="tabAlignment"
[style.width.px]="calculateWidth()">
<section fxLayout="row"
fxLayoutAlign="start center">
<button mat-icon-button
class="m4"
(click)="toggleExpanded()">
<mat-icon *ngIf="expanded">close_fullscreen</mat-icon>
<mat-icon *ngIf="!(expanded)">open_in_full</mat-icon>
</button>
<p *ngIf="heading && expanded"
[ngClass]="headingStyle">{{heading}}</p>
</section>
<p *ngFor="let tab of getTabs()"
class="tab cursor-pointer no-outline"
[ngClass]="tabStyle"
[routerLink]="tab.link"
[routerLinkActive]="activeStyle"
[routerLinkActiveOptions]="{exact: true}"
[matTooltip]="tab.label"
[matTooltipDisabled]="expanded">
<span *ngIf="expanded">{{tab.label}}</span>
<span *ngIf="!(expanded)">{{tab.label[0]}}</span>
</p>
</section>
<section fxLayout="column"
fxLayoutAlign="start stretch"
class="el-4"
fxFlex>
<ng-content></ng-content>
</section>
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment