-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,76 @@ | ||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import { ChangeDetectionStrategy, Component, ElementRef, EventEmitter, Input, Output, SimpleChanges, ViewChild } from '@angular/core'; | ||
import { ItAbstractComponent } from '../../../abstracts/abstract.component'; | ||
import { NgIf } from '@angular/common'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { ItIconComponent } from '../../utils/icon/icon.component'; | ||
import { ItNavBarModule } from '../../navigation/navbar/navbar.module'; | ||
|
||
import { ItButtonDirective } from '../../core/button/button.directive'; | ||
import { inputToBoolean } from '../../../utils/coercion'; | ||
import { HeaderSticky, Sticky } from 'bootstrap-italia'; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'it-header', | ||
templateUrl: './header.component.html', | ||
styleUrls: ['./header.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [NgIf, TranslateModule, ItIconComponent, ItButtonDirective] | ||
imports: [NgIf, TranslateModule, ItIconComponent, ItButtonDirective, ItNavBarModule] | ||
}) | ||
export class ItHeaderComponent extends ItAbstractComponent { | ||
|
||
@Input({ transform: inputToBoolean }) light?: boolean; | ||
|
||
@Input({ transform: inputToBoolean }) showSlim?: boolean = true; | ||
@Input({ transform: inputToBoolean }) sticky?: boolean; | ||
|
||
@Input() slimTitle: string | undefined; | ||
|
||
@Input() loginStyle: 'none' | 'default' | 'full' = 'none'; | ||
@Input({ transform: inputToBoolean }) showSlim?: boolean = true; | ||
|
||
@Input({ transform: inputToBoolean }) smallHeader?: boolean = true; | ||
|
||
@Input({ transform: inputToBoolean }) showSearch?: boolean = true; | ||
|
||
@Input() slimTitle: string | undefined; | ||
|
||
@Input() loginStyle: 'none' | 'default' | 'full' = 'none'; | ||
|
||
@Output() loginClick: EventEmitter<Event>; | ||
|
||
@Output() searchClick: EventEmitter<Event>; | ||
|
||
/** | ||
* TODO: complete header | ||
*/ | ||
@ViewChild('headerWrapper') private headerWrapper?: ElementRef<HTMLButtonElement>; | ||
|
||
private stickyHeader?: HeaderSticky; | ||
|
||
|
||
constructor() { | ||
super(); | ||
|
||
this.loginClick = new EventEmitter<Event>(); | ||
this.searchClick = new EventEmitter<Event>(); | ||
} | ||
|
||
override ngAfterViewInit() { | ||
super.ngAfterViewInit(); | ||
this.updateListeners() | ||
} | ||
|
||
override ngOnChanges(changes: SimpleChanges): void { | ||
if (changes['sticky'] && changes['sticky'].currentValue == true && !changes['sticky'].firstChange) { | ||
this.updateListeners(); | ||
Check warning on line 59 in projects/design-angular-kit/src/lib/components/navigation/header/header.component.ts Codecov / codecov/patchprojects/design-angular-kit/src/lib/components/navigation/header/header.component.ts#L59
|
||
} | ||
if (changes['sticky'] && changes['sticky'].currentValue == false){ | ||
this.stickyHeader?._elementObj?._unsetSticky(); | ||
this.stickyHeader?._elementObj?.dispose() | ||
delete this.stickyHeader; | ||
this.stickyHeader = undefined; | ||
Check warning on line 65 in projects/design-angular-kit/src/lib/components/navigation/header/header.component.ts Codecov / codecov/patchprojects/design-angular-kit/src/lib/components/navigation/header/header.component.ts#L62-L65
|
||
} | ||
super.ngOnChanges(changes); | ||
Check warning on line 67 in projects/design-angular-kit/src/lib/components/navigation/header/header.component.ts Codecov / codecov/patchprojects/design-angular-kit/src/lib/components/navigation/header/header.component.ts#L67
|
||
} | ||
|
||
updateListeners() { | ||
if (!this.stickyHeader && this.headerWrapper && this.sticky) { | ||
this.stickyHeader = new HeaderSticky(this.headerWrapper.nativeElement); | ||
Check warning on line 72 in projects/design-angular-kit/src/lib/components/navigation/header/header.component.ts Codecov / codecov/patchprojects/design-angular-kit/src/lib/components/navigation/header/header.component.ts#L72
|
||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<li class="nav-item"> | ||
<ng-content></ng-content> | ||
</li> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import { ItAbstractComponent } from '../../../../abstracts/abstract.component'; | ||
import { NgIf } from '@angular/common'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'it-navbar-item', | ||
templateUrl: './navbar-item.component.html', | ||
styleUrls: ['./navbar-item.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [NgIf, TranslateModule] | ||
}) | ||
export class ItNavBarItemComponent extends ItAbstractComponent { | ||
|
||
constructor() { | ||
super(); | ||
Check warning on line 17 in projects/design-angular-kit/src/lib/components/navigation/navbar/navbar-item/navbar-item.component.ts Codecov / codecov/patchprojects/design-angular-kit/src/lib/components/navigation/navbar/navbar-item/navbar-item.component.ts#L17
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { ItNavBarComponent } from './navbar/navbar.component'; | ||
import { ItNavBarItemComponent } from './navbar-item/navbar-item.component'; | ||
|
||
const navbarComponents = [ItNavBarComponent, ItNavBarItemComponent]; | ||
|
||
@NgModule({ | ||
imports: navbarComponents, | ||
exports: navbarComponents | ||
}) | ||
export class ItNavBarModule { } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<nav class="navbar" [class.navbar-expand-lg]="expand" [class.has-megamenu]="megamenu" [attr.aria-label]="'it.navbar.aria-label-main'|translate"> | ||
<button (click)="toggleCollapse()" #collapseButton class="custom-navbar-toggler" type="button" [attr.aria-label]="'it.navbar.aria-label-toggle'|translate"> | ||
<it-icon name="burger"></it-icon> | ||
</button> | ||
<div #collapseView class="navbar-collapsable" style="display: none;"> | ||
<div class="overlay" style="display: none;"></div> | ||
<div class="close-div"> | ||
<button class="btn close-menu" type="button"> | ||
<span class="visually-hidden">{{'it.navbar.hide'|translate}}</span> | ||
<it-icon name="close-big"></it-icon> | ||
</button> | ||
</div> | ||
<div class="menu-wrapper"> | ||
<ul class="navbar-nav"> | ||
<ng-content select="[navItems]"></ng-content> | ||
</ul> | ||
</div> | ||
</div> | ||
</nav> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ChangeDetectionStrategy, Component, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core'; | ||
import { ItAbstractComponent } from '../../../../abstracts/abstract.component'; | ||
import { NgIf } from '@angular/common'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { ItIconComponent } from '../../../utils/icon/icon.component'; | ||
import { ItButtonDirective } from '../../../core/button/button.directive'; | ||
import { inputToBoolean } from '../../../../utils/coercion'; | ||
|
||
import { NavBarCollapsible } from 'bootstrap-italia'; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'it-navbar', | ||
templateUrl: './navbar.component.html', | ||
styleUrls: ['./navbar.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [NgIf, TranslateModule, ItIconComponent, ItButtonDirective] | ||
}) | ||
export class ItNavBarComponent extends ItAbstractComponent { | ||
|
||
private navbar?: NavBarCollapsible; | ||
@Input({ transform: inputToBoolean }) megamenu?: boolean; | ||
@Input({ transform: inputToBoolean }) expand?: boolean = true; | ||
@ViewChild('collapseButton') private collapseButton?: ElementRef<HTMLButtonElement>; | ||
@ViewChild('collapseView') private collapseView?: ElementRef<HTMLButtonElement>; | ||
|
||
|
||
constructor() { | ||
super(); | ||
} | ||
|
||
override ngAfterViewInit() { | ||
super.ngAfterViewInit(); | ||
if (this.collapseButton && this.collapseView) { | ||
this.navbar = NavBarCollapsible.getOrCreateInstance(this.collapseView.nativeElement); | ||
} | ||
} | ||
|
||
toggleCollapse() { | ||
this.navbar?.toggle(this.collapseButton?.nativeElement) | ||
Check warning on line 40 in projects/design-angular-kit/src/lib/components/navigation/navbar/navbar/navbar.component.ts Codecov / codecov/patchprojects/design-angular-kit/src/lib/components/navigation/navbar/navbar/navbar.component.ts#L40
|
||
} | ||
|
||
} |