# Resizable

用指针和键盘调整、收起并保存面板布局。

用一组可调整大小的面板，让人们拖动它们之间的句柄或使用键盘，调整布局中各窗格的大小，比如编辑器旁边的文件列表。

```vue title="basic.vue"
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from "@ui-sdk/vue/resizable"
</script>

<template>
  <Resizable>
    <ResizablePanel :default-size="35" :min-size="20">
      <h3>Files</h3>
      <ul>
        <li>page.tsx</li>
        <li>layout.tsx</li>
        <li>globals.css</li>
      </ul>
    </ResizablePanel>
    <ResizableHandle aria-label="Resize files" />
    <ResizablePanel :default-size="65" :min-size="40">
      <Resizable orientation="vertical">
        <ResizablePanel :default-size="60" :min-size="30">
          <h3>page.tsx</h3>
          <span data-slot="hint">Saved just now</span>
        </ResizablePanel>
        <ResizableHandle aria-label="Resize editor" />
        <ResizablePanel :default-size="40" :min-size="30">
          <h3>Terminal</h3>
          <span data-slot="hint">Ready on port 3000</span>
        </ResizablePanel>
      </Resizable>
    </ResizablePanel>
  </Resizable>
</template>
```

拖动 Files 旁边的句柄，再拖动 page.tsx 和 Terminal 之间的那个。

## 安装
```bash
npm install @ui-sdk/vue @ui-sdk/core
```

## 组合
用下面的组合构建一个 `Resizable`：

```text
Resizable
├── ResizablePanel
├── ResizableHandle
└── ResizablePanel
```

在你想调整大小的面板之间放一个句柄，并用 `aria-label` 给它命名，比如“Resize files”。这一组会把面板排成一行，所以要给它一个尺寸，每个面板的大小是各面板共享空间的百分比。一组面板可以放在一个面板里面，比如终端上方的编辑器。

## 用法
导入各个部件并把它们组合起来：

```vue
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from "@ui-sdk/vue/resizable"
</script>

<template>
  <Resizable>
    <ResizablePanel :default-size="30">Files</ResizablePanel>
    <ResizableHandle aria-label="Resize files" />
    <ResizablePanel>Editor</ResizablePanel>
  </Resizable>
</template>
```

没有 `default-size` 的面板占剩下的空间，这里是 70%。

## 自己构建
`@ui-sdk/vue/resizable` 自带一个现成的 Resizable。如果你想用自己的名字构建一个，可以从 `@ui-sdk/core` 里的 `resizable` 原语（primitive）开始：

```ts title="split-view.ts"
import { resizable } from "@ui-sdk/core/resizable"
import { createParts } from "@ui-sdk/vue/primitive"

const {
  Root: SplitView,
  Panel: SplitViewPane,
  Handle: SplitViewDivider,
} = createParts(resizable, { root: "div", panel: "div", handle: "div" })

export { SplitView, SplitViewDivider, SplitViewPane }
```

```vue
<template>
  <SplitView>
    <SplitViewPane :default-size="30">Files</SplitViewPane>
    <SplitViewDivider aria-label="Resize files" />
    <SplitViewPane>Editor</SplitViewPane>
  </SplitView>
</template>
```

每个部件都保留其现成对应部件的行为、状态和数据属性：根部件负责排列面板，每个窗格把大小写入 `--resizable-panel-size`，分隔部件是可聚焦的 `separator`。更多内容见[渲染原语](/docs/vue/rendering)和[自定义部件](/docs/vue/custom-parts)。

## 垂直
设置 `orientation="vertical"` 把面板堆叠起来，并给这一组一个高度。ArrowUp 和 ArrowDown 移动句柄。每个部件都会得到带有这一组方向的 `data-orientation`，所以垂直组的句柄是 `[data-slot="resizable-handle"][data-orientation="vertical"]`。

```vue title="vertical.vue"
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from "@ui-sdk/vue/resizable"
</script>

<template>
  <Resizable orientation="vertical">
    <ResizablePanel :default-size="45" :min-size="25">
      <h3>Inbox</h3>
      <span data-slot="hint">3 unread messages</span>
    </ResizablePanel>
    <ResizableHandle aria-label="Resize inbox" />
    <ResizablePanel :default-size="55" :min-size="25">
      <h3>Quarterly report</h3>
      <span data-slot="hint">From Hollis Grant</span>
    </ResizablePanel>
  </Resizable>
</template>
```

拖动 Inbox 和 Quarterly report 之间的句柄，或者聚焦它并使用 ArrowUp 和 ArrowDown。

## 句柄
把任何内容放进句柄，比如一个表明它可以拖动的握柄。句柄本身可以保持成一条细线：即使不加任何样式，它的命中区域也至少有 10 像素宽，以它为中心，触摸时为 24 像素。

```vue title="handle.vue"
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from "@ui-sdk/vue/resizable"
</script>

<template>
  <Resizable>
    <ResizablePanel :default-size="35" :min-size="20">
      <h3>Channels</h3>
      <ul>
        <li>general</li>
        <li>design</li>
        <li>releases</li>
      </ul>
    </ResizablePanel>
    <ResizableHandle aria-label="Resize channels">
      <div />
    </ResizableHandle>
    <ResizablePanel :default-size="65" :min-size="20">
      <h3>general</h3>
      <span data-slot="hint">Kofi Mensah: The release notes are ready.</span>
    </ResizablePanel>
  </Resizable>
</template>
```

抓住 Channels 旁边的握柄，或者聚焦句柄并使用方向键。

## 可收起
`collapsible` 让面板越过它的 `min-size` 一直收起到 `collapsed-size`（默认 0）：可以拖过中点到达它的收起尺寸，也可以在它的句柄上按 Enter 或双击，或者通过控制器。往回拖过同一个位置会以最小尺寸打开它，按 Enter 则恢复它原来的尺寸。收起的面板会得到 `data-collapsed`，尺寸为 0 时，它的内容会离开 Tab 顺序和无障碍树。

```vue title="collapsible.vue"
<script setup lang="ts">
import { FolderIcon, SearchIcon, SettingsIcon } from "@lucide/vue"
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from "@ui-sdk/vue/resizable"
</script>

<template>
  <Resizable>
    <ResizablePanel
      :default-size="30"
      :min-size="25"
      collapsible
      collapsed-size="48px"
    >
      <ul>
        <li data-slot="row">
          <FolderIcon aria-hidden="true" />
          <span>Files</span>
        </li>
        <li data-slot="row">
          <SearchIcon aria-hidden="true" />
          <span>Search</span>
        </li>
        <li data-slot="row">
          <SettingsIcon aria-hidden="true" />
          <span>Settings</span>
        </li>
      </ul>
    </ResizablePanel>
    <ResizableHandle aria-label="Resize sidebar">
      <div />
    </ResizableHandle>
    <ResizablePanel :min-size="40">
      <h3>README.md</h3>
      <span data-slot="hint">Edited by Inès Moreau</span>
    </ResizablePanel>
  </Resizable>
</template>
```

把侧边栏拖到关闭，只留下它的图标；或者聚焦它的句柄并按 Enter 收起或恢复它。

## 像素尺寸
尺寸是作为数字的百分比，或者带 `%`、`px` 或 `rem` 的字符串。这一组调整大小时，像素和 rem 的限制仍然成立，所以 `min-size="160px"` 的导航永远不会变得更窄，由它引起的变更会报告 `resize` 原因。

```vue title="sizes.vue"
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from "@ui-sdk/vue/resizable"
</script>

<template>
  <Resizable>
    <ResizablePanel default-size="200px" min-size="160px" max-size="320px">
      <h3>Docs</h3>
      <ul>
        <li>Getting Started</li>
        <li>Components</li>
        <li>Guides</li>
      </ul>
    </ResizablePanel>
    <ResizableHandle aria-label="Resize navigation">
      <div />
    </ResizableHandle>
    <ResizablePanel :min-size="30">
      <h3>Getting Started</h3>
      <span data-slot="hint">Install the packages</span>
    </ResizablePanel>
  </Resizable>
</template>
```

调整 Docs 的大小。无论这一组有多宽，它的宽度都保持在 160 到 320 像素之间。

## 默认布局
`default-layout` 按顺序一次设置每个面板的大小。否则，没有 `default-size` 的面板会平均分配剩下的空间。

```vue title="default-layout.vue"
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from "@ui-sdk/vue/resizable"
</script>

<template>
  <Resizable :default-layout="[25, 35, 40]">
    <ResizablePanel :min-size="15">
      <h3>Mail</h3>
      <ul>
        <li>Inbox</li>
        <li>Drafts</li>
        <li>Sent</li>
      </ul>
    </ResizablePanel>
    <ResizableHandle aria-label="Resize folders" />
    <ResizablePanel :min-size="15">
      <h3>Inbox</h3>
      <ul>
        <li>Hollis Grant</li>
        <li>Inès Moreau</li>
        <li>Kofi Mensah</li>
      </ul>
    </ResizablePanel>
    <ResizableHandle aria-label="Resize inbox" />
    <ResizablePanel :min-size="15">
      <h3>Quarterly report</h3>
      <span data-slot="hint">From Hollis Grant</span>
    </ResizablePanel>
  </Resizable>
</template>
```

三个邮件面板的起始大小是 25%、35% 和 40%。调整其中任意一个。

## 受控
绑定 `v-model:layout` 来控制这一组，并监听 `@layout-change` 获取原因。布局是按顺序排列的每个面板一个百分比，加起来是 100。每次变更都带有[原因](https://ui-sdk.cn/docs/vue/components/resizable#reasons)，比如 `drag`、`step-key` 或 `collapse`，而 `details.cancel()` 会保留当前的布局。

```vue title="controlled.vue"
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
  type ResizableLayoutChangeDetails,
} from "@ui-sdk/vue/resizable"
import { ref } from "vue"
import { useLog } from "./log"

const format = (layout: number[]) => layout.map(Math.round).join(" / ")

const log = useLog()
const layout = ref([30, 70])

function onLayoutChange(next: number[], details: ResizableLayoutChangeDetails) {
  if (format(next) !== format(layout.value)) {
    log(`${format(next)} (${details.reason})`)
  }
}
</script>

<template>
  <div data-slot="stack">
    <div data-slot="controls">
      <button type="button" @click="layout = [50, 50]">Split Evenly</button>
      <button type="button" @click="layout = [30, 70]">Reset</button>
    </div>
    <Resizable v-model:layout="layout" @layout-change="onLayoutChange">
      <ResizablePanel :min-size="20">
        <h3>Files</h3>
        <ul>
          <li>page.tsx</li>
          <li>layout.tsx</li>
          <li>globals.css</li>
        </ul>
      </ResizablePanel>
      <ResizableHandle aria-label="Resize files" />
      <ResizablePanel :min-size="20">
        <h3>page.tsx</h3>
        <span data-slot="hint">Saved just now</span>
      </ResizablePanel>
    </Resizable>
  </div>
</template>
```

调整 Files 的大小，记录布局和它的原因。Split Evenly 和 Reset 会从外部设置布局。

## 完成后保存
`@layout-change` 在拖动的每一帧运行。`@layout-commit` 只运行一次，在改变布局的交互结束时：指针抬起、按键松开，或者面板收起。在那里保存。拖动期间按 Escape 会把面板放回开始的位置，不会提交任何内容。

```vue title="complete.vue"
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
  type ResizableLayoutCommitDetails,
} from "@ui-sdk/vue/resizable"
import { useLog } from "./log"

const log = useLog()

function onLayoutCommit(
  layout: number[],
  details: ResizableLayoutCommitDetails
) {
  log(`Saved ${layout.map(Math.round).join(" / ")} (${details.reason})`)
}
</script>

<template>
  <Resizable @layout-commit="onLayoutCommit">
    <ResizablePanel :default-size="40" :min-size="20">
      <h3>Files</h3>
      <ul>
        <li>page.tsx</li>
        <li>layout.tsx</li>
        <li>globals.css</li>
      </ul>
    </ResizablePanel>
    <ResizableHandle aria-label="Resize files" />
    <ResizablePanel :min-size="20">
      <h3>page.tsx</h3>
      <span data-slot="hint">Saved just now</span>
    </ResizablePanel>
  </Resizable>
</template>
```

拖动句柄并松开，或者按一次方向键。松手时，控制台会记录一次布局。

## 持久化
`auto-save-id` 在交互完成时把布局保存到 `localStorage`，并在这一组于浏览器中挂载时恢复它。服务端标记从默认尺寸开始。每一组面板都保留自己的布局，所以一个时有时无的面板也能取回它的大小。给面板一个 `id`，这样即使页面别处发生变化，保存的布局也能保留下来。

这和 [Preferences](/docs/vue/components/preferences) 是同一个思路，后者在多次访问之间保存一项选择，比如主题。Resizable 则在它的 `auto-save-id` 下保存整个布局。

```vue title="persistence.vue"
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from "@ui-sdk/vue/resizable"
</script>

<template>
  <Resizable auto-save-id="docs-persistence">
    <ResizablePanel id="docs-sidebar" :default-size="30" :min-size="20">
      <h3>Outline</h3>
      <ul>
        <li>Introduction</li>
        <li>Installation</li>
        <li>Usage</li>
      </ul>
    </ResizablePanel>
    <ResizableHandle aria-label="Resize outline">
      <div />
    </ResizableHandle>
    <ResizablePanel id="docs-content" :min-size="30">
      <h3>Introduction</h3>
      <span data-slot="hint">Last edited by Wren Takahashi</span>
    </ResizablePanel>
  </Resizable>
</template>
```

调整 Outline 的大小，然后重新加载这个页面，恢复它保存的宽度。

## 存储
`storage` 接受任何带有 `getItem` 和 `setItem` 的对象，比如 `sessionStorage` 或 cookie。那是浏览器的存储形状，而不是 Preferences 接受的[存储](https://ui-sdk.cn/docs/vue/components/preferences#save-the-value)辅助函数，比如 `createLocalStorage`；那些辅助函数各自只保存一个值。像选择偏好那样，在[记住选择](https://ui-sdk.cn/docs/core/behaviors/preferences#remember-the-choice)里决定用 local storage、session storage 还是 cookie。

这个示例把布局保存在 `sessionStorage` 里，作用于这个标签页的会话：

```vue title="storage.vue"
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
  type ResizableStorage,
} from "@ui-sdk/vue/resizable"

const session: ResizableStorage = {
  getItem: (key) => sessionStorage.getItem(key),
  setItem: (key, value) => sessionStorage.setItem(key, value),
}
</script>

<template>
  <Resizable auto-save-id="docs-storage" :storage="session">
    <ResizablePanel id="session-chats" :default-size="35" :min-size="20">
      <h3>Messages</h3>
      <ul>
        <li>Inès Moreau</li>
        <li>Kofi Mensah</li>
        <li>Wren Takahashi</li>
      </ul>
    </ResizablePanel>
    <ResizableHandle aria-label="Resize messages" />
    <ResizablePanel id="session-thread" :min-size="20">
      <h3>Inès Moreau</h3>
      <span data-slot="hint">Can we move the review to Friday?</span>
    </ResizablePanel>
  </Resizable>
</template>
```

调整 Messages 的大小，然后重新加载。宽度在这个标签页里会回来，但在新标签页里不会。

服务器无法读取 `localStorage`，所以它会渲染每个面板的 `default-size`，保存的布局在页面水合后才到达。要在首次绘制时就渲染保存的布局，就把它放进 cookie，并把各面板的大小作为各自的 `default-size` 传回去。这里有一个 Nuxt 页面用 `useCookie` 读取 cookie，它也会解析其中的 JSON。它导入 `resizableStorageKey`（它给 cookie 命名）：

```vue title="pages/index.vue"
<script setup lang="ts">
import { resizableStorageKey } from "@ui-sdk/vue/resizable"

const saved = useCookie<Record<string, number[]>>(
  resizableStorageKey("editor"),
  { default: () => ({}) }
)
const [sidebar = 25, main = 75] = saved.value["sidebar,main"] ?? []
</script>

<template>
  <Editor :sidebar="sidebar" :main="main" />
</template>
```

```vue title="components/Editor.vue"
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
  type ResizableStorage,
} from "@ui-sdk/vue/resizable"

defineProps<{ sidebar: number; main: number }>()

const cookieStorage: ResizableStorage = {
  getItem: (key) => {
    const value = document.cookie.match(
      new RegExp(`(?:^|; )${key}=([^;]*)`)
    )?.[1]
    return value === undefined ? null : decodeURIComponent(value)
  },
  setItem: (key, value) => {
    document.cookie = `${key}=${encodeURIComponent(value)}; path=/; max-age=31536000`
  },
}
</script>

<template>
  <Resizable auto-save-id="editor" :storage="cookieStorage">
    <ResizablePanel id="sidebar" :default-size="sidebar" />
    <ResizableHandle aria-label="Resize sidebar" />
    <ResizablePanel id="main" :default-size="main" />
  </Resizable>
</template>
```

## 控制器
来自 `createResizableController()` 的控制器可以在任何地方按 id 或索引收起、展开和调整面板大小，并用 `getLayout()` 读取布局。它做出的变更会报告 `imperative` 原因。

```vue title="controller.vue"
<script setup lang="ts">
import {
  createResizableController,
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from "@ui-sdk/vue/resizable"
import { useLog } from "./log"

const log = useLog()
const editor = createResizableController()

function read() {
  log(
    `Layout ${editor.getLayout().map(Math.round).join(" / ")}${editor.isCollapsed("controller-sidebar") ? ", collapsed" : ""}`
  )
}
</script>

<template>
  <div data-slot="stack">
    <div data-slot="controls">
      <button type="button" @click="editor.collapse('controller-sidebar')">
        Collapse
      </button>
      <button type="button" @click="editor.expand('controller-sidebar')">
        Expand
      </button>
      <button
        type="button"
        @click="editor.resize('controller-sidebar', '240px')"
      >
        240px
      </button>
      <button type="button" @click="read">Read</button>
    </div>
    <Resizable :controller="editor">
      <ResizablePanel
        id="controller-sidebar"
        :default-size="30"
        :min-size="20"
        collapsible
      >
        <h3>Files</h3>
        <ul>
          <li>page.tsx</li>
          <li>layout.tsx</li>
          <li>globals.css</li>
        </ul>
      </ResizablePanel>
      <ResizableHandle aria-label="Resize files" />
      <ResizablePanel :min-size="30">
        <h3>page.tsx</h3>
        <span data-slot="hint">Saved just now</span>
      </ResizablePanel>
    </Resizable>
  </div>
</template>
```

用 Collapse、Expand 和 240px 从这一组之外移动 Files，用 Read 记录它的大小。

## 步长
`step` 设置方向键移动句柄的距离，默认 1%；`large-step` 设置 Shift 加方向键移动的距离，默认 10%。

```vue title="keyboard.vue"
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from "@ui-sdk/vue/resizable"
</script>

<template>
  <Resizable :step="5" :large-step="25">
    <ResizablePanel :default-size="50" :min-size="20">
      <h3>Original</h3>
      <span data-slot="hint">v1.2.0</span>
    </ResizablePanel>
    <ResizableHandle aria-label="Resize original" />
    <ResizablePanel :default-size="50" :min-size="20">
      <h3>Changes</h3>
      <span data-slot="hint">v1.3.0</span>
    </ResizablePanel>
  </Resizable>
</template>
```

聚焦 Original 和 Changes 之间的句柄。方向键移动 5%，Shift 加方向键移动 25%，Home 和 End 则会移到它能到的最远处。

## 禁用
在句柄上设置 `disabled` 会把它固定在原处。设置在组上会固定每个句柄。禁用的句柄会离开 Tab 顺序，它们旁边的面板保持原有大小。用禁用的 `<fieldset>` 包住这一组，也会固定每个句柄。

```vue title="disabled.vue"
<script setup lang="ts">
import { CheckIcon } from "@lucide/vue"
import {
  Checkbox,
  CheckboxIndicator,
  type CheckedState,
} from "@ui-sdk/vue/checkbox"
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from "@ui-sdk/vue/resizable"
import { ref } from "vue"

const locked = ref<CheckedState>(false)
</script>

<template>
  <div data-slot="stack">
    <div data-slot="controls">
      <label data-slot="label">
        <Checkbox v-model:checked="locked">
          <CheckboxIndicator>
            <CheckIcon aria-hidden="true" />
          </CheckboxIndicator>
        </Checkbox>
        Lock layout
      </label>
    </div>
    <Resizable :disabled="locked === true">
      <ResizablePanel :min-size="15">
        <h3>Pinned</h3>
        <span data-slot="hint">2 notes</span>
      </ResizablePanel>
      <ResizableHandle disabled aria-label="Resize pinned" />
      <ResizablePanel :min-size="15">
        <h3>Inbox</h3>
        <span data-slot="hint">3 unread</span>
      </ResizablePanel>
      <ResizableHandle aria-label="Resize inbox" />
      <ResizablePanel :min-size="15">
        <h3>Message</h3>
        <span data-slot="hint">From Kofi Mensah</span>
      </ResizablePanel>
    </Resizable>
  </div>
</template>
```

Pinned 之后的句柄保持固定。拖动 Inbox 之后的那个，然后勾选 Lock layout 把它也固定住。

## 自定义渲染
`#render` 槽位和默认槽位会收到部件的状态，比如面板的 `size` 和它是否 `collapsed`，或者句柄是否 `dragging` 或 `hovering`。渲染约定见[部件与组合](/docs/vue/parts-and-composition)。

```vue title="render.vue"
<script setup lang="ts">
import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from "@ui-sdk/vue/resizable"
</script>

<template>
  <Resizable>
    <ResizablePanel
      v-slot="{ state }"
      :default-size="35"
      :min-size="20"
      collapsible
    >
      <h3>Files</h3>
      <span data-slot="hint">{{
        state.collapsed ? "Collapsed" : `${Math.round(state.size)}%`
      }}</span>
    </ResizablePanel>
    <ResizableHandle aria-label="Resize files">
      <template #render="{ props }">
        <div v-bind="props" />
      </template>
    </ResizableHandle>
    <ResizablePanel v-slot="{ state }" :min-size="30">
      <h3>Editor</h3>
      <span data-slot="hint">{{ `${Math.round(state.size)}%` }}</span>
    </ResizablePanel>
  </Resizable>
</template>
```

调整 Files 的大小，看两个面板报告各自的尺寸；或者收起它，看到 Collapsed。

原语会把拖动中的尺寸直接写入面板样式。在槽位里读取 `size` 或 `layout`，也会让该部件在拖动的每一帧重新渲染。

## 样式
除了所需的布局，部件没有样式：这一组是 flex 行或列，面板以 flex basis 取得自己的大小，句柄不收缩，并采用 `touch-action: none`。给这一组一个尺寸，给句柄宽度或高度以及背景，并用 `data-hovering`、`data-dragging` 和 `:focus-visible` 设置样式。句柄被悬停或拖动时，它的光标会显示在整个页面上，并在到达限制时指向它唯一能走的方向。

每个部件都有一个 `data-slot`，比如 `resizable-handle`，它的状态属性列在[数据属性](https://ui-sdk.cn/docs/vue/components/resizable#data-attributes)下。

### ResizablePanel
- `--resizable-panel-size`: The panel's share of the group, as a percentage. Written on every frame of a drag, without a render.

## 数据属性
### Resizable
`[data-slot="resizable"]`

- `data-orientation` (`horizontal`, `vertical`): The group's direction, on every part. A handle's own `aria-orientation` is the other one, since it runs across the group.
- `data-disabled`: Present when the group, or this handle, is disabled.
- `data-dragging`: Present while a handle of the group is being dragged.

### ResizablePanel
`[data-slot="resizable-panel"]`

- `data-orientation` (`horizontal`, `vertical`): The group's direction, on every part. A handle's own `aria-orientation` is the other one, since it runs across the group.
- `data-collapsed`: Present while a collapsible panel is collapsed.

### ResizableHandle
`[data-slot="resizable-handle"]`

- `data-orientation` (`horizontal`, `vertical`): The group's direction, on every part. A handle's own `aria-orientation` is the other one, since it runs across the group.
- `data-disabled`: Present when the group, or this handle, is disabled.
- `data-dragging`: Present while this handle is being dragged.
- `data-hovering`: Present while the pointer is over the handle or within its hit area, which reaches past the handle itself.

## API 参考
属性和下面相同，回调是事件。

### Resizable
- `layout?` (`number[]`): Each panel's size in percent, in panel order, like `[25, 75]`. Pass it to control the group.
- `defaultLayout?` (`number[]`): The layout at first, when uncontrolled. Panels' own `defaultSize` is what a server renders, so prefer that with server rendering.
- `@layout-change` (`((layout: number[], details: ResizableLayoutChangeDetails) => void)`): Runs while the layout changes: on every frame of a drag and every key. `details.cancel()` keeps the layout.
- `@layout-commit` (`((layout: number[], details: ResizableLayoutCommitDetails) => void)`): Runs once an interaction that changed the layout ends: the pointer lifts, the key comes up, or a panel collapses. For saving.
- `orientation?` (`"horizontal" | "vertical"`): The direction panels are laid out in. Horizontal panels sit side by side, vertical ones stack.
- `disabled?` (`boolean`): Stops every handle: no drags, no keys, and handles leave the tab order.
- `step?` (`number`): How far an arrow key moves a handle, in percent.
- `largeStep?` (`number`): How far Shift with an arrow key moves a handle, in percent.
- `autoSaveId?` (`string`): Saves the layout when an interaction completes and restores it on the next visit, under this key. Give panels an `id` so it survives changes elsewhere on the page.
- `storage?` (`ResizableStorage`): Where `autoSaveId` saves: anything with `getItem` and `setItem`, like a cookie store a server can read.
- `controller?` (`object`): Resizes the group from anywhere. Create one with `createResizableController()`.
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.

### ResizablePanel
- `id?` (`string`): Identifies the panel for the controller, `aria-controls` and saved layouts. It's the element's id. Generated when left out.
- `defaultSize?` (`ResizableSize`): Where the panel starts, in percent or with a unit, like `30` or `"240px"`. Without one, panels share what's left evenly. A server renders this size.
- `minSize?` (`ResizableSize`): The smallest the panel gets while open.
- `maxSize?` (`ResizableSize`): The largest the panel gets.
- `collapsible?` (`boolean`): Lets the panel collapse below its minimum to `collapsedSize`: by dragging past half the way there, with Enter or a double-click on its handle, or through the controller.
- `collapsedSize?` (`ResizableSize`): The size a collapsible panel collapses to. At 0, its content leaves the tab order and the accessibility tree.

### ResizableHandle
- `disabled?` (`boolean`): Stops this handle: no drags and no keys, and it leaves the tab order.

### 状态
渲染函数、基于状态的类名和槽位会收到什么。

- `orientation` (`"horizontal" | "vertical"`): The direction panels are laid out in.
- `disabled` (`boolean`): Whether the group is disabled.
- `dragging` (`boolean`): Whether a handle is being dragged.
- `layout` (`number[]`): Each panel's size in percent. Reading it renders on every frame of a drag.

面板：

- `orientation` (`"horizontal" | "vertical"`): The direction panels are laid out in.
- `size` (`number`): The panel's size in percent. Reading it renders on every frame of a drag.
- `collapsed` (`boolean`): Whether the panel is down at its `collapsedSize`, below its minimum.
- `collapsible` (`boolean`): Whether the panel can collapse.

句柄：

- `orientation` (`"horizontal" | "vertical"`): The direction panels are laid out in. The separator itself runs across it.
- `disabled` (`boolean`): Whether the handle can't move.
- `dragging` (`boolean`): Whether the handle is being dragged.
- `hovering` (`boolean`): Whether the pointer is over the handle or within its hit area.

### 原因
`details.reason` 说明布局为什么改变。

- `drag` (`PointerEvent`): A slider thumb or a resize handle was dragged, or an item was dragged to a new place in a list.
- `step-key` (`KeyboardEvent`): Arrow, Page Up, Page Down, Home or End stepped a slider or a number input.
- `collapse` (`MouseEvent | KeyboardEvent`): Enter or a double-click on a resize handle collapsed the panel beside it, or restored it.
- `resize` (`none`): The group changed size, so panels with sizes in pixels moved to stay within their bounds.
- `imperative` (`none`): A controller or `api` call.

### 控制器
用 `createResizableController()` 创建一个，并把它作为 `controller` 传入。

写方法接受可选的 `{ reason, event }`，像拖动一样运行变更回调，并在没有任何改变或变更被取消时返回 `false`。

- `getLayout()` (`() => number[]`): Each panel's size in percent, in order.
- `setLayout(layout, options?)` (`(layout: number[], options?: ResizableChangeOptions | undefined) => boolean`): Sets every panel's size at once, in percent. It's fitted to the panels' bounds and adds up to 100. Returns whether anything changed.
- `collapse(panel, options?)` (`(panel: string | number, options?: ResizableChangeOptions | undefined) => boolean`): Collapses a collapsible panel, by its id or its index. Returns whether it collapsed.
- `expand(panel, options?)` (`(panel: string | number, options?: ResizableChangeOptions | undefined) => boolean`): Expands a collapsed panel to the size it had before it collapsed, or its minimum. Returns whether it expanded.
- `resize(panel, size, options?)` (`(panel: string | number, size: ResizableSize, options?: ResizableChangeOptions | undefined) => boolean`): Resizes one panel, by its id or its index, like `resize("sidebar", "240px")`. Its neighbours give or take the difference.
- `isCollapsed(panel)` (`(panel: string | number) => boolean`): Whether a panel is collapsed.

### 事件
事件先收到新布局，再收到详情。`v-model` 只在变更事件没有被取消时更新。

| 绑定             | 所属        | 收到                                              |
| ---------------- | ----------- | ------------------------------------------------- |
| `v-model:layout` | `Resizable` | 布局：每个面板一个百分比                          |
| `@layout-change` | `Resizable` | `(layout, details)`: 新布局，以及[原因](https://ui-sdk.cn/docs/vue/components/resizable#reasons) |
| `@layout-commit` | `Resizable` | `(layout, details)`: 交互结束时的布局             |

## 无障碍
句柄遵循 [WAI-ARIA 窗口分隔条模式](https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/)。每个句柄都是一个可聚焦的 `separator`，它的 `aria-valuenow` 是它前面那个面板的大小，`aria-valuemin` 和 `aria-valuemax` 是各面板允许的范围，`aria-controls` 指向那个面板，`aria-orientation` 则横跨这一组的排列方向。用 `aria-label` 给每个句柄命名。

### 键盘
聚焦一个句柄，沿这一组的轴线按方向键，让它移动 `step`；按住 Shift 则移动 `large-step`。Home 和 End 会把它移到各面板允许的最远处，Enter 收起或恢复它旁边的可收起面板。到达最小值的面板会把剩余的移动量传给下一个面板。禁用的句柄会离开 Tab 顺序。

### 经过测试的行为
下面每一行都是一个自动化测试。

**Keyboard**

- Starts at each panel's default size, and panels without one share the rest.
- ArrowRight grows the panel before the handle by one step, and ArrowLeft shrinks it.
- Shift with an arrow key moves by the large step.
- Arrows across the group's axis do nothing.
- ArrowDown and ArrowUp move a vertical group's handle.
- Home collapses a collapsible panel, and End grows it to its maximum.
- Home stops at the minimum of a panel that can't collapse.
- Enter collapses the panel before the handle, and restores its size.
- Enter collapses the panel after the handle when only that one can collapse.
- One step past a collapsible panel's minimum collapses it.
- A panel at its minimum passes the rest on to the next one.
- End stops where the panels' bounds meet.
- Keys pressed without waiting all land.
- Keys complete the change once they come up.
- Step and large step set how far keys move.
- A canceled change keeps the layout.
- A controlled group follows its layout.
- A controlled group that ignores a change completes nothing. React 和 Vue only.
- A disabled handle stops a move from the next one, so the panels past it keep their sizes.
- DefaultLayout sets where the panels start.
- A disabled group's handles leave the tab order and ignore drags.

**Pointer**

- Dragging a handle moves it with the pointer.
- A drag reports its moves with the drag reason and completes once.
- Dragging past a disabled handle moves nothing beyond it.
- Dragging a vertical group's handle moves it up and down.
- Dragging past half a collapsible panel's minimum collapses it, and back opens it.
- A drag stops at the panels' bounds.
- Escape during a drag puts the panels back where they started.
- A double-click on a handle collapses its panel, and another restores it.
- A press just beside the thin handle drags it.
- A press farther from the handle doesn't drag.
- Where two handles meet, one drag moves both.
- A drag shows the axis cursor over the whole page until it ends.

**Controller**

- Collapses and expands a panel, with the imperative reason.
- Resizes a panel to a size in pixels.

**Container**

- A panel with a minimum in pixels keeps it as the group shrinks.
- Panels keep their share as the group grows.

**Pages around a group**

- A layer above a handle keeps its presses.
- A press beside a handle doesn't click what's under it.
- Only the main button drags.
- An iframe under the pointer doesn't stop a drag.
- At a limit, the cursor points the only way a handle can go.
- A saved layout is there on the first paint.

**Touch**

- A touch drag that starts beside the handle, in its touch hit area, resizes without scrolling.

Runs in React、Vue 和 web components.
