Blocks
Full pages and layouts built from the registry.
dashboard-01/dashboard-01.svelte
<script lang="ts" module>
import type { Snippet } from 'svelte';
import type { FeatureModule, FeatureScreen } from '$lib/registry/blocks/feature-menu/types.js';
import type { DashboardData } from './types.js';
export type Dashboard01Props = {
data: DashboardData;
/** Selected scope ids. Empty means everything. */
scope?: string[];
pinned?: string[];
/** Id of the screen the user is on. */
current?: string;
onNavigate?: (screen: FeatureScreen, module: FeatureModule) => void;
onSignOut?: () => void;
/** Logo or product name at the far left of the header. */
brand?: Snippet;
/** Buttons beside the page heading. */
actions?: Snippet;
class?: string;
};
</script>
<script lang="ts">
import AppHeader from '$lib/registry/blocks/app-header/app-header.svelte';
import MetricLedger from '$lib/registry/blocks/metric-ledger/metric-ledger.svelte';
import TreasuryWaterfallGrid from '$lib/registry/blocks/treasury-waterfall-grid/treasury-waterfall-grid.svelte';
import { cn } from '#lib/utils.js';
let {
data,
scope = $bindable([]),
pinned = $bindable([]),
current = $bindable(),
onNavigate,
onSignOut,
brand,
actions,
class: className
}: Dashboard01Props = $props();
</script>
<div class={cn('flex min-h-svh flex-col bg-muted/40', className)}>
<AppHeader
class="sticky top-0 z-30 border-b bg-background"
scopeItems={data.header.scopeItems}
scopeGroups={data.header.scopeGroups}
bind:scope
modules={data.header.modules}
bind:pinned
{current}
actions={data.header.actions}
user={data.header.user}
onNavigate={(screen, module) => {
current = screen.id;
onNavigate?.(screen, module);
}}
{onSignOut}
{brand}
/>
<main class="mx-auto flex w-full max-w-screen-2xl flex-1 flex-col gap-8 px-4 py-6 sm:px-6">
<div class="flex flex-wrap items-end justify-between gap-4">
<div class="flex min-w-0 flex-col gap-1">
<h1 class="text-xl font-semibold tracking-tight">{data.title}</h1>
{#if data.description}
<p class="text-sm text-muted-foreground">{data.description}</p>
{/if}
</div>
{#if actions}
<div class="flex items-center gap-2">{@render actions()}</div>
{/if}
</div>
<section class="flex min-w-0 flex-col gap-3">
<h2 class="text-sm font-medium">{data.ledger.heading}</h2>
<MetricLedger title={data.ledger.title} data={data.ledger.data} />
</section>
<section class="flex min-w-0 flex-col gap-3">
<h2 class="text-sm font-medium">{data.treasury.heading}</h2>
<TreasuryWaterfallGrid
data={data.treasury.data}
defaultMonthIndex={data.treasury.defaultMonthIndex}
/>
</section>
</main>
</div>
app-shell/app-shell.svelte
<script lang="ts" module>
import type { Snippet } from 'svelte';
import type { CommandPaletteAction } from '$lib/registry/blocks/command-palette/types.js';
import type {
AppShellData,
AppShellLabels,
AppShellMenuItem,
AppShellModule,
AppShellNotification,
AppShellNotificationLink,
AppShellPanel,
AppShellScreen
} from './types.js';
export type AppShellProps = {
data: AppShellData;
/** Id of the screen the user is on. */
current?: string;
/** Right-hand panel that is open, if any. */
panel?: AppShellPanel | null;
notifications?: AppShellNotification[];
/** Desktop sidebar expanded (true) or icons only (false). Cmd/Ctrl+B toggles it. */
sidebarOpen?: boolean;
/** State of the dark mode switch in the account menu. The consumer applies it. */
dark?: boolean;
labels?: Partial<AppShellLabels>;
/** Logo, shown at 16px. */
logo?: Snippet;
/** The page. */
children?: Snippet;
/** Conversation in the assistant panel. Without it the greeting and suggestions show. */
conversation?: Snippet;
onNavigate?: (screen: AppShellScreen, module: AppShellModule) => void;
onAction?: (action: CommandPaletteAction) => void;
onAsk?: (prompt: string) => void;
onAccount?: (item: AppShellMenuItem) => void;
onHelp?: (item: AppShellMenuItem) => void;
onSettings?: () => void;
onFeedback?: () => void;
onSignOut?: () => void;
onNotification?: (notification: AppShellNotification) => void;
onNotificationLink?: (
link: AppShellNotificationLink,
notification: AppShellNotification
) => void;
class?: string;
};
</script>
<script lang="ts">
import CommandPalette from '$lib/registry/blocks/command-palette/command-palette.svelte';
import { SidePanel } from '$lib/registry/ui/side-panel/index.js';
import * as Sidebar from '#lib/components/ui/sidebar/index.js';
import { cn } from '#lib/utils.js';
import AppSidebar from './app-sidebar.svelte';
import AssistantPanel from './assistant-panel.svelte';
import NotificationList from './notification-list.svelte';
import ShellHeader from './shell-header.svelte';
import { defaultAppShellLabels } from './types.js';
let {
data,
current = $bindable(),
panel = $bindable(null),
notifications = $bindable([]),
sidebarOpen = $bindable(true),
dark = $bindable(false),
labels: labelOverrides,
logo,
children,
conversation,
onNavigate,
onAction,
onAsk,
onAccount,
onHelp,
onSettings,
onFeedback,
onSignOut,
onNotification,
onNotificationLink,
class: className
}: AppShellProps = $props();
const labels = $derived({ ...defaultAppShellLabels, ...labelOverrides });
const unread = $derived(notifications.filter((n) => n.unread).length);
let searchOpen = $state(false);
// Search lists each module's own page first, then its screens.
const paletteModules = $derived(
data.modules.map((m) => ({
...m,
screens: [{ id: m.id, label: m.label, icon: m.icon, href: m.href }, ...m.screens]
}))
);
// A bookmark reports the module that owns its screen, not the bookmarks heading.
function navigate(screen: AppShellScreen, module: AppShellModule) {
current = screen.id;
const owner = module.heading
? (data.modules.find((m) => m.screens.some((s) => s.id === screen.id)) ?? module)
: module;
onNavigate?.(screen, owner);
}
</script>
<Sidebar.Provider
bind:open={sidebarOpen}
class={cn('bg-sidebar', className)}
style="--sidebar-width: 15rem;"
>
<AppSidebar
{data}
{labels}
{current}
{logo}
onNavigate={navigate}
{onHelp}
{onSettings}
{onFeedback}
/>
<!-- One screen tall: the page scrolls inside its card, so nothing slides under the header. -->
<Sidebar.Inset class="h-svh min-w-0 bg-sidebar">
<ShellHeader
{data}
{labels}
{unread}
bind:panel
bind:dark
onSearch={() => (searchOpen = true)}
{onAccount}
{onSignOut}
/>
<div class="flex min-h-0 flex-1 gap-2 px-2 pb-2">
<div
class="min-w-0 flex-1 overflow-y-auto rounded-xl bg-background shadow-sm ring-1 ring-foreground/5"
>
{@render children?.()}
</div>
<SidePanel
bind:open={() => panel !== null, (open) => !open && (panel = null)}
title={panel === 'assistant' ? labels.assistant : labels.notifications}
closeLabel={labels.close}
class="rounded-xl shadow-sm ring-1 ring-foreground/10"
>
{#if panel === 'assistant'}
<AssistantPanel suggestions={data.suggestions} {labels} {onAsk} children={conversation} />
{:else}
<NotificationList
bind:notifications
{labels}
onOpen={onNotification}
onLink={onNotificationLink}
/>
{/if}
</SidePanel>
</div>
</Sidebar.Inset>
</Sidebar.Provider>
<CommandPalette
bind:open={searchOpen}
data={{ modules: paletteModules, actions: data.actions }}
onSelect={(selection) => {
if (selection.type === 'action') return onAction?.(selection.action);
const module = data.modules.find((m) => m.id === selection.module.id);
if (module) navigate(selection.screen, module);
}}
/>