# App Frame

> The frame every app shares: a sidebar of links that becomes a drawer on a phone, a header row with breadcrumbs and actions, and an optional rail, tabs, side panel and status bar.

Page: https://uicontext.com/docs/components/app-frame

Group: Foundations.

## When to use

The frame every app shares: a sidebar of links that becomes a drawer on a phone, a header row with breadcrumbs and actions, and an optional rail, tabs, side panel and status bar. Use [App Shell](https://uicontext.com/docs/components/app-shell.md) instead when you lay out the regions yourself, without the sidebar's links and header row.

## Usage

```ts
import { AppFrame, PageBar } from "./ui/uicontext/components/AppFrame.ts"

export const Frame = <M>(h: Html.H<M>, current: string, page: View.Content<M>) =>
	AppFrame(h, {
		app: { name: "Northwind", mark: "N", href: "/" },
		agentId: "app",
		sections: [{ items: [{ id: "inbox", label: "Inbox", href: "/inbox", icon: "inbox" }, { id: "projects", label: "Projects", href: "/projects", icon: "folder" }] }],
		current,
		main: [PageBar(h, { trail: [{ label: "Northwind", href: "/" }, { label: "Projects" }] }), page],
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### A small app

The example the page opens with: App Frame in “A small app”.

This example also uses Empty State. Install it too:

```sh
npx shadcn@latest add checkfu/uicontext/empty-state
```

```ts title="src/demo.ts" source="www/src/examples/app-frame/demo.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Button } from "./ui/uicontext/components/Button.ts"
import { AppFrame, PageBar } from "./ui/uicontext/components/AppFrame.ts"
import { EmptyState } from "./ui/uicontext/components/States.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({ frame: { inlineSize: "100%", blockSize: 420 } })

// a whole small app: the sidebar's links and account, and a page with its header row
export const SmallApp = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.frame)).children(
		AppFrame(h, {
			app: { name: "Northwind", mark: "N", href: "#" },
			agentId: "app-frame-demo",
			sections: [
				{ items: [{ id: "inbox", label: "Inbox", href: "#inbox", icon: "inbox", count: 4 }, { id: "projects", label: "Projects", href: "#projects", icon: "folder" }] },
				{ label: "Teams", items: [{ id: "design", label: "Design", href: "#design", dot: "#8b5cf6" }, { id: "freight", label: "Freight ops", href: "#freight", dot: "#0ea5e9" }] },
			],
			current: "projects",
			account: { name: "Ada Okafor", meta: "Northwind Freight" },
			main: [
				PageBar(h, { trail: [{ label: "Northwind", href: "#" }, { label: "Projects" }], actions: Button(h, { size: "sm" }).children("New project") }),
				EmptyState(h, { title: "No projects yet", hint: "Projects you create or join show here." }),
			],
		}),
	)
