Installation
Usage
"use client"
import { MobileAppShell, useAppShell } from "@/components/mobile-app-shell"
function Trips() {
const shell = useAppShell()
return (
<ul className="grid gap-2 px-4">
{["Lofoten", "Kyoto", "Porto"].map((trip) => (
<li key={trip}>
<button
type="button"
className="w-full rounded-xl bg-muted p-4 text-left"
onClick={() => shell.push({ title: trip, content: <p className="px-4">Plans for {trip}.</p> })}
>
{trip}
</button>
</li>
))}
</ul>
)
}
export default function App() {
return (
<MobileAppShell
brand="Nordlys"
tabs={[
{ value: "trips", label: "Trips", icon: "plane", content: <Trips /> },
{ value: "inbox", label: "Inbox", icon: "inbox", badge: 2, content: <p className="px-4">No new messages.</p> },
{ value: "profile", label: "Profile", icon: "user", content: <p className="px-4">Elena Novak</p> },
]}
menu={[{ label: "Account", items: [{ label: "Settings", icon: "settings", href: "/settings" }] }]}
/>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| tabs | AppShellTab[] | — | Tab bar items plus title?, content? (the tab's first screen when the shell holds the screens) and actions?. |
| value / defaultValue / onValueChange | string | first tab | The current tab, controlled or not. |
| brand | string | — | The app's name, atop the menu and the wide-screen sidebar. |
| children | ReactNode | — | With routes: the current page, shown in the current tab. |
| title | string | tab title | With routes: the current page's title. |
| backHref / backLabel / onBack | string / string / () => void | — | With routes: the parent page. Shows a back button and enables swipe-back. |
| path | string | — | With routes: the pathname. Each tab then remembers the last page opened in it. |
| actions | ReactNode | — | Buttons at the right of the top bar. |
| menu | { label?, items: { label, icon?, href?, onSelect?, badge? }[] }[] | — | Extra places: a menu from the left on phones, the sidebar on wide screens. |
| look / indicator / labels / action | see Bottom Tab Bar | classic / pill / always | Passed to the tab bar. |
| hideTabBarOnScroll | boolean | false | Slide the tab bar away while a screen scrolls down. |
| largeTitle | boolean | true | First screens show a large title that moves into the top bar on scroll. |
| swipeBack | boolean | true | Drag from the left edge to go back. |
| linkComponent | ElementType | "a" | Renders tabs, menu items and back links, e.g. Next.js Link. |
| headingLevel | 1 | 2 | 1 | 1 when the shell is the page; 2 when it sits under another title. |
| useAppShell() | { push, pop, popToRoot, select, tab, depth } | — | From inside a tab: open a screen on top ({ title, content, actions? }), go back, or switch tabs. |
Accessibility
- One navigation landmark at a time: the tab bar on phones, the sidebar from 48rem; the current tab has aria-current="page".
- The menu is a modal dialog: focus moves in and is trapped, Escape, a tap outside or choosing an item closes it, and focus returns to the menu button.
- A pushed screen takes focus on its title; going back returns focus to what opened it. Screens underneath and tabs out of view are inert.
- Back buttons say where they go ("Back to Trips"); under prefers-reduced-motion screens change without sliding.
Changelog
- v1.0.0Latest
First release.