Expand menu item clickable area to full width for better UX (#1107)
This commit is contained in:
@@ -31,49 +31,61 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class="flex flex-row items-center justify-between hover:bg-surface-800 rounded-md">
|
<div
|
||||||
|
class="flex flex-row items-center justify-between hover:bg-surface-800 rounded-md cursor-pointer"
|
||||||
|
(click)="triggerLink()"
|
||||||
|
>
|
||||||
@if ((item.routerLink && !item.items)) {
|
@if ((item.routerLink && !item.items)) {
|
||||||
<a
|
<a
|
||||||
|
#link
|
||||||
(click)="itemClick($event)"
|
(click)="itemClick($event)"
|
||||||
[ngClass]="item.class"
|
[ngClass]="item.class + ' flex items-center gap-2 w-full'"
|
||||||
[routerLink]="item.routerLink" routerLinkActive="active-route"
|
[routerLink]="item.routerLink"
|
||||||
|
routerLinkActive="active-route"
|
||||||
[routerLinkActiveOptions]="item.routerLinkActiveOptions || { paths: 'exact', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored' }"
|
[routerLinkActiveOptions]="item.routerLinkActiveOptions || { paths: 'exact', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored' }"
|
||||||
[fragment]="item.fragment" [queryParamsHandling]="item.queryParamsHandling"
|
[fragment]="item.fragment"
|
||||||
|
[queryParamsHandling]="item.queryParamsHandling"
|
||||||
[preserveFragment]="item.preserveFragment"
|
[preserveFragment]="item.preserveFragment"
|
||||||
[skipLocationChange]="item.skipLocationChange" [replaceUrl]="item.replaceUrl" [state]="item.state"
|
[skipLocationChange]="item.skipLocationChange"
|
||||||
|
[replaceUrl]="item.replaceUrl"
|
||||||
|
[state]="item.state"
|
||||||
[queryParams]="item.queryParams"
|
[queryParams]="item.queryParams"
|
||||||
[attr.target]="item.target" tabindex="0" pRipple>
|
[attr.target]="item.target"
|
||||||
|
tabindex="0"
|
||||||
|
pRipple
|
||||||
|
>
|
||||||
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
|
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
|
||||||
<span class="layout-menuitem-text w-full truncate">
|
<span class="layout-menuitem-text w-full truncate">
|
||||||
{{ item.label }}
|
{{ item.label }}
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|
||||||
<span>
|
<span>
|
||||||
@if (item.type === 'Library' || item.type === 'Shelf' || item.type === 'magicShelfItem') {
|
@if (item.type === 'Library' || item.type === 'Shelf' || item.type === 'magicShelfItem') {
|
||||||
@if ((item.type !== 'Library' || (admin || canManipulateLibrary)) && item.label !== 'Unshelved' && item.label !== 'Kobo') {
|
@if ((item.type !== 'Library' || (admin || canManipulateLibrary)) && item.label !== 'Unshelved' && item.label !== 'Kobo') {
|
||||||
<p-button
|
<p-button
|
||||||
(click)="entitymenu.toggle($event)"
|
(click)="entitymenu.toggle($event); $event.stopPropagation()"
|
||||||
(mouseover)="hovered = true"
|
(mouseover)="hovered = true"
|
||||||
(mouseleave)="hovered = false"
|
(mouseleave)="hovered = false"
|
||||||
[text]="true"
|
[text]="true"
|
||||||
[outlined]="false"
|
[outlined]="false"
|
||||||
[rounded]="true"
|
[rounded]="true"
|
||||||
[label]="hovered ? '' : (item.bookCount$ | async)?.toString() || ''"
|
[label]="hovered ? '' : (item.bookCount$ | async)?.toString() || ''"
|
||||||
[icon]="hovered ? 'pi pi-ellipsis-v' : ''"
|
[icon]="hovered ? 'pi pi-ellipsis-v' : ''"
|
||||||
[style.height]="'30px'"
|
[style.height]="'30px'"
|
||||||
[style.display]="'flex'">
|
[style.display]="'flex'"
|
||||||
</p-button>
|
></p-button>
|
||||||
}
|
}
|
||||||
<p-menu #entitymenu [model]="item.menu" [popup]="true" appendTo="body"></p-menu>
|
<p-menu #entitymenu [model]="item.menu" [popup]="true" appendTo="body"></p-menu>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (item.type === 'Library' && (!admin && !canManipulateLibrary) || item.type === 'All Books' || item.label === 'Unshelved' || item.label === 'Kobo') {
|
@if (item.type === 'Library' && (!admin && !canManipulateLibrary) || item.type === 'All Books' || item.label === 'Unshelved' || item.label === 'Kobo') {
|
||||||
<p class="text-[var(--primary-color)] pr-3">
|
<p class="text-[var(--primary-color)] pr-3">
|
||||||
{{ (item.bookCount$ | async)?.toString() || '0' }}
|
{{ (item.bookCount$ | async)?.toString() || '0' }}
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div [@children]="isExpanded(key) ? 'expanded' : 'collapsed'" style="overflow: hidden;">
|
<div [@children]="isExpanded(key) ? 'expanded' : 'collapsed'" style="overflow: hidden;">
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, HostBinding, Input, OnDestroy, OnInit} from '@angular/core';
|
import {Component, ElementRef, HostBinding, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
||||||
import {NavigationEnd, Router, RouterLink, RouterLinkActive} from '@angular/router';
|
import {NavigationEnd, Router, RouterLink, RouterLinkActive} from '@angular/router';
|
||||||
import {animate, state, style, transition, trigger} from '@angular/animations';
|
import {animate, state, style, transition, trigger} from '@angular/animations';
|
||||||
import {Subscription} from 'rxjs';
|
import {Subscription} from 'rxjs';
|
||||||
@@ -41,38 +41,30 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
|
|||||||
@Input() index!: number;
|
@Input() index!: number;
|
||||||
@Input() @HostBinding('class.layout-root-menuitem') root!: boolean;
|
@Input() @HostBinding('class.layout-root-menuitem') root!: boolean;
|
||||||
@Input() parentKey!: string;
|
@Input() parentKey!: string;
|
||||||
|
@ViewChild('linkRef') linkRef!: ElementRef<HTMLAnchorElement>;
|
||||||
|
|
||||||
hovered = false;
|
hovered = false;
|
||||||
active = false;
|
active = false;
|
||||||
key: string = "";
|
key: string = "";
|
||||||
|
|
||||||
canManipulateLibrary: boolean = false;
|
canManipulateLibrary: boolean = false;
|
||||||
admin: boolean = false;
|
admin: boolean = false;
|
||||||
|
expandedItems = new Set<string>();
|
||||||
menuSourceSubscription: Subscription;
|
menuSourceSubscription: Subscription;
|
||||||
menuResetSubscription: Subscription;
|
menuResetSubscription: Subscription;
|
||||||
|
|
||||||
expandedItems = new Set<string>();
|
constructor(
|
||||||
|
public router: Router,
|
||||||
toggleExpand(key: string) {
|
private menuService: MenuService,
|
||||||
if (this.expandedItems.has(key)) {
|
private userService: UserService,
|
||||||
this.expandedItems.delete(key);
|
private dialogLauncher: DialogLauncherService
|
||||||
} else {
|
) {
|
||||||
this.expandedItems.add(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isExpanded(key: string): boolean {
|
|
||||||
return this.expandedItems.has(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(public router: Router, private menuService: MenuService, private userService: UserService, private dialogLauncher: DialogLauncherService) {
|
|
||||||
this.userService.userState$.subscribe(userState => {
|
this.userService.userState$.subscribe(userState => {
|
||||||
if (userState?.user) {
|
if (userState?.user) {
|
||||||
this.canManipulateLibrary = userState.user.permissions.canManipulateLibrary;
|
this.canManipulateLibrary = userState.user.permissions.canManipulateLibrary;
|
||||||
this.admin = userState.user.permissions.admin;
|
this.admin = userState.user.permissions.admin;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
|
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
|
||||||
Promise.resolve(null).then(() => {
|
Promise.resolve(null).then(() => {
|
||||||
if (value.routeEvent) {
|
if (value.routeEvent) {
|
||||||
@@ -105,6 +97,27 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
if (this.menuSourceSubscription) {
|
||||||
|
this.menuSourceSubscription.unsubscribe();
|
||||||
|
}
|
||||||
|
if (this.menuResetSubscription) {
|
||||||
|
this.menuResetSubscription.unsubscribe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleExpand(key: string) {
|
||||||
|
if (this.expandedItems.has(key)) {
|
||||||
|
this.expandedItems.delete(key);
|
||||||
|
} else {
|
||||||
|
this.expandedItems.add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isExpanded(key: string): boolean {
|
||||||
|
return this.expandedItems.has(key);
|
||||||
|
}
|
||||||
|
|
||||||
updateActiveStateFromRoute() {
|
updateActiveStateFromRoute() {
|
||||||
const activeRoute = this.router.isActive(this.item.routerLink[0], {
|
const activeRoute = this.router.isActive(this.item.routerLink[0], {
|
||||||
paths: 'exact',
|
paths: 'exact',
|
||||||
@@ -131,20 +144,6 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
|
|||||||
this.menuService.onMenuStateChange({key: this.key});
|
this.menuService.onMenuStateChange({key: this.key});
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostBinding('class.active-menuitem')
|
|
||||||
get activeClass() {
|
|
||||||
return this.active && !this.root;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy() {
|
|
||||||
if (this.menuSourceSubscription) {
|
|
||||||
this.menuSourceSubscription.unsubscribe();
|
|
||||||
}
|
|
||||||
if (this.menuResetSubscription) {
|
|
||||||
this.menuResetSubscription.unsubscribe();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
openDialog(item: any) {
|
openDialog(item: any) {
|
||||||
if (item.type === 'library' && this.canManipulateLibrary) {
|
if (item.type === 'library' && this.canManipulateLibrary) {
|
||||||
this.dialogLauncher.openLibraryCreatorDialog();
|
this.dialogLauncher.openLibraryCreatorDialog();
|
||||||
@@ -153,4 +152,15 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
|
|||||||
this.dialogLauncher.openMagicShelfDialog();
|
this.dialogLauncher.openMagicShelfDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
triggerLink() {
|
||||||
|
if (this.item.routerLink && !this.item.items && this.linkRef) {
|
||||||
|
this.linkRef.nativeElement.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@HostBinding('class.active-menuitem')
|
||||||
|
get activeClass() {
|
||||||
|
return this.active && !this.root;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user