# Pane

> 对话旁边的一格：它的 TabBar、前面那个对象带一个 ⋯ 的按钮行，以及它的内容。

Source: https://raft-design.botiverse.build/zh/components/pane. Translated from https://raft-design.botiverse.build/components/pane.md; where the two differ, the English page is right.

一格一次显示它的标签页里的一个对象：它的 [TabBar](https://raft-design.botiverse.build/zh/components/tab-bar.md)，然后是前面那个对象的按钮行（只在对象有自己的按钮时才有），然后是内容。`PaneRoot` 是这一格，`PaneToolRow` 是那一行，`PaneBody` 是内容（[标签页与分栏](https://raft-design.botiverse.build/zh/patterns/tabs-and-panes.md)）。

```tsx
import { useCallback, useState } from "react";
import type { MouseEvent } from "react";
import { ArrowLeft, ArrowRight, FileText, Globe, Hash, MessageSquare } from "lucide-react";
import { DropdownMenuItem, DropdownMenuSeparator } from "@botiverse/raft-ui";
import {
  FitToolbarButton,
  PaneBody,
  PaneRoot,
  PaneToolRow,
  SiteDomain,
  Tab,
  TabBar,
} from "@botiverse/raft-ui/wip";
import { TabMenuItems } from "../../tab/tab-menu.tsx";
import { useExampleTabs } from "../../tab/use-example-tabs.ts";

const TABS = ["notes", "vite"];

/**
 * One pane: its tab bar, the front object's row, and its content. A document
 * has its own buttons and a ⋯ with its actions at the row's end; a web page's
 * row is its navigation and its domain, and its ⋯ at the end holds the page's
 * actions, as every kind of object's does.
 */
export function PanePreviewContent() {
  const tabs = useExampleTabs(TABS, "notes");
  // What the last button did, shown in the pane's content.
  const [done, setDone] = useState<string | null>(null);
  const report = useCallback(
    (event: MouseEvent<HTMLElement>) => setDone(event.currentTarget.dataset.done ?? null),
    [],
  );
  return (
    <div className="flex h-72 w-full max-w-3xl flex-col overflow-hidden rounded-container border border-line-hairline">
      <PaneRoot focused>
        <TabBar
          label="Tabs"
          value={tabs.front}
          onValueChange={tabs.setFront}
          onNewTab={tabs.newTab}
          maximized={tabs.maximized}
          onToggleMaximize={tabs.toggleMaximized}
        >
          {tabs.isOpen("notes") ? (
            <Tab
              value="notes"
              source="object"
              icon={<FileText />}
              title="Launch notes"
              onClose={tabs.close}
              menu={
                <TabMenuItems value="notes" onClose={tabs.close} onCloseOthers={tabs.closeOthers} />
              }
            />
          ) : null}
          {tabs.isOpen("vite") ? (
            <Tab
              value="vite"
              source="site"
              icon={<Globe />}
              title="vite.dev"
              pageTitle="Getting started"
              onClose={tabs.close}
              menu={
                <TabMenuItems value="vite" onClose={tabs.close} onCloseOthers={tabs.closeOthers} />
              }
            />
          ) : null}
          {tabs.added.map((value) => (
            <Tab
              key={value}
              value={value}
              source="object"
              icon={<FileText />}
              title="New tab"
              onClose={tabs.close}
            />
          ))}
        </TabBar>
        {tabs.front === "notes" ? (
          <PaneToolRow
            label="Document tools"
            menu={
              <>
                <DropdownMenuItem data-done="Renaming Launch notes" onClick={report}>
                  Rename
                </DropdownMenuItem>
                <DropdownMenuItem data-done="Link to Launch notes copied" onClick={report}>
                  Copy link
                </DropdownMenuItem>
                <DropdownMenuItem data-done="Launch notes: 4 versions" onClick={report}>
                  Version history
                </DropdownMenuItem>
                <DropdownMenuSeparator />
                <DropdownMenuItem data-done="Delete Launch notes?" onClick={report}>
                  Delete
                </DropdownMenuItem>
              </>
            }
          >
            <div className="flex-1" />
            <FitToolbarButton
              variant="ghost"
              icon={<MessageSquare />}
              labelOrder={10}
              data-done="Comments on Launch notes"
              onClick={report}
            >
              Comments
            </FitToolbarButton>
            <FitToolbarButton
              variant="ghost"
              icon={<Hash />}
              labelOrder={20}
              data-done="Shared with #launch-week"
              onClick={report}
            >
              Share
            </FitToolbarButton>
          </PaneToolRow>
        ) : tabs.front === "vite" ? (
          <PaneToolRow
            label="Page tools"
            menu={
              <>
                <DropdownMenuItem data-done="Link to vite.dev copied" onClick={report}>
                  Copy link address
                </DropdownMenuItem>
                <DropdownMenuItem data-done="vite.dev opened in the browser" onClick={report}>
                  Open in browser
                </DropdownMenuItem>
                <DropdownMenuItem data-done="vite.dev reloaded" onClick={report}>
                  Reload
                </DropdownMenuItem>
                <DropdownMenuSeparator />
                <DropdownMenuItem data-done="vite.dev muted" onClick={report}>
                  Mute
                </DropdownMenuItem>
              </>
            }
          >
            <FitToolbarButton variant="ghost" icon={<ArrowLeft />} labelOrder={1} disabled>
              Back
            </FitToolbarButton>
            <FitToolbarButton variant="ghost" icon={<ArrowRight />} labelOrder={1} disabled>
              Forward
            </FitToolbarButton>
            <SiteDomain host="vite.dev" className="mx-2 flex-1" />
          </PaneToolRow>
        ) : null}
        <PaneBody>
          <div className="flex size-full items-center justify-center bg-fill-muted text-callout text-foreground-muted">
            {done ??
              (tabs.front === "notes"
                ? "Launch notes"
                : tabs.front === "vite"
                  ? "vite.dev"
                  : "New tab")}
          </div>
        </PaneBody>
      </PaneRoot>
    </div>
  );
}
```

## 何时使用
| 场景 | 使用 |
| --- | --- |
| 开在对话旁边、带标签页的对象 | Pane |
| 有自己头部的侧边面板（消息列、资料） | [Panel](https://raft-design.botiverse.build/zh/components/panel.md) |
| 左右并排或上下叠放的几格 | [PaneGrid](https://raft-design.botiverse.build/zh/components/pane-grid.md)，每个单元格里一个 Pane |

## 结构
- `PaneRoot`：这一格，一列。`focused` 标出键盘和 App 快捷键作用的那一格（`data-focused`）。
- 一个 `TabBar`。
- `PaneToolRow`：前面那个对象的那一行。它的按钮是一个以 `label` 命名的 [FitToolbar](https://raft-design.botiverse.build/components/fit-toolbar.md)；对象的 ⋯ 来自 `menu`，排在它后面。可选。
- `PaneBody`：内容，占满剩下的空间。从固定图层叠到这一格上的页面占的就是这个框。

## 行为
- 那一行放对象自己的按钮，和它今天那一行一样，不新造，最右边一个 ⋯ 放对象的动作，每种对象都一样。页面（App 或网页）的那一行是它今天的标题栏（App 也一样）或它的地址行，它的 ⋯ 放页面的动作：复制链接地址、在浏览器中打开、刷新、静音或取消静音。标签页菜单里没有这些。
- 那一行从不放这一格的控件：最大化在 TabBar 上，关闭和移动在标签页菜单里。
- 这一格变窄时，按钮按模块给的顺序让出空间，先去掉文字，再收进工具条的「更多」，和 FitToolbar 一样。⋯ 从不收起。
- ⋯ 关上后焦点回到它，除非 `menuHandsFocus` 说选中的项把焦点交给了别处：对话框、面板、查找栏。
- 在一格里任何地方按下指针，由 App 把它变成焦点，在 `PaneRoot` 上用 `onPointerDownCapture`；打开菜单不移动焦点。

## 内容
- 那一行以它的对象命名：「Document tools」「Page tools」「Task tools」。
- ⋯ 的名字和这个对象今天的 ⋯ 一样：默认 More actions，任务是 Task actions。

## 无障碍
- 那一行是一个工具条：一个 Tab 停靠点，里面用方向键（[FitToolbar](https://raft-design.botiverse.build/components/fit-toolbar.md)）。⋯ 是下一个 Tab 停靠点，一个带 `aria-haspopup="menu"` 和提示的按钮。
- 在各格之间移动（F6 和 Shift+F6）归 App；它设置 `focused`，并把那一格标一次。
- `PaneBody` 只是一个容器。它显示前面那个标签页的内容时，给它 `role="tabpanel"`、标签页 `aria-controls` 指向的 `id`，以及指向标签页 `id` 的 `aria-labelledby`（[Tab](https://raft-design.botiverse.build/zh/components/tab.md#accessibility)）。

## 规则
- 一格里最多一个 ⋯，放在那一行最右边，只放对象的动作。
- 对象没有自己的按钮时不要那一行；不画空行。
- 从不把最大化、关闭或移动放在那一行。

## API

### PaneBody

Also takes the attributes of its element.

### PaneRoot

One pane: its `TabBar`, then the front tab's `PaneToolRow` (only where the object has buttons of its own), then `PaneBody`.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `focused` | `boolean` | `false` | The pane the keyboard and the app's shortcuts act on, one at a time across the row (`data-focused`). The app sets it, on a pointer press anywhere in the pane for instance (`onPointerDownCapture`). |

Also takes the attributes of its element.

### PaneToolRow

A pane's second row: the front object's own buttons, then one ⋯ with the object's actions. Never the pane's controls (maximize, close): those are on the TabBar and in the tab's menu. The buttons are a `FitToolbar`: one Tab stop, the arrow keys inside, and they give way as the pane narrows. The ⋯ sits after the toolbar and never folds.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` (required) | `ReactNode` |  | The front object's own buttons, as `FitToolbar` items: they give way as the pane narrows. |
| `label` (required) | `string` |  | The toolbar's accessible name: "Document tools", "Page tools". |
| `menu` | `ReactNode` |  | The object's ⋯ at the row's end: `DropdownMenu` items, the object's own actions. Never the tab's or the pane's (those are in the tab's menu). Without it there is no ⋯: a page's actions lead its tab's menu. |
| `menuHandsFocus` | `() => boolean` |  | Read once as the ⋯ closes: true when the item chosen moved focus on (a dialog, a panel, a find bar); otherwise focus returns to the ⋯. |
| `menuLabel` | `string` | `"More actions"` | The ⋯'s name and tooltip. |

Also takes the attributes of its element.
