> ## Documentation Index
> Fetch the complete documentation index at: https://anvil.servicetitan.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Window – Design

> Windows present contained, moveable or framed content regions.

export const LiveCode = ({children, customHeight, clickToLoad, example, fullWidth, fullHeight, hideCodeInLiveCode, screenshot, screenshotOnly, showCode: showCodeProp}) => {
  const SCREENSHOTS_BASE = "https://servicetitan.github.io/anvil2-docs-live-code/screenshots";
  const STACKBLITZ_BASE = "https://stackblitz.com/github/servicetitan/anvil2-docs-live-code/tree/main/examples";
  const [showCodeBlock, setShowCodeBlock] = useState(showCodeProp ?? false);
  const [isLocalOverride, setIsLocalOverride] = useState(false);
  useEffect(() => {
    const examplePath = `/images/live-code-screenshots-tmp/${example}.png`;
    fetch(examplePath, {
      method: "HEAD"
    }).then(r => {
      if (r.ok) setIsLocalOverride(true);
    }).catch(() => {});
  }, [example]);
  const screenshotBase = isLocalOverride ? "/images/live-code-screenshots-tmp" : SCREENSHOTS_BASE;
  if (screenshotOnly) {
    return <Frame className="flex flex-col">
        <div className="flex dark:hidden" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined,
      background: "#FFFFFF"
    }}>
          <img srcset={`${screenshotBase}/${example}.png, ${screenshotBase}/${example}-2x.png 2x`} src={`${screenshotBase}/${example}.png`} alt={example} noZoom />
        </div>
        <div className="hidden dark:flex" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined,
      background: "#141414"
    }}>
          <img srcset={`${screenshotBase}/${example}-dark.png, ${screenshotBase}/${example}-dark-2x.png 2x`} src={`${screenshotBase}/${example}-dark.png`} alt={example} noZoom />
        </div>
      </Frame>;
  }
  if (screenshot) {
    return <Frame className="flex flex-col -mb-2">
        <div className="flex dark:hidden bg-white dark:bg-codeblock border border-gray-950/10 dark:border-white/10 dark:twoslash-dark rounded-2xl overflow-hidden" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined
    }}>
          <img srcset={`${screenshotBase}/${example}.png, ${screenshotBase}/${example}-2x.png 2x`} src={`${screenshotBase}/${example}.png`} alt={example} noZoom />
        </div>

        <div className="hidden dark:flex bg-white dark:bg-codeblock border border-gray-950/10 dark:border-white/10 dark:twoslash-dark rounded-2xl overflow-hidden" style={{
      background: "#141414",
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined
    }}>
          <img srcset={`${screenshotBase}/${example}-dark.png, ${screenshotBase}/${example}-dark-2x.png 2x`} src={`${screenshotBase}/${example}-dark.png`} alt={example} noZoom />
        </div>

        <div className="flex justify-end items-center text-xs py-2 px-1 gap-4">
          {!showCodeProp ? <button className="inline-flex justify-end items-center text-gray-700 dark:text-gray-50 hover:text-blue-500 dark:hover:text-blue-300 transition-colors group self-end gap-1 cursor-pointer" onClick={() => setShowCodeBlock(!showCodeBlock)} style={{
      appearance: "none"
    }}>
              <Icon icon="code" size="12px" className="group-hover:bg-blue-500 dark:group-hover:bg-blue-300" />
              <span>{showCodeBlock ? "Hide code" : "Show code"}</span>
            </button> : null}

          <a className="inline-flex justify-end items-center hover:text-blue-500 dark:hover:text-blue-300 transition-colors group self-end gap-1" href={`${STACKBLITZ_BASE}/${example}?file=src/App.tsx`} target="_blank" rel="noreferrer">
            <Icon icon="bolt" size="12px" className="group-hover:bg-blue-500 dark:group-hover:bg-blue-300" />
            <span>StackBlitz demo</span>
          </a>
        </div>

        <div className="grid transition-[grid-template-rows] duration-300 ease-in-out overflow-auto overflow-y-hidden overflow-x-auto" style={showCodeBlock ? {
      gridTemplateRows: "1fr"
    } : {
      gridTemplateRows: "0fr"
    }}>
          <div style={{
      minHeight: 0,
      overflowX: "auto",
      overflowY: "hidden",
      marginBlockStart: "-1.25rem",
      marginBlockEnd: "-1.5rem"
    }}>
            {children}
          </div>
        </div>
      </Frame>;
  } else {
    return <div style={{
      display: "flex",
      width: fullWidth ? "100%" : "50%",
      minHeight: customHeight ? customHeight : "316px",
      resize: "vertical",
      overflow: "auto"
    }}>
        <iframe title={example} style={{
      flex: 1,
      width: fullWidth ? "100%" : "50%",
      minHeight: customHeight ? customHeight : "316px"
    }} src={`${STACKBLITZ_BASE}/${example}?embed=1&hideNavigation=1&hideExplorer=1&terminalHeight=0&file=src/App.tsx${clickToLoad ? "&ctl=1" : ""}${hideCodeInLiveCode ? "&view=preview" : ""}`} allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" />
      </div>;
  }
};

