Files
shared/packages/web-ui/src/lib/components/Header.svelte
T
Gabriel20xx 2f57554154
Lint / Lint (Node/Svelte) (push) Successful in 23s
Lint / Lint (Go) (push) Successful in 16s
Lint / Lint (Python) (push) Successful in 9s
Tests / Test (Node/Svelte) (push) Successful in 14s
Tests / Test (Go) (push) Successful in 17s
Tests / Test (Python) (push) Successful in 9s
Extend shared UI component customization
2026-08-04 16:53:36 +02:00

94 lines
2.4 KiB
Svelte
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts">
import type { Snippet } from 'svelte';
import type { NavItem } from '../types';
let {
brand = 'Application',
brandHref = '/',
currentPath = '',
navItems = [],
actions,
onLogout,
onNavigate,
onProfile,
onSettings,
showSettings = true,
username = ''
}: {
brand?: string;
brandHref?: string;
currentPath?: string;
navItems?: NavItem[];
actions?: Snippet;
onLogout?: () => void | Promise<void>;
onNavigate?: (item: NavItem) => void;
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}
onclick={(event) => {
if (onNavigate) {
event.preventDefault();
onNavigate(item);
}
navOpen = false;
}}
>
{item.label}
</a>
{/each}
</nav>
<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 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>