diff --git a/projects/design-angular-kit/assets/i18n/en.json b/projects/design-angular-kit/assets/i18n/en.json index 4741ab60..850f7461 100644 --- a/projects/design-angular-kit/assets/i18n/en.json +++ b/projects/design-angular-kit/assets/i18n/en.json @@ -98,6 +98,11 @@ "website-search": "Search in the site", "navigation-path": "Navigation path" }, + "navbar": { + "aria-label-main": "Main navigation", + "aria-label-toggle": "Show/Hide navigation", + "hide": "Hide navigation" + }, "utils": { "selected": "Selected", "language-selection": "Language selection: {{lang}}", diff --git a/projects/design-angular-kit/assets/i18n/it.json b/projects/design-angular-kit/assets/i18n/it.json index 2a5b998b..5b9479d9 100644 --- a/projects/design-angular-kit/assets/i18n/it.json +++ b/projects/design-angular-kit/assets/i18n/it.json @@ -98,6 +98,11 @@ "website-search": "Cerca nel sito", "navigation-path": "Percorso di navigazione" }, + "navbar": { + "aria-label-main": "Navigazione principale", + "aria-label-toggle": "Mostra/Nascondi la navigazione", + "hide": "Nascondi la navigazione" + }, "utils": { "selected": "Selezionata", "language-selection": "Selezione lingua: {{lang}}", diff --git a/projects/design-angular-kit/src/lib/components/components.module.ts b/projects/design-angular-kit/src/lib/components/components.module.ts index 1c91b736..ad252426 100644 --- a/projects/design-angular-kit/src/lib/components/components.module.ts +++ b/projects/design-angular-kit/src/lib/components/components.module.ts @@ -32,6 +32,7 @@ import { ItBreadcrumbsModule } from './navigation/breadcrumbs/breadcrumbs.module import { ItHeaderComponent } from './navigation/header/header.component'; import { ItIconComponent } from './utils/icon/icon.component'; import { ItLanguageSwitcherComponent } from './utils/language-switcher/language-switcher.component'; +import { ItNavBarModule } from './navigation/navbar/navbar.module'; import { ItErrorPageComponent } from './utils/error-page/error-page.component'; import { ItChipComponent } from './core/chip/chip.component'; import { ItForwardDirective } from './core/forward/forward.directive'; @@ -84,7 +85,8 @@ const navigation = [ ItBackButtonComponent, ItBackToTopComponent, ItBreadcrumbsModule, - ItHeaderComponent + ItHeaderComponent, + ItNavBarModule ]; /** diff --git a/projects/design-angular-kit/src/lib/components/navigation/header/header.component.html b/projects/design-angular-kit/src/lib/components/navigation/header/header.component.html index de9b080a..272e3ec3 100644 --- a/projects/design-angular-kit/src/lib/components/navigation/header/header.component.html +++ b/projects/design-angular-kit/src/lib/components/navigation/header/header.component.html @@ -1,4 +1,4 @@ -
+
@@ -60,7 +60,16 @@
- - +
+
+
+
+ + + +
+
+
+
diff --git a/projects/design-angular-kit/src/lib/components/navigation/header/header.component.ts b/projects/design-angular-kit/src/lib/components/navigation/header/header.component.ts index d0bafd7a..0d0e2a24 100644 --- a/projects/design-angular-kit/src/lib/components/navigation/header/header.component.ts +++ b/projects/design-angular-kit/src/lib/components/navigation/header/header.component.ts @@ -1,10 +1,13 @@ -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 } from 'bootstrap-italia'; @Component({ standalone: true, @@ -12,29 +15,33 @@ import { inputToBoolean } from '../../../utils/coercion'; 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; @Output() searchClick: EventEmitter; - /** - * TODO: complete header - */ + @ViewChild('headerWrapper') private headerWrapper?: ElementRef; + + private stickyHeader?: HeaderSticky; + + constructor() { super(); @@ -42,4 +49,28 @@ export class ItHeaderComponent extends ItAbstractComponent { this.searchClick = new EventEmitter(); } + override ngAfterViewInit() { + super.ngAfterViewInit(); + this.updateListeners() + } + + override ngOnChanges(changes: SimpleChanges): void { + console.log(changes['sticky']) + if (changes['sticky'] && changes['sticky'].currentValue == true && !changes['sticky'].firstChange) { + this.updateListeners(); + } + if (changes['sticky'] && changes['sticky'].currentValue == false){ + this.stickyHeader?._elementObj?.dispose() + delete this.stickyHeader; + this.stickyHeader = undefined; + } + super.ngOnChanges(changes); + } + + updateListeners() { + if (!this.stickyHeader && this.headerWrapper && this.sticky) { + this.stickyHeader = HeaderSticky.getOrCreateInstance(this.headerWrapper.nativeElement); + } + } + } diff --git a/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar-item/navbar-item.component.html b/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar-item/navbar-item.component.html new file mode 100644 index 00000000..17864cd1 --- /dev/null +++ b/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar-item/navbar-item.component.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar-item/navbar-item.component.scss b/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar-item/navbar-item.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar-item/navbar-item.component.ts b/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar-item/navbar-item.component.ts new file mode 100644 index 00000000..5bb5446d --- /dev/null +++ b/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar-item/navbar-item.component.ts @@ -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(); + } + +} diff --git a/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar.module.ts b/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar.module.ts new file mode 100644 index 00000000..5912ef96 --- /dev/null +++ b/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar.module.ts @@ -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 { } diff --git a/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar/navbar.component.html b/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar/navbar.component.html new file mode 100644 index 00000000..95ba9ca1 --- /dev/null +++ b/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar/navbar.component.html @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar/navbar.component.scss b/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar/navbar.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar/navbar.component.ts b/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar/navbar.component.ts new file mode 100644 index 00000000..de9b9031 --- /dev/null +++ b/projects/design-angular-kit/src/lib/components/navigation/navbar/navbar/navbar.component.ts @@ -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; + @ViewChild('collapseView') private collapseView?: ElementRef; + + + 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) + } + +} diff --git a/projects/design-angular-kit/src/public_api.ts b/projects/design-angular-kit/src/public_api.ts index 2bd18a57..d7294d4b 100644 --- a/projects/design-angular-kit/src/public_api.ts +++ b/projects/design-angular-kit/src/public_api.ts @@ -87,6 +87,10 @@ export * from './lib/components/navigation/breadcrumbs/breadcrumb/breadcrumb.com export * from './lib/components/navigation/breadcrumbs/breadcrumb-item/breadcrumb-item.component'; export * from './lib/components/navigation/header/header.component'; +export * from './lib/components/navigation/navbar/navbar/navbar.component'; +export * from './lib/components/navigation/navbar/navbar-item/navbar-item.component'; +export * from './lib/components/navigation/navbar/navbar.module'; + // Utils components export * from './lib/components/utils/error-page/error-page.component'; diff --git a/src/app/header/header-example/header-example.component.html b/src/app/header/header-example/header-example.component.html index 004d24d9..a7cb3119 100644 --- a/src/app/header/header-example/header-example.component.html +++ b/src/app/header/header-example/header-example.component.html @@ -1,18 +1,12 @@

Componente Header

+ + Link 1 (attivo) + Link 2 (disabilitato) + Link 3 + Link 4 + + + Menu dropdown + + Link lista 1 + Link lista 2 + + + + - - -
-
-
Opzioni
- - -
-
-
Tipologia di login
- - - +
+
+
Opzioni
+ + + +
+
+
Tipologia di login
+ + + +
\ No newline at end of file diff --git a/src/app/header/header-example/header-example.component.ts b/src/app/header/header-example/header-example.component.ts index f42ca972..de14b294 100644 --- a/src/app/header/header-example/header-example.component.ts +++ b/src/app/header/header-example/header-example.component.ts @@ -7,6 +7,7 @@ import { Component } from '@angular/core'; }) export class HeaderExampleComponent { light = false; + sticky = false; search = false; login = 'none'; }