export const CodePreviewPlaceholder = ({double, fullWidth}) => {
  const single = <div style={{
    width: fullWidth ? "100%" : "50%",
    borderRadius: "1rem",
    display: "flex",
    padding: "1rem",
    flexDirection: "column",
    gap: "0.5rem",
    height: "10rem",
    marginBlockEnd: "1rem"
  }} className="border-width-default border-color-subdued">
      <div className="bg-strong border-radius-large" style={{
    width: "100%",
    flexGrow: "1"
  }} />
      <div className="bg-strong border-radius-large" style={{
    width: "100%",
    flexGrow: "1"
  }} />
    </div>;
  return double ? <div style={{
    display: "flex",
    gap: "1rem"
  }}>
      {single}
      {single}
    </div> : single;
};

<LiveCode example="carto-window" screenshot fullWidth>
  ```tsx lines theme={null}
  import { Text, Window } from "@servicetitan/carto-react-kit";

  function App() {
    return (
      <div style={{ position: "fixed", inset: 0, background: "#e9ecf1" }}>
        <Window
          chat={
            <div
              style={{
                display: "flex",
                alignItems: "center",
                justifyContent: "center",
                height: "100%",
              }}
            >
              <Text text="Chat content" />
            </div>
          }
        />
      </div>
    );
  }

  export default App;
  ```
</LiveCode>

## Options

Window owns the same slots as [AppShell](/docs/kits/ai-kit/components/app-shell/design) — `header` and `chat` (shown in both states), plus `rail` and `artifact` (fullscreen only) — and presents them in one of two sizes.

### Window States

