@molecule/app-top-nav-layout-svelte
Feature · top-nav-layout · App (browser) · v1.2.3 · Apache-2.0
Top navigation app shell: brand link + horizontal NavLinks + UserMenu slot, with a router outlet for nested routes
npm install @molecule/app-top-nav-layout-svelteHow it works
@molecule/app-top-nav-layout-svelte is a ready-made top-nav-layout 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 { TopNavLayout, type TopNavItem } from '@molecule/app-top-nav-layout-svelte'
const nav: TopNavItem[] = [
{ key: 'dashboard', to: '/dashboard', icon: 'dashboard', label: 'Dashboard' },
{ key: 'reports', to: '/reports', icon: 'bar_chart', label: 'Reports' },
]
</script>
<TopNavLayout appName="Acme" {nav}>
{#snippet userMenu()}
<button type="button">Account</button>
{/snippet}
<!-- The routed page body. -->
<h1>Home</h1>
</TopNavLayout>Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte
Reference
Svelte top navigation app shell layout for routed Svelte apps — the Svelte
counterpart of @molecule/app-top-nav-layout-react, with the same props
(React names) and the same DOM for the same input.
Exports TopNavLayout — sticky header with brand link + horizontal router
links + a user-menu slot, plus the <main> holding the routed page body —
and the TopNavItem / TopNavLayoutProps types.
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 { TopNavLayout, type TopNavItem } from '@molecule/app-top-nav-layout-svelte'
const nav: TopNavItem[] = [
{ key: 'dashboard', to: '/dashboard', icon: 'dashboard', label: 'Dashboard' },
{ key: 'reports', to: '/reports', icon: 'bar_chart', label: 'Reports' },
]
</script>
<TopNavLayout appName="Acme" {nav}>
{#snippet userMenu()}
<button type="button">Account</button>
{/snippet}
<!-- The routed page body. -->
<h1>Home</h1>
</TopNavLayout>
Type
feature
Installation
npm install @molecule/app-top-nav-layout-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
API
Interfaces
TopNavItem
A single navigation item rendered in the top nav bar.
interface TopNavItem {
/** Route path the link goes to. */
to: string
/** Stable key — used to key the rendered link and as the i18n key suffix in apps. */
key: string
/** Material symbol icon name (or any glyph) shown next to the label. */
icon?: string
/** Visible label. Apps that route this through `t(...)` should pass the resolved string. */
label: string
}
TopNavLayoutProps
Props accepted by the TopNavLayout component.
interface TopNavLayoutProps {
/** Brand text shown in the top-left link (typically the app name). */
appName: string
/** Path the brand link navigates to. Defaults to `'/'`. */
logoTo?: string
/** Horizontal nav items rendered in the header. */
navItems: ReadonlyArray<TopNavItem>
/** Snippet rendered at the right of the header (typically a user menu). */
userMenu?: Snippet
/**
* Aria-label for the primary `<nav>`. Overrides the translated /
* `defaultValue` `'Primary navigation'` (prop > `t()` > default).
*/
navAriaLabel?: string
/** Extra classes on the outer wrapper. */
className?: string
/** `data-mol-id` for AI-agent selectors. */
dataMolId?: string
/**
* The routed page body. React renders its router's `<Outlet />` in the
* `<main>`; pass the routed view (the layout's page content) here.
*/
children?: Snippet
}
Constants
TopNavLayout
const TopNavLayout: LegacyComponentType
Injection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.14.0 || ^4.0.0@molecule/app-ui^1.3.11@molecule/app-ui-svelte^1.1.0svelte^5.0.0
Runtime Dependencies
@molecule/app-svelte@molecule/app-ui@molecule/app-ui-sveltesvelte
Use it as a LAYOUT component and put the routed page in the default content:
React renders React Router's <Outlet /> in the <main>, and this package
renders its children snippet there. Nav labels are hidden below the md
breakpoint (icon-only mobile nav), so always provide icon names; they
render as Material Symbols ligatures and need the Material Symbols font
loaded by the host app. Styling comes from the bonded ClassMap, so a
theme/ClassMap bond is a prerequisite. label is rendered as-is: pass an
already-translated string.
Translations
Translation strings are provided by @molecule/app-locales-top-nav-layout.