> ## 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.

# Tabbed Layout – Code

> The TabbedLayout arranges one or more panes as stacked tabs or a two-pane split.

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>;
  }
};

<Tabs>
  <Tab title="Implementation">
    <LiveCode showCode example="ai-kit-tabbed-layout" fullWidth screenshot>
      ```tsx lines expandable theme={null}
      import { TabbedLayout, Text } from "@servicetitan/anvil2-ai-kit";
      import type { TabbedLayoutTab } from "@servicetitan/anvil2-ai-kit";

      const tabs: TabbedLayoutTab[] = [
        {
          key: "tab-a",
          label: "Tab Name A",
          content: <Text text="Tab A contents." />,
        },
        {
          key: "tab-b",
          label: "Tab Name B",
          content: <Text text="Tab B contents." />,
        },
      ];

      function App() {
        return (
          <div
            style={{
              width: 900,
              height: 420,
              border: "1px solid #ccc",
              overflow: "hidden",
            }}
          >
            <TabbedLayout tabs={tabs} />
          </div>
        );
      }

      export default App;
      ```
    </LiveCode>

    ## Common Examples

    To use the `TabbedLayout`, pass one or more `tabs` with a unique `key`, a localized `label`, and `content`. The kit forbids `children`.

    ```tsx theme={null}
    import { TabbedLayout } from "@servicetitan/anvil2-ai-kit";

    function ExampleComponent() {
      return (
        <TabbedLayout
          tabs={[
            { key: "a", label: "Summary", content: <Summary /> },
            { key: "b", label: "Details", content: <Details /> },
          ]}
        />
      );
    }
    ```

    Its primary home is the artifact region of an `AppShell` or `Window`. When the artifact is a drawer, the layout surfaces a close button wired through `useAppSurface`.

    ### Display modes

    `stacked` shows one panel at a time. `vertical-split` and `horizontal-split` show both panels. Splits are offered only with exactly two tabs and a component width of at least 720px. Below that, the layout forces `stacked` and hides the mode picker. The last chosen mode is restored when the layout grows past the threshold.

    <LiveCode showCode example="ai-kit-tabbed-layout-display-modes" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { CartoTheme, TabbedLayout, Text } from "@servicetitan/anvil2-ai-kit";
      import type {
        TabbedLayoutMode,
        TabbedLayoutTab,
      } from "@servicetitan/anvil2-ai-kit";
      import "@servicetitan/anvil2-ai-kit/styles.css";

      const tabs: TabbedLayoutTab[] = [
        {
          key: "tab-a",
          label: "Tab Name A",
          content: <Text text="Tab A contents." />,
        },
        {
          key: "tab-b",
          label: "Tab Name B",
          content: <Text text="Tab B contents." />,
        },
      ];

      function Labeled({ label, mode }: { label: string; mode: TabbedLayoutMode }) {
        return (
          <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
            <Text variant="eyebrow" text={label} />
            <div
              style={{
                width: 820,
                height: 220,
                border: "1px solid #ccc",
                overflow: "hidden",
              }}
            >
              <TabbedLayout tabs={tabs} defaultMode={mode} />
            </div>
          </div>
        );
      }

      function App() {
        return (
          <CartoTheme>
            <div style={{ display: "flex", flexDirection: "column", gap: 24 }}>
              <Labeled label="Stacked" mode="stacked" />
              <Labeled label="Vertical Split" mode="vertical-split" />
              <Labeled label="Horizontal Split" mode="horizontal-split" />
            </div>
          </CartoTheme>
        );
      }

      export default App;
      ```
    </LiveCode>

    Seed the starting mode with `defaultMode`. The layout coerces to `stacked` when a split is unavailable.

    <LiveCode showCode example="ai-kit-tabbed-layout-mode-picker" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { CartoTheme, TabbedLayout, Text } from "@servicetitan/anvil2-ai-kit";
      import type { TabbedLayoutTab } from "@servicetitan/anvil2-ai-kit";
      import "@servicetitan/anvil2-ai-kit/styles.css";

      const tabs: TabbedLayoutTab[] = [
        {
          key: "tab-a",
          label: "Tab Name A",
          content: <Text text="Tab A contents." />,
        },
        {
          key: "tab-b",
          label: "Tab Name B",
          content: <Text text="Tab B contents." />,
        },
      ];

      function App() {
        return (
          <CartoTheme>
            <div
              style={{
                width: 900,
                height: 300,
                border: "1px solid #ccc",
                overflow: "hidden",
              }}
            >
              <TabbedLayout tabs={tabs} />
            </div>
          </CartoTheme>
        );
      }

      export default App;
      ```
    </LiveCode>

    ### Single tab

    A single tab shows neither a tab strip nor the mode menu — only its content. The drawer close button still appears when applicable.

    <LiveCode showCode example="ai-kit-tabbed-layout-single-tab" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { CartoTheme, TabbedLayout, Text } from "@servicetitan/anvil2-ai-kit";
      import type { TabbedLayoutTab } from "@servicetitan/anvil2-ai-kit";
      import "@servicetitan/anvil2-ai-kit/styles.css";

      const tabs: TabbedLayoutTab[] = [
        {
          key: "preview",
          label: "Preview",
          content: <Text text="Preview contents." />,
        },
      ];

      function App() {
        return (
          <CartoTheme>
            <div
              style={{
                width: 420,
                height: 140,
                padding: 8,
                background: "#e0e0e0",
              }}
            >
              <div style={{ width: "100%", height: "100%", overflow: "hidden" }}>
                <TabbedLayout tabs={tabs} />
              </div>
            </div>
          </CartoTheme>
        );
      }

      export default App;
      ```
    </LiveCode>

    ### Selection

    Pass `defaultSelectedKey` for uncontrolled selection, or `selectedKey` with `onSelectionChange` to own it. Selection changes the visible panel only in `stacked` mode. Split modes show both panels.

    ### Overflow and narrow widths

    Extra tabs overflow the strip. Below 720px the layout stays stacked.

    <LiveCode showCode example="ai-kit-tabbed-layout-overflow-handling" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { CartoTheme, TabbedLayout, Text } from "@servicetitan/anvil2-ai-kit";
      import type { TabbedLayoutTab } from "@servicetitan/anvil2-ai-kit";
      import "@servicetitan/anvil2-ai-kit/styles.css";

      const tabs: TabbedLayoutTab[] = [
        {
          key: "doc",
          label: "Document",
          content: (
            <>
              {Array.from({ length: 12 }, (_, i) => (
                <p key={i} style={{ marginTop: i === 0 ? 0 : undefined }}>
                  Paragraph {i + 1}. Overflowing content scrolls within the panel's
                  padding, not flush to its edge.
                </p>
              ))}
            </>
          ),
        },
        { key: "notes", label: "Notes", content: <Text text="Short notes." /> },
      ];

      function App() {
        return (
          <CartoTheme>
            <div
              style={{
                width: 900,
                height: 320,
                border: "1px solid #ccc",
                overflow: "hidden",
              }}
            >
              <TabbedLayout tabs={tabs} defaultMode="vertical-split" />
            </div>
          </CartoTheme>
        );
      }

      export default App;
      ```
    </LiveCode>

    <LiveCode showCode example="ai-kit-tabbed-layout-narrow" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { CartoTheme, TabbedLayout, Text } from "@servicetitan/anvil2-ai-kit";
      import type { TabbedLayoutTab } from "@servicetitan/anvil2-ai-kit";
      import "@servicetitan/anvil2-ai-kit/styles.css";

      const tabs: TabbedLayoutTab[] = [
        {
          key: "tab-a",
          label: "Tab Name A",
          content: <Text text="Tab A contents." />,
        },
        {
          key: "tab-b",
          label: "Tab Name B",
          content: <Text text="Tab B contents." />,
        },
      ];

      function App() {
        return (
          <CartoTheme>
            <div
              style={{
                width: 560,
                height: 160,
                border: "1px solid #ccc",
                overflow: "hidden",
              }}
            >
              <TabbedLayout tabs={tabs} defaultMode="vertical-split" />
            </div>
          </CartoTheme>
        );
      }

      export default App;
      ```
    </LiveCode>

    ### Split resize

    Split modes include a drag handle between panes.

    <LiveCode showCode example="ai-kit-tabbed-layout-split-resize" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { CartoTheme, TabbedLayout, Text } from "@servicetitan/anvil2-ai-kit";
      import type { TabbedLayoutTab } from "@servicetitan/anvil2-ai-kit";
      import "@servicetitan/anvil2-ai-kit/styles.css";

      const tabs: TabbedLayoutTab[] = [
        {
          key: "tab-a",
          label: "Tab Name A",
          content: <Text text="Tab A contents." />,
        },
        {
          key: "tab-b",
          label: "Tab Name B",
          content: <Text text="Tab B contents." />,
        },
      ];

      function App() {
        return (
          <CartoTheme>
            <div
              style={{
                width: 820,
                height: 260,
                border: "1px solid #ccc",
                overflow: "hidden",
              }}
            >
              <TabbedLayout tabs={tabs} defaultMode="vertical-split" />
            </div>
          </CartoTheme>
        );
      }

      export default App;
      ```
    </LiveCode>

    ## Internationalization

    `TabbedLayout` owns these localized strings:

    * `ai-kit.tabbedLayout.layoutOptions`
    * `ai-kit.tabbedLayout.layoutMenu`
    * `ai-kit.tabbedLayout.modeStacked`
    * `ai-kit.tabbedLayout.modeVerticalSplit`
    * `ai-kit.tabbedLayout.modeHorizontalSplit`
    * `ai-kit.tabbedLayout.close`
    * `ai-kit.tabbedLayout.resizePanes`
    * `ai-kit.tabbedLayout.tabs`

    Localize tab `label` values before passing them. Mount `AiKitIntlProvider` inside `CartoTheme` to switch the chrome strings.

    ## React Accessibility

    * The tab strip is a labeled tablist. Split pane resize exposes a localized name.
    * Close appears only when the artifact is a drawer, and uses the localized close label.
  </Tab>

  <Tab title="TabbedLayout Props">
    ```tsx theme={null}
    <TabbedLayout
      tabs={tabs}
      defaultMode="stacked"
      selectedKey={key}
      onSelectionChange={setKey}
    />
    ```

    ## `TabbedLayout` Props

    The `TabbedLayout` accepts the following props and forwards remaining `<div>` attributes except `children` and `style`.

    <ParamField path="tabs" type="TabbedLayoutTab[]" required>
      One or more tabs. Split modes require exactly two.
    </ParamField>

    <ParamField path="className" type="string">
      Class merged onto the root element.
    </ParamField>

    <ParamField path="defaultMode" type={`"stacked" | "vertical-split" | "horizontal-split"`} default="stacked">
      Uncontrolled starting display mode. Coerced to `stacked` when a split is
      unavailable.
    </ParamField>

    <ParamField path="defaultSelectedKey" type="string">
      Uncontrolled selected tab at mount. Defaults to the first tab.
    </ParamField>

    <ParamField path="onSelectionChange" type="(key: string) => void">
      Fired when the user picks a tab, controlled or not.
    </ParamField>

    <ParamField path="selectedKey" type="string">
      Controlled selected tab. Pair with `onSelectionChange`.
    </ParamField>
  </Tab>

  <Tab title="TabbedLayoutTab">
    ```tsx theme={null}
    const tab: TabbedLayoutTab = {
      key: "summary",
      label: "Summary",
      content: <Summary />,
    };
    ```

    ## `TabbedLayoutTab`

    <ParamField path="content" type="ReactNode" required>
      Panel content.
    </ParamField>

    <ParamField path="key" type="string" required>
      Stable identity. Must be unique within `tabs`.
    </ParamField>

    <ParamField path="label" type="string" required>
      Localized label for the strip and split pane heading.
    </ParamField>
  </Tab>
</Tabs>
