2026-04-28 08:43:57 -04:00
|
|
|
import { ChangeDetectionStrategy, Component, HostListener, signal, OnDestroy, OnInit } from '@angular/core';
|
2026-04-25 19:02:57 +00:00
|
|
|
import { RouterLink, RouterLinkActive } from '@angular/router';
|
|
|
|
|
import { MatIconModule } from '@angular/material/icon';
|
|
|
|
|
import { MatBadgeModule } from '@angular/material/badge';
|
|
|
|
|
import { NAV_DESTINATIONS } from '../../models/nav.model';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-nav-rail',
|
|
|
|
|
standalone: true,
|
|
|
|
|
imports: [RouterLink, RouterLinkActive, MatIconModule, MatBadgeModule],
|
|
|
|
|
templateUrl: './nav-rail.component.html',
|
|
|
|
|
styleUrl: './nav-rail.component.scss',
|
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
|
|
})
|
2026-04-28 08:43:57 -04:00
|
|
|
export class NavRailComponent implements OnInit, OnDestroy {
|
2026-04-25 19:02:57 +00:00
|
|
|
protected readonly destinations = NAV_DESTINATIONS;
|
|
|
|
|
protected readonly expanded = signal(false);
|
2026-04-28 08:43:57 -04:00
|
|
|
protected readonly isExpandedBreakpoint = signal(false);
|
|
|
|
|
|
|
|
|
|
private readonly EXPANDED_BP = 1024;
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.updateBreakpoint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@HostListener('window:resize')
|
|
|
|
|
onResize(): void {
|
|
|
|
|
this.updateBreakpoint();
|
|
|
|
|
}
|
2026-04-25 19:02:57 +00:00
|
|
|
|
|
|
|
|
@HostListener('mouseenter')
|
|
|
|
|
onHoverIn(): void {
|
2026-04-28 08:43:57 -04:00
|
|
|
if (this.isExpandedBreakpoint()) {
|
|
|
|
|
this.expanded.set(true);
|
|
|
|
|
}
|
2026-04-25 19:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@HostListener('mouseleave')
|
|
|
|
|
onHoverOut(): void {
|
2026-04-28 08:43:57 -04:00
|
|
|
if (this.isExpandedBreakpoint()) {
|
|
|
|
|
this.expanded.set(false);
|
|
|
|
|
}
|
2026-04-25 19:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleExpand(): void {
|
2026-04-28 08:43:57 -04:00
|
|
|
if (this.isExpandedBreakpoint()) {
|
|
|
|
|
this.expanded.update(v => !v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private updateBreakpoint(): void {
|
|
|
|
|
const isExpanded = window.innerWidth >= this.EXPANDED_BP;
|
|
|
|
|
this.isExpandedBreakpoint.set(isExpanded);
|
|
|
|
|
// Collapse when leaving expanded breakpoint
|
|
|
|
|
if (!isExpanded) {
|
|
|
|
|
this.expanded.set(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
|
// Cleanup is handled by HostListener auto-unsubscribe
|
2026-04-25 19:02:57 +00:00
|
|
|
}
|
|
|
|
|
}
|