Files
CollabTable/CollabTableServer/webui/src/lib/components/Header.svelte
T

87 lines
2.8 KiB
Svelte
Raw Normal View History

<script module>
import { Info, LayoutDashboard } from '@lucide/svelte';
const navItems = [
{ to: '/', end: true, icon: LayoutDashboard, label: 'Overview' },
{ to: '/about', icon: Info, label: 'About' },
];
function isActive(pathname, target, end) {
if (end) return pathname === target;
return pathname === target || pathname.startsWith(`${target}/`);
}
</script>
<script>
import { page } from '$app/state';
import { resolve } from '$app/paths';
import { Menu, Table2, Settings, X } from '@lucide/svelte';
import { cn } from '$lib/utils/cn.js';
import Button from '$lib/components/ui/button.svelte';
import HealthWidget from '$lib/features/health/HealthWidget.svelte';
import SettingsDialog from '$lib/features/layout/SettingsDialog.svelte';
const navLinkClass = (active) =>
cn(
'inline-flex shrink-0 items-center gap-2 whitespace-nowrap rounded-md px-3 py-1.5 text-sm font-medium transition-colors hover:bg-surface-hover',
active && 'bg-surface-hover text-primary',
);
let navOpen = $state(false);
let settingsOpen = $state(false);
</script>
<header class="sticky top-0 z-40 flex h-14 items-center gap-2 border-b border-border bg-bg px-3">
<a href={resolve('/')} class="flex shrink-0 items-center gap-2 pr-1 font-semibold text-fg">
<Table2 class="size-5 text-primary" />
<span>CollabTable</span>
</a>
<Button
variant="ghost"
size="icon"
class="ml-auto min-[640px]:hidden"
aria-label="Toggle navigation"
aria-expanded={navOpen}
aria-controls="primary-navigation"
onclick={() => (navOpen = !navOpen)}
>
{#if navOpen}
<X class="size-5" />
{:else}
<Menu class="size-5" />
{/if}
</Button>
<nav
id="primary-navigation"
class={cn(
'min-[640px]:flex min-[640px]:items-center min-[640px]:gap-1',
'absolute left-0 right-0 top-full flex flex-col gap-1 border-b border-border bg-bg p-2 shadow-lg min-[640px]:static min-[640px]:flex-row min-[640px]:border-b-0 min-[640px]:bg-transparent min-[640px]:p-0 min-[640px]:shadow-none',
!navOpen && 'hidden min-[640px]:flex',
)}
>
{#each navItems as item (item.to)}
{@const href = resolve(item.to)}
<a
{href}
class={cn(
navLinkClass(isActive(page.url.pathname, href, item.end)),
'w-full justify-start py-2 min-[640px]:w-auto min-[640px]:py-1.5',
)}
onclick={() => (navOpen = false)}
>
<item.icon class="size-4" />
{item.label}
</a>
{/each}
</nav>
<div class="flex shrink-0 items-center gap-1 min-[640px]:ml-auto">
<HealthWidget />
<Button variant="ghost" size="icon" aria-label="Settings" onclick={() => (settingsOpen = true)}>
<Settings class="size-5" />
</Button>
</div>
</header>
<SettingsDialog bind:open={settingsOpen} />