# @geoffcox/react-splitter 中文文档

规范地址：https://npmcn.com/package/%40geoffcox/react-splitter/

版本：2\.1\.2
npm 元数据更新时间：2023-01-16T22:59:11.955Z
中文译文更新时间：2026-11-16T04:22:34.503Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40geoffcox/react-splitter
原文对照：https://npmcn.com/package/%40geoffcox/react-splitter/?lang=original
项目主页：https://github.com/GeoffCox/react-splitter/

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：153 kB，8 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- peer 依赖：react \>=16\.8\.0 \<19\.0\.0，react-dom \>=16\.8\.0 \<19\.0\.0
- 首次发布：2020-06-11T18:38:42.022Z
- 最新版本发布：2023-01-16T22:59:11.868Z
- 近 30 天下载量：11059（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：12（近 12 个月 0 个）

## 中文简介

一个利用 CSS 网格模板进行简单和相容再大小调整的 React 组件分解器.

## 安装

```sh
npm install @geoffcox/react-splitter
```

也可以使用：`pnpm add @geoffcox/react-splitter`、`yarn add @geoffcox/react-splitter`、`bun add @geoffcox/react-splitter`

## README

# @geoffcox/反应散射器

利用 CSS 显示的可调整分解器: grid

[现场直播](https://geoffcox.github.io/react-splitter-demo/index.html)

## 概览

见 [./读取.md](https://npmcn.com/package/%40geoffcox/README.md) 用于特性、版本历史等.

# 安装

```
npm install --save @geoffcox/react-splitter
```

# 使用量

要创建垂直或水平分割, 您只需要 `Split` 组件.

## 垂直分割

默认创建了从中间向下分割的左正弦, 没有最小的窗格大小, 并让默认分取器 .

```tsx
<Split>
  <div>This is the left pane.</div>
  <div>This is the right pane.<div>
</Split>
```

## 水平分割

添加数据 `horizontal` 属性到上下分拆.

```tsx
<Split horizontal>
  <div>This is the top pane.</div>
  <div>This is the bottom pane.<div>
</Split>
```

## 设置初始分割大小

添加数据 `initialPrimarySize` 属性以控制初始拆分发生的地方.

```tsx
<Split initialPrimarySize='30%'>
  <div>Primary pane</div>
  <div>Secondary pane<div>
</Split>
```

要支持双击重置到初始大小,请添加 `resetOnDoubleClick` 属性.

```tsx
<Split initialPrimarySize='30%' resetOnDoubleClick>
  <div>Primary pane</div>
  <div>Secondary pane<div>
</Split>
```

## 雀巢分块

只要筑巢分块 来创造你喜欢的布局. 以下是主要,细节,和输出视图的共同布局的例子.

```tsx
<Split initialPrimarySize='30%'>
  <div>This is the left pane.</div>
  <Split horizontal initialPrimarySize='60%'>
    <div>This is the right-top pane.</div>
    <div>This is the right-bottom pane.</div>
  </Split>
</Split>
```

## 约束最小面板大小

您可以防止窗帘变小 `minPrimarySize` 财务报告和审定财务报表 `minSecondarySize` 属性. 对于垂直分块,主面为左面板,次面为右面板. 对于水平分法,初级为上平面,二级为下平面.

```tsx
<Split minPrimarySize='250px' minSecondarySize='15%'>
  <div>This pane won't get smaller than 250 pixels.</div>
  <div>This pane won't get any smaller than 15% of the overall size of the split control./<div>
</Split>
```

## 自定义分数大小

您可以设定命中区域的大小( 用户可以点击此区域开始拖动拆分器) `splitterSize` 属性.

```tsx
<Split splitterSize='10px'>
  <div>Primary pane</div>
  <div>Secondary pane<div>
</Split>
```

## 自定义分数颜色

您可以用 `defaultSplitterColors` 属性.

```tsx
const colors = {
  color: 'red',
  hover: '#00FF00',
  drag: 'blue'
};

<Split defaultSplitterColors={colors}>
  <div>Primary pane</div>
  <div>Secondary pane<div>
</Split>
```

## 自定义渲染分解符

你可以让自己的分裂者 通过回电到 `renderSplitter` 属性.

```tsx
const renderSplitter = (props: RenderSplitterProps) => {
  return <div>Your splitter code goes here.</div>
};

<Split renderSplitter={renderSplitter}>
  <div>Primary pane</div>
  <div>Secondary pane<div>
</Split>
```

回电收到 `RenderSplitterProps` ,以便让您知道当前拆分器的大小,如果拆分是水平的,如果拆分器正在被拖动.

```ts
export type RenderSplitterProps = {
  pixelSize: number;
  horizontal: boolean;
  dragging: boolean;
};
```

## 监测变化

您可以使用事件召回来监视主大小和被测量大小的变化. 主大小为CSS单位字符串(百分比或初始大小). 所测量的大小为像素大小.

```tsx
const onSplitChanged = (primarySize: string) => {
  console.log(`The split is: ${primarySize}`);
};

const onMeasuredSizesChanged = (sizes: SplitMeasuredPixelSizes) => {
  console.log(`The primary pane is: ${sizes.primary}px`);
  console.log(`The splitter is: ${sizes.splitter}px`);
  console.log(`The secondary pane is: ${sizes.secondary}px`);
};

<Split onSplitChanged={onSplitChanged} onMeasuredSizesChanged={onMeasuredSizesChanged}>
  <div>Primary pane</div>
  <div>Secondary pane<div>
</Split>
```

# 整合到网络应用程序

如果您正在使用 Fluent 、 Materical UI 或 Bootstrap 等样式框架, 那么您的根 div 可能会应用 CSS 样式来帮助此分解器正确工作 . 如果没有根样式表,则可能存在垂直滚动的问题.

如果您正在构建一个单页应用程序, 您可在此推荐一些 CSS 属性 。 在这种情况下,#app是反应的上升点. R. 您可以在演示应用程序中看到这个方法 .

```css
body {
  height: 100vh;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: hidden;
  padding: 0;
  margin: 0;
}

body,
div {
  box-sizing: border-box;
}

#app {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  outline: none;
  overflow: hidden;
}
```

## 常见问题

### @geoffcox/react-splitter 是什么？

一个利用 CSS 网格模板进行简单和相容再大小调整的 React 组件分解器\.

### 如何安装 @geoffcox/react-splitter？

在项目目录运行 npm install @geoffcox/react-splitter，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（\>=16\.8\.0 \<19\.0\.0）、react-dom（\>=16\.8\.0 \<19\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @geoffcox/react-splitter 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @geoffcox/react-splitter 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @geoffcox/react-splitter 可以商用吗？

@geoffcox/react-splitter 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @geoffcox/react-splitter 的下载量有多少？

根据 npm 官方下载统计，@geoffcox/react-splitter 在 2026/10/16 – 2026/11/14 这 30 天内被下载 11,059 次，日均约 369 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @geoffcox/react-splitter 还在维护吗？

最新版本 2\.1\.2 发布于 2023/01/17（3 年前）；至今共发布 12 个版本，其中过去 12 个月发布了 0 个；首次发布于 2020/06/12。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

