feat(ui): New sidebar & search UI (#831)

This commit is contained in:
Alex
2026-05-04 09:46:48 +01:00
committed by GitHub
parent c9b2a5734e
commit f3138a88c5
182 changed files with 8318 additions and 4660 deletions
@@ -0,0 +1,49 @@
<ng-container *transloco="let t; prefix: 'layout'">
<header class="mobile-topbar">
<button
type="button"
class="mobile-topbar-button"
[attr.aria-label]="t('menu.toggleNavigation')"
(click)="layoutService.onMenuToggle()"
>
<i class="pi pi-bars" aria-hidden="true"></i>
</button>
<div class="mobile-topbar-brand">
<svg class="mobile-topbar-brand-icon" viewBox="0 0 100 126" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path d="M25.8062 106.614V113.077V119.537V126L32.2559 119.537L38.7093 126V119.537V113.077V106.614H25.8062Z" fill="white"/>
<path d="M38.7093 29.0758H96.7715C98.5535 29.0758 99.9964 27.6307 99.9964 25.846V3.22984C99.9964 1.44512 98.5535 0 96.7715 0H12.9031C10.5512 0 8.35077 0.63224 6.44975 1.73414C4.49102 2.86856 2.86054 4.50155 1.72787 6.4633C0.631268 8.36363 0 10.5674 0 12.923V106.614C0 113.753 5.7752 119.537 12.9031 119.537H21.1529V113.077H12.9031C9.33915 113.077 6.44975 110.183 6.44975 106.614C6.44975 103.044 9.33915 100.15 12.9031 100.15H93.5466C97.1106 100.15 100 97.2566 100 93.6871V41.9988C100 38.4293 97.1106 35.5355 93.5466 35.5355H38.7093C36.9273 35.5355 35.4845 36.9806 35.4845 38.7653V61.3815C35.4845 63.1662 36.9273 64.6113 38.7093 64.6113H67.7404C69.5224 64.6113 70.9653 66.0564 70.9653 67.8412C70.9653 69.6259 69.5224 71.071 67.7404 71.071H38.7093C33.3634 71.071 29.0311 66.732 29.0311 61.3779V38.7617C29.0311 33.4076 33.3634 29.0686 38.7093 29.0686V29.0758Z" fill="url(#mobile-topbar-brand-primary-gradient)"/>
<path d="M96.7715 113.077H43.5539V119.537H96.7715C98.5535 119.537 99.9964 118.092 99.9964 116.307C99.9964 114.522 98.5535 113.077 96.7715 113.077Z" fill="url(#mobile-topbar-brand-secondary-gradient)"/>
<defs>
<linearGradient id="mobile-topbar-brand-primary-gradient" x1="50" y1="0" x2="50" y2="119.537" gradientUnits="userSpaceOnUse">
<stop offset="0" style="stop-color: var(--primary-300)"/>
<stop offset="1" style="stop-color: var(--primary-500)"/>
</linearGradient>
<linearGradient id="mobile-topbar-brand-secondary-gradient" x1="50" y1="0" x2="50" y2="119.537" gradientUnits="userSpaceOnUse">
<stop offset="0" style="stop-color: var(--primary-300)"/>
<stop offset="1" style="stop-color: var(--primary-500)"/>
</linearGradient>
</defs>
</svg>
<span class="mobile-topbar-brand-text">Grimmory</span>
</div>
@if (commandPaletteService.isOpen()) {
<button
type="button"
class="mobile-topbar-button"
[attr.aria-label]="'common.close' | transloco"
(click)="closeSearch()"
>
<i class="pi pi-times" aria-hidden="true"></i>
</button>
} @else {
<button
type="button"
class="mobile-topbar-button"
[attr.aria-label]="t('menu.search')"
(click)="openSearch()"
>
<i class="pi pi-search" aria-hidden="true"></i>
</button>
}
</header>
</ng-container>
@@ -0,0 +1,81 @@
:host {
display: contents;
}
.mobile-topbar {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
height: 3.5rem;
z-index: 100;
background-color: var(--app-background);
border-bottom: 1px solid var(--content-border-color);
padding: 0 0.75rem;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
}
.mobile-topbar-brand {
display: flex;
align-items: center;
justify-content: center;
flex: 1 1 auto;
min-width: 0;
gap: 0.4rem;
color: var(--text-color);
}
.mobile-topbar-brand-icon {
width: auto;
height: 1.75rem;
flex-shrink: 0;
transform: translateY(1px);
}
.mobile-topbar-brand-text {
font-size: 1.25rem;
font-weight: 600;
line-height: 1;
white-space: nowrap;
}
.mobile-topbar-button {
flex-shrink: 0;
}
.mobile-topbar-button {
display: inline-flex;
align-items: center;
justify-content: center;
width: 2.5rem;
height: 2.5rem;
padding: 0;
border: 0;
background: none;
border-radius: 6px;
color: var(--text-color);
cursor: pointer;
transition: background-color 0.15s ease, color 0.15s ease;
&:hover {
background-color: var(--surface-hover);
}
&:focus-visible {
outline: 2px solid var(--primary-color);
outline-offset: 2px;
}
i {
font-size: 1.25rem;
}
}
@media (width <= 991px) {
.mobile-topbar {
display: flex;
}
}
@@ -0,0 +1,81 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { signal } from '@angular/core';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { getTranslocoModule } from '../../../core/testing/transloco-testing';
import { CommandPaletteService } from '../../../features/command-palette/command-palette.service';
import { LayoutService } from '../layout.service';
import { AppMobileTopbarComponent } from './app.mobile-topbar.component';
describe('AppMobileTopbarComponent', () => {
let fixture: ComponentFixture<AppMobileTopbarComponent>;
let component: AppMobileTopbarComponent;
let layoutService: {
closeMobileSidebar: ReturnType<typeof vi.fn>;
onMenuToggle: ReturnType<typeof vi.fn>;
};
let commandPaletteService: {
open: ReturnType<typeof vi.fn>;
hide: ReturnType<typeof vi.fn>;
toggle: ReturnType<typeof vi.fn>;
isOpen: ReturnType<typeof signal>;
query: ReturnType<typeof signal>;
visibleItems: ReturnType<typeof signal>;
groups: ReturnType<typeof signal>;
};
beforeEach(() => {
layoutService = {
closeMobileSidebar: vi.fn(),
onMenuToggle: vi.fn(),
};
commandPaletteService = {
open: vi.fn(),
hide: vi.fn(),
toggle: vi.fn(),
isOpen: signal(false),
query: signal(''),
visibleItems: signal([]),
groups: signal([]),
};
TestBed.configureTestingModule({
imports: [AppMobileTopbarComponent, getTranslocoModule()],
providers: [
{ provide: LayoutService, useValue: layoutService },
{ provide: CommandPaletteService, useValue: commandPaletteService },
],
});
fixture = TestBed.createComponent(AppMobileTopbarComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('opens the command palette and closes the mobile sidebar when search is pressed', () => {
component.openSearch();
expect(layoutService.closeMobileSidebar).toHaveBeenCalledOnce();
expect(commandPaletteService.open).toHaveBeenCalledOnce();
});
it('shows the search icon when the palette is closed', () => {
commandPaletteService.isOpen.set(false);
fixture.detectChanges();
const icon = fixture.nativeElement.querySelector('.mobile-topbar button:last-of-type i');
expect(icon?.classList.contains('pi-search')).toBe(true);
});
it('swaps to a close button that hides the palette when it is open', () => {
commandPaletteService.isOpen.set(true);
fixture.detectChanges();
const button = fixture.nativeElement.querySelector('.mobile-topbar button:last-of-type') as HTMLButtonElement;
const icon = button.querySelector('i');
expect(icon?.classList.contains('pi-times')).toBe(true);
button.click();
expect(commandPaletteService.hide).toHaveBeenCalledOnce();
});
});
@@ -0,0 +1,24 @@
import { Component, inject } from '@angular/core';
import { TranslocoDirective, TranslocoPipe } from '@jsverse/transloco';
import { CommandPaletteService } from '../../../features/command-palette/command-palette.service';
import { LayoutService } from '../layout.service';
@Component({
selector: 'app-mobile-topbar',
templateUrl: './app.mobile-topbar.component.html',
styleUrl: './app.mobile-topbar.component.scss',
imports: [TranslocoDirective, TranslocoPipe],
})
export class AppMobileTopbarComponent {
readonly layoutService = inject(LayoutService);
protected readonly commandPaletteService = inject(CommandPaletteService);
openSearch(): void {
this.layoutService.closeMobileSidebar();
this.commandPaletteService.open();
}
closeSearch(): void {
this.commandPaletteService.hide();
}
}