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

96 lines
2.5 KiB
Svelte
Raw Normal View History

2026-08-04 15:17:15 +02:00
<script lang="ts">
import { onMount } from 'svelte';
2026-08-04 15:17:15 +02:00
import type { Snippet } from 'svelte';
import type { NavItem } from '../types';
import Header from './Header.svelte';
import NotificationStack from './NotificationStack.svelte';
import PageHeader from './PageHeader.svelte';
import { initPrimaryColor, setPrimaryColorUser } from '../primary-color.svelte';
2026-08-04 15:17:15 +02:00
let {
2026-08-09 10:34:06 +02:00
aboutHref,
2026-08-04 15:17:15 +02:00
brand = 'Application',
brandHref = '/',
children,
class: className = '',
currentPath = '',
faviconHref = '/favicon.svg',
2026-08-04 16:53:36 +02:00
headerActions,
2026-08-04 15:17:15 +02:00
navItems = [],
2026-08-09 10:34:06 +02:00
onAbout,
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,
2026-08-31 17:17:52 +02:00
pageHeaderActions,
showPageHeader = true,
2026-08-04 15:17:15 +02:00
showSettings = true,
theme = 'dark',
username = '',
2026-08-04 15:17:15 +02:00
}: {
2026-08-09 10:34:06 +02:00
aboutHref?: string;
2026-08-04 15:17:15 +02:00
brand?: string;
brandHref?: string;
children?: Snippet;
class?: string;
currentPath?: string;
faviconHref?: string;
2026-08-04 16:53:36 +02:00
headerActions?: Snippet;
2026-08-04 15:17:15 +02:00
navItems?: NavItem[];
2026-08-09 10:34:06 +02:00
onAbout?: () => void | Promise<void>;
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;
2026-08-31 17:17:52 +02:00
pageHeaderActions?: Snippet;
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}/`),
),
);
$effect(() => {
setPrimaryColorUser(username);
});
onMount(() => initPrimaryColor(brand, username));
2026-08-04 15:17:15 +02:00
</script>
<div class={`sc-root sc-app-shell ${className}`} data-theme={theme === 'system' ? undefined : theme}>
<NotificationStack />
2026-08-04 15:17:15 +02:00
<Header
aboutHref={aboutHref ?? navItems.find((item) => item.label.toLowerCase() === 'about')?.href ?? '/about'}
2026-08-04 15:17:15 +02:00
{brand}
{brandHref}
{currentPath}
{faviconHref}
2026-08-04 16:53:36 +02:00
actions={headerActions}
2026-08-04 15:17:15 +02:00
{navItems}
2026-08-09 10:34:06 +02:00
{onAbout}
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}
{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.`}
2026-08-31 17:17:52 +02:00
actions={pageHeaderActions}
/>
{/if}
2026-08-04 15:17:15 +02:00
{@render children?.()}
</main>
</div>