The frame of an app: a sidebar, a header and the page, on any screen size.
Issues
Select a page from the workspace navigation.
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/app-shellUsage
import { AppShell } from "./ui/uicontext/components/kit/AppShell.ts"const Message = UiSchema.TaggedEnum({ RequestedCloseAgent: {}, SavedSidebarWidth: { width: Schema.Number }, ToggledSidebar: { collapsed: Schema.Boolean },})// the app keeps the panel open or shut, and saves the width and collapse it hears aboutexport const Frame = (h: Html.H<typeof Message.Type>, agentOpen: boolean, sidebarWidth: number) => AppShell(h, { props: { label: "Workspace", panelOpen: agentOpen, panelLabel: "Agent", sidebarWidth }, onEmit: { RequestedClosePanel: () => Message.RequestedCloseAgent(), ResizedSidebar: ({ width }) => Message.SavedSidebarWidth({ width }), ResizedPanel: () => undefined, ToggledSidebar: ({ collapsed }) => Message.ToggledSidebar({ collapsed }), }, slots: { sidebar: h.nav.children("Inbox, Projects, Teams"), main: h.main.children("The page"), panel: h.div.children("The agent"), }, })API reference
AppShellComponentComponent
Props
| Name | Type | Default | Description |
|---|---|---|---|
label | string | — | The sidebar's accessible name: "Workspace" |
panelOpen | boolean | — | Whether the end panel shows; the app owns it and hears RequestedClosePanel |
panelLabel | string | — | The panel's accessible name: "Agent" |
panelHeader | boolean | — | False: no built-in header row with its close button, for a panel that draws its own header (and its own close, which the app handles; agents still have ClickedClosePanel) |
sidebarWidth | number | — | Widths to start from, in px: a person's saved ones |
panelWidth | number | 380 | The end panel's width to start from, in px; 380 by default |
collapsed | boolean | — | Start with the sidebar collapsed |
agentId | string | — | This shell's id for agents |
Events
| Event | Payload | Description |
|---|---|---|
ToggledSidebar | { collapsed: boolean } | The sidebar was collapsed or expanded: save it to start from next time |
ResizedSidebar | { width: number } | A drag or the arrow keys on its edge finished resizing the sidebar: save the width |
ResizedPanel | { width: number } | The end panel was resized: save the width |
RequestedClosePanel | {} | The panel's close button or Escape asked to close it: set panelOpen to false |
Slots
sidebar, sidebarHeader, main, panel, banner
Agent actions
| Action | Description |
|---|---|
RequestedToggleSidebar | Show or hide the sidebar |
ClickedClosePanel | Close the side panel |
AppShellView function
Options
| Name | Type | Description |
|---|---|---|
key | string | Names the shell among others in the same view; needed only for more than one. |
propsrequired | AppShellProps | The shell's props: its names, widths and whether the panel shows. |
onEmitrequired | AppShellOnEmit<Message> | The parent's message for each event, by name or from one function. |
slotsrequired | AppShellSlots<Message> | What goes in the sidebar, the main area, the end panel and the banner. |
Accessibility
- The page sits in a
mainlandmark and the side panel in a labelledaside. - The sidebar's button says whether it's shown (
aria-expanded), and Mod+\ does the same. Its edge is a focusable separator: Left and Right resize it, Home and End jump, and Enter collapses it. - On a narrow frame the sidebar is a drawer that closes with Escape or a click outside. Agents can show or hide the sidebar and close the panel.