@alisowski/react-resizable-panels

中文文档
0.1.27发布于 2024/08/07MITTypeScriptESM + CJS零依赖近 30 天下载 7863

React components for resizable panel groups/layouts

原始使用文档
文档目录5 节
  1. If you like this project, 🎉 become a sponsor or ☕ buy me a …
  2. Props
  3. PanelGroup
  4. Panel
  5. PanelResizeHandle

react-resizable-panels

React components for resizable panel groups/layouts

import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";

<PanelGroup autoSaveId="example" direction="horizontal">
  <Panel defaultSize={25}>
    <SourcesExplorer />
  </Panel>
  <PanelResizeHandle />
  <Panel>
    <SourceViewer />
  </Panel>
  <PanelResizeHandle />
  <Panel defaultSize={25}>
    <Console />
  </Panel>
</PanelGroup>

If you like this project, 🎉 become a sponsor or ☕ buy me a coffee

Props

PanelGroup

proptypedescription
autoSaveId?stringUnique id used to auto-save group arrangement via localStorage
childrenReactNodeArbitrary React element(s)
className?stringClass name to attach to root element
direction"horizontal" | "vertical"Group orientation
disablePointerEventsDuringResize?boolean = falseDisable pointer events inside Panels during resize 2
id?stringGroup id; falls back to useId when not provided
onLayout?(sizes: number[]) => voidCalled when group layout changes
storage?PanelGroupStorageCustom storage API; defaults to localStorage 1
style?CSSPropertiesCSS style to attach to root element
tagName?string = "div"HTML element tag name for root element

1: Storage API must define the following synchronous methods:

  • getItem: (name:string) => string
  • setItem: (name: string, value: string) => void

2: This behavior is disabled by default because it can interfere with scrollbar styles, but it can be useful in the edge case where a Panel contains an <iframe>

PanelGroup components also expose an imperative API for manual resizing:

methoddescription
setLayout(panelSizes: number[])Resize panel group to the specified panelSizes ([1 - 100, ...]).

Panel

proptypedescription
childrenReactNodeArbitrary React element(s)
className?stringClass name to attach to root element
collapsedSize?number=0Panel should collapse to this size
collapsible?boolean=falsePanel should collapse when resized beyond its minSize
defaultSize?numberInitial size of panel (numeric value between 1-100)
id?stringPanel id (unique within group); falls back to useId when not provided
maxSize?number = 100Maximum allowable size of panel (numeric value between 1-100); defaults to 100
minSize?number = 10Minimum allowable size of panel (numeric value between 1-100); defaults to 10
onCollapse?(collapsed: boolean) => voidCalled when panel is collapsed; collapsed boolean parameter reflecting the new state
onResize?(size: number) => voidCalled when panel is resized; size parameter is a numeric value between 1-100. 1
order?numberOrder of panel within group; required for groups with conditionally rendered panels
style?CSSPropertiesCSS style to attach to root element
tagName?string = "div"HTML element tag name for root element

1: If any Panel has an onResize callback, the order prop should be provided for all Panels.

Panel components also expose an imperative API for manual resizing:

methoddescription
collapse()If panel is collapsible, collapse it fully.
expand()If panel is currently collapsed, expand it to its most recent size.
getCollapsed(): booleanReturns true if the panel is currently collapsed (size === 0).
getSize(): numberReturns the most recently commited size of the panel as a percentage (1 - 100).
resize(percentage: number)Resize panel to the specified percentage (1 - 100).

PanelResizeHandle

proptypedescription
children?ReactNodeCustom drag UI; can be any arbitrary React element(s)
className?stringClass name to attach to root element
disabled?booleanDisable drag handle
id?stringResize handle id (unique within group); falls back to useId when not provided
onDragging?(isDragging: boolean) => voidCalled when group layout changes
style?CSSPropertiesCSS style to attach to root element
tagName?string = "div"HTML element tag name for root element

If you like this project, buy me a coffee.

版本与发布记录

@alisowski/react-resizable-panels 共发布 24 个版本,首次发布于 2023/10/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.27latest2024/08/072 年前
0.1.232024/05/222 年前
0.1.222024/03/222 年前
0.1.212024/03/132 年前
0.1.202024/02/032 年前
0.1.192024/01/252 年前

关于 @alisowski/react-resizable-panels 的常见问题

@alisowski/react-resizable-panels 是什么?

React components for resizable panel groups/layouts

如何安装 @alisowski/react-resizable-panels?

在项目目录运行 npm install @alisowski/react-resizable-panels,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^16.14.0 || ^17.0.0 || ^18.0.0)、react-dom(^16.14.0 || ^17.0.0 || ^18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@alisowski/react-resizable-panels 支持 TypeScript 吗?

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

@alisowski/react-resizable-panels 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@alisowski/react-resizable-panels 可以商用吗?

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

@alisowski/react-resizable-panels 的下载量有多少?

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

@alisowski/react-resizable-panels 还在维护吗?

最新版本 0.1.27 发布于 2024/08/07(2 年前);至今共发布 24 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/10/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。