projects/tl-elements/src/lib/tl-mega-menu/tl-mega-menu-section/tl-mega-menu-section.component.ts
changeDetection | ChangeDetectionStrategy.Default |
selector | tl-mega-menu-section-component |
styleUrls | ./tl-mega-menu-section.component.scss |
templateUrl | ./tl-mega-menu-section.component.html |
Properties |
Methods |
Inputs |
HostBindings |
constructor(injector: Injector)
|
||||||
Parameters :
|
sectionTitle | |
Type : string
|
|
Default value : 'Section Title'
|
|
The text value to be displayed as section title in the tl-mega-menu dropdown menu. |
viewAllHref | |
Type : string
|
|
The href value for the view all button. |
inheritFontStyle | |
Type : "true" | "false"
|
|
Inherited from
TamuAbstractBaseComponent
|
|
Defined in
TamuAbstractBaseComponent:14
|
class.mobile-layout |
Type : any
|
Default value : this.isMobileLayout
|
Toggles the mobile-layout class on the root element. |
style.--wvr-nav-list-component-max-height |
Type : string
|
Allows for the override of the --tl-mobile-display-wvr-nav-list-component-max-height variable. |
style.--tl-font-family-sans-serif |
Type : string
|
Default value : 'var(--tl-default-font-family-sans-serif)'
|
Inherited from
TamuAbstractBaseComponent
|
Defined in
TamuAbstractBaseComponent:12
|
Allows for the override of the --tl-font-family-sans-serif css variable. |
style.--tl-font-size |
Type : string
|
Default value : 'var(--tl-default-font-size)'
|
Inherited from
TamuAbstractBaseComponent
|
Defined in
TamuAbstractBaseComponent:9
|
Allows for the override of the --tl-default-font-size css variable. |
close |
close()
|
Returns :
void
|
getElementHeight |
getElementHeight()
|
Returns :
number
|
getExpandedHeight |
getExpandedHeight()
|
Returns :
number
|
ngAfterContentInit |
ngAfterContentInit()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
open |
open()
|
Returns :
void
|
toggleOpenClose |
toggleOpenClose()
|
Returns :
void
|
active |
Default value : false
|
mobileLayout |
Default value : this.isMobileLayout
|
Decorators :
@HostBinding('class.mobile-layout')
|
Toggles the mobile-layout class on the root element. |
Private parent |
Type : TlMegaMenuComponent
|
wvrNavListComponentMaxHeight |
Type : string
|
Decorators :
@HostBinding('style.--wvr-nav-list-component-max-height')
|
Allows for the override of the --tl-mobile-display-wvr-nav-list-component-max-height variable. |
_fontFamily |
Type : string
|
Default value : 'var(--tl-default-font-family-sans-serif)'
|
Decorators :
@HostBinding('style.--tl-font-family-sans-serif')
|
Inherited from
TamuAbstractBaseComponent
|
Defined in
TamuAbstractBaseComponent:12
|
Allows for the override of the --tl-font-family-sans-serif css variable. |
_fontSize |
Type : string
|
Default value : 'var(--tl-default-font-size)'
|
Decorators :
@HostBinding('style.--tl-font-size')
|
Inherited from
TamuAbstractBaseComponent
|
Defined in
TamuAbstractBaseComponent:9
|
Allows for the override of the --tl-default-font-size css variable. |
import { AfterContentInit, ChangeDetectionStrategy, Component, HostBinding, Injector, Input, OnInit } from '@angular/core';
import { TamuAbstractBaseComponent } from '../../shared/tl-abstract-base.component';
import { TlMegaMenuComponent } from '../tl-mega-menu.component';
@Component({
selector: 'tl-mega-menu-section-component',
templateUrl: './tl-mega-menu-section.component.html',
styleUrls: ['./tl-mega-menu-section.component.scss'],
changeDetection: ChangeDetectionStrategy.Default
})
export class TlMegaMenuSectionComponent extends TamuAbstractBaseComponent implements AfterContentInit, OnInit {
private parent: TlMegaMenuComponent;
/** Toggles the mobile-layout class on the root element. */
@HostBinding('class.mobile-layout') mobileLayout = this.isMobileLayout;
/** Allows for the override of the --tl-mobile-display-wvr-nav-list-component-max-height variable. */
@HostBinding('style.--wvr-nav-list-component-max-height') wvrNavListComponentMaxHeight: string;
/** The text value to be displayed as section title in the tl-mega-menu dropdown menu. */
@Input() sectionTitle = 'Section Title';
/** The href value for the view all button. */
@Input() viewAllHref: string;
active = false;
// tslint:disable-next-line:unnecessary-constructor
constructor(injector: Injector) {
super(injector);
}
ngOnInit(): void {
super.ngOnInit();
const elem = this.eRef.nativeElement as HTMLElement;
const parentElem = elem.closest('tl-mega-menu');
if (parentElem) {
this.parent = this.componentRegistry.getComponentByElement(parentElem as HTMLElement) as TlMegaMenuComponent;
} else {
console.warn(`TlMegaMenuSectionComponent (${this.id}) is not within a TlMegaMenuComponent`);
}
}
ngAfterContentInit(): void {
super.ngAfterContentInit();
setTimeout(() => {
this.parent.addSection(this);
}, 1500);
}
open(): void {
// tslint:disable-next-line: radix
let mobileDisplayMaxHeight = parseInt(this.parent.mobileDisplayMaxHeight.replace('px', ''));
mobileDisplayMaxHeight += this.getExpandedHeight();
this.active = true;
this.parent.mobileDisplayMaxHeight = `${mobileDisplayMaxHeight}px`;
this.wvrNavListComponentMaxHeight = `${this.getExpandedHeight()}px`;
}
close(): void {
// tslint:disable-next-line: radix
let mobileDisplayMaxHeight = parseInt(this.parent.mobileDisplayMaxHeight.replace('px', ''));
this.active = false;
mobileDisplayMaxHeight -= this.getExpandedHeight();
this.parent.mobileDisplayMaxHeight = `${mobileDisplayMaxHeight}px`;
}
toggleOpenClose(): void {
if (this.active) {
this.close();
} else {
this.open();
}
}
getElementHeight(): number {
return (this.eRef.nativeElement as HTMLElement).clientHeight;
}
getExpandedHeight(): number {
const elem = (this.eRef.nativeElement as HTMLElement);
const lis = elem.querySelectorAll('tl-nav-li');
const liHeight = lis.length ? lis[0].clientHeight : 0;
return lis.length * liHeight;
}
}
<p *ngIf="!viewAllHref" class="section-title" [ngClass]="{ active: active, 'mobile-layout': isMobileLayout }" (click)="toggleOpenClose()">
{{sectionTitle}}
<tl-icon-component *ngIf="isMobileLayout" [set]="'bootstrap'" [name]="'chevron-right'" [size]="'16px'"></tl-icon-component>
</p>
<a class="section-title" href="{{viewAllHref}}" *ngIf="viewAllHref">
{{sectionTitle}}
</a>
<wvr-nav-list-component vertical="true" [ngClass]="{ active: active, 'mobile-layout': isMobileLayout }">
<template nav-list-items>
<ng-content select="tl-nav-li, tl-mega-menu-custom" ngProjectAs="wvre-nav-li"></ng-content>
</template>
</wvr-nav-list-component>
./tl-mega-menu-section.component.scss
@import "../../shared/styles/tl-variables.scss";
:host {
--wvr-nav-list-component-max-height: 450px;
width: 27%;
padding-bottom: 35px;
.section-title {
padding-bottom: 3px;
color: var(--tl-primary);
font-size: var(--tl-h3-font-size);
font-weight: 600;
border-bottom: 2px solid var(--tl-primary);
}
.section-title.mobile-layout {
tl-icon-component {
float: right;
transition: 0.5s ease-in-out;
transform: rotate(0deg);
}
}
.section-title.mobile-layout.active {
tl-icon-component {
float: right;
transition: 0.25s ease-in-out;
transform: rotate(90deg);
}
}
wvr-nav-list-component.mobile-layout {
display: inline-block;
overflow: hidden;
max-height: 0px;
transition: max-height 0.25s ease-in-out;
}
wvr-nav-list-component.mobile-layout.active {
max-height: var(--wvr-nav-list-component-max-height);
transition: max-height 1s ease-in-out;
}
p {
margin-bottom: 3px;
}
wvr-nav-list-component {
::ng-deep {
ul{
height: auto;
}
tl-nav-li {
width: 100%;
a {
padding: 4px 0px 6px 25px;
margin-bottom:2px;
color: var(--tl-deep-grey);
font-weight: lighter;
width: 100%;
display: block;
}
a:focus-within,
a:hover {
font-weight: bolder;
color: var(--tl-white);
background: var(--tl-deep-grey);
text-decoration: none;
}
}
}
}
}