feature/refactor-login #19
|
@ -1,159 +1,194 @@
|
|||
<div class="flex flex-col h-screen overflow-hidden">
|
||||
<!-- Header -->
|
||||
<header class="w-full navbar bg-primary text-primary-content z-40">
|
||||
<div class="flex-1">
|
||||
<a class="btn btn-ghost normal-case text-xl text-primary-content">
|
||||
[APP-NAME]
|
||||
</a>
|
||||
</div>
|
||||
<!-- Der Button wird nur auf mobilen Geräten angezeigt -->
|
||||
<div class="flex-none lg:hidden">
|
||||
<button
|
||||
(click)="toggleDrawer()"
|
||||
class="btn btn-square btn-ghost drawer-button">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
class="inline-block w-6 h-6 stroke-current">
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M4 6h16M4 12h16M4 18h16"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
<div class="flex h-screen w-screen bg-base-200">
|
||||
<div class="flex flex-col w-full lg:w-full bg-base-100 h-screen">
|
||||
<!-- Header mit dem Burger-Menü -->
|
||||
<header class="w-full navbar bg-primary text-primary-content z-40">
|
||||
<div class="flex-1">
|
||||
<a class="btn btn-ghost normal-case text-xl text-primary-content">
|
||||
[APP-NAME]
|
||||
</a>
|
||||
</div>
|
||||
<!-- Der Button wird nur auf mobilen Geräten angezeigt -->
|
||||
<div class="flex-none lg:hidden">
|
||||
<button
|
||||
(click)="toggleDrawer()"
|
||||
class="btn btn-square btn-ghost drawer-button">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
class="inline-block w-6 h-6 stroke-current">
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M4 6h16M4 12h16M4 18h16"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Hauptcontainer -->
|
||||
<div class="flex-1 flex overflow-hidden relative">
|
||||
<!-- Backdrop -->
|
||||
<div
|
||||
*ngIf="isDrawerOpen"
|
||||
class="fixed inset-0 bg-black bg-opacity-50 z-20 lg:hidden"
|
||||
(click)="toggleDrawer()"></div>
|
||||
<!-- Compact Mode Toggle Button für Desktop -->
|
||||
<div class="hidden lg:flex items-center space-x-2 mr-4">
|
||||
<button (click)="toggleCompactMode()" class="btn btn-square btn-ghost">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
class="inline-block w-6 h-6 stroke-current">
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M3 3h18v18H3V3z"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Drawer -->
|
||||
<div
|
||||
class="h-full transition-transform duration-300 ease-in-out bg-primary text-primary-content w-64 flex flex-col lg:translate-x-0"
|
||||
[ngClass]="{
|
||||
'translate-x-0': isDrawerOpen,
|
||||
'-translate-x-full': !isDrawerOpen,
|
||||
'fixed lg:relative': true,
|
||||
'top-0 left-0 z-30': true
|
||||
}">
|
||||
<aside class="h-full flex flex-col">
|
||||
<!-- Drawer-Inhalt -->
|
||||
<div class="flex-1 overflow-y-auto pt-16 lg:pt-0">
|
||||
<ul class="w-full p-0 m-0 [&_li>*]:rounded-none">
|
||||
<ng-container *ngFor="let item of menuItems">
|
||||
<li class="w-full">
|
||||
<ng-container *ngIf="!item.subitems; else submenu">
|
||||
<a
|
||||
[routerLink]="item.route"
|
||||
[class.active]="item.active"
|
||||
class="flex items-center w-full px-4 py-3 transition-colors duration-200 ease-in-out focus:outline-none hover:bg-base-300 hover:text-primary"
|
||||
[class.bg-base-100]="item.active"
|
||||
[class.text-base-content]="item.active"
|
||||
[class.text-primary]="item.active"
|
||||
[class.font-semibold]="item.active"
|
||||
role="menuitem"
|
||||
tabindex="0"
|
||||
(click)="onLinkClick()">
|
||||
<span
|
||||
class="flex-shrink-0 w-6 h-6 mr-3"
|
||||
[innerHTML]="item.icon"></span>
|
||||
<span class="flex-grow">{{ item.name }}</span>
|
||||
</a>
|
||||
</ng-container>
|
||||
<!-- Hauptcontainer -->
|
||||
<div class="flex-1 flex overflow-hidden">
|
||||
<!-- Drawer -->
|
||||
<div
|
||||
class="h-full transition-transform duration-300 ease-in-out bg-primary text-primary-content flex flex-col lg:translate-x-0"
|
||||
[ngClass]="{
|
||||
'w-16': isCompact && !isDrawerOpen,
|
||||
'w-64': isDrawerOpen,
|
||||
'fixed lg:relative': true,
|
||||
'top-0 left-0 z-30': true,
|
||||
'translate-x-0': isDrawerOpen,
|
||||
'-translate-x-full': !isDrawerOpen && !isCompact
|
||||
}">
|
||||
<aside class="h-full flex flex-col">
|
||||
<!-- Drawer-Inhalt -->
|
||||
<div class="flex-1 overflow-y-auto pt-16 lg:pt-0">
|
||||
<ul class="w-full p-0 m-0 [&_li>*]:rounded-none">
|
||||
<ng-container *ngFor="let item of menuItems">
|
||||
<li class="w-full">
|
||||
<ng-container *ngIf="!item.subitems; else submenu">
|
||||
<a
|
||||
[routerLink]="item.route"
|
||||
[class.active]="item.active"
|
||||
class="flex items-center w-full px-4 py-3 transition-colors duration-200 ease-in-out focus:outline-none hover:bg-base-300 hover:text-primary"
|
||||
[class.bg-base-100]="item.active"
|
||||
[class.text-base-content]="item.active"
|
||||
[class.text-primary]="item.active"
|
||||
[class.font-semibold]="item.active"
|
||||
role="menuitem"
|
||||
tabindex="0"
|
||||
(click)="onLinkClick()">
|
||||
<span
|
||||
class="flex-shrink-0 w-6 h-6 mr-3"
|
||||
[innerHTML]="item.icon"></span>
|
||||
<span class="flex-grow" *ngIf="isDrawerOpen">
|
||||
{{ item.name }}
|
||||
</span>
|
||||
</a>
|
||||
</ng-container>
|
||||
|
||||
<ng-template #submenu>
|
||||
<div
|
||||
(click)="toggleSubmenu(item, $event)"
|
||||
class="flex items-center w-full px-4 py-3 transition-colors duration-200 ease-in-out focus:outline-none hover:bg-base-300 hover:text-primary cursor-pointer"
|
||||
[class.bg-base-300]="item.active"
|
||||
[class.text-primary]="item.active"
|
||||
[class.font-semibold]="item.active"
|
||||
[class.bg-base-100]="item.isOpen"
|
||||
[class.text-base-content]="item.isOpen">
|
||||
<span
|
||||
class="flex-shrink-0 w-6 h-6 mr-3"
|
||||
[innerHTML]="item.icon"></span>
|
||||
<span class="flex-grow">{{ item.name }}</span>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="w-4 h-4 transition-transform"
|
||||
[class.rotate-180]="item.isOpen">
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M19.5 8.25l-7.5 7.5-7.5-7.5" />
|
||||
</svg>
|
||||
</div>
|
||||
<div
|
||||
[@submenuAnimation]="item.isOpen ? 'open' : 'closed'"
|
||||
class="overflow-hidden">
|
||||
<ul class="bg-base-100">
|
||||
<li *ngFor="let subItem of item.subitems" class="w-full">
|
||||
<a
|
||||
[routerLink]="subItem.route"
|
||||
[class.active]="subItem.active"
|
||||
class="flex items-center w-full px-4 pl-8 py-2 transition-colors duration-200 ease-in-out focus:outline-none hover:bg-base-300 hover:text-primary"
|
||||
[class.bg-base-300]="subItem.active"
|
||||
[class.text-primary]="subItem.active"
|
||||
[class.font-semibold]="subItem.active"
|
||||
[class.bg-base-100]="item.isOpen"
|
||||
[class.text-base-content]="item.isOpen"
|
||||
role="menuitem"
|
||||
tabindex="0"
|
||||
(click)="onLinkClick()">
|
||||
<span
|
||||
class="flex-shrink-0 w-5 h-5 mr-2"
|
||||
[innerHTML]="subItem.icon"></span>
|
||||
{{ subItem.name }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</ng-template>
|
||||
</li>
|
||||
</ng-container>
|
||||
</ul>
|
||||
</div>
|
||||
<hr class="border-t border-base-100" />
|
||||
|
||||
<div style="background-color: rgba(0, 0, 0, 0.2)">
|
||||
<ul class="w-full px-2 py-4">
|
||||
<ng-container *ngFor="let item of bottomMenuItems">
|
||||
<li>
|
||||
<button
|
||||
(click)="executeAction(item)"
|
||||
(keydown.enter)="executeAction(item)"
|
||||
class="py-2 px-4 rounded flex items-center space-x-2 bg-base-100 text-base-content hover:text-primary hover:font-semibold w-full text-left">
|
||||
<span [innerHTML]="item.icon"></span>
|
||||
<span>{{ item.name }}</span>
|
||||
</button>
|
||||
</li>
|
||||
</ng-container>
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<!-- Hauptinhalt -->
|
||||
<div class="flex-1 overflow-y-auto p-4 bg-base-100">
|
||||
<main class="flex-1">
|
||||
<div class="w-full h-full flex items-center justify-center">
|
||||
<div class="w-full max-w-5xl">
|
||||
<router-outlet></router-outlet>
|
||||
<ng-template #submenu>
|
||||
<div
|
||||
(click)="toggleSubmenu(item, $event)"
|
||||
class="flex items-center w-full px-4 py-3 transition-colors duration-200 ease-in-out focus:outline-none hover:bg-base-300 hover:text-primary cursor-pointer"
|
||||
[class.bg-base-300]="item.active"
|
||||
[class.text-primary]="item.active"
|
||||
[class.font-semibold]="item.active"
|
||||
[class.bg-base-100]="item.isOpen"
|
||||
[class.text-base-content]="item.isOpen">
|
||||
<span
|
||||
class="flex-shrink-0 w-6 h-6 mr-3"
|
||||
[innerHTML]="item.icon"></span>
|
||||
<span class="flex-grow" *ngIf="isDrawerOpen">
|
||||
{{ item.name }}
|
||||
</span>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="w-4 h-4 transition-transform"
|
||||
[class.rotate-180]="item.isOpen">
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M19.5 8.25l-7.5 7.5-7.5-7.5" />
|
||||
</svg>
|
||||
</div>
|
||||
<div
|
||||
[@submenuAnimation]="item.isOpen ? 'open' : 'closed'"
|
||||
class="overflow-hidden">
|
||||
<ul class="bg-base-100">
|
||||
<li
|
||||
*ngFor="let subItem of item.subitems"
|
||||
class="w-full">
|
||||
<a
|
||||
[routerLink]="subItem.route"
|
||||
[class.active]="subItem.active"
|
||||
class="flex items-center w-full px-4 pl-8 py-2 transition-colors duration-200 ease-in-out focus:outline-none hover:bg-base-300 hover:text-primary"
|
||||
[class.bg-base-300]="subItem.active"
|
||||
[class.text-primary]="subItem.active"
|
||||
[class.font-semibold]="subItem.active"
|
||||
[class.bg-base-100]="item.isOpen"
|
||||
[class.text-base-content]="item.isOpen"
|
||||
role="menuitem"
|
||||
tabindex="0"
|
||||
(click)="onLinkClick()">
|
||||
<span
|
||||
class="flex-shrink-0 w-5 h-5 mr-2"
|
||||
[innerHTML]="subItem.icon"></span>
|
||||
{{ subItem.name }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</ng-template>
|
||||
</li>
|
||||
</ng-container>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<hr class="border-t border-base-100" />
|
||||
|
||||
<div style="background-color: rgba(0, 0, 0, 0.2)">
|
||||
<ul class="w-full px-2 py-4">
|
||||
<ng-container *ngFor="let item of bottomMenuItems">
|
||||
<li>
|
||||
<button
|
||||
(click)="executeAction(item)"
|
||||
(keydown.enter)="executeAction(item)"
|
||||
class="py-2 px-4 rounded flex items-center space-x-2 bg-base-300 text-base-content hover:text-primary hover:font-semibold w-full text-left"
|
||||
role="menuitem"
|
||||
tabindex="0">
|
||||
<span [innerHTML]="item.icon"></span>
|
||||
<span *ngIf="isDrawerOpen">{{ item.name }}</span>
|
||||
</button>
|
||||
</li>
|
||||
</ng-container>
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<!-- Backdrop -->
|
||||
<!-- Backdrop -->
|
||||
<div
|
||||
*ngIf="isDrawerOpen && !isCompact && isMobile"
|
||||
class="fixed inset-0 bg-black bg-opacity-50 z-20"
|
||||
(click)="toggleDrawer()"></div>
|
||||
|
||||
<!-- Hauptinhalt -->
|
||||
<div
|
||||
class="flex-1 overflow-y-auto p-4 bg-base-100"
|
||||
[ngClass]="{
|
||||
'lg:ml-16': isCompact && !isDrawerOpen,
|
||||
'ml-0': !isDrawerOpen || isCompact
|
||||
}">
|
||||
<main class="flex-1">
|
||||
<div class="w-full h-full flex items-center justify-center">
|
||||
<div class="w-full max-w-5xl">
|
||||
<router-outlet></router-outlet>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
ElementRef,
|
||||
HostListener,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
} from '@angular/core';
|
||||
|
@ -82,6 +83,8 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
|||
public isDesktopCollapsed: boolean = false;
|
||||
public showMobileMenu: boolean = false;
|
||||
public isDrawerOpen: boolean = true;
|
||||
public isCompact: boolean = false;
|
||||
public isMobile: boolean = window.innerWidth < 1024;
|
||||
public menuItems: TopMenuItem[] = [
|
||||
{
|
||||
name: 'Dashboard',
|
||||
|
@ -154,12 +157,16 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
|||
private readonly authService: AuthService
|
||||
) {}
|
||||
|
||||
@HostListener('window:resize', ['$event'])
|
||||
public onResize(event: any): void {
|
||||
this.isMobile = event.target.innerWidth < 1024;
|
||||
this.adjustDrawerState(event.target.innerWidth);
|
||||
}
|
||||
|
||||
public ngOnInit(): void {
|
||||
this.adjustDrawerState(window.innerWidth);
|
||||
|
||||
window.addEventListener('resize', () => {
|
||||
this.adjustDrawerState(window.innerWidth);
|
||||
});
|
||||
window.addEventListener('resize', this.onResize.bind(this));
|
||||
|
||||
this.updateMenuState(this.router.url);
|
||||
|
||||
|
@ -175,8 +182,10 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
|||
});
|
||||
}
|
||||
|
||||
public onResize(): void {
|
||||
this.adjustDrawerState(window.innerWidth);
|
||||
public ngOnDestroy(): void {
|
||||
window.removeEventListener('resize', this.onResize.bind(this));
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
public onLinkClick(): void {
|
||||
|
@ -185,22 +194,23 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
}
|
||||
|
||||
public ngOnDestroy(): void {
|
||||
window.removeEventListener('resize', this.onResize.bind(this));
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
public toggleDrawer(): void {
|
||||
this.isDrawerOpen = !this.isDrawerOpen;
|
||||
this.isCompact = !this.isDrawerOpen; // Wechsel zwischen kompaktem und vollem Zustand
|
||||
}
|
||||
|
||||
public toggleCompactMode(): void {
|
||||
this.isCompact = !this.isCompact;
|
||||
this.isDrawerOpen = !this.isCompact; // Wenn kompaktes Mode aktiviert wird, Drawer geschlossen
|
||||
}
|
||||
|
||||
public adjustDrawerState(width: number): void {
|
||||
// Hier wird geprüft, ob wir uns im mobilen Bereich befinden.
|
||||
if (width < 1024) {
|
||||
this.toggleDrawer();
|
||||
this.isCompact = true;
|
||||
this.isDrawerOpen = false; // Kompaktmodus auf mobilen Geräten
|
||||
} else {
|
||||
this.toggleDrawer();
|
||||
this.isCompact = false;
|
||||
this.isDrawerOpen = true; // Vollmodus auf Desktop
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue