Gathering detailed insights and metrics for react-resizable-panels
Gathering detailed insights and metrics for react-resizable-panels
Gathering detailed insights and metrics for react-resizable-panels
Gathering detailed insights and metrics for react-resizable-panels
@superdesk/react-resizable-panels
React components for resizable panel groups/layouts
@alisowski/react-resizable-panels
React components for resizable panel groups/layouts
resizable-panes-react
A straightforward library that enables dynamic resizing of layouts and saves the layout configurations.
resizable-panels-react
A simple react component to build resizable panels :D
npm install react-resizable-panels
Typescript
Module System
Node Version
NPM Version
95.5
Supply Chain
95.9
Quality
87.6
Maintenance
100
Vulnerability
100
License
TypeScript (96.19%)
CSS (3.44%)
JavaScript (0.28%)
HTML (0.1%)
Total Downloads
21,678,162
Last Day
57,205
Last Week
358,091
Last Month
2,426,353
Last Year
18,514,136
4,129 Stars
506 Commits
151 Forks
6 Watching
2 Branches
40 Contributors
Minified
Minified + Gzipped
Latest Version
2.1.7
Package Id
react-resizable-panels@2.1.7
Unpacked Size
0.96 MB
Size
212.80 kB
File Count
44
NPM Version
9.6.6
Node Version
20.2.0
Publised On
16 Nov 2024
Cumulative downloads
Total Downloads
Last day
-3.4%
57,205
Compared to previous day
Last week
-34.7%
358,091
Compared to previous week
Last month
2.9%
2,426,353
Compared to previous month
Last year
485.7%
18,514,136
Compared to previous year
React components for resizable panel groups/layouts
1import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels"; 2 3<PanelGroup autoSaveId="example" direction="horizontal"> 4 <Panel defaultSize={25}> 5 <SourcesExplorer /> 6 </Panel> 7 <PanelResizeHandle /> 8 <Panel> 9 <SourceViewer /> 10 </Panel> 11 <PanelResizeHandle /> 12 <Panel defaultSize={25}> 13 <Console /> 14 </Panel> 15</PanelGroup>;
PanelGroup
prop | type | description |
---|---|---|
autoSaveId | ?string | Unique id used to auto-save group arrangement via localStorage |
children | ReactNode | Arbitrary React element(s) |
className | ?string | Class name to attach to root element |
direction | "horizontal" | "vertical" | Group orientation |
id | ?string | Group id; falls back to useId when not provided |
onLayout | ?(sizes: number[]) => void | Called when group layout changes |
storage | ?PanelGroupStorage | Custom storage API; defaults to localStorage 1 |
style | ?CSSProperties | CSS 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
PanelGroup
components also expose an imperative API for manual resizing:
method | description |
---|---|
getId(): string | Gets the panel group's ID. |
getLayout(): number[] | Gets the panel group's current layout ([1 - 100, ...] ). |
setLayout(layout: number[]) | Resize panel group to the specified layout ([1 - 100, ...] ). |
Panel
prop | type | description |
---|---|---|
children | ReactNode | Arbitrary React element(s) |
className | ?string | Class name to attach to root element |
collapsedSize | ?number=0 | Panel should collapse to this size |
collapsible | ?boolean=false | Panel should collapse when resized beyond its minSize |
defaultSize | ?number | Initial size of panel (numeric value between 1-100) |
id | ?string | Panel id (unique within group); falls back to useId when not provided |
maxSize | ?number = 100 | Maximum allowable size of panel (numeric value between 1-100); defaults to 100 |
minSize | ?number = 10 | Minimum allowable size of panel (numeric value between 1-100); defaults to 10 |
onCollapse | ?() => void | Called when panel is collapsed |
onExpand | ?() => void | Called when panel is expanded |
onResize | ?(size: number) => void | Called when panel is resized; size parameter is a numeric value between 1-100. 1 |
order | ?number | Order of panel within group; required for groups with conditionally rendered panels |
style | ?CSSProperties | CSS 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 Panel
s.
Panel
components also expose an imperative API for manual resizing:
method | description |
---|---|
collapse() | If panel is collapsible , collapse it fully. |
expand() | If panel is currently collapsed, expand it to its most recent size. |
getId(): string | Gets the ID of the panel. |
getSize(): number | Gets the current size of the panel as a percentage (1 - 100 ). |
isCollapsed(): boolean | Returns true if the panel is currently collapsed (size === 0 ). |
isExpanded(): boolean | Returns true if the panel is currently not collapsed (!isCollapsed() ). |
getSize(): number | Returns the most recently committed size of the panel as a percentage (1 - 100 ). |
resize(size: number) | Resize panel to the specified percentage (1 - 100 ). |
PanelResizeHandle
prop | type | description |
---|---|---|
children | ?ReactNode | Custom drag UI; can be any arbitrary React element(s) |
className | ?string | Class name to attach to root element |
hitAreaMargins | ?{ coarse: number = 15; fine: number = 5; } | Allow this much margin when determining resizable handle hit detection |
disabled | ?boolean | Disable drag handle |
id | ?string | Resize handle id (unique within group); falls back to useId when not provided |
onDragging | ?(isDragging: boolean) => void | Called when group layout changes |
style | ?CSSProperties | CSS style to attach to root element |
tagName | ?string = "div" | HTML element tag name for root element |
No. Pixel-based constraints added significant complexity to the initialization and validation logic and so I've decided not to support them. You may be able to implement a version of this yourself following a pattern like this but it is not officially supported by this library.
The Panel
API doesn't require id
and order
props because they aren't necessary for static layouts. When panels are conditionally rendered though, it's best to supply these values.
1<PanelGroup direction="horizontal"> 2 {renderSideBar && ( 3 <> 4 <Panel id="sidebar" minSize={25} order={1}> 5 <Sidebar /> 6 </Panel> 7 <PanelResizeHandle /> 8 </> 9 )} 10 <Panel minSize={25} order={2}> 11 <Main /> 12 </Panel> 13</PanelGroup>
No. I think exposing two refs (one for the component's imperative API and one for a DOM element) would be awkward. This library does export several utility methods for accessing the underlying DOM elements though. For example:
1import { 2 getPanelElement, 3 getPanelGroupElement, 4 getResizeHandleElement, 5 Panel, 6 PanelGroup, 7 PanelResizeHandle, 8} from "react-resizable-panels"; 9 10export function Example() { 11 const refs = useRef(); 12 13 useEffect(() => { 14 const groupElement = getPanelGroupElement("group"); 15 const leftPanelElement = getPanelElement("left-panel"); 16 const rightPanelElement = getPanelElement("right-panel"); 17 const resizeHandleElement = getResizeHandleElement("resize-handle"); 18 19 // If you want to, you can store them in a ref to pass around 20 refs.current = { 21 groupElement, 22 leftPanelElement, 23 rightPanelElement, 24 resizeHandleElement, 25 }; 26 }, []); 27 28 return ( 29 <PanelGroup direction="horizontal" id="group"> 30 <Panel id="left-panel">{/* ... */}</Panel> 31 <PanelResizeHandle id="resize-handle" /> 32 <Panel id="right-panel">{/* ... */}</Panel> 33 </PanelGroup> 34 ); 35}
This likely means that you haven't applied any CSS to style the resize handles. By default, a resize handle is just an empty DOM element. To add styling, use the className
or style
props:
1// Tailwind example 2<PanelResizeHandle className="w-2 bg-blue-800" />
By default, this library uses localStorage
to persist layouts. With server rendering, this can cause a flicker when the default layout (rendered on the server) is replaced with the persisted layout (in localStorage
). The way to avoid this flicker is to also persist the layout with a cookie like so:
1import ResizablePanels from "@/app/ResizablePanels"; 2import { cookies } from "next/headers"; 3 4export function ServerComponent() { 5 const layout = cookies().get("react-resizable-panels:layout"); 6 7 let defaultLayout; 8 if (layout) { 9 defaultLayout = JSON.parse(layout.value); 10 } 11 12 return <ClientComponent defaultLayout={defaultLayout} />; 13}
1"use client"; 2 3import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels"; 4 5export function ClientComponent({ 6 defaultLayout = [33, 67], 7}: { 8 defaultLayout: number[] | undefined; 9}) { 10 const onLayout = (sizes: number[]) => { 11 document.cookie = `react-resizable-panels:layout=${JSON.stringify(sizes)}`; 12 }; 13 14 return ( 15 <PanelGroup direction="horizontal" onLayout={onLayout}> 16 <Panel defaultSize={defaultLayout[0]}>{/* ... */}</Panel> 17 <PanelResizeHandle className="w-2 bg-blue-800" /> 18 <Panel defaultSize={defaultLayout[1]}>{/* ... */}</Panel> 19 </PanelGroup> 20 ); 21}
[!NOTE] Be sure to specify a
defaultSize
prop for everyPanel
component to avoid layout flicker.
A demo of this is available here.
"nonce"
attribute?1import { setNonce } from "react-resizable-panels"; 2 3setNonce("your-nonce-value-here");
1import { disableGlobalCursorStyles } from "react-resizable-panels"; 2 3disableGlobalCursorStyles();
No vulnerabilities found.
No security vulnerabilities found.