Visually indicate the active menu item in the left sidebar (#1738)

This commit is contained in:
Aditya Chandel
2025-12-02 20:22:25 -07:00
committed by GitHub
parent 76e904436b
commit a4b0e22ad8
4 changed files with 108 additions and 22 deletions
@@ -4,7 +4,7 @@
@if (homeMenu$ | async; as homeMenu) {
@for (item of homeMenu; track item; let i = $index) {
@if (!item.separator) {
<li app-menuitem [item]="item" [index]="i" [root]="true"></li>
<li app-menuitem [item]="item" [index]="i" [root]="true" menuKey="home"></li>
}
}
}
@@ -14,7 +14,7 @@
@if (libraryMenu$ | async; as libraryMenu) {
@for (item of libraryMenu; track item; let i = $index) {
@if (!item.separator) {
<li app-menuitem [item]="item" [index]="i" [root]="true"></li>
<li app-menuitem [item]="item" [index]="i" [root]="true" menuKey="library"></li>
}
}
}
@@ -24,7 +24,7 @@
@if (shelfMenu$ | async; as shelfMenu) {
@for (item of shelfMenu; track item; let i = $index) {
@if (!item.separator) {
<li app-menuitem [item]="item" [index]="i" [root]="true"></li>
<li app-menuitem [item]="item" [index]="i" [root]="true" menuKey="shelf"></li>
}
}
}
@@ -34,7 +34,7 @@
@if (magicShelfMenu$ | async; as shelfMenu) {
@for (item of shelfMenu; track item; let i = $index) {
@if (!item.separator) {
<li app-menuitem [item]="item" [index]="i" [root]="true"></li>
<li app-menuitem [item]="item" [index]="i" [root]="true" menuKey="magicShelf"></li>
}
}
}
@@ -1,13 +1,12 @@
<ng-container>
@if (root) {
@if (item.hasDropDown) {
<div class=" flex items-center justify-between layout-menuitem-root-text cursor-pointer pt-4">
<div class="flex items-center justify-between gap-2 cursor-pointer">
<div class="layout-menuitem-root-text root-item-with-dropdown">
<div class="root-item-label-container">
<div>{{ item.label }}</div>
@if (item.hasCreate) {
<i
class="pi pi-plus plus-icon"
style="font-size: 0.8rem; cursor: pointer;"
(click)="openDialog(item)"
></i>
}
@@ -17,14 +16,13 @@
[ngClass]="{
'pi': true,
'pi-angle-up': isExpanded(key),
'pi-angle-down': !isExpanded(key),
'text-surface-500': true,
'hover:text-surface-200': true,
'pr-3': true
}"></i>
'pi-angle-down': !isExpanded(key)
}"
class="expand-icon"
></i>
</div>
} @else {
<div class="flex items-center justify-between layout-menuitem-root-text">
<div class="layout-menuitem-root-text root-item">
<div>{{ item.label }}</div>
</div>
}
@@ -32,14 +30,15 @@
<div>
<div
class="flex flex-row items-center justify-between hover:bg-surface-800 rounded-md cursor-pointer"
class="menu-item-container"
(click)="triggerLink()"
>
@if ((item.routerLink && !item.items)) {
<a
#link
(click)="itemClick($event)"
[ngClass]="item.class + ' flex items-center gap-2 w-full'"
[ngClass]="item.class"
class="menu-item-link"
[routerLink]="item.routerLink"
routerLinkActive="active-route"
[routerLinkActiveOptions]="item.routerLinkActiveOptions || { paths: 'exact', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored' }"
@@ -55,13 +54,13 @@
pRipple
>
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
<span class="layout-menuitem-text w-full truncate">
<span class="layout-menuitem-text menu-item-text">
{{ item.label }}
</span>
</a>
}
<span>
<span class="menu-item-end-content">
@if (item.type === 'Library' || item.type === 'Shelf' || item.type === 'magicShelfItem') {
@if ((item.type !== 'Library' || (admin || canManipulateLibrary)) && item.label !== 'Unshelved' && item.label !== 'Kobo') {
<p-button
@@ -73,22 +72,21 @@
[rounded]="true"
[label]="hovered ? '' : (item.bookCount$ | async)?.toString() || ''"
[icon]="hovered ? 'pi pi-ellipsis-v' : ''"
[style.height]="'30px'"
[style.display]="'flex'"
class="entity-menu-button"
></p-button>
}
<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') {
<p class="text-[var(--primary-color)] pr-3">
<p class="book-count">
{{ (item.bookCount$ | async)?.toString() || '0' }}
</p>
}
</span>
</div>
<div [@children]="isExpanded(key) ? 'expanded' : 'collapsed'" style="overflow: hidden;">
<div [@children]="isExpanded(key) ? 'expanded' : 'collapsed'" class="submenu-container">
@if (item.items) {
<ul>
@for (child of item.items; track child; let i = $index) {
@@ -1,8 +1,92 @@
.plus-icon {
color: var(--p-primary-color);
transition: color 0.2s ease;
font-size: 0.8rem;
cursor: pointer;
&:hover {
color: var(--p-green-400);
}
}
.root-item-with-dropdown {
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
padding-top: 1rem;
}
.root-item-label-container {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
cursor: pointer;
}
.expand-icon {
color: var(--p-surface-500);
padding-right: 0.75rem;
&:hover {
color: var(--p-surface-200);
}
}
.root-item {
display: flex;
align-items: center;
justify-content: space-between;
}
.menu-item-container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
border-radius: 8px;
cursor: pointer;
&:hover {
background-color: var(--p-surface-700);
border-radius: 8px;
}
}
:host(.active-menuitem) .menu-item-container {
background-color: var(--p-surface-800);
border-radius: 8px;
}
.menu-item-link {
display: flex;
align-items: center;
gap: 0.5rem;
width: 100%;
}
.menu-item-text {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.menu-item-end-content {
display: flex;
}
.entity-menu-button {
height: 30px;
display: flex;
}
.book-count {
color: var(--primary-color);
padding-right: 0.75rem;
}
.submenu-container {
overflow: hidden;
}
@@ -43,6 +43,7 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
@Input() index!: number;
@Input() @HostBinding('class.layout-root-menuitem') root!: boolean;
@Input() parentKey!: string;
@Input() menuKey!: string;
@ViewChild('linkRef') linkRef!: ElementRef<HTMLAnchorElement>;
hovered = false;
@@ -93,7 +94,8 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
}
ngOnInit() {
this.key = this.parentKey ? this.parentKey + '-' + this.index : String(this.index);
const rootKey = this.menuKey ? this.menuKey + '-' : '';
this.key = this.parentKey ? this.parentKey + '-' + this.index : rootKey + String(this.index);
this.expandedItems.add(this.key);
if (this.item.routerLink) {
this.updateActiveStateFromRoute();
@@ -143,6 +145,8 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
}
if (this.item.items) {
this.active = !this.active;
} else {
this.active = true;
}
this.menuService.onMenuStateChange({key: this.key});
}