Top Related Projects
🖱 A resizable and draggable component for React.
A draggable and resizable grid layout with responsive breakpoints, for React.
A simple React component that is resizable with a handle.
Drag and Drop for React
Moveable! Draggable! Resizable! Scalable! Rotatable! Warpable! Pinchable! Groupable! Snappable!
Quick Overview
React Resizable Panels is a React component library that enables the creation of resizable panel layouts. It provides a flexible and customizable way to build split-view interfaces with draggable dividers, allowing users to adjust panel sizes dynamically.
Pros
- Lightweight and performant, with minimal dependencies
- Supports both horizontal and vertical layouts
- Offers keyboard accessibility and screen reader support
- Provides smooth animations and touch device compatibility
Cons
- Limited to React applications only
- Requires some setup and configuration for complex layouts
- May have a learning curve for developers new to React or panel-based layouts
- Documentation could be more comprehensive for advanced use cases
Code Examples
- Basic horizontal layout:
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
function App() {
return (
<PanelGroup direction="horizontal">
<Panel>Left panel</Panel>
<PanelResizeHandle />
<Panel>Right panel</Panel>
</PanelGroup>
);
}
- Vertical layout with multiple panels:
<PanelGroup direction="vertical">
<Panel>Top panel</Panel>
<PanelResizeHandle />
<Panel>Middle panel</Panel>
<PanelResizeHandle />
<Panel>Bottom panel</Panel>
</PanelGroup>
- Using imperative handle to control panel size:
function App() {
const panelRef = useRef(null);
const handleResize = () => {
panelRef.current?.resize(50);
};
return (
<PanelGroup>
<Panel ref={panelRef}>Resizable panel</Panel>
<PanelResizeHandle />
<Panel>Fixed panel</Panel>
<button onClick={handleResize}>Resize to 50%</button>
</PanelGroup>
);
}
Getting Started
-
Install the package:
npm install react-resizable-panels -
Import and use the components in your React application:
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels"; function App() { return ( <PanelGroup direction="horizontal"> <Panel minSize={20}>Left panel</Panel> <PanelResizeHandle /> <Panel minSize={30}>Right panel</Panel> </PanelGroup> ); } -
Style the components as needed using CSS or the provided
classNameprops.
Competitor Comparisons
🖱 A resizable and draggable component for React.
Pros of react-rnd
- More flexible: Allows both resizing and dragging of components
- Supports touch devices and multiple resize handles
- Offers more customization options for resize and drag behavior
Cons of react-rnd
- Larger bundle size due to additional features
- May have a steeper learning curve for basic resizing tasks
- Less focused on performance optimizations for resizing operations
Code Comparison
react-rnd:
<Rnd
size={{ width: 200, height: 200 }}
position={{ x: 0, y: 0 }}
onDragStop={(e, d) => { /* Handle drag */ }}
onResizeStop={(e, direction, ref, delta, position) => { /* Handle resize */ }}
>
Content
</Rnd>
react-resizable-panels:
<PanelGroup direction="horizontal">
<Panel defaultSize={20}>
Left panel
</Panel>
<PanelResizeHandle />
<Panel>
Right panel
</Panel>
</PanelGroup>
react-rnd offers more flexibility with dragging and resizing, while react-resizable-panels focuses on a simpler, performance-oriented approach for creating resizable layouts. The choice between the two depends on the specific requirements of your project, such as the need for draggable components or the importance of optimized resizing performance.
A draggable and resizable grid layout with responsive breakpoints, for React.
Pros of react-grid-layout
- More feature-rich with built-in grid system and draggable elements
- Supports responsive layouts out of the box
- Offers a wider range of customization options for grid items
Cons of react-grid-layout
- Steeper learning curve due to more complex API
- Heavier bundle size, which may impact performance for simpler use cases
- Less focused on resizable panels, as it's a more general-purpose grid system
Code Comparison
react-grid-layout:
import GridLayout from 'react-grid-layout';
<GridLayout className="layout" layout={layout} cols={12} rowHeight={30} width={1200}>
<div key="a">a</div>
<div key="b">b</div>
<div key="c">c</div>
</GridLayout>
react-resizable-panels:
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
<PanelGroup direction="horizontal">
<Panel>Left panel</Panel>
<PanelResizeHandle />
<Panel>Right panel</Panel>
</PanelGroup>
react-resizable-panels focuses specifically on resizable panels with a simpler API, while react-grid-layout provides a more comprehensive grid system with additional features like draggable elements and responsive layouts. The choice between the two depends on the specific requirements of your project and the level of complexity you need.
A simple React component that is resizable with a handle.
Pros of react-resizable
- More mature and widely adopted, with a larger community and ecosystem
- Offers a complete grid layout system, not just resizable panels
- Supports both vertical and horizontal resizing out of the box
Cons of react-resizable
- Heavier and more complex, which may impact performance for simpler use cases
- Less focused on accessibility features compared to react-resizable-panels
- May require more setup and configuration for basic resizing functionality
Code Comparison
react-resizable:
import { Resizable } from 'react-resizable';
<Resizable width={200} height={200} onResize={this.onResize}>
<div className="box">Contents</div>
</Resizable>
react-resizable-panels:
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
<PanelGroup direction="horizontal">
<Panel>Left panel</Panel>
<PanelResizeHandle />
<Panel>Right panel</Panel>
</PanelGroup>
The code comparison shows that react-resizable-panels offers a more declarative API with dedicated components for panels and resize handles, while react-resizable provides a wrapper component with resize functionality. react-resizable-panels' approach may be more intuitive for creating complex layouts with multiple resizable panels.
Drag and Drop for React
Pros of react-dnd
- More versatile, supporting a wide range of drag-and-drop interactions beyond just resizing panels
- Extensive ecosystem with additional utilities and extensions
- Well-established project with a large community and long-term support
Cons of react-dnd
- Steeper learning curve due to its more complex API and concepts
- Potentially overkill for simple resizing tasks, leading to unnecessary overhead
- Requires more setup and configuration for basic functionality
Code Comparison
react-dnd:
import { useDrag, useDrop } from 'react-dnd';
function DraggableItem() {
const [{ isDragging }, drag] = useDrag(() => ({
type: 'ITEM',
collect: (monitor) => ({
isDragging: !!monitor.isDragging(),
}),
}));
return <div ref={drag}>Drag me</div>;
}
react-resizable-panels:
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
function ResizablePanels() {
return (
<PanelGroup direction="horizontal">
<Panel>Left panel</Panel>
<PanelResizeHandle />
<Panel>Right panel</Panel>
</PanelGroup>
);
}
The code comparison shows that react-resizable-panels offers a more straightforward API for creating resizable panels, while react-dnd requires more setup but provides greater flexibility for complex drag-and-drop interactions.
Moveable! Draggable! Resizable! Scalable! Rotatable! Warpable! Pinchable! Groupable! Snappable!
Pros of Moveable
- More versatile: Supports resizing, dragging, rotating, and other transformations
- Framework-agnostic: Can be used with various JavaScript frameworks or vanilla JS
- Extensive customization options and event handling
Cons of Moveable
- Steeper learning curve due to its extensive feature set
- Potentially heavier in terms of bundle size and performance impact
- May require more setup and configuration for simple resizing tasks
Code Comparison
Moveable:
import Moveable from "moveable";
const moveable = new Moveable(document.body, {
target: document.querySelector(".target"),
draggable: true,
resizable: true,
});
moveable.on("drag", ({ target, transform }) => {
target.style.transform = transform;
});
React-resizable-panels:
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
<PanelGroup direction="horizontal">
<Panel>Left panel</Panel>
<PanelResizeHandle />
<Panel>Right panel</Panel>
</PanelGroup>
Summary
Moveable offers a more comprehensive set of features for element manipulation, making it suitable for complex use cases across different frameworks. React-resizable-panels, on the other hand, provides a simpler, React-specific solution focused primarily on resizable panels. The choice between the two depends on the specific requirements of your project, desired level of customization, and the framework you're using.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
react-resizable-panels: React components for resizable panel groups/layouts.
Support
If you like this project there are several ways to support it:
Installation
Begin by installing the library from NPM:
npm install react-resizable-panels
TypeScript types
TypeScript definitions are included within the published dist folder
FAQs
Frequently asked questions can be found here.
Documentation
Documentation for this project is available at react-resizable-panels.vercel.app.
Group
A Group wraps a set of resizable Panel components. Group content can be resized horizontally or vertically.
Group elements always include the following attributes:
<div data-group data-testid="group-id-prop" id="group-id-prop">
â¹ï¸ Test id can be used to narrow selection when unit testing.
Required props
None
Optional props
| Name | Description |
|---|---|
| className | CSS class name. |
| id | Uniquely identifies this group within an application.
Falls back to â¹ï¸ This value will also be assigned to the |
| style | CSS properties. â ï¸ The following styles cannot be overridden: |
| children | Panel and Separator components that comprise this group. |
| defaultLayout | Default layout for the Group. â¹ï¸ This value allows layouts to be remembered between page reloads. â ï¸ Refer to the documentation for how to avoid layout shift when using server components. |
| disableCursor | This library sets custom mouse cursor styles to indicate drag state. Use this prop to disable that behavior for Panels and Separators in this group. |
| disabled | Disable resize functionality. |
| elementRef | Ref attached to the root |
| groupRef | Exposes the following imperative API:
â¹ï¸ The |
| onLayoutChange | Called when the Group's layout is changing. â ï¸ For layout changes caused by pointer events, this method is called each time the pointer is moved.
For most cases, it is recommended to use the |
| onLayoutChanged | Called after the Group's layout has been changed. â¹ï¸ For layout changes caused by pointer events, this method is not called until the pointer has been released. This method is recommended when saving layouts to some storage api. |
| orientation | Specifies the resizable orientation ("horizontal" or "vertical"); defaults to "horizontal" |
Panel
A Panel wraps resizable content and can be configured with min/max size constraints and collapsible behavior.
Panel size props can be in the following formats:
- Percentage of the parent Group (0..100)
- Pixels
- Relative font units (em, rem)
- Viewport relative units (vh, vw)
â¹ï¸ Numeric values are assumed to be pixels. Strings without explicit units are assumed to be percentages (0%..100%). Percentages may also be specified as strings ending with "%" (e.g. "33%") Pixels may also be specified as strings ending with the unit "px". Other units should be specified as strings ending with their CSS property units (e.g. 1rem, 50vh)
Panel elements always include the following attributes:
<div data-panel data-testid="panel-id-prop" id="panel-id-prop">
â¹ï¸ Test id can be used to narrow selection when unit testing.
â ï¸ Panel elements must be direct DOM children of their parent Group elements.
Required props
None
Optional props
| Name | Description |
|---|---|
| className | CSS class name. â ï¸ Class is applied to nested |
| id | Uniquely identifies this panel within the parent group.
Falls back to â¹ï¸ This prop is used to associate persisted group layouts with the original panel. â¹ï¸ This value will also be assigned to the |
| style | CSS properties. â ï¸ Style is applied to nested |
| collapsedSize | Panel size when collapsed; defaults to 0%. |
| collapsible | This panel can be collapsed. â¹ï¸ A collapsible panel will collapse when it's size is less than of the specified |
| defaultSize | Default size of Panel within its parent group; default is auto-assigned based on the total number of Panels. |
| elementRef | Ref attached to the root |
| maxSize | Maximum size of Panel within its parent group; defaults to 100%. |
| minSize | Minimum size of Panel within its parent group; defaults to 0%. |
| onResize | Called when panel sizes change. @param panelSize Panel size (both as a percentage of the parent Group and in pixels) @param id Panel id (if one was provided as a prop) @param prevPanelSize Previous panel size (will be undefined on mount) |
| panelRef | Exposes the following imperative API:
â¹ï¸ The |
Separator
Separators are not required but they are recommended as they improve keyboard accessibility.
â ï¸ Separator elements must be direct DOM children of their parent Group elements.
Separator elements always include the following attributes:
<div data-separator data-testid="separator-id-prop" id="separator-id-prop" role="separator">
â¹ï¸ Test id can be used to narrow selection when unit testing.
â¹ï¸ In addition to the attributes shown above, separator also renders all required WAI-ARIA properties.
Required props
None
Optional props
| Name | Description |
|---|---|
| className | CSS class name. â¹ï¸ Use the â ï¸ The following properties cannot be overridden: |
| id | Uniquely identifies the separator within the parent group.
Falls back to â¹ï¸ This value will also be assigned to the |
| style | CSS properties. â¹ï¸ Use the â ï¸ The following properties cannot be overridden: |
| elementRef | Ref attached to the root |
Top Related Projects
🖱 A resizable and draggable component for React.
A draggable and resizable grid layout with responsive breakpoints, for React.
A simple React component that is resizable with a handle.
Drag and Drop for React
Moveable! Draggable! Resizable! Scalable! Rotatable! Warpable! Pinchable! Groupable! Snappable!
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot