This commit is contained in:
1 parent
295aa978f9
commit
599351e1c0
4 files changed
+188
-22
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>
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -184,7 +284,7 @@
|
||||
type="button"
|
||||
onclick={() => (navOpen = !navOpen)}
|
||||
>
|
||||
{navOpen ? '×' : '☰'}
|
||||
{navOpen ? '×' : '☰'}
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user