Skip to content

MobileAppShell

Responsive application shell that composes existing Faststrap navigation primitives for desktop and mobile layouts. It does not replace Navbar, SidebarNavbar, Drawer, or BottomNav; it gives those surfaces predictable responsive slots.

Quick Start

from faststrap import BottomNav, BottomNavItem, MobileAppShell, Navbar

MobileAppShell(
    "Dashboard content",
    desktop_nav=Navbar(brand="Console"),
    mobile_nav=Navbar(brand="Console", expand="none"),
    bottom_nav=BottomNav(
        BottomNavItem("Home", href="/", icon="house", active=True),
        BottomNavItem("Profile", href="/profile", icon="person"),
    ),
)

Parameters

Parameter Type Default Description
*children Any () Main page content.
desktop_nav Any \| None None Content shown from breakpoint upward.
mobile_nav Any \| None None Content shown below breakpoint.
sidebar Any \| None None Desktop sidebar, laid out beside <main> from breakpoint upward.
drawer Any \| None None Drawer/offcanvas slot, usually paired with a trigger.
mobile_toolbar Any \| None None Mobile-only top toolbar.
bottom_nav Any \| None None Mobile-only bottom navigation.
safe_area bool True Adds bottom safe-area padding around main content.
breakpoint Literal["sm", "md", "lg", "xl", "xxl"] "lg" Bootstrap breakpoint at which desktop navigation/sidebar replace mobile navigation.
content_id str \| None "main-content" ID for the <main> landmark; use None to omit it when composing multiple shells.
content_cls str \| None None Additional classes for the <main> content region.
**kwargs Any Shell attributes, including id, data_*, and hx_*.

The shell renders a main-content landmark by default. With a sidebar, the shell places the sidebar and main region in a shared desktop flex row; below the configured breakpoint the sidebar is hidden and the main content remains in the mobile flow. BottomNav already applies its own bottom safe-area inset, so the shell does not add a second inset to that slot. Pass navigation components through the slots rather than duplicating their markup in the page body.

faststrap.components.layout.mobile_app_shell.MobileAppShell(*children, desktop_nav=None, mobile_nav=None, sidebar=None, drawer=None, mobile_toolbar=None, bottom_nav=None, safe_area=True, breakpoint='lg', content_id='main-content', content_cls=None, **kwargs)

Compose responsive navigation, content, and mobile-safe-area surfaces.

Navigation slots are deliberately rendered by the caller, so existing Navbar, SidebarNavbar, Drawer, and BottomNav APIs remain unchanged and can be replaced independently.

Source code in src/faststrap/components/layout/mobile_app_shell.py
@register(category="layout")
@beta
def MobileAppShell(
    *children: Any,
    desktop_nav: Any | None = None,
    mobile_nav: Any | None = None,
    sidebar: Any | None = None,
    drawer: Any | None = None,
    mobile_toolbar: Any | None = None,
    bottom_nav: Any | None = None,
    safe_area: bool = True,
    breakpoint: Literal["sm", "md", "lg", "xl", "xxl"] = "lg",
    content_id: str | None = "main-content",
    content_cls: str | None = None,
    **kwargs: Any,
) -> Div:
    """Compose responsive navigation, content, and mobile-safe-area surfaces.

    Navigation slots are deliberately rendered by the caller, so existing
    ``Navbar``, ``SidebarNavbar``, ``Drawer``, and ``BottomNav`` APIs remain
    unchanged and can be replaced independently.
    """
    if breakpoint not in {"sm", "md", "lg", "xl", "xxl"}:
        raise ValueError("breakpoint must be a Bootstrap breakpoint")
    user_cls = kwargs.pop("cls", "")
    content_children = [SafeArea(*children, edges="bottom")] if safe_area else list(children)
    content: Any = Main(
        *content_children,
        cls=merge_classes("faststrap-mobile-app-content flex-grow-1 min-w-0", content_cls or ""),
        id=content_id,
    )

    parts: list[Any] = []
    for value, cls in (
        (desktop_nav, f"d-none d-{breakpoint}-block"),
        (mobile_nav, f"d-{breakpoint}-none"),
        (drawer, "faststrap-mobile-app-drawer"),
        (mobile_toolbar, f"d-{breakpoint}-none"),
    ):
        if (part := _slot(value, cls=cls)) is not None:
            parts.append(part)

    if sidebar is not None:
        parts.append(
            Div(
                _slot(
                    sidebar,
                    cls=f"d-none d-{breakpoint}-block faststrap-mobile-app-sidebar flex-shrink-0",
                ),
                content,
                cls="faststrap-mobile-app-desktop-layout d-flex flex-grow-1 min-w-0",
            )
        )
    else:
        parts.append(content)
    if bottom_nav is not None:
        parts.append(_slot(bottom_nav, cls=f"d-{breakpoint}-none faststrap-mobile-app-bottom-nav"))

    attrs: dict[str, Any] = {
        "cls": merge_classes("faststrap-mobile-app-shell d-flex flex-column min-vh-100", user_cls),
    }
    attrs.update(convert_attrs(kwargs))
    return Div(*parts, **attrs)