fix(ui): mobile UI enhancements (#1184)
This commit is contained in:
@@ -23,7 +23,12 @@
|
||||
[displayEmpty]="true"
|
||||
></app-icon-display>
|
||||
</span>
|
||||
<span class="layout-menuitem-text menu-item-text">{{ currentItem.label }}</span>
|
||||
<span class="layout-menuitem-text menu-item-text">
|
||||
<span class="menu-item-label">{{ currentItem.label }}</span>
|
||||
@if (currentItem.bookCount) {
|
||||
<span class="book-count book-count-inline">{{ formatCount(currentItem.bookCount) }}</span>
|
||||
}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
} @else if (currentItem.routerLink) {
|
||||
@@ -55,7 +60,12 @@
|
||||
[displayEmpty]="true"
|
||||
></app-icon-display>
|
||||
</span>
|
||||
<span class="layout-menuitem-text menu-item-text">{{ currentItem.label }}</span>
|
||||
<span class="layout-menuitem-text menu-item-text">
|
||||
<span class="menu-item-label">{{ currentItem.label }}</span>
|
||||
@if (currentItem.bookCount) {
|
||||
<span class="book-count book-count-inline">{{ formatCount(currentItem.bookCount) }}</span>
|
||||
}
|
||||
</span>
|
||||
</span>
|
||||
</a>
|
||||
}
|
||||
@@ -74,9 +84,17 @@
|
||||
<span class="entity-menu-count">{{ formatCount(currentItem.bookCount) }}</span>
|
||||
</span>
|
||||
</button>
|
||||
<p-menu #entitymenu [model]="currentItem.contextMenuItems" [popup]="true" appendTo="body" (onHide)="closeContextMenu()"></p-menu>
|
||||
<p-menu
|
||||
#entitymenu
|
||||
[model]="currentItem.contextMenuItems"
|
||||
[popup]="true"
|
||||
appendTo="body"
|
||||
styleClass="sidebar-entity-menu"
|
||||
(onShow)="positionContextMenu(entitymenu)"
|
||||
(onHide)="closeContextMenu()"
|
||||
></p-menu>
|
||||
} @else if (currentItem.bookCount) {
|
||||
<p class="book-count">{{ formatCount(currentItem.bookCount) }}</p>
|
||||
<p class="book-count book-count-end">{{ formatCount(currentItem.bookCount) }}</p>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@use "../../../../assets/layout/styles/layout/variables";
|
||||
|
||||
:host {
|
||||
display: block;
|
||||
width: 100%;
|
||||
@@ -15,12 +17,29 @@
|
||||
min-width: 0;
|
||||
border-radius: var(--sidebar-row-radius);
|
||||
|
||||
&:hover,
|
||||
&:focus-within {
|
||||
background-color: var(--surface-hover);
|
||||
}
|
||||
}
|
||||
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
.menu-item-container:hover {
|
||||
background-color: var(--surface-hover);
|
||||
}
|
||||
|
||||
.menu-item-container:hover .menu-item-chevron {
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.menu-item-container:hover .entity-menu-icon {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.menu-item-container:hover .entity-menu-count {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.menu-item-container.active-route-container {
|
||||
background-color: color-mix(in srgb, var(--primary-color) 8%, transparent);
|
||||
}
|
||||
@@ -82,11 +101,11 @@ a.menu-item-link.active-route {
|
||||
transition: color var(--transition-fast);
|
||||
}
|
||||
|
||||
.menu-item-container:hover .menu-item-chevron {
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.menu-item-text {
|
||||
.layout-menuitem-text.menu-item-text {
|
||||
display: inline-flex;
|
||||
align-items: baseline;
|
||||
justify-content: flex-start;
|
||||
gap: var(--space-2);
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
@@ -95,6 +114,12 @@ a.menu-item-link.active-route {
|
||||
font-size: var(--text-base);
|
||||
}
|
||||
|
||||
.menu-item-label {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.menu-item-leading {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
@@ -163,23 +188,29 @@ a.menu-item-link.active-route {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.menu-item-container:hover .entity-menu-icon,
|
||||
.menu-item-container.menu-open .entity-menu-icon {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.menu-item-container:hover .entity-menu-count,
|
||||
.menu-item-container.menu-open .entity-menu-count {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.book-count {
|
||||
color: var(--text-color-secondary);
|
||||
padding-right: var(--space-3);
|
||||
font-size: var(--text-sm);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.book-count-end {
|
||||
padding-right: var(--space-3);
|
||||
}
|
||||
|
||||
.book-count-inline {
|
||||
display: none;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.library-health-dot {
|
||||
position: absolute;
|
||||
top: -1px;
|
||||
@@ -192,6 +223,56 @@ a.menu-item-link.active-route {
|
||||
animation: pulse 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@media #{variables.$mobile-shell-media-query} {
|
||||
.menu-item-container:hover,
|
||||
.menu-item-container:focus-within,
|
||||
.menu-item-container:has(.menu-item-link:focus-visible),
|
||||
.menu-item-container:has(:focus-visible) {
|
||||
background-color: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.menu-item-container.active-route-container {
|
||||
background-color: color-mix(in srgb, var(--primary-color) 8%, transparent);
|
||||
}
|
||||
|
||||
.menu-item-container:has(:focus-visible) {
|
||||
outline: 2px solid var(--primary-color);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
.entity-menu-button:focus-visible {
|
||||
background-color: transparent;
|
||||
box-shadow: none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.book-count-inline {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.menu-item-end-content:not(:has(.entity-menu-button)) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.book-count-end,
|
||||
.entity-menu-count {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.entity-menu-icon {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.menu-item-end-content {
|
||||
padding-right: var(--sidebar-row-padding-inline-end);
|
||||
}
|
||||
|
||||
.entity-menu-button {
|
||||
margin-right: -0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
opacity: 1;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ChangeDetectionStrategy, Component, computed, inject, input, signal } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, Renderer2, RendererStyleFlags2, computed, inject, input, signal } from '@angular/core';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { Menu } from 'primeng/menu';
|
||||
import { Tooltip } from 'primeng/tooltip';
|
||||
@@ -35,6 +35,8 @@ export class AppMenuItemRowComponent {
|
||||
|
||||
private readonly userService = inject(UserService);
|
||||
readonly layoutService = inject(LayoutService);
|
||||
private readonly renderer = inject(Renderer2);
|
||||
private contextMenuTrigger: HTMLElement | null = null;
|
||||
|
||||
readonly isRouteActive = computed(() => {
|
||||
const route = this.item().routerLink?.[0];
|
||||
@@ -56,13 +58,43 @@ export class AppMenuItemRowComponent {
|
||||
}
|
||||
|
||||
openContextMenu(event: Event, menu: Menu): void {
|
||||
this.contextMenuTrigger = event.currentTarget instanceof HTMLElement
|
||||
? event.currentTarget
|
||||
: null;
|
||||
menu.toggle(event);
|
||||
this.menuOpen.update((open) => !open);
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
positionContextMenu(menu: Menu): void {
|
||||
this.menuOpen.set(true);
|
||||
if (this.layoutService.isDesktop()) return;
|
||||
|
||||
const trigger = this.contextMenuTrigger;
|
||||
const panel = menu.container;
|
||||
if (!trigger || !(panel instanceof HTMLElement)) return;
|
||||
|
||||
const gutter = 8;
|
||||
const rect = trigger.getBoundingClientRect();
|
||||
const panelWidth = panel.offsetWidth;
|
||||
const panelHeight = panel.offsetHeight;
|
||||
const spaceAbove = rect.top - gutter;
|
||||
const spaceBelow = window.innerHeight - rect.bottom - gutter;
|
||||
const placeBelow = spaceBelow >= panelHeight || spaceBelow >= spaceAbove;
|
||||
const availableHeight = Math.max(placeBelow ? spaceBelow : spaceAbove, 0);
|
||||
const left = Math.max(Math.min(rect.right + gutter, window.innerWidth - panelWidth - gutter), gutter);
|
||||
const top = placeBelow
|
||||
? rect.bottom + gutter
|
||||
: rect.top - Math.min(panelHeight, availableHeight) - gutter;
|
||||
|
||||
const flags = RendererStyleFlags2.DashCase;
|
||||
this.renderer.setStyle(panel, '--sidebar-popover-left', `${left}px`, flags);
|
||||
this.renderer.setStyle(panel, '--sidebar-popover-top', `${Math.max(top, gutter)}px`, flags);
|
||||
this.renderer.setStyle(panel, '--sidebar-popover-max-height', `${availableHeight}px`, flags);
|
||||
}
|
||||
|
||||
closeContextMenu(): void {
|
||||
this.menuOpen.set(false);
|
||||
this.contextMenuTrigger = null;
|
||||
}
|
||||
|
||||
getIconSelection(): IconSelection | null {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@use "../../../../assets/layout/styles/layout/variables";
|
||||
|
||||
:host {
|
||||
display: block;
|
||||
list-style: none;
|
||||
@@ -52,12 +54,23 @@
|
||||
|
||||
.expand-icon {
|
||||
color: var(--surface-500);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
.expand-icon:hover {
|
||||
color: var(--surface-200);
|
||||
}
|
||||
}
|
||||
|
||||
@media #{variables.$mobile-shell-media-query} {
|
||||
.root-item-with-dropdown:focus-visible {
|
||||
background-color: transparent;
|
||||
box-shadow: none;
|
||||
outline: 2px solid var(--primary-color);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
}
|
||||
|
||||
.root-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -93,7 +106,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 767px) {
|
||||
@media #{variables.$mobile-shell-media-query} {
|
||||
.expand-icon-button {
|
||||
opacity: 1;
|
||||
width: 2rem;
|
||||
|
||||
@@ -1,5 +1,30 @@
|
||||
<ng-container *transloco="let t; prefix: 'layout.menu'">
|
||||
<div class="menu-container">
|
||||
<ng-template #sidebarUserMenuStart>
|
||||
@if (currentUser(); as menuUser) {
|
||||
<div class="sidebar-user-menu-header">
|
||||
<span class="sidebar-user-avatar" aria-hidden="true">{{ userInitials() }}</span>
|
||||
<span class="sidebar-user-meta">
|
||||
<span class="sidebar-user-name">{{ menuUser.name || menuUser.username }}</span>
|
||||
@if (menuUser.name) {
|
||||
<span class="sidebar-user-handle">@{{ menuUser.username }}</span>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
</ng-template>
|
||||
|
||||
<ng-template #sidebarUserMenuEnd>
|
||||
@if (version(); as v) {
|
||||
<div class="sidebar-user-menu-footer">
|
||||
<span>Grimmory v{{ v.current }}</span>
|
||||
@if (hasUpdate()) {
|
||||
<span class="sidebar-user-update">{{ t('update') }}</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</ng-template>
|
||||
|
||||
<div class="sidebar-header">
|
||||
<a class="sidebar-brand" [routerLink]="['/dashboard']" [attr.aria-label]="t('goToDashboard')">
|
||||
<span class="sidebar-brand-mark" aria-hidden="true">
|
||||
@@ -48,6 +73,75 @@
|
||||
</svg>
|
||||
</a>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-icon-button sidebar-mobile-landscape-action"
|
||||
[pTooltip]="t('add')"
|
||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||
tooltipPosition="bottom"
|
||||
[attr.aria-label]="t('add')"
|
||||
aria-haspopup="menu"
|
||||
[attr.aria-expanded]="addMenuOpen() ? 'true' : 'false'"
|
||||
(click)="openSidebarOverlay($event, addMenu, 'below')"
|
||||
>
|
||||
<i class="pi pi-plus" aria-hidden="true"></i>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-icon-button sidebar-mobile-landscape-action"
|
||||
[attr.aria-label]="t('notifications')"
|
||||
[pTooltip]="t('notifications')"
|
||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||
tooltipPosition="bottom"
|
||||
aria-haspopup="dialog"
|
||||
[attr.aria-expanded]="notificationsOpen() ? 'true' : 'false'"
|
||||
(click)="openSidebarOverlay($event, notificationsPopover, 'below')"
|
||||
>
|
||||
<i class="pi pi-bell" aria-hidden="true"></i>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-icon-button sidebar-mobile-landscape-action"
|
||||
[attr.aria-label]="t('more')"
|
||||
[pTooltip]="t('more')"
|
||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||
tooltipPosition="bottom"
|
||||
aria-haspopup="menu"
|
||||
[attr.aria-expanded]="moreMenuOpen() ? 'true' : 'false'"
|
||||
(click)="openSidebarOverlay($event, moreMenu, 'below')"
|
||||
>
|
||||
<i class="pi pi-ellipsis-h" aria-hidden="true"></i>
|
||||
</button>
|
||||
|
||||
<p-menu #addMenu [model]="addMenuItems()" [popup]="true" appendTo="body" styleClass="sidebar-more-menu sidebar-footer-popover" (onShow)="addMenuOpen.set(true); applySidebarOverlayPosition(addMenu)" (onHide)="addMenuOpen.set(false)"/>
|
||||
<p-popover #notificationsPopover appendTo="body" styleClass="sidebar-flyout-popover" (onShow)="notificationsOpen.set(true); applySidebarOverlayPosition(notificationsPopover)" (onHide)="notificationsOpen.set(false)">
|
||||
<app-unified-notification-popover-component></app-unified-notification-popover-component>
|
||||
</p-popover>
|
||||
<p-menu #moreMenu [model]="moreMenuItems()" [popup]="true" appendTo="body" styleClass="sidebar-more-menu sidebar-footer-popover" (onShow)="moreMenuOpen.set(true); applySidebarOverlayPosition(moreMenu)" (onHide)="moreMenuOpen.set(false)"/>
|
||||
|
||||
@if (currentUser(); as user) {
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-icon-button sidebar-mobile-user-button"
|
||||
[attr.aria-label]="t('profile')"
|
||||
aria-haspopup="menu"
|
||||
(click)="openSidebarOverlay($event, mobileUserMenu, 'below')"
|
||||
>
|
||||
<span class="sidebar-user-avatar" aria-hidden="true">{{ userInitials() }}</span>
|
||||
</button>
|
||||
|
||||
<p-menu #mobileUserMenu [model]="userMenuItems()" [popup]="true" appendTo="body" styleClass="sidebar-user-menu" (onShow)="applySidebarOverlayPosition(mobileUserMenu)">
|
||||
<ng-template pTemplate="start">
|
||||
<ng-container [ngTemplateOutlet]="sidebarUserMenuStart"></ng-container>
|
||||
</ng-template>
|
||||
<ng-template pTemplate="end">
|
||||
<ng-container [ngTemplateOutlet]="sidebarUserMenuEnd"></ng-container>
|
||||
</ng-template>
|
||||
</p-menu>
|
||||
}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-icon-button sidebar-mobile-close-button"
|
||||
@@ -87,6 +181,7 @@
|
||||
type="button"
|
||||
class="sidebar-action-link sidebar-footer-action sidebar-toolbar-button"
|
||||
[pTooltip]="t('add')"
|
||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||
tooltipPosition="top"
|
||||
[attr.aria-label]="t('add')"
|
||||
(click)="openSidebarOverlay($event, addMenu, 'above')"
|
||||
@@ -100,6 +195,7 @@
|
||||
class="sidebar-action-link sidebar-footer-action"
|
||||
[attr.aria-label]="t('notifications')"
|
||||
[pTooltip]="t('notifications')"
|
||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||
tooltipPosition="top"
|
||||
(click)="openSidebarOverlay($event, notificationsPopover, layoutService.isDesktop() ? 'below' : 'above')"
|
||||
>
|
||||
@@ -112,6 +208,7 @@
|
||||
class="sidebar-action-link sidebar-footer-action"
|
||||
[attr.aria-label]="t('more')"
|
||||
[pTooltip]="t('more')"
|
||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||
tooltipPosition="top"
|
||||
(click)="openSidebarOverlay($event, moreMenu, 'above')"
|
||||
>
|
||||
@@ -119,12 +216,6 @@
|
||||
<span>{{ t('more') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<p-menu #addMenu [model]="addMenuItems()" [popup]="true" appendTo="body" styleClass="sidebar-more-menu sidebar-footer-popover" (onShow)="applyOverlayBottom(addMenu)"/>
|
||||
<p-popover #notificationsPopover appendTo="body" styleClass="sidebar-flyout-popover" (onShow)="applyOverlayBottom(notificationsPopover)">
|
||||
<app-unified-notification-popover-component></app-unified-notification-popover-component>
|
||||
</p-popover>
|
||||
<p-menu #moreMenu [model]="moreMenuItems()" [popup]="true" appendTo="body" styleClass="sidebar-more-menu sidebar-footer-popover" (onShow)="applyOverlayBottom(moreMenu)"/>
|
||||
|
||||
@if (currentUser(); as user) {
|
||||
<div class="sidebar-footer-bottom">
|
||||
<button
|
||||
@@ -164,27 +255,12 @@
|
||||
></i>
|
||||
</button>
|
||||
</div>
|
||||
<p-menu #userMenu [model]="userMenuItems()" [popup]="true" appendTo="body" styleClass="sidebar-user-menu" (onShow)="applyOverlayBottom(userMenu)">
|
||||
<p-menu #userMenu [model]="userMenuItems()" [popup]="true" appendTo="body" styleClass="sidebar-user-menu" (onShow)="applySidebarOverlayPosition(userMenu)">
|
||||
<ng-template pTemplate="start">
|
||||
<div class="sidebar-user-menu-header">
|
||||
<span class="sidebar-user-avatar" aria-hidden="true">{{ userInitials() }}</span>
|
||||
<span class="sidebar-user-meta">
|
||||
<span class="sidebar-user-name">{{ user.name || user.username }}</span>
|
||||
@if (user.name) {
|
||||
<span class="sidebar-user-handle">@{{ user.username }}</span>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
<ng-container [ngTemplateOutlet]="sidebarUserMenuStart"></ng-container>
|
||||
</ng-template>
|
||||
<ng-template pTemplate="end">
|
||||
@if (version(); as v) {
|
||||
<div class="sidebar-user-menu-footer">
|
||||
<span>Grimmory v{{ v.current }}</span>
|
||||
@if (hasUpdate()) {
|
||||
<span class="sidebar-user-update">{{ t('update') }}</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<ng-container [ngTemplateOutlet]="sidebarUserMenuEnd"></ng-container>
|
||||
</ng-template>
|
||||
</p-menu>
|
||||
} @else {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@use "../../../../assets/layout/styles/layout/variables";
|
||||
|
||||
.menu-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -14,6 +16,11 @@
|
||||
margin-bottom: var(--sidebar-header-gap-after);
|
||||
}
|
||||
|
||||
.sidebar-header > p-menu,
|
||||
.sidebar-header > p-popover {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sidebar-brand {
|
||||
/* Shared rendered-height for both SVGs — derived from wordmark's width × aspect
|
||||
at default sidebar width. Keeps the wordmark and G-only mark the same pixel
|
||||
@@ -93,6 +100,14 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sidebar-icon-button.sidebar-mobile-user-button {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sidebar-icon-button.sidebar-mobile-landscape-action {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sidebar-action-link.sidebar-toolbar-button {
|
||||
color: var(--primary-color);
|
||||
|
||||
@@ -353,21 +368,37 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@media (width <= 767px) {
|
||||
@media #{variables.$mobile-shell-media-query} {
|
||||
.sidebar-header {
|
||||
align-items: flex-start;
|
||||
margin-bottom: var(--space-3);
|
||||
box-sizing: border-box;
|
||||
align-items: center;
|
||||
min-height: 3.5rem;
|
||||
height: 3.5rem;
|
||||
gap: 0.5rem;
|
||||
padding:
|
||||
0
|
||||
calc(var(--sidebar-shell-padding-inline-end) + env(safe-area-inset-right))
|
||||
0
|
||||
calc(var(--sidebar-shell-padding-inline-start) + env(safe-area-inset-left));
|
||||
margin:
|
||||
calc(0px - var(--space-3) - env(safe-area-inset-top))
|
||||
calc(0px - var(--sidebar-shell-padding-inline-end) - env(safe-area-inset-right))
|
||||
var(--space-3)
|
||||
calc(0px - var(--sidebar-shell-padding-inline-start) - env(safe-area-inset-left));
|
||||
}
|
||||
|
||||
.sidebar-brand {
|
||||
width: auto;
|
||||
flex: 1 1 auto;
|
||||
min-height: 3.5rem;
|
||||
padding: 0 var(--space-3);
|
||||
align-self: stretch;
|
||||
}
|
||||
|
||||
.sidebar-icon-button.sidebar-mobile-close-button {
|
||||
display: inline-flex;
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
border-radius: var(--radius-pill);
|
||||
background-color: var(--surface-hover);
|
||||
color: var(--text-color);
|
||||
@@ -381,6 +412,19 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
margin-inline:
|
||||
calc(0px - var(--sidebar-shell-padding-inline-start) - env(safe-area-inset-left))
|
||||
calc(0px - var(--sidebar-shell-padding-inline-end) - env(safe-area-inset-right));
|
||||
}
|
||||
|
||||
.sidebar-nav > .layout-menu {
|
||||
box-sizing: border-box;
|
||||
padding-inline:
|
||||
calc(var(--sidebar-shell-padding-inline-start) + env(safe-area-inset-left))
|
||||
calc(var(--sidebar-shell-padding-inline-end) + env(safe-area-inset-right));
|
||||
}
|
||||
|
||||
.sidebar-search-shortcut {
|
||||
display: none;
|
||||
}
|
||||
@@ -435,4 +479,102 @@
|
||||
.sidebar-collapse-button {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (orientation: landscape) {
|
||||
.sidebar-header {
|
||||
gap: 0.5rem;
|
||||
min-height: 4rem;
|
||||
height: 4rem;
|
||||
padding:
|
||||
var(--space-2)
|
||||
var(--sidebar-shell-padding-inline-end)
|
||||
0
|
||||
calc(var(--sidebar-shell-padding-inline-start) + env(safe-area-inset-left));
|
||||
margin:
|
||||
calc(0px - var(--space-3) - env(safe-area-inset-top))
|
||||
calc(0px - var(--sidebar-shell-padding-inline-end))
|
||||
var(--space-3)
|
||||
calc(0px - var(--sidebar-shell-padding-inline-start) - env(safe-area-inset-left));
|
||||
}
|
||||
|
||||
.sidebar-brand {
|
||||
flex: 0 0 auto;
|
||||
grid-template-columns: var(--sidebar-row-icon-size);
|
||||
min-height: 4rem;
|
||||
}
|
||||
|
||||
.sidebar-brand-mark {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.sidebar-brand-wordmark {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
margin-inline:
|
||||
calc(0px - var(--sidebar-shell-padding-inline-start) - env(safe-area-inset-left))
|
||||
calc(0px - var(--sidebar-shell-padding-inline-end));
|
||||
}
|
||||
|
||||
.sidebar-nav > .layout-menu {
|
||||
padding-inline:
|
||||
calc(var(--sidebar-shell-padding-inline-start) + env(safe-area-inset-left))
|
||||
var(--sidebar-shell-padding-inline-end);
|
||||
}
|
||||
|
||||
.sidebar-icon-button.sidebar-mobile-close-button {
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
background: none;
|
||||
|
||||
&:hover {
|
||||
background-color: var(--surface-hover);
|
||||
}
|
||||
}
|
||||
|
||||
.sidebar-icon-button.sidebar-mobile-user-button {
|
||||
display: inline-flex;
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
border-radius: var(--radius-pill);
|
||||
background: none;
|
||||
|
||||
&:hover {
|
||||
background: none;
|
||||
|
||||
.sidebar-user-avatar {
|
||||
background-color: color-mix(in srgb, var(--primary-color) 24%, transparent);
|
||||
}
|
||||
}
|
||||
|
||||
.sidebar-user-avatar {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
margin-left: 0;
|
||||
font-size: var(--text-sm);
|
||||
}
|
||||
}
|
||||
|
||||
.sidebar-icon-button.sidebar-mobile-landscape-action {
|
||||
display: inline-flex;
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
border-radius: var(--radius-pill);
|
||||
background: none;
|
||||
color: var(--text-color);
|
||||
|
||||
&:hover {
|
||||
background-color: var(--surface-hover);
|
||||
}
|
||||
}
|
||||
|
||||
.sidebar-footer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sidebar-footer-bottom {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,10 @@ describe('AppMenuComponent', () => {
|
||||
component = fixture.componentInstance;
|
||||
layoutService.isDesktop.set(true);
|
||||
layoutService.closeMobileSidebar.mockReset();
|
||||
vi.spyOn(window, 'requestAnimationFrame').mockImplementation((callback: FrameRequestCallback): number => {
|
||||
callback(0);
|
||||
return 0;
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -133,13 +137,13 @@ describe('AppMenuComponent', () => {
|
||||
vi.spyOn(trigger, 'getBoundingClientRect').mockReturnValue(createRect(100, 148, 40));
|
||||
const container = document.createElement('div');
|
||||
const overlay = { container, toggle: vi.fn() };
|
||||
const menuHarness = component as unknown as { applyOverlayBottom(overlay: MenuOverlay): void };
|
||||
const menuHarness = component as unknown as { applySidebarOverlayPosition(overlay: MenuOverlay): void };
|
||||
|
||||
component.openSidebarOverlay({ currentTarget: trigger } as unknown as MouseEvent, overlay as never, 'above');
|
||||
menuHarness.applyOverlayBottom(overlay);
|
||||
menuHarness.applySidebarOverlayPosition(overlay);
|
||||
|
||||
expect(overlay.toggle).toHaveBeenCalled();
|
||||
expect(container.style.getPropertyValue('--sidebar-popover-bottom')).toBe(`${window.innerHeight - 100 + 8}px`);
|
||||
expect(container.style.getPropertyValue('--sidebar-popover-top')).toBe('92px');
|
||||
expect(container.style.getPropertyValue('--sidebar-popover-left')).toBe('40px');
|
||||
});
|
||||
|
||||
@@ -148,12 +152,12 @@ describe('AppMenuComponent', () => {
|
||||
vi.spyOn(trigger, 'getBoundingClientRect').mockReturnValue(createRect(220, 260, 24));
|
||||
const container = document.createElement('div');
|
||||
const overlay = { container, toggle: vi.fn() };
|
||||
const menuHarness = component as unknown as { applyOverlayBottom(overlay: MenuOverlay): void };
|
||||
const menuHarness = component as unknown as { applySidebarOverlayPosition(overlay: MenuOverlay): void };
|
||||
|
||||
component.openSidebarOverlay({ currentTarget: trigger } as unknown as MouseEvent, overlay as never, 'below');
|
||||
menuHarness.applyOverlayBottom(overlay);
|
||||
menuHarness.applySidebarOverlayPosition(overlay);
|
||||
|
||||
expect(container.style.getPropertyValue('--sidebar-popover-bottom')).toBe(`${window.innerHeight - 260}px`);
|
||||
expect(container.style.getPropertyValue('--sidebar-popover-top')).toBe('268px');
|
||||
expect(container.style.getPropertyValue('--sidebar-popover-left')).toBe('');
|
||||
});
|
||||
|
||||
@@ -189,12 +193,12 @@ describe('AppMenuComponent', () => {
|
||||
const container = document.createElement('div');
|
||||
Object.defineProperty(container, 'offsetWidth', { value: 120, configurable: true });
|
||||
const overlay = { container, toggle: vi.fn() };
|
||||
const menuHarness = component as unknown as { applyOverlayBottom(overlay: MenuOverlay): void };
|
||||
const menuHarness = component as unknown as { applySidebarOverlayPosition(overlay: MenuOverlay): void };
|
||||
|
||||
component.openSidebarOverlay({ currentTarget: trigger } as unknown as MouseEvent, overlay as never, 'above');
|
||||
menuHarness.applyOverlayBottom(overlay);
|
||||
menuHarness.applySidebarOverlayPosition(overlay);
|
||||
|
||||
expect(container.style.getPropertyValue('--sidebar-popover-bottom')).toBe(`${window.innerHeight - 220 + 8}px`);
|
||||
expect(container.style.getPropertyValue('--sidebar-popover-top')).toBe('212px');
|
||||
expect(container.style.getPropertyValue('--sidebar-popover-left')).toBe(`${window.innerWidth - 128}px`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Component, computed, inject } from '@angular/core';
|
||||
import { NgTemplateOutlet } from '@angular/common';
|
||||
import { Component, Renderer2, RendererStyleFlags2, computed, inject, signal } from '@angular/core';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { AppMenuSectionComponent } from './app.menu-section.component';
|
||||
import { Popover } from 'primeng/popover';
|
||||
@@ -55,7 +56,7 @@ function detectSearchShortcut(userAgent: string): string {
|
||||
|
||||
@Component({
|
||||
selector: 'app-menu',
|
||||
imports: [AppMenuSectionComponent, Popover, Menu, UnifiedNotificationBoxComponent, RouterLink, TranslocoDirective, TranslocoPipe, Tooltip],
|
||||
imports: [AppMenuSectionComponent, Popover, Menu, UnifiedNotificationBoxComponent, RouterLink, TranslocoDirective, TranslocoPipe, Tooltip, NgTemplateOutlet],
|
||||
templateUrl: './app.menu.component.html',
|
||||
styleUrl: './app.menu.component.scss',
|
||||
})
|
||||
@@ -76,6 +77,7 @@ export class AppMenuComponent {
|
||||
private readonly authorService = inject(AuthorService);
|
||||
private readonly versionService = inject(VersionService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly renderer = inject(Renderer2);
|
||||
|
||||
readonly currentUser = this.userService.currentUser;
|
||||
readonly version = toSignal<AppVersion | null>(
|
||||
@@ -144,6 +146,9 @@ export class AppMenuComponent {
|
||||
});
|
||||
|
||||
readonly hasUpdate = computed(() => hasAppUpdate(this.version()));
|
||||
protected readonly addMenuOpen = signal(false);
|
||||
protected readonly notificationsOpen = signal(false);
|
||||
protected readonly moreMenuOpen = signal(false);
|
||||
|
||||
readonly userMenuItems = computed<MenuItem[]>(() => {
|
||||
this.activeLang();
|
||||
@@ -199,35 +204,42 @@ export class AppMenuComponent {
|
||||
this.layoutService.closeMobileSidebar();
|
||||
}
|
||||
|
||||
// Each overlay remembers its own trigger so the position can be re-read when the
|
||||
// panel renders. Scoping the offset to each panel (instead of a shared variable on
|
||||
// <html>) means a closing overlay holds its place while a new one opens elsewhere.
|
||||
private readonly anchorByOverlay = new WeakMap<Menu | Popover, { trigger: HTMLElement; placement: 'above' | 'below' }>();
|
||||
|
||||
protected applyOverlayBottom(overlay: Menu | Popover): void {
|
||||
protected applySidebarOverlayPosition(overlay: Menu | Popover): void {
|
||||
const anchor = this.anchorByOverlay.get(overlay);
|
||||
const panel = overlay.container;
|
||||
if (!anchor || !panel) return;
|
||||
|
||||
window.requestAnimationFrame(() => {
|
||||
this.positionSidebarOverlay(anchor, panel);
|
||||
});
|
||||
}
|
||||
|
||||
private positionSidebarOverlay(
|
||||
anchor: { trigger: HTMLElement; placement: 'above' | 'below' },
|
||||
panel: HTMLElement,
|
||||
): void {
|
||||
const rect = anchor.trigger.getBoundingClientRect();
|
||||
const panelWidth = panel.offsetWidth;
|
||||
const panelHeight = panel.offsetHeight;
|
||||
const left = Math.max(Math.min(rect.left, window.innerWidth - panelWidth - 8), 8);
|
||||
const maxTop = Math.max(window.innerHeight - panelHeight - 8, 8);
|
||||
|
||||
// `above` collapses to `below` when the sidebar is narrow, because the
|
||||
// anchored left offset assumes an expanded footer row.
|
||||
const anchorAbove = anchor.placement === 'above' && !this.layoutService.desktopSidebarCollapsed();
|
||||
if (anchorAbove) {
|
||||
const bottom = Math.max(window.innerHeight - rect.top + 8, 8);
|
||||
panel.style.setProperty('--sidebar-popover-bottom', `${bottom}px`);
|
||||
panel.style.setProperty('--sidebar-popover-left', `${left}px`);
|
||||
const requestedTop = anchorAbove
|
||||
? rect.top - panelHeight - 8
|
||||
: rect.bottom + 8;
|
||||
const top = Math.max(Math.min(requestedTop, maxTop), 8);
|
||||
|
||||
const flags = RendererStyleFlags2.DashCase;
|
||||
this.renderer.setStyle(panel, '--sidebar-popover-top', `${top}px`, flags);
|
||||
this.renderer.setStyle(panel, '--sidebar-popover-max-height', `${Math.max(window.innerHeight - top - 8, 0)}px`, flags);
|
||||
|
||||
if (anchorAbove || !this.layoutService.isDesktop()) {
|
||||
this.renderer.setStyle(panel, '--sidebar-popover-left', `${left}px`, flags);
|
||||
} else {
|
||||
const bottom = Math.max(window.innerHeight - rect.bottom, 8);
|
||||
panel.style.setProperty('--sidebar-popover-bottom', `${bottom}px`);
|
||||
if (this.layoutService.isDesktop()) {
|
||||
panel.style.removeProperty('--sidebar-popover-left');
|
||||
} else {
|
||||
panel.style.setProperty('--sidebar-popover-left', `${left}px`);
|
||||
}
|
||||
this.renderer.removeStyle(panel, '--sidebar-popover-left', flags);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-2
@@ -1,3 +1,5 @@
|
||||
@use "../../../../assets/layout/styles/layout/variables";
|
||||
|
||||
:host {
|
||||
display: contents;
|
||||
}
|
||||
@@ -8,11 +10,16 @@
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
box-sizing: border-box;
|
||||
height: 3.5rem;
|
||||
z-index: 100;
|
||||
background-color: var(--app-background);
|
||||
border-bottom: 1px solid var(--content-border-color);
|
||||
padding: 0 0.75rem;
|
||||
padding:
|
||||
0
|
||||
calc(0.75rem + env(safe-area-inset-right))
|
||||
0
|
||||
calc(0.75rem + env(safe-area-inset-left));
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
@@ -74,7 +81,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 767px) {
|
||||
@media #{variables.$mobile-shell-media-query} {
|
||||
.mobile-topbar {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ describe('LayoutService', () => {
|
||||
},
|
||||
} as never);
|
||||
const updateUserSetting = vi.fn();
|
||||
let resizeListener: (() => void) | undefined;
|
||||
let mobileShellActive = false;
|
||||
const localStorageService = {
|
||||
get: vi.fn((key: string) => {
|
||||
if (key === 'sidebarCollapsed') {
|
||||
@@ -35,6 +37,18 @@ describe('LayoutService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
routerEvents = new Subject<unknown>();
|
||||
resizeListener = undefined;
|
||||
mobileShellActive = false;
|
||||
vi.spyOn(window, 'addEventListener').mockImplementation((type, listener) => {
|
||||
if (type === 'resize') {
|
||||
resizeListener = listener as () => void;
|
||||
}
|
||||
});
|
||||
vi.spyOn(window, 'removeEventListener').mockImplementation(vi.fn());
|
||||
vi.spyOn(window, 'getComputedStyle').mockImplementation(() => ({
|
||||
getPropertyValue: (property: string) =>
|
||||
property === '--mobile-shell-active' && mobileShellActive ? '1' : '',
|
||||
}) as CSSStyleDeclaration);
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
LayoutService,
|
||||
@@ -82,6 +96,21 @@ describe('LayoutService', () => {
|
||||
expect(service.mobileDrawerOpen()).toBe(false);
|
||||
});
|
||||
|
||||
it('derives desktop state from the mobile shell CSS state', () => {
|
||||
expect(service.isDesktop()).toBe(true);
|
||||
|
||||
mobileShellActive = true;
|
||||
resizeListener?.();
|
||||
expect(service.isDesktop()).toBe(false);
|
||||
|
||||
service.mobileDrawerOpen.set(true);
|
||||
mobileShellActive = false;
|
||||
resizeListener?.();
|
||||
|
||||
expect(service.isDesktop()).toBe(true);
|
||||
expect(service.mobileDrawerOpen()).toBe(false);
|
||||
});
|
||||
|
||||
it('closeMobileSidebar resets mobileDrawerOpen to false', () => {
|
||||
service.mobileDrawerOpen.set(true);
|
||||
service.closeMobileSidebar();
|
||||
@@ -145,12 +174,10 @@ describe('LayoutService', () => {
|
||||
});
|
||||
|
||||
it('cleans up global listeners and router events when destroyed', () => {
|
||||
const removeEventListener = vi.spyOn(window, 'removeEventListener');
|
||||
|
||||
TestBed.resetTestingModule();
|
||||
routerEvents.next(new NavigationEnd(1, '/series', '/series'));
|
||||
|
||||
expect(removeEventListener).toHaveBeenCalledWith('resize', expect.any(Function));
|
||||
expect(window.removeEventListener).toHaveBeenCalledWith('resize', expect.any(Function));
|
||||
expect(service.currentPath()).toBe('/dashboard');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,9 +18,9 @@ import {
|
||||
export const SIDEBAR_MIN_WIDTH = 175;
|
||||
export const SIDEBAR_MAX_WIDTH = 400;
|
||||
export const SIDEBAR_DEFAULT_WIDTH = 225;
|
||||
const DESKTOP_MIN_WIDTH = 768;
|
||||
const SIDEBAR_EXPANDED_STATE_KEY = 'sidebarExpandedState';
|
||||
const SIDEBAR_TRANSITION_MS = 220;
|
||||
export const MOBILE_SHELL_ACTIVE_PROPERTY = '--mobile-shell-active';
|
||||
|
||||
function readBooleanRecord(storage: LocalStorageService, key: string): Record<string, boolean> {
|
||||
const stored = storage.get<unknown>(key);
|
||||
@@ -149,11 +149,21 @@ export class LayoutService {
|
||||
}
|
||||
|
||||
private computeIsDesktop(): boolean {
|
||||
return (this.document.defaultView?.innerWidth ?? DESKTOP_MIN_WIDTH) >= DESKTOP_MIN_WIDTH;
|
||||
const view = this.document.defaultView;
|
||||
if (!view) return true;
|
||||
|
||||
return view
|
||||
.getComputedStyle(this.document.documentElement)
|
||||
.getPropertyValue(MOBILE_SHELL_ACTIVE_PROPERTY)
|
||||
.trim() !== '1';
|
||||
}
|
||||
|
||||
private readonly onResize = (): void => {
|
||||
this.isDesktop.set(this.computeIsDesktop());
|
||||
const isDesktop = this.computeIsDesktop();
|
||||
this.isDesktop.set(isDesktop);
|
||||
if (isDesktop) {
|
||||
this.closeMobileSidebar();
|
||||
}
|
||||
};
|
||||
|
||||
private setSidebarCollapsed(collapsed: boolean): void {
|
||||
|
||||
Reference in New Issue
Block a user