Files
shared/packages/web-ui/src/lib/components/AppShell.svelte
T

73 lines
1.8 KiB
Svelte
Raw Normal View History

2026-08-04 15:17:15 +02:00
<script lang="ts">
import type { Snippet } from 'svelte';
import type { NavItem } from '../types';
import Header from './Header.svelte';
import PageHeader from './PageHeader.svelte';
2026-08-04 15:17:15 +02:00
let {
brand = 'Application',
brandHref = '/',
children,
class: className = '',
currentPath = '',
2026-08-04 16:53:36 +02:00
headerActions,
2026-08-04 15:17:15 +02:00
navItems = [],
onLogout,
2026-08-04 16:53:36 +02:00
onNavigate,
2026-08-04 15:17:15 +02:00
onProfile,
onSettings,
showPageHeader = true,
2026-08-04 15:17:15 +02:00
showSettings = true,
theme = 'dark',
username = '',
2026-08-04 15:17:15 +02:00
}: {
brand?: string;
brandHref?: string;
children?: Snippet;
class?: string;
currentPath?: string;
2026-08-04 16:53:36 +02:00
headerActions?: Snippet;
2026-08-04 15:17:15 +02:00
navItems?: NavItem[];
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;
showPageHeader?: boolean;
2026-08-04 15:17:15 +02:00
showSettings?: boolean;
theme?: 'dark' | 'light' | 'system';
username?: string;
} = $props();
const activeNavItem = $derived(
navItems.find((item) =>
item.href === '/' ? currentPath === '/' : currentPath === item.href || currentPath.startsWith(`${item.href}/`),
),
);
2026-08-04 15:17:15 +02:00
</script>
<div class={`sc-root sc-app-shell ${className}`} data-theme={theme === 'system' ? undefined : theme}>
<Header
{brand}
{brandHref}
{currentPath}
2026-08-04 16:53:36 +02:00
actions={headerActions}
2026-08-04 15:17:15 +02:00
{navItems}
{onLogout}
2026-08-04 16:53:36 +02:00
{onNavigate}
2026-08-04 15:17:15 +02:00
{onProfile}
{onSettings}
{showSettings}
{username}
/>
<main class="sc-main">
{#if showPageHeader && activeNavItem?.href !== '/about'}
<PageHeader
title={activeNavItem?.label ?? brand}
description={activeNavItem?.description ??
`Explore the ${activeNavItem?.label?.toLowerCase() ?? 'application'} section.`}
/>
{/if}
2026-08-04 15:17:15 +02:00
{@render children?.()}
</main>
</div>