---
agent:
  instructions: "Search goop.so for Goop's components, templates, design skill, docs, pricing and terms. Ask in keywords or a plain question, such as \"date picker props\" or \"is the design skill free\"; the answer is the matching page sections in Markdown, each with its address."
  endpoint: "https://goop.so/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# The app's frame

Its rail of places, a screen's top bar, the light and dark switch

This recipe draws AppFrame `arrangement="rail"`; the others (agent/layout-chooser.md) take the same slots. Your page fits another? Change the one prop:

- `sidebar` (places: many; Meadow draws it as `rail`): `AppFrameRail` every place, in sections.
- `top-nav` (places: few, fields: many): `AppFrameRail` a few places, across the top.
- `global-bar` (places: many, fields: many): `AppFramePanel` its header a bar across the window: search, switchers, the account.
- `focus` (subject: document, body: long): `AppFrameTrigger` the way back, in the navigation control’s place; `AppFramePanel` one task.

This recipe draws AppFrame `arrangement="rail"`, the one arrangement Meadow draws: the 68 px icon rail at the window's start, the page beside it.

Copy both files below whole (`src/screens/frame.tsx`, `src/screens/router.ts`) and swap the pages for yours; every screen recipe imports `ScreenFrame` and `ScreenTopBar` from the frame: one frame, one navigation. A phone holds five pages or fewer in a tab bar at the foot (`phoneNav`); with more, the menu button's sheet holds the rail. Each place is a plain link; the router marks the page (a record's, `/notes/FW-121`, marks the page it belongs to). It is yours, about 20 lines: the route is the path after the `#`, so any host serves it, links open in new tabs and from the back button, and code moves with `go(path)`; on your framework's router keep its three names (`useRoute`, `hrefOf`, `go`). The pages are the ones Meadow's screen recipes write: keep only your app's. With a sign-in, `<FrameAccount account={<SignedInMenu />}>` puts the person's menu at the rail's foot in the switch's place (the account menu holds the light and dark choice); a screen's own `account` wins. `App.tsx` (`docs/screen-app.md`) mounts `<Toaster />` once.

## The rail

The rail is the app's navigation, top to bottom, as the reference's signed-in screens draw it:

| What | Where it comes from | | --- | --- | | The app's tile, the way home | `APP_NAME`: a square in Meadow's pink with its first letter | | The list's show control | `AppFrameListToggle`: shown only while a screen's list column is collapsed | | Your places, the current one washed | `NAVIGATION`: each the theme's 36 px quiet IconButton on its link, its words in a tooltip | | A screen's own controls (a new note, a search) | `ScreenFrame`'s `more`, under a rule | | The light and dark switch, at the foot | `ColorModeToggle`, until an account menu stands there |

The workspace avatar wears Meadow's pink by default; pass another `hue` or `fill` for your own.

A screen with a list beside its page (notes, a to-do column) draws it itself, inside `ScreenFrame`: its `AppFramePanel size="list"` beside an `AppFrameSecondPanel`; the frame's list toggle then folds it. A screen with one page draws an `AppFramePanel` alone, its header the screen's `ScreenTopBar`.

