App Shell

The frame of an app: a sidebar, a header and the page, on any screen size.

Preview

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/app-shell

Usage

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

AppShellComponent props
NameTypeDefaultDescription
labelstring—The sidebar's accessible name: "Workspace"
panelOpenboolean—Whether the end panel shows; the app owns it and hears RequestedClosePanel
panelLabelstring—The panel's accessible name: "Agent"
panelHeaderboolean—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)
sidebarWidthnumber—Widths to start from, in px: a person's saved ones
panelWidthnumber380The end panel's width to start from, in px; 380 by default
collapsedboolean—Start with the sidebar collapsed
agentIdstring—This shell's id for agents

Events

AppShellComponent events
EventPayloadDescription
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

What agents can do with AppShellComponent
ActionDescription
RequestedToggleSidebarShow or hide the sidebar
ClickedClosePanelClose the side panel

AppShellView function

Options

AppShell options
NameTypeDescription
keystringNames the shell among others in the same view; needed only for more than one.
propsrequiredAppShellPropsThe shell's props: its names, widths and whether the panel shows.
onEmitrequiredAppShellOnEmit<Message>The parent's message for each event, by name or from one function.
slotsrequiredAppShellSlots<Message>What goes in the sidebar, the main area, the end panel and the banner.

Accessibility

  • The page sits in a main landmark and the side panel in a labelled aside.
  • 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.

Source