Skip to content

AppShell

Document shell with optional side nav and a MainPanel body.

Phase 0.61 published surface

This additive contract is implemented and verified for the published 0.61.x Supported surface. See RELEASE_0_61.

Import from hedron import AppShell
Distribution hedron
Backend activity No
Normal render mode RenderMode.FRAGMENT

Live demo

Docs simulation — not a running Hedron server. Interactive demos show a “Simulated HTMX” trace when applicable.

HomeOverview metrics stay in MainPanel.

Minimal runnable app.py that reproduces this demo (real Hedron, not the docs simulator):

app.py
import os

from hedron import AppShell, Hedron, Nav, NavLink, Page, html, swap

app = Hedron(
    title="AppShell demo",
    security="standard",
    explorer="off",
    session_secret=os.environ.get("HEDRON_SESSION_SECRET", "dev-only"),
)

panel = app.region("comp-main-panel")


def panel_body(name: str, detail: str):
    return html.div(html.strong(name), html.span(detail))


@app.page("/")
def home() -> Page:
    return Page(
        AppShell(
            nav=Nav(
                NavLink("Home", "/home", target=panel.selector, swap="innerHTML", active=True),
                NavLink("Reports", "/reports", target=panel.selector, swap="innerHTML"),
                NavLink("Settings", "/settings", target=panel.selector, swap="innerHTML"),
            ),
            body=panel_body("Home", "Overview metrics stay in MainPanel."),
            panel_id=panel.id,
        ),
        title="AppShell",
    )


@app.view("/home", fragment_regions=(panel,))
def home_frag():
    return swap(panel_body("Home", "Overview metrics stay in MainPanel."))


@app.view("/reports", fragment_regions=(panel,))
def reports_frag():
    return swap(panel_body("Reports", "Reports fragment swapped into the panel."))


@app.view("/settings", fragment_regions=(panel,))
def settings_frag():
    return swap(panel_body("Settings", "Settings fragment; side nav stays put."))

Basic use

from hedron import AppShell, Heading, Nav, NavGroup, NavLink
component = AppShell(body=Heading('Home', level=1), nav=Nav(NavGroup('Workspace', NavLink('Home', '/'), NavLink('Reports', '/reports'))), panel_id='main-panel')

Compose under Page for full documents, or return from a fragment route for HTMX swaps.

How it works

AppShell composes landmark-friendly chrome with a swappable MainPanel so full page loads and HTMX fragment swaps share one layout. Use HtmxLink/NavLink targeting the panel id for the primary swap. When side chrome must update too, return an explicit OobUpdate(element_id=..., swap='innerHTML') and do not also set select_oob for that same id—hx-select-oob selects response nodes for OOB handling, while OobUpdate already emits hx-swap-oob.

This component can initiate or represent a backend interaction. The live documentation intercepts that interaction with JavaScript and shows the same pending, success, or replacement states without making a real request. In an application, keep the URL, authorization, validation, and returned fragment on the server; JavaScript is only progressive enhancement.

Constructor and parameters

AppShell(*body, *, nav=None, nav_groups=None, panel_id='main-panel', content_width='default', nav_collapse='never', nav_collapsed=False, class_=None, id=None)
Parameter Type Meaning
body NodeLike Primary content placed inside MainPanel.
nav NodeLike | None Optional side navigation (often Nav of NavLinks).
nav_groups Mapping[str, Sequence[NodeLike]] | Sequence[tuple[str, Sequence[NodeLike]]] | None Ordered grouped navigation lowered through NavGroup.
panel_id str Id forwarded to the composed MainPanel.
content_width narrow | default | wide | full Bounded content measure independent of navigation width.
nav_collapse never | user | always Desktop rail policy; user adds an accessible persisted toggle.
nav_collapsed bool Initial compact rail state.

Composition and backend behavior

Keep AppShell at the smallest semantic boundary. Fragment routes should return only the replaced region and preserve stable target IDs across success, validation, empty, loading, and error responses.

Mutating flows must use POST, validate CSRF, authorize on the server, re-validate typed input, and return a bounded fragment. GET remains safe and repeatable; native submit should still work without HTMX.

Accessibility

Keep global chrome outside MainPanel; put page-specific content inside the body slot. Prefer one OOB mechanism per target so <nav> / landmark hosts keep their tag and aria-* attributes.

Security

Escaping and SafeUrl / TrustedHtml are framework concerns; authorization and data exposure remain application code. Redact secrets before rendering.

Common mistakes

  • Do not use AppShell as a generic card or modal wrapper. Do not combine select_oob='#side-nav' with OobUpdate(element_id='side-nav') on the same navigation flow.
  • Do not copy docs-preview JavaScript into an application server.

Testing

from hedron import RenderMode, render

result = render(component, mode=RenderMode.FRAGMENT)
assert result.html
assert not result.diagnostics

All component demos · Built-in API · Testing