refactor(ui): app-menu positioning and styling refinements (#2308)
This commit is contained in:
@@ -24,6 +24,7 @@ import {
|
|||||||
appMenuLabelClass,
|
appMenuLabelClass,
|
||||||
appMenuLeadingSlotClass,
|
appMenuLeadingSlotClass,
|
||||||
appMenuShortcutClass,
|
appMenuShortcutClass,
|
||||||
|
appMenuTrailingTextClass,
|
||||||
appMenuSpinnerClass,
|
appMenuSpinnerClass,
|
||||||
appMenuSubmenuIconClass,
|
appMenuSubmenuIconClass,
|
||||||
appMenuTrailingIconClass,
|
appMenuTrailingIconClass,
|
||||||
@@ -48,6 +49,8 @@ import {
|
|||||||
#anchor
|
#anchor
|
||||||
[routerLink]="link()"
|
[routerLink]="link()"
|
||||||
[queryParams]="queryParams()"
|
[queryParams]="queryParams()"
|
||||||
|
[target]="target() || undefined"
|
||||||
|
[attr.rel]="target() === '_blank' ? 'noopener' : null"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
class="flex min-h-full w-full items-center gap-2 no-underline text-inherit outline-none">
|
class="flex min-h-full w-full items-center gap-2 no-underline text-inherit outline-none">
|
||||||
<ng-container [ngTemplateOutlet]="body" />
|
<ng-container [ngTemplateOutlet]="body" />
|
||||||
@@ -76,6 +79,9 @@ import {
|
|||||||
@if (trailingIcon(); as iconData) {
|
@if (trailingIcon(); as iconData) {
|
||||||
<svg [lucideIcon]="iconData" [class]="trailingIconClass" aria-hidden="true"></svg>
|
<svg [lucideIcon]="iconData" [class]="trailingIconClass" aria-hidden="true"></svg>
|
||||||
}
|
}
|
||||||
|
@if (trailingText()) {
|
||||||
|
<span [class]="trailingTextClass" aria-hidden="true">{{ trailingText() }}</span>
|
||||||
|
}
|
||||||
@if (shortcut()) {
|
@if (shortcut()) {
|
||||||
<span [class]="shortcutClass" aria-hidden="true">{{ shortcut() }}</span>
|
<span [class]="shortcutClass" aria-hidden="true">{{ shortcut() }}</span>
|
||||||
}
|
}
|
||||||
@@ -92,9 +98,11 @@ export class AppMenuItemComponent {
|
|||||||
readonly loading = input(false, { transform: booleanAttribute });
|
readonly loading = input(false, { transform: booleanAttribute });
|
||||||
readonly inset = input(false, { transform: booleanAttribute });
|
readonly inset = input(false, { transform: booleanAttribute });
|
||||||
readonly shortcut = input('');
|
readonly shortcut = input('');
|
||||||
|
readonly trailingText = input('');
|
||||||
readonly variant = input<AppMenuItemVariant>('default');
|
readonly variant = input<AppMenuItemVariant>('default');
|
||||||
readonly closeOnSelect = input(true, { transform: booleanAttribute });
|
readonly closeOnSelect = input(true, { transform: booleanAttribute });
|
||||||
readonly link = input<string | readonly unknown[] | null>(null);
|
readonly link = input<string | readonly unknown[] | null>(null);
|
||||||
|
readonly target = input('');
|
||||||
readonly queryParams = input<Record<string, unknown> | null>(null);
|
readonly queryParams = input<Record<string, unknown> | null>(null);
|
||||||
readonly searchLabel = input('');
|
readonly searchLabel = input('');
|
||||||
|
|
||||||
@@ -112,6 +120,7 @@ export class AppMenuItemComponent {
|
|||||||
protected readonly labelClass = appMenuLabelClass;
|
protected readonly labelClass = appMenuLabelClass;
|
||||||
protected readonly trailingIconClass = appMenuTrailingIconClass;
|
protected readonly trailingIconClass = appMenuTrailingIconClass;
|
||||||
protected readonly shortcutClass = appMenuShortcutClass;
|
protected readonly shortcutClass = appMenuShortcutClass;
|
||||||
|
protected readonly trailingTextClass = appMenuTrailingTextClass;
|
||||||
protected readonly submenuIconClass = appMenuSubmenuIconClass;
|
protected readonly submenuIconClass = appMenuSubmenuIconClass;
|
||||||
protected readonly rowClass = computed(() => appMenuItemRowClass(this.variant()));
|
protected readonly rowClass = computed(() => appMenuItemRowClass(this.variant()));
|
||||||
protected readonly inert = computed(() => this.loading() || this.menuItem.disabled());
|
protected readonly inert = computed(() => this.loading() || this.menuItem.disabled());
|
||||||
|
|||||||
@@ -54,6 +54,23 @@ import { AppMenuContentDirective } from './app-menu-content.directive';
|
|||||||
|
|
||||||
const menuByElement = new WeakMap<Element, AppMenuComponent>();
|
const menuByElement = new WeakMap<Element, AppMenuComponent>();
|
||||||
|
|
||||||
|
export interface ContextMenuRequest {
|
||||||
|
origin: HTMLElement;
|
||||||
|
cursor: {x: number; y: number} | null;
|
||||||
|
contextmenu: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function contextMenuRequest(event: MouseEvent): ContextMenuRequest {
|
||||||
|
const contextmenu = event.type === 'contextmenu';
|
||||||
|
return {
|
||||||
|
origin: event.currentTarget as HTMLElement,
|
||||||
|
cursor: contextmenu && (event.clientX !== 0 || event.clientY !== 0)
|
||||||
|
? {x: event.clientX, y: event.clientY}
|
||||||
|
: null,
|
||||||
|
contextmenu,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
type MenuPresentation = 'popup' | 'sheet' | 'push';
|
type MenuPresentation = 'popup' | 'sheet' | 'push';
|
||||||
|
|
||||||
const SUBMENU_GAP = 4;
|
const SUBMENU_GAP = 4;
|
||||||
@@ -214,6 +231,14 @@ export class AppMenuComponent {
|
|||||||
this.show();
|
this.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openFrom(request: ContextMenuRequest): void {
|
||||||
|
if (request.cursor) {
|
||||||
|
this.openAt(request.cursor.x, request.cursor.y, request.origin);
|
||||||
|
} else {
|
||||||
|
this.open(request.origin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
openAt(x: number, y: number, contextZone?: HTMLElement, fromPointer = true): void {
|
openAt(x: number, y: number, contextZone?: HTMLElement, fromPointer = true): void {
|
||||||
this.pendingFocus = 'first';
|
this.pendingFocus = 'first';
|
||||||
if (!this.openState()) {
|
if (!this.openState()) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export const appMenuSheetPanelClass =
|
|||||||
'rounded-t-xl rounded-b-none border-x-0 border-b-0 ' +
|
'rounded-t-xl rounded-b-none border-x-0 border-b-0 ' +
|
||||||
'pt-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]';
|
'pt-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]';
|
||||||
|
|
||||||
export const appMenuScrollRegionClass = 'flex min-h-0 flex-col overflow-y-auto overscroll-contain';
|
export const appMenuScrollRegionClass = 'flex min-h-0 flex-col overflow-x-hidden overflow-y-auto overscroll-contain';
|
||||||
|
|
||||||
export const appMenuSheetPaneClass = 'will-change-transform animate-in-sheet slide-in-from-bottom-full';
|
export const appMenuSheetPaneClass = 'will-change-transform animate-in-sheet slide-in-from-bottom-full';
|
||||||
|
|
||||||
@@ -51,14 +51,16 @@ export function appMenuItemRowClass(variant: AppMenuItemVariant): string {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const appMenuLeadingSlotClass = 'flex size-4 shrink-0 items-center justify-center text-text-muted';
|
const menuIconToneClass = 'text-surface-400 dark:text-text-muted';
|
||||||
export const appMenuBadgeSlotClass = cn(appMenuLeadingSlotClass, 'text-xs font-medium tabular-nums');
|
export const appMenuLeadingSlotClass = cn('flex size-4 shrink-0 items-center justify-center', menuIconToneClass);
|
||||||
|
export const appMenuBadgeSlotClass = cn(appMenuLeadingSlotClass, 'text-xs font-medium tabular-nums text-text-muted');
|
||||||
export const appMenuIconClass = 'size-3.5 shrink-0';
|
export const appMenuIconClass = 'size-3.5 shrink-0';
|
||||||
export const appMenuSpinnerClass = 'size-4 shrink-0 border-2';
|
export const appMenuSpinnerClass = 'size-4 shrink-0 border-2';
|
||||||
export const appMenuLabelClass = 'min-w-0 flex-1 truncate leading-5';
|
export const appMenuLabelClass = 'min-w-0 flex-1 truncate leading-5';
|
||||||
export const appMenuShortcutClass = overlayListShortcutClass;
|
export const appMenuShortcutClass = overlayListShortcutClass;
|
||||||
export const appMenuTrailingIconClass = 'size-4 shrink-0';
|
export const appMenuTrailingTextClass = 'text-xs text-text-muted';
|
||||||
export const appMenuSubmenuIconClass = 'ml-auto size-4 shrink-0 text-text-muted';
|
export const appMenuTrailingIconClass = cn('ml-2 size-3.5 shrink-0', menuIconToneClass);
|
||||||
|
export const appMenuSubmenuIconClass = cn(appMenuTrailingIconClass, 'ml-auto');
|
||||||
export const appMenuCheckIconClass = 'size-4 shrink-0 text-primary';
|
export const appMenuCheckIconClass = 'size-4 shrink-0 text-primary';
|
||||||
export const appMenuSectionClass = cn(overlayListSectionLabelClass, 'text-text-muted');
|
export const appMenuSectionClass = cn(overlayListSectionLabelClass, 'text-text-muted');
|
||||||
export const appMenuSeparatorClass = overlayListSeparatorClass;
|
export const appMenuSeparatorClass = overlayListSeparatorClass;
|
||||||
|
|||||||
Reference in New Issue
Block a user