Update shared web UI auth and profile menu

This commit is contained in:
Gabriel20xx committed 2026-08-09 10:34:06 +02:00
1 parent e3544617e1
commit d0b18a4902
5 files changed
+189 -20

No files matched your search

@@ -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<void>;
onLogout?: () => void | Promise<void>;
onNavigate?: (item: NavItem) => void;
onProfile?: () => void;
@@ -47,11 +51,13 @@
<div class={`sc-root sc-app-shell ${className}`} data-theme={theme === 'system' ? undefined : theme}>
<Header
aboutHref={aboutHref ?? navItems.find((item) => item.label.toLowerCase() === 'about')?.href}
{brand}
{brandHref}
{currentPath}
actions={headerActions}
{navItems}
{onAbout}
{onLogout}
{onNavigate}
{onProfile}
@@ -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<void>;
onConfirmReset?: AuthResetConfirm;
@@ -134,7 +136,7 @@
<div class="sc-root sc-auth-page">
<section aria-labelledby="sc-auth-title" class="sc-auth-card">
<div class="sc-auth-brand">
<span aria-hidden="true" class="sc-brand-mark">{brand.slice(0, 1).toUpperCase()}</span>
<img alt="" aria-hidden="true" class="sc-auth-brand-icon" src={faviconHref} />
<span>{brand}</span>
</div>
+119 -19
View File
@@ -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<void>;
onLogout?: () => void | Promise<void>;
onNavigate?: (item: NavItem) => void;
onProfile?: () => void;
onSettings?: () => void;
onProfile?: () => void | Promise<void>;
onSettings?: () => void | Promise<void>;
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 @@
}
</script>
<svelte:window onclick={handleWindowClick} onkeydown={handleWindowKeydown} />
<header class="sc-header">
<a class="sc-brand" href={brandHref} onclick={() => (navOpen = false)}>
<span aria-hidden="true" class="sc-brand-mark">{brand.slice(0, 1).toUpperCase()}</span>
<a class="sc-brand" href={brandHref} onclick={closeMenus}>
<span aria-hidden="true" class="sc-brand-mark">
{#if brandIcon}
{@render brandIcon()}
{:else}
{brand.slice(0, 1).toUpperCase()}
{/if}
</span>
<span>{brand}</span>
</a>
@@ -148,7 +184,7 @@
event.preventDefault();
onNavigate(item);
}
navOpen = false;
closeMenus();
}}
>
<Icon aria-hidden="true" class="sc-nav-icon" size={16} strokeWidth={2} />
@@ -160,21 +196,85 @@
<div class="sc-header-actions">
{#if actions}{@render actions()}{/if}
{#if showSettings && onSettings}
<button aria-label="Open settings" class="sc-icon-button" type="button" onclick={onSettings}>⚙</button>
{/if}
{#if hasProfileMenu}
<div class="sc-profile-menu" data-profile-menu>
<button
aria-expanded={profileOpen}
aria-haspopup="menu"
class="sc-profile-button"
type="button"
onclick={() => (profileOpen = !profileOpen)}
>
<CircleUserRound aria-hidden="true" class="sc-profile-icon" size={16} strokeWidth={2} />
<span>{username}</span>
<ChevronDown aria-hidden="true" class="sc-profile-chevron" size={15} strokeWidth={2} />
</button>
{#if username && onProfile}
<button class="sc-profile-button" type="button" onclick={onProfile}>
<CircleUserRound aria-hidden="true" class="sc-profile-icon" size={16} strokeWidth={2} />
<span>{username}</span>
</button>
{/if}
{#if profileOpen}
<div aria-label="Account menu" class="sc-profile-dropdown" role="menu">
{#if onProfile}
<button
class="sc-profile-menu-item"
role="menuitem"
type="button"
onclick={() => {
profileOpen = false;
void onProfile?.();
}}
>
Profile
</button>
{/if}
{#if onLogout}
<button class="sc-button sc-button-ghost sc-button-sm" type="button" onclick={() => void onLogout?.()}>
Log out
</button>
{#if showSettings && onSettings}
<button
class="sc-profile-menu-item"
role="menuitem"
type="button"
onclick={() => {
profileOpen = false;
void onSettings?.();
}}
>
Settings
</button>
{/if}
{#if onAbout}
<button
class="sc-profile-menu-item"
role="menuitem"
type="button"
onclick={() => {
profileOpen = false;
void onAbout?.();
}}
>
About
</button>
{:else if aboutHref}
<a class="sc-profile-menu-item" href={aboutHref} role="menuitem" onclick={() => (profileOpen = false)}>
About
</a>
{/if}
{#if onLogout}
<button
class="sc-profile-menu-item"
role="menuitem"
type="button"
onclick={() => {
profileOpen = false;
void onLogout?.();
}}
>
<LogOut aria-hidden="true" size={15} strokeWidth={2} />
Log out
</button>
{/if}
</div>
{/if}
</div>
{/if}
<button