@molecule/app-header-svelte
Feature · header · App (browser) · v1.2.5 · Apache-2.0
Top app-shell header: branded logo + appName on the left, slotted actions (theme toggle, user menu, extras) on the right
npm install @molecule/app-header-svelteHow it works
@molecule/app-header-svelte is a ready-made header feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
<script lang="ts">
import { AppHeader } from '@molecule/app-header-svelte'
import { UserMenu } from '@molecule/app-ui-svelte'
</script>
<!-- UserMenu takes the settings panel as its children snippet; panel
content dismisses the drawer via usePanelClose(). -->
<AppHeader appName="Bearing">
{#snippet userMenu()}
<UserMenu>
<div>Your settings panel here</div>
</UserMenu>
{/snippet}
</AppHeader>Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte
Reference
Svelte top app-shell header — the Svelte counterpart of
@molecule/app-header-react, with the same props and the same DOM: branded
logo + appName on the left, slotted actions (theme toggle, extra actions,
user menu) on the right.
Reproduces the byte-identical Header pattern from 9 flagship apps as a
single composable primitive. Pair with @molecule/app-shell-layout-svelte's
AppShellLayout to assemble a full chrome.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
<script lang="ts">
import { AppHeader } from '@molecule/app-header-svelte'
import { UserMenu } from '@molecule/app-ui-svelte'
</script>
<!-- UserMenu takes the settings panel as its children snippet; panel
content dismisses the drawer via usePanelClose(). -->
<AppHeader appName="Bearing">
{#snippet userMenu()}
<UserMenu>
<div>Your settings panel here</div>
</UserMenu>
{/snippet}
</AppHeader>
Type
feature
Installation
npm install @molecule/app-header-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
API
Interfaces
AppHeaderNavigation
A primary navigation landmark with one link per declared destination.
interface AppHeaderNavigation {
/** Accessible name for the navigation landmark. */
label: string
/**
* Router destinations mapped to anchor props, with the link's content as
* `children`: text, or a snippet. Put a destination's icon and text in the
* same snippet so they share one native link and one keyboard stop. The
* anchor's class is `className`, as in React's entries.
*/
links: Readonly<
Record<
string,
| (Omit<LinkProps, 'to' | 'children' | 'class'> & {
children: Snippet | string | number
className?: string
})
| undefined
>
>
/** Additional class on the native nav element. */
className?: string
/** Additional class on the links' list. */
listClassName?: string
/** Additional class on each list item. */
itemClassName?: string
}
AppHeaderProps
Props for the AppHeader component.
interface AppHeaderProps {
/** Brand display name shown next to the logo. */
appName: string
/** Logo image source. Defaults to `/logo.svg` (the convention scaffolded by mlcl). */
logoSrc?: string
/** Logo size in pixels (square). Defaults to 30 to match the flagship-app convention. */
logoSize?: number
/** Path the brand link navigates to. Defaults to `/`. */
brandTo?: string
/** Additional class on the brand anchor. */
brandClassName?: string
/** Primary destinations, such as public links or links for the current session. */
navigation?: AppHeaderNavigation
/** Slot for the right-side user menu — typically `<UserMenu />` from `@molecule/app-ui-svelte`. */
userMenu?: Snippet
/**
* Theme toggle slot. Defaults to a resilient wrapper around
* `<ThemeToggle />` (from `@molecule/app-ui-svelte`) that renders the toggle
* ONLY when `@molecule/app-svelte`'s theme + i18n providers are both
* mounted above the header, and omits it (never throws) when they are not —
* so the header renders out of the box even before theme/i18n are wired.
* Pass `null` to force-hide it, or your own snippet (e.g. an icon-bonded
* variant) to override.
*/
themeToggle?: Snippet | null
/** Optional extra actions rendered between the theme toggle and the user menu. */
extraActions?: Snippet
/**
* Apply `cm.headerFixed` for sticky/fixed positioning. Defaults to `true`,
* matching the flagship-app convention. Set to `false` for a non-sticky header.
*/
fixed?: boolean
/** Extra className on the outer `<header>` (composed with `cm.headerBar` + optional `cm.headerFixed`). */
className?: string
/** `data-mol-id` for AI-agent selectors. */
dataMolId?: string
}
Constants
AppHeader
const AppHeader: LegacyComponentType
Injection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.13.0 || ^4.0.0@molecule/app-ui^1.0.1@molecule/app-ui-svelte^1.1.0svelte^5.0.0
Runtime Dependencies
-
@molecule/app-svelte -
@molecule/app-ui -
@molecule/app-ui-svelte -
svelte -
Must render inside
@molecule/app-svelte's router context (setMoleculeContext({ router })) — the brand link navigates through it, exactly as the React header requires areact-router-domrouter. -
The DEFAULT
themeToggleslot renders<ThemeToggle />(which callsuseTheme()+useTranslation()) ONLY when the binding'sThemeProviderI18nProviderare both mounted above the header — it probes their presence first. Without those providers the toggle is silently OMITTED instead of throwing, so<AppHeader appName="…" />renders out of the box; it lights up automatically once they are wired. PassthemeToggle={null}to force-hide it, or your own snippet to override.
-
fixeddefaults totrue(cm.headerFixedpositions the header fixed): give the page content a matching top offset (flagships get it fromAppShellLayout), or passfixed={false}for an in-flow header. -
logoSrcdefaults to/logo.svg, the file mlcl scaffolds intopublic/. -
Styling routes through ClassMap tokens (
cm.headerBar,cm.headerFixed,cm.headerInner,cm.logoText) — requires a bonded ClassMap.