AppShell
A responsive application layout with a sidebar that becomes a drawer below a breakpoint.
Purpose
AppShell lays out an application: a Sidebar and a main column
(AppShellMain) containing a header and the page content (AppShellContent, a <main>). At and
above its breakpoint the sidebar sits beside the content (expanded or as an icon rail); below it,
the sidebar content moves into a modal drawer.
Import
import { AppShell, AppShellContent, AppShellMain } from "@neshel-ui/components";Usage
Use the trigger to collapse the sidebar into an icon rail.
collapsed: false"use client";
import {
AppShell,
AppShellContent,
AppShellMain,
Navbar,
NavbarBrand,
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarHeader,
SidebarItem,
SidebarSeparator,
SidebarSub,
SidebarTrigger,
} from "@neshel-ui/components";
import { Stack } from "@neshel-ui/layout";
import { Paragraph, Text } from "@neshel-ui/typography";
import { BarChart3, Home, Settings, Users } from "lucide-react";
import { useState } from "react";
/**
* Desktop from md (expanded sidebar or icon rail); below md the sidebar becomes a drawer.
* Here the collapsed state is controlled; persist it yourself (for example in a cookie).
*/
export default function AppShellBasic() {
const [collapsed, setCollapsed] = useState(false);
return (
<AppShell
breakpoint="md"
collapsed={collapsed}
onCollapsedChange={setCollapsed}
className="min-h-[420px] overflow-hidden rounded-lg border border-[var(--neshel-border)]"
>
<Sidebar collapsible="icon" className="!h-auto">
<SidebarHeader>
<Text weight="semibold">Acme</Text>
</SidebarHeader>
<SidebarContent>
<SidebarGroup label="Workspace">
<SidebarItem asChild active icon={<Home aria-hidden="true" />}>
<a href="#dashboard">Dashboard</a>
</SidebarItem>
<SidebarItem asChild icon={<BarChart3 aria-hidden="true" />}>
<a href="#reports">Reports</a>
</SidebarItem>
<SidebarSub label="Team" icon={<Users aria-hidden="true" />}>
<SidebarItem asChild>
<a href="#members">Members</a>
</SidebarItem>
<SidebarItem asChild>
<a href="#roles">Roles</a>
</SidebarItem>
</SidebarSub>
</SidebarGroup>
<SidebarSeparator />
<SidebarGroup label="System">
<SidebarItem asChild icon={<Settings aria-hidden="true" />}>
<a href="#settings">Settings</a>
</SidebarItem>
</SidebarGroup>
</SidebarContent>
<SidebarFooter>
<Text size="sm" tone="muted">
Signed in as Ana
</Text>
</SidebarFooter>
</Sidebar>
<AppShellMain>
<Navbar>
<SidebarTrigger />
<NavbarBrand>Dashboard</NavbarBrand>
</Navbar>
<AppShellContent>
<Stack space="3">
<Paragraph>Use the trigger to collapse the sidebar into an icon rail.</Paragraph>
<Text tone="muted" size="sm">
collapsed: {String(collapsed)}
</Text>
</Stack>
</AppShellContent>
</AppShellMain>
</AppShell>
);
}API
AppShellProps
| Prop | Type | Default | Description |
|---|---|---|---|
| breakpoint | Breakpoint | — | Desktop layout at and above this breakpoint (default "lg"; "base" = always desktop). |
| collapsed | boolean | — | Desktop rail/hidden state (controlled). |
| defaultCollapsed | boolean | false | Initial collapsed state when uncontrolled (default false). |
| defaultMobileOpen | boolean | false | Initial mobile drawer state when uncontrolled (default false). |
| mobileOpen | boolean | — | Mobile drawer state (controlled). |
| onCollapsedChange | (collapsed: boolean) => void | — | Called when the desktop collapsed state should change. |
| onMobileOpenChange | (open: boolean) => void | — | Called when the mobile drawer should open or close (trigger, Escape, overlay, navigation, switch to desktop). |
| ref | Ref<HTMLDivElement> | — | — |
Also accepts the props of: React DOM attributes.
AppShellPartProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLDivElement> | — | — |
Also accepts the props of: React DOM attributes.
AppShellState
| Prop | Type | Default | Description |
|---|---|---|---|
| collapsed(required) | boolean | — | Desktop sidebar collapsed state. |
| mobileOpen(required) | boolean | — | Mobile drawer open state. |
| mode(required) | CssMode | undefined | — | undefined until the shell has read its CSS mode after hydration. |
| setCollapsed(required) | (collapsed: boolean) => void | — | — |
| setMobileOpen(required) | (open: boolean) => void | — | — |
| toggle(required) | () => void | — | Toggles the rail on desktop and the drawer on mobile. |
breakpoint: default"lg", any configured name, or"base"for always-desktop.collapsed/defaultCollapsed/onCollapsedChange: the desktop collapse state.mobileOpen/defaultMobileOpen/onMobileOpenChange: the mobile drawer.
useAppShell
"use client";
import { Button, useAppShell } from "@neshel-ui/components";
export function CollapseButton() {
const { mode, collapsed, toggle } = useAppShell();
return (
<Button variant="ghost" onClick={toggle}>
{mode === "mobile" ? "Menu" : collapsed ? "Expand" : "Collapse"}
</Button>
);
}Returns { mode, collapsed, setCollapsed, mobileOpen, setMobileOpen, toggle }; throws outside an
AppShell. mode is undefined during server rendering and before hydration, then "desktop" or
"mobile".
How the mode is decided
CSS decides the mode at the breakpoint (so it follows neshel generate and custom breakpoints);
JavaScript reads it after hydration and on resize. Server and client markup never depend on the mode,
so there are no hydration mismatches. When the viewport becomes desktop while the drawer is open, the
shell requests onMobileOpenChange(false).
Persistence
The library never reads storage. Persist collapsed yourself — for example a cookie read on the
server and passed as defaultCollapsed, written in onCollapsedChange.
Accessibility
Give AppShellContent an id and add a skip link to it. The drawer is a modal dialog titled by the
Sidebar's mobileTitle; it closes after navigation, on Escape and on overlay press.
Common mistakes
- Expecting
modeduring server rendering: render the same markup for both modes. - Storing component state inside sidebar children: see Sidebar → Limitations.