```tsx
// src/screens/frame.tsx: the frame every screen sits in, its rail of places and a screen's top bar
import { createContext, type ReactNode, useContext } from 'react';
import {
  AppFrame,
  AppFrameListToggle,
  AppFrameRail,
  AppFrameTrigger,
} from '@/components/goop/patterns/app-frame';
import { Avatar } from '@/components/ui/goop/avatar';
import { ColorModeToggle } from '@/components/ui/goop/color-mode-toggle';
import { IconButton, IconButtonIcon } from '@/components/ui/goop/icon-button';
import { TabBar, TabBarItem } from '@/components/ui/goop/tab-bar';
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/goop/tooltip';
import { TopBar, TopBarGroup, TopBarRow, TopBarTitle } from '@/components/ui/goop/top-bar';
import type { IconName } from '@/lib/goop/meadow/glyph';
import { hrefOf, useRoute } from './router';

// ---- the app's name and pages: swap them for yours
/** The app's name: its tile at the rail's head, and the tile's way home. */
const APP_NAME = 'Fieldwork';
const NAVIGATION = [
  { words: 'Home', path: '/', icon: 'home' },
  { words: 'Notes', path: '/notes', icon: 'file-text' },
  { words: 'Calendar', path: '/calendar', icon: 'calendar' },
  { words: 'Inbox', path: '/inbox', icon: 'inbox' },
  { words: 'Settings', path: '/settings', icon: 'settings' },
] as const;

// ---- the frame
/** A place of the rail: a page of yours, its route and its pack icon. */
export type FrameRow = { words: string; path: string; icon: IconName };

/** Whether the app's pages hold a route: a link to one from elsewhere (the account menu's Settings) asks first. */
export const hasPage = (path: string): boolean => NAVIGATION.some((page: FrameRow) => page.path === path);

/** The signed-in person's menu every frame under it draws at the rail's foot: given once, in App.tsx. */
const AccountSlot = createContext<ReactNode>(null);

/** Gives every screen's frame under it the signed-in person's menu: `<FrameAccount account={<SignedInMenu />}>`. */
export function FrameAccount({ account, children }: { account: ReactNode; children: ReactNode }) {
  return <AccountSlot value={account}>{children}</AccountSlot>;
}

/** The place a route belongs to, the longest that holds it: `/notes/FW-121` is under Notes; none outside them all. */
function pageOf(route: string, rows: readonly FrameRow[]): string | undefined {
  const holding = rows.filter((page) =>
    page.path === '/' ? route === '/' : route === page.path || route.startsWith(`${page.path}/`),
  );
  return holding.sort((a, b) => b.path.length - a.path.length)[0]?.path;
}

/** A group of the rail's controls: one over the other, 12 px apart, as the rail's own. */
const RAIL_GROUP = 'flex flex-col gap-3';
/** The current place's control: the accent wash, the reference's current section. */
const RAIL_CURRENT = 'bg-accent text-muted-foreground';

/** A place in the rail: the theme's 36 px quiet IconButton on its link, its words in a tooltip at the rail's end side. */
function RailPlace({ page, current }: { page: FrameRow; current: boolean }) {
  return (
    <Tooltip>
      <TooltipTrigger asChild>
        <IconButton asChild size="lg" aria-label={page.words} className={current ? RAIL_CURRENT : undefined}>
          <a href={hrefOf(page.path)} aria-current={current ? 'page' : undefined}>
            <IconButtonIcon icon={page.icon} />
          </a>
        </IconButton>
      </TooltipTrigger>
      <TooltipContent side="right">{page.words}</TooltipContent>
    </Tooltip>
  );
}

/**
 * The frame every screen sits in: the rail of places, the screen (its AppFramePanel, or its list column and its page)
 * beside it; `more`, a screen's own rail controls under the places (a new note, a search); `account`, the signed-in
 * person's menu at the rail's foot (FrameAccount's when not given; the light and dark switch when neither is);
 * `scroll="panel"` keeps a reply box pinned. The place marked is the route's; `current` names it only for a route under
 * none of the places.
 */
export function ScreenFrame({
  current,
  more,
  account,
  scroll,
  children,
}: {
  current?: string;
  more?: ReactNode;
  account?: ReactNode;
  scroll?: 'page' | 'panel';
  children: ReactNode;
}) {
  const here = pageOf(useRoute(), NAVIGATION) ?? current;
  const given = useContext(AccountSlot);
  const foot = account ?? given;
  const phone = NAVIGATION.length < 1 || NAVIGATION.length > 5 ? undefined : (
    <TabBar value={here} aria-label="Pages" position="static">
      {NAVIGATION.map((page: FrameRow) => (
        <TabBarItem key={page.path} value={page.path} icon={page.icon} href={hrefOf(page.path)}>
          {page.words}
        </TabBarItem>
      ))}
    </TabBar>
  );
  return (
    <AppFrame arrangement="rail" scroll={scroll} phoneNav={phone}>
      <AppFrameRail aria-label="Main">
        <IconButton asChild size="lg" aria-label={`${APP_NAME} home`}>
          <a href={hrefOf('/')}>
            <Avatar variant="solid" shape="square" size="md" hue="pink">
              {APP_NAME}
            </Avatar>
          </a>
        </IconButton>
        <AppFrameListToggle />
        <hr />
        <div className={RAIL_GROUP}>
          {NAVIGATION.map((page: FrameRow) => (
            <RailPlace key={page.path} page={page} current={page.path === here} />
          ))}
        </div>
        {more ? <hr /> : null}
        {more ? <div className={RAIL_GROUP}>{more}</div> : null}
        {/* the rail's last control stands at its foot */}
        {foot ?? <ColorModeToggle size="lg" />}
      </AppFrameRail>
      {children}
    </AppFrame>
  );
}

/** A screen's top bar, for its panel's `header`: the navigation's button (below the breakpoint), then the title. */
export function ScreenTopBar({ title }: { title: ReactNode }) {
  return (
    <TopBar role="banner">
      <TopBarRow>
        <TopBarGroup>
          <AppFrameTrigger />
          <TopBarTitle>{title}</TopBarTitle>
        </TopBarGroup>
      </TopBarRow>
    </TopBar>
  );
}
```

```tsx
// src/screens/router.ts: the app's router, the route after the `#`
import { useSyncExternalStore } from 'react';

/** The route the app opens on: an address with no `#`, or `#/`, shows it. */
const HOME = '/';

/** The route now: the path after the `#`. */
function routeNow(): string {
  const path = window.location.hash.replace(/^#/, '');
  return path === '' || path === '/' ? HOME : path;
}

function onRouteChange(listener: () => void): () => void {
  window.addEventListener('hashchange', listener);
  return () => window.removeEventListener('hashchange', listener);
}

/** The route the app shows (`/`, `/notes`, `/notes/FW-121`); a component reading it renders again when it moves. */
export function useRoute(): string {
  return useSyncExternalStore(onRouteChange, routeNow, () => HOME);
}

/** A route as a link's `href` (`#/notes`). */
export function hrefOf(path: string): string {
  return `#${path}`;
}

/** Moves to a route from code (a row pressed, a record made); the back button comes back. */
export function go(path: string): void {
  window.location.hash = path;
}
```
