2026-08-04 15:17:15 +02:00
|
|
|
|
<script lang="ts">
|
2026-08-04 16:53:36 +02:00
|
|
|
|
import type { Snippet } from 'svelte';
|
2026-08-04 15:17:15 +02:00
|
|
|
|
import type { NavItem } from '../types';
|
|
|
|
|
|
|
|
|
|
|
|
let {
|
|
|
|
|
|
brand = 'Application',
|
|
|
|
|
|
brandHref = '/',
|
|
|
|
|
|
currentPath = '',
|
|
|
|
|
|
navItems = [],
|
2026-08-04 16:53:36 +02:00
|
|
|
|
actions,
|
2026-08-04 15:17:15 +02:00
|
|
|
|
onLogout,
|
2026-08-04 16:53:36 +02:00
|
|
|
|
onNavigate,
|
2026-08-04 15:17:15 +02:00
|
|
|
|
onProfile,
|
|
|
|
|
|
onSettings,
|
|
|
|
|
|
showSettings = true,
|
|
|
|
|
|
username = ''
|
|
|
|
|
|
}: {
|
|
|
|
|
|
brand?: string;
|
|
|
|
|
|
brandHref?: string;
|
|
|
|
|
|
currentPath?: string;
|
|
|
|
|
|
navItems?: NavItem[];
|
2026-08-04 16:53:36 +02:00
|
|
|
|
actions?: Snippet;
|
2026-08-04 15:17:15 +02:00
|
|
|
|
onLogout?: () => void | Promise<void>;
|
2026-08-04 16:53:36 +02:00
|
|
|
|
onNavigate?: (item: NavItem) => void;
|
2026-08-04 15:17:15 +02:00
|
|
|
|
onProfile?: () => void;
|
|
|
|
|
|
onSettings?: () => void;
|
|
|
|
|
|
showSettings?: boolean;
|
|
|
|
|
|
username?: string;
|
|
|
|
|
|
} = $props();
|
|
|
|
|
|
|
|
|
|
|
|
let navOpen = $state(false);
|
|
|
|
|
|
|
|
|
|
|
|
function isActive(item: NavItem): boolean {
|
|
|
|
|
|
return item.href === '/'
|
|
|
|
|
|
? currentPath === '/'
|
|
|
|
|
|
: currentPath === item.href || currentPath.startsWith(`${item.href}/`);
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
|
<span>{brand}</span>
|
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
|
|
<nav aria-label="Primary navigation" class="sc-nav" data-open={navOpen}>
|
|
|
|
|
|
{#each navItems as item}
|
|
|
|
|
|
<a
|
|
|
|
|
|
aria-current={isActive(item) ? 'page' : undefined}
|
|
|
|
|
|
class="sc-nav-link"
|
|
|
|
|
|
data-active={isActive(item)}
|
|
|
|
|
|
href={item.href}
|
2026-08-04 16:53:36 +02:00
|
|
|
|
onclick={(event) => {
|
|
|
|
|
|
if (onNavigate) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
onNavigate(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
navOpen = false;
|
|
|
|
|
|
}}
|
2026-08-04 15:17:15 +02:00
|
|
|
|
>
|
|
|
|
|
|
{item.label}
|
|
|
|
|
|
</a>
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="sc-header-actions">
|
2026-08-04 16:53:36 +02:00
|
|
|
|
{#if actions}{@render actions()}{/if}
|
|
|
|
|
|
|
2026-08-04 15:17:15 +02:00
|
|
|
|
{#if showSettings && onSettings}
|
|
|
|
|
|
<button aria-label="Open settings" class="sc-icon-button" type="button" onclick={onSettings}>⚙</button>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
{#if username && onProfile}
|
|
|
|
|
|
<button class="sc-profile-button" type="button" onclick={onProfile}>{username}</button>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
{#if onLogout}
|
|
|
|
|
|
<button class="sc-button sc-button-ghost sc-button-sm" type="button" onclick={() => void onLogout?.()}>
|
|
|
|
|
|
Log out
|
|
|
|
|
|
</button>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
|
aria-expanded={navOpen}
|
|
|
|
|
|
aria-label={navOpen ? 'Close navigation menu' : 'Open navigation menu'}
|
|
|
|
|
|
class="sc-icon-button sc-mobile-menu-button"
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onclick={() => (navOpen = !navOpen)}
|
|
|
|
|
|
>
|
|
|
|
|
|
{navOpen ? '×' : '☰'}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</header>
|