App Shell
Application shell: a Sidebar plus a main column. The frame measures its own width, so the same markup works on a phone, in a narrow window and in a Studio device preview. When it runs out of room the Sidebar becomes a slide-in drawer, written once, with no breakpoint classes, hamburger state or second copy of the navigation.
// Plain markup
import { AppFrame, useAppFrame } from "@shavin/ui";One Sidebar, any width
Pick a size or drag the frame's corner. Below 768px of frame width the same Sidebar becomes a drawer and the menu button appears in the top bar.
Groceries
$412 of $600
Rent
$1,850 of $1,850
Utilities
$138 of $220
Childcare
$640 of $900
The cards use Grid columns="auto", so they reflow as the frame narrows or the sidebar becomes a drawer, with no breakpoint classes.
import { useState } from "react";
import { usePathname } from "next/navigation";
import {
AppFrame, Sidebar, SidebarHeader, SidebarBody, SidebarSection,
SidebarNavItem, SidebarTrigger, TopBar, Grid, Card, Icon, Text,
} from "@shavin/ui";
export function BudgetApp() {
const pathname = usePathname();
const [view, setView] = useState("budgets");
return (
<AppFrame
routeKey={pathname}
className="h-dvh"
sidebar={
<Sidebar width="w-56">
<SidebarHeader>
<Text as="span" size="sm" weight="semibold">Household budget</Text>
</SidebarHeader>
<SidebarBody>
<SidebarSection title="Money">
<SidebarNavItem
label="Budgets"
icon={<Icon name="PiggyBank" size="sm" color="inherit" />}
active={view === "budgets"}
onClick={() => setView("budgets")}
/>
{/* more items */}
</SidebarSection>
</SidebarBody>
</Sidebar>
}
>
<TopBar className="gap-2">
<SidebarTrigger />
<Text as="span" size="sm" weight="medium">Budgets</Text>
</TopBar>
<div className="min-h-0 flex-1 overflow-y-auto p-4">
<Grid columns="auto" minWidth="sm" gap="3">
{/* cards */}
</Grid>
</div>
</AppFrame>
);
}How the frame decides
AppFrame measures its own width, not the window, so it is right inside panels, embeds and device previews. compactBelow sets the switch point: md (768px, default) or lg (1024px). In compact mode the drawer has a scrim, makes the page behind it inert, moves focus in, closes on Escape or a swipe to the left, and returns focus to the trigger. A collapsed icon rail opens in full inside the drawer.
Pass the current route as routeKey so the drawer closes after navigation. SidebarNavItem also closes it on click; for any other control, call useAppFrame().closeNav().
const pathname = usePathname();
<AppFrame routeKey={pathname} compactBelow="lg" navLabel="Main navigation" sidebar={<Sidebar>…</Sidebar>}>
…
</AppFrame>Content for one width only
Inside an AppFrame, use shavin-frame-compact-only for something that should show only while the sidebar is a drawer, such as the product name in the top bar, and shavin-frame-wide-only for the opposite. Both follow the frame and compactBelow. Avoid md:hidden here: it follows the window.
<TopBar className="gap-2">
<SidebarTrigger />
<Text as="span" size="sm" weight="semibold" className="shavin-frame-compact-only">Household budget</Text>
<Text as="span" size="sm" weight="medium">Budgets</Text>
</TopBar>TopBar
Header row
A 56px-minimum header with a bottom border. Lay out its children with className.
<TopBar className="gap-2">
<Text as="span" size="sm" weight="medium">Budgets</Text>
<Button size="sm" className="ml-auto">New budget</Button>
</TopBar>Keyboard
| Key | Action |
|---|---|
| Tab | The first stop is a Skip to content link that jumps to the main column. |
| Enter / Space | On the menu button: opens the navigation drawer and moves focus into it. |
| Tab | While the drawer is open, stays inside it; the page behind is inert. |
| Escape | Closes the drawer and returns focus to the menu button. |
Props
AppFrame
| Prop | Type | Default | Description |
|---|---|---|---|
| sidebar* | ReactNode | — | The app's navigation: a `<Sidebar>`. Written once; the frame turns it into a slide-in drawer when it runs out of room. |
| children* | ReactNode | — | Main application content (usually a `<TopBar>` followed by the page body). |
| compactBelow | "md" | "lg" | — | Frame width below which the sidebar becomes a drawer: "md" (768px, default) or "lg" (1024px). Measured on the frame itself, not the window. |
| navLabel | string | Navigation | Accessible name of the navigation drawer. Default "Navigation". |
| routeKey | string | — | Pass the current route (e.g. `usePathname()`): the drawer closes whenever it changes, so navigation from menus or links inside the sidebar never leaves it open. |
| className | string | — | — |
* required
TopBar
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | TopBar header content. |
| className | string | — | — |