suiss/ui ยท Pattern
App Shell
An application frame with a collapsible sidebar on desktop and a floating tab bar on mobile.
App Shell is an open-source pattern from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
AppShell builds navigation from an items array and wraps your page content. On desktop it renders a collapsible Sidebar and the page renders in a SidebarInset. On mobile a TabBar pinned to the bottom of the screen replaces the sidebar.
Use it as the outermost layout of an app with a handful of top-level destinations.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Examples
With header and footer
Use header and footer to add a brand menu at the top of the sidebar and an account menu at the bottom.
Grouped
Items with the same group render under a shared SidebarGroupLabel, here Platform and Workspace. Set disabled on an item to disable it.
More tab
Uses eight items with defaultValue. Items that do not fit in the mobile tab bar move behind its More trigger, whose text comes from moreLabel.
Links
Gives every item an href so each renders as a link to its route through render.
Floating
Set variant="floating" to use the floating sidebar style.
Inset
Set variant="inset" to use the inset sidebar style.
Offcanvas
Sets collapsible to offcanvas so collapsing slides the whole sidebar out of view.
Right side
Set side="right" to place the sidebar on the right.
Collapsed
Set defaultOpen={false} to start with the sidebar collapsed to icons. Collapsed items show their label in a tooltip.
Accessibility
- The selected item has
aria-current="page". - Collapsed sidebar items show their label in a tooltip on hover.
AppShellTriggeris labelled Toggle Sidebar, andCmd+Bon macOS orCtrl+Belsewhere toggles the sidebar.- With
collapsible="offcanvas", the hidden sidebar is removed from view and the tab order. - Disabled items are disabled buttons.
API Reference
AppShell
The root layout that renders the sidebar or tab bar from items and wraps the page content.
| Prop | Type | Default |
|---|---|---|
items | AppShellItem[] | Required |
value | string | - |
defaultValue | string | First item |
onValueChange | (value: string) => void | - |
header | React.ReactNode | - |
footer | React.ReactNode | - |
variant | "sidebar" | "floating" | "inset" | "sidebar" |
collapsible | "offcanvas" | "icon" | "none" | "icon" |
side | "left" | "right" | "left" |
rail | boolean | true |
open | boolean | - |
defaultOpen | boolean | true |
onOpenChange | (open: boolean) => void | - |
moreLabel | string | "More" |
label | string | "Main" |
className | string | - |
children | React.ReactNode | - |
| Prop | Type | Default |
|---|---|---|
render | React.ReactElement | A plain a |
| Prop | Type | Default |
|---|---|---|
render | (props: React.ComponentProps<"a">) => React.ReactNode | A plain a |
Each AppShellItem has a value, label and icon, plus optional href, badge, group and disabled. The selected item is controlled with value and onValueChange, or uncontrolled with defaultValue; it defaults to the first item. open, defaultOpen and onOpenChange hold the sidebar's expanded state. rail renders a rail along the sidebar edge that toggles it, only when collapsible is not none. label names the navigation landmark on mobile.
Items with an href render as the render element, a plain anchor by default, so you can pass your router's link component.
Items with an href render through the render function, a plain anchor by default, so you can return your router's link component. It receives the link props, including href.
Below the 48rem breakpoint the content renders in a main element padded to clear the tab bar. className applies to the content area on both layouts. The sidebar sets data-state (expanded or collapsed), data-collapsible, data-variant and data-side, and on mobile the wrapper and content set data-slot="app-shell" and data-slot="app-shell-content", for styling.
AppShellTrigger
A SidebarTrigger that toggles the sidebar on desktop and renders nothing on mobile.
Also accepts the props of React.ComponentProps<typeof SidebarTrigger>.
Place it in your page header to toggle the sidebar.