diff --git a/shared/packages/web-ui/src/lib/components/AppShell.svelte b/shared/packages/web-ui/src/lib/components/AppShell.svelte index c0fa251..f168a0b 100644 --- a/shared/packages/web-ui/src/lib/components/AppShell.svelte +++ b/shared/packages/web-ui/src/lib/components/AppShell.svelte @@ -5,6 +5,7 @@ import PageHeader from './PageHeader.svelte'; let { + aboutHref, brand = 'Application', brandHref = '/', children, @@ -12,6 +13,7 @@ currentPath = '', headerActions, navItems = [], + onAbout, onLogout, onNavigate, onProfile, @@ -21,6 +23,7 @@ theme = 'dark', username = '', }: { + aboutHref?: string; brand?: string; brandHref?: string; children?: Snippet; @@ -28,6 +31,7 @@ currentPath?: string; headerActions?: Snippet; navItems?: NavItem[]; + onAbout?: () => void | Promise; onLogout?: () => void | Promise; onNavigate?: (item: NavItem) => void; onProfile?: () => void; @@ -47,11 +51,13 @@
item.label.toLowerCase() === 'about')?.href} {brand} {brandHref} {currentPath} actions={headerActions} {navItems} + {onAbout} {onLogout} {onNavigate} {onProfile} diff --git a/shared/packages/web-ui/src/lib/components/AuthPage.svelte b/shared/packages/web-ui/src/lib/components/AuthPage.svelte index e885e8e..b93afdd 100644 --- a/shared/packages/web-ui/src/lib/components/AuthPage.svelte +++ b/shared/packages/web-ui/src/lib/components/AuthPage.svelte @@ -12,6 +12,7 @@ brand = 'Application', children, error = '', + faviconHref = '/favicon.svg', loading = false, onLogin, onConfirmReset, @@ -24,6 +25,7 @@ brand?: string; children?: Snippet; error?: string; + faviconHref?: string; loading?: boolean; onLogin?: (input: AuthLoginInput) => void | Promise; onConfirmReset?: AuthResetConfirm; @@ -134,7 +136,7 @@
- + {brand}
diff --git a/shared/packages/web-ui/src/lib/components/Header.svelte b/shared/packages/web-ui/src/lib/components/Header.svelte index 688cc97..3203a63 100644 --- a/shared/packages/web-ui/src/lib/components/Header.svelte +++ b/shared/packages/web-ui/src/lib/components/Header.svelte @@ -5,6 +5,7 @@ BarChart3, Bot, Box, + ChevronDown, CircleAlert, CircleHelp, CircleUserRound, @@ -19,6 +20,7 @@ Info, LayoutDashboard, ListVideo, + LogOut, Logs, Magnet, Map, @@ -91,32 +93,58 @@ }; let { + aboutHref, brand = 'Application', brandHref = '/', + brandIcon, currentPath = '', navItems = [], actions, + onAbout, onLogout, onNavigate, onProfile, onSettings, showSettings = true, - username = '' + username = '', }: { + aboutHref?: string; brand?: string; brandHref?: string; + brandIcon?: Snippet; currentPath?: string; navItems?: NavItem[]; actions?: Snippet; + onAbout?: () => void | Promise; onLogout?: () => void | Promise; onNavigate?: (item: NavItem) => void; - onProfile?: () => void; - onSettings?: () => void; + onProfile?: () => void | Promise; + onSettings?: () => void | Promise; showSettings?: boolean; username?: string; } = $props(); let navOpen = $state(false); + let profileOpen = $state(false); + + const hasProfileMenu = $derived( + Boolean(username && (onProfile || (showSettings && onSettings) || onAbout || aboutHref || onLogout)), + ); + + function closeMenus(): void { + navOpen = false; + profileOpen = false; + } + + function handleWindowKeydown(event: KeyboardEvent): void { + if (event.key === 'Escape') closeMenus(); + } + + function handleWindowClick(event: MouseEvent): void { + if (event.target instanceof Element && !event.target.closest('[data-profile-menu]')) { + profileOpen = false; + } + } function iconFor(item: NavItem) { return icons[item.icon ?? 'layout-dashboard'] ?? LayoutDashboard; @@ -129,9 +157,17 @@ } + +
- (navOpen = false)}> - + + {brand} @@ -148,7 +184,7 @@ event.preventDefault(); onNavigate(item); } - navOpen = false; + closeMenus(); }} >
diff --git a/shared/packages/web-ui/src/lib/styles.css b/shared/packages/web-ui/src/lib/styles.css index 666587c..678c57f 100644 --- a/shared/packages/web-ui/src/lib/styles.css +++ b/shared/packages/web-ui/src/lib/styles.css @@ -1,4 +1,4 @@ -@import "../../../design-tokens/theme.css"; +@import '../../../design-tokens/theme.css'; :where(.sc-root, .sc-root *) { box-sizing: border-box; @@ -139,6 +139,55 @@ font-size: 0.875rem; } +.sc-profile-menu { + position: relative; +} + +.sc-profile-chevron { + transition: transform 140ms ease; +} + +.sc-profile-button[aria-expanded="true"] .sc-profile-chevron { + transform: rotate(180deg); +} + +.sc-profile-dropdown { + position: absolute; + top: calc(100% + 0.5rem); + right: 0; + z-index: 20; + display: grid; + min-width: 11rem; + gap: 0.125rem; + padding: 0.375rem; + background: var(--sc-surface); + border: 1px solid var(--sc-border); + border-radius: var(--sc-radius-md); + box-shadow: var(--sc-shadow-lg); +} + +.sc-profile-menu-item { + display: flex; + width: 100%; + align-items: center; + gap: 0.5rem; + padding: 0.625rem 0.75rem; + color: var(--sc-muted-fg); + background: transparent; + border: 0; + border-radius: var(--sc-radius-sm); + font: inherit; + font-size: 0.875rem; + text-align: left; + text-decoration: none; + cursor: pointer; +} + +.sc-profile-menu-item:hover { + color: var(--sc-fg); + background: var(--sc-surface-hover); +} + .sc-icon-button:hover, .sc-profile-button:hover { color: var(--sc-fg); @@ -274,6 +323,7 @@ .sc-button:focus-visible, .sc-icon-button:focus-visible, .sc-profile-button:focus-visible, +.sc-profile-menu-item:focus-visible, .sc-nav-link:focus-visible, .sc-dialog-close:focus-visible { outline: 3px solid color-mix(in srgb, var(--sc-ring) 45%, transparent); @@ -604,6 +654,14 @@ font-weight: 750; } +.sc-auth-brand-icon { + display: block; + width: 2rem; + height: 2rem; + object-fit: contain; + border-radius: var(--sc-radius-md); +} + .sc-auth-card h1 { font-size: 1.7rem; }