diff --git a/README.md b/README.md index 72d78f0..160b67c 100644 --- a/README.md +++ b/README.md @@ -196,11 +196,14 @@ The Node and Python packages intentionally expose the same infrastructure concep /> ``` +The shared profile menu exposes Profile, Settings, About, and Log out. It uses the `About` navigation item's href automatically; pass `aboutHref` or `onAbout` to `AppShell` when a project uses a custom About destination or dialog. + For authentication, use the same shell with `AuthPage` and connect the callbacks to the application's existing auth service: ```svelte auth.login(credentials.identifier, credentials.password)} onSetup={(credentials) => auth.setup(credentials)} onRequestReset={() => auth.requestAdminReset()} diff --git a/packages/web-ui/src/lib/components/AppShell.svelte b/packages/web-ui/src/lib/components/AppShell.svelte index c0fa251..f168a0b 100644 --- a/packages/web-ui/src/lib/components/AppShell.svelte +++ b/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/packages/web-ui/src/lib/components/AuthPage.svelte b/packages/web-ui/src/lib/components/AuthPage.svelte index e885e8e..b93afdd 100644 --- a/packages/web-ui/src/lib/components/AuthPage.svelte +++ b/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/packages/web-ui/src/lib/components/Header.svelte b/packages/web-ui/src/lib/components/Header.svelte index 688cc97..d405010 100644 --- a/packages/web-ui/src/lib/components/Header.svelte +++ b/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(); }} >