```

## API reference

### AppFrame (view function)

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `app` (required) | `{ readonly name: string; readonly mark: string; readonly href: string }` | — |
| `agentId` (required) | `string` | The shell's agent id, unique on the page |
| `sections` (required) | `FrameSection[]` | — |
| `current` (required) | `string` | The id of the link for the current route |
| `account` | `{ readonly name: string; readonly meta: string }` | Who's signed in, at the foot of the sidebar; leave it out when the rail shows them |
| `sidebarTop` | `View.Input` | A control above the links: a "New issue" button, a search |
| `sidebarHeader` | `View.Input` | In place of the brand at the top of the sidebar: a workspace switcher |
| `sidebar` | `View.Input` | In place of the route links: a list of records |
| `main` (required) | `View.Input` | — |
| `mainLabel` | `string` | The main region's accessible name: the page or tab it shows |
| `panel` | `{ readonly open: boolean; readonly label: string; readonly content: View.Input; readonly closed: Message; readonly toggled?: Message \| undefined /** false: the panel draws its own header and close button */ readonly header?: boolean \| undefined }` | An end panel: an assistant, a detail rail; `toggled` answers ⌘. |
| `rail` | `View.Input` | The far-start rail: a WorkspaceRail |
| `tabs` | `View.Input` | Document tabs over the page: a TabStrip |
| `status` | `View.Input` | The bottom strip: a StatusBar |
| `storageKey` | `string` | Keeps the frame's widths and the sidebar's state in this browser, under this key |
| `shortcuts` | `ShellShortcut[]` | The app's own shortcuts, listed under the frame's on ⌘/ |
| `sidebarId` | `string` | The sidebar's id, when every page draws its button in its own header (PageBar's `sidebarId`): a phone then gets no row of its own for the button |

### PageBar (view function)

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `trail` (required) | `Crumb[]` | — |
| `actions` | `View.Input` | — |
| `sidebarId` | `string` | The frame's sidebar, when it is a drawer on a phone: its button leads this row instead of a row of its own |

## Keyboard and accessibility

- The page sits in a `main` landmark named by `mainLabel`, and the sidebar is a `nav` named for the app.
- The link for `current` is `aria-current="page"`. PageBar's breadcrumbs are a `nav` named Breadcrumb, and the separators are hidden from screen readers.
- On a phone the sidebar is a drawer that closes with Escape or a press outside; ⌘. toggles the side panel.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/app-frame
```

With npm: `npx shadcn@latest add checkfu/uicontext/app-frame`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/app-frame`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/app-frame`.

It writes these files:

- `src/ui/uicontext/components/AppFrame.ts`
- `src/ui/uicontext/components/AppShell.ts`
- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/Dialog.ts`
- `src/ui/uicontext/components/Direction.ts`
- `src/ui/uicontext/components/Kbd.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/appShell.stylex.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/safeArea.stylex.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/AppFrame.ts](https://github.com/checkfu/uicontext/blob/main/src/AppFrame.ts)

## Used in

- [SaaS dashboard](https://uicontext.com/blocks/saas-dashboard.md)
- [Chat](https://uicontext.com/blocks/ai-chat.md)
- [Task manager](https://uicontext.com/blocks/issue-tracker.md)
- [Company brain](https://uicontext.com/blocks/doc-workspace.md)
- [Workflow builder](https://uicontext.com/blocks/automation-builder.md)
- [Database](https://uicontext.com/blocks/tables.md)
- [CRM](https://uicontext.com/blocks/crm.md)
- [Analytics dashboard](https://uicontext.com/blocks/analytics.md)
- [Email](https://uicontext.com/blocks/email.md)
- [Scheduling](https://uicontext.com/blocks/scheduling.md)
- [Storefront](https://uicontext.com/blocks/storefront.md)
- [Helpdesk](https://uicontext.com/blocks/helpdesk.md)
- [Agent studio](https://uicontext.com/blocks/agent-studio.md)
- [Work](https://uicontext.com/blocks/work.md)
- [Team assistant](https://uicontext.com/blocks/team-assistant.md)
- [Bots](https://uicontext.com/blocks/bot-console.md)
- [Design](https://uicontext.com/blocks/design-tool.md)
- [Whiteboard](https://uicontext.com/blocks/whiteboard.md)

## Related

- [App Setup](https://uicontext.com/docs/components/app-setup.md) (`app-setup`): The build setup an app needs: Vite with StyleX, a base stylesheet and TypeScript settings.
- [App Bootstrap](https://uicontext.com/docs/components/app-bootstrap.md) (`app-bootstrap`): Starts an app from its routes, with sign-in in front and the shell and pages behind it.
- [Themes](https://uicontext.com/docs/components/themes.md) (`themes`): Color, type and spacing tokens, with light, dark and app themes you can nest.
- [Theme Spec](https://uicontext.com/docs/components/theme-spec.md) (`theme-spec`): A design language on one sheet, drawn from its tokens, from type and color to motion.