<LiveCode example="carto-window-window-states" screenshot fullWidth>
  ```tsx lines theme={null}
  import {
    AppHeader,
    CartoTheme,
    Text,
    Window,
    useAppSurface,
  } from "@servicetitan/carto-react-kit";
  import { IconMinimize2, IconX } from "@servicetitan/carto-react-kit/icons";
  import "@servicetitan/carto-react-kit/styles.css";

  function WindowHeader() {
    const { toggleSize, close } = useAppSurface();
    return (
      <AppHeader
        title="Title of conversation"
        trailingActions={[
          {
            id: "size",
            icon: <IconMinimize2 />,
            label: "Restore",
            onPress: toggleSize,
          },
          { id: "close", icon: <IconX />, label: "Close", onPress: close },
        ]}
      />
    );
  }

  function App() {
    return (
      <CartoTheme>
        <div style={{ position: "fixed", inset: 0, background: "#e9ecf1" }}>
          <Window
            defaultState="fullscreen"
            header={<WindowHeader />}
            chat={
              <div
                style={{
                  display: "flex",
                  alignItems: "center",
                  justifyContent: "center",
                  height: "100%",
                }}
              >
                <Text text="Chat content" />
              </div>
            }
          />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

**Docked** (shown above) is a fixed-size floating panel — header + chat, anchored bottom-right by default — that sits non-modally over the rest of the page. **Fullscreen** (shown here) is a modal takeover revealing the full `AppShell`: header, rail, chat, and artifact, over a scrim, with focus trapped inside. The `header` and `chat` nodes are the same React instance in both states — same DOM, scroll position, and in-flight state — so expanding or restoring never resets the conversation.

### Open Control

<LiveCode example="carto-window-open-control" screenshot fullWidth>
  ```tsx lines theme={null}
  import { useRef } from "react";
  import {
    AppHeader,
    Button,
    CartoTheme,
    Text,
    Window,
    useAppSurface,
  } from "@servicetitan/carto-react-kit";
  import type { AppSurfaceHandle } from "@servicetitan/carto-react-kit";
  import { IconMaximize2, IconX } from "@servicetitan/carto-react-kit/icons";
  import "@servicetitan/carto-react-kit/styles.css";

  function WindowHeader() {
    const { toggleSize, close } = useAppSurface();
    return (
      <AppHeader
        title="Title of conversation"
        trailingActions={[
          {
            id: "size",
            icon: <IconMaximize2 />,
            label: "Maximize",
            onPress: toggleSize,
          },
          { id: "close", icon: <IconX />, label: "Close", onPress: close },
        ]}
      />
    );
  }

  function App() {
    const ctrl = useRef<AppSurfaceHandle>(null);

    return (
      <CartoTheme>
        <div style={{ position: "fixed", inset: 0, background: "#e9ecf1" }}>
          <div style={{ position: "fixed", top: 24, left: 24 }}>
            <Button label="Open chat" onPress={() => ctrl.current?.open()} />
          </div>
          <Window
            controlRef={ctrl}
            header={<WindowHeader />}
            chat={
              <div
                style={{
                  display: "flex",
                  alignItems: "center",
                  justifyContent: "center",
                  height: "100%",
                }}
              >
                <Text text="Chat content" />
              </div>
            }
          />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

Open/close and docked/fullscreen work uncontrolled by default (seeded by `defaultOpen` / `defaultState`), or controlled by passing `open` / `state` alongside `onOpenChange` / `onStateChange` so an external store can be the source of truth. Either way, drive the same transitions imperatively via the `AppSurfaceHandle` — from a parent through `controlRef` (as shown here, with an external launcher button), or from inside the window (a header button, or a card in the chat) via `useAppSurface()`.

## Behavior

Both states share one surface, so the panel animates between them, and the docked panel can be repositioned.

### Maximize and Restore

<LiveCode example="carto-window-maximize-and-restore" screenshot fullWidth>
  ```tsx lines theme={null}
  import {
    AppHeader,
    CartoTheme,
    Text,
    Window,
    useAppSurface,
  } from "@servicetitan/carto-react-kit";
  import { IconMaximize2, IconX } from "@servicetitan/carto-react-kit/icons";
  import "@servicetitan/carto-react-kit/styles.css";

  function WindowHeader() {
    const { toggleSize, close } = useAppSurface();
    return (
      <AppHeader
        title="Title of conversation"
        trailingActions={[
          {
            id: "size",
            icon: <IconMaximize2 />,
            label: "Maximize",
            onPress: toggleSize,
          },
          { id: "close", icon: <IconX />, label: "Close", onPress: close },
        ]}
      />
    );
  }

  function App() {
    return (
      <CartoTheme>
        <div style={{ position: "fixed", inset: 0, background: "#e9ecf1" }}>
          <Window
            header={<WindowHeader />}
            chat={
              <div
                style={{
                  display: "flex",
                  alignItems: "center",
                  justifyContent: "center",
                  height: "100%",
                }}
              >
                <Text text="Chat content" />
              </div>
            }
          />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

The header's maximize control expands the docked panel into the fullscreen modal shell; restore (or Esc) shrinks it back. Docked and fullscreen share one surface, so the panel visibly grows and shrinks between the two rects rather than swapping instantly.

### Drag

<LiveCode example="carto-window-drag" screenshot fullWidth>
  ```tsx lines theme={null}
  import {
    AppHeader,
    CartoTheme,
    Text,
    Window,
    useAppSurface,
  } from "@servicetitan/carto-react-kit";
  import {
    IconGrip,
    IconMaximize2,
    IconX,
  } from "@servicetitan/carto-react-kit/icons";
  import "@servicetitan/carto-react-kit/styles.css";

  // A marker at the panel's default anchor (bottom-right, 24px inset — matching
  // the docked panel's own resting corner) so a screenshot of the dragged panel
  // still shows where it started, proving it moved.
  function DefaultCornerMarker() {
    return (
      <div
        style={{
          position: "fixed",
          insetBlockEnd: 24,
          insetInlineEnd: 24,
          width: 120,
          height: 48,
          border: "2px dashed #99a3ad",
          borderRadius: 8,
          display: "flex",
          alignItems: "center",
          justifyContent: "center",
        }}
      >
        <Text size="fine" text="Default corner" />
      </div>
    );
  }

  function WindowHeader() {
    const { toggleSize, close, dragHandleProps } = useAppSurface();
    return (
      <AppHeader
        title="Title of conversation"
        leadingActions={[
          {
            id: "drag",
            icon: <IconGrip />,
            label: "Move window",
            dragHandleProps,
          },
        ]}
        trailingActions={[
          {
            id: "size",
            icon: <IconMaximize2 />,
            label: "Maximize",
            onPress: toggleSize,
          },
          { id: "close", icon: <IconX />, label: "Close", onPress: close },
        ]}
      />
    );
  }

  function App() {
    return (
      <CartoTheme>
        <div style={{ position: "fixed", inset: 0, background: "#e9ecf1" }}>
          <DefaultCornerMarker />
          <Window
            header={<WindowHeader />}
            chat={
              <div
                style={{
                  display: "flex",
                  alignItems: "center",
                  justifyContent: "center",
                  height: "100%",
                }}
              >
                <Text text="Chat content" />
              </div>
            }
          />
        </div>
      </CartoTheme>
    );
  }

  export default App;
  ```
</LiveCode>

Docked, the panel is draggable: spread the surface's `dragHandleProps` (from `controlRef` / `useAppSurface()`) onto a leading header action — here an `IconGrip` — to turn it into a grip that moves the panel anywhere in the viewport. Arrow keys nudge it too, for keyboard users. The dragged position survives a maximize→restore round-trip (restore returns to it) and resets to the default corner only on close.

### Scrim Dismiss

Fullscreen is modal: a scrim sits behind the shell and dismisses back to docked on click, the same as pressing Esc. Because the shell fills the viewport, the scrim itself has no visible edge — the affordance is the dismissal, not a visible backdrop.

## Keyboard Interaction

Users can maximize, restore, move, and dismiss a window using standard keyboard controls.

| Key           | Description                                            |
| ------------- | ------------------------------------------------------ |
| Tab           | Moves focus among header actions and chat content      |
| Enter / Space | Activates the focused action                           |
| Arrow keys    | Moves the docked panel when the drag handle is focused |
| Escape        | Restores a fullscreen window to docked                 |

## Patterns that use this component

* [Agentic Experience Shell](/docs/kits/ai-kit/patterns/agentic-experience-shell) — Presents the shell as a floating or fullscreen experience
