react-resizable vs react-split-pane vs react-splitter-layout
React Resizable and Splitter Libraries
react-resizablereact-split-panereact-splitter-layoutSimilar Packages:

React Resizable and Splitter Libraries

React resizable and splitter libraries provide components that allow users to dynamically resize elements within a React application. These libraries are useful for creating flexible layouts where users can adjust the size of panels, columns, or any other elements by dragging their borders. This functionality enhances user experience by providing more control over the interface, especially in applications with complex or adjustable layouts. Examples include resizable panels, split views, and adjustable grids.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
react-resizable02,57454.6 kB74 months agoMIT
react-split-pane03,383104 kB72 months agoMIT
react-splitter-layout0432-387 years agoMIT

Feature Comparison: react-resizable vs react-split-pane vs react-splitter-layout

Basic Resizing

  • react-resizable:

    react-resizable provides basic resizing functionality for any element. You can make elements resizable by wrapping them with the Resizable component and specifying the dimensions you want to allow resizing in.

  • react-split-pane:

    react-split-pane allows for resizing between two panes (or more with nested split panes). It provides a simple interface for adjusting the size of each pane by dragging the divider.

  • react-splitter-layout:

    react-splitter-layout offers advanced resizing capabilities with support for multiple panes, both horizontal and vertical. It allows for more complex layouts with multiple resizable areas.

Customization

  • react-resizable:

    react-resizable is highly customizable. You can style the resizable handles, set minimum and maximum sizes, and control the resizing behavior through props.

  • react-split-pane:

    react-split-pane offers some customization options, such as setting the initial size of the panes, defining minimum and maximum sizes, and styling the divider.

  • react-splitter-layout:

    react-splitter-layout provides extensive customization options, including the ability to style the splitter, set default sizes, and configure nested splitters for more complex layouts.

Nested Resizing

  • react-resizable:

    react-resizable does not support nested resizing out of the box, but you can implement it by combining multiple resizable components.

  • react-split-pane:

    react-split-pane supports nested split panes, allowing you to create multi-level resizable layouts by nesting SplitPane components.

  • react-splitter-layout:

    react-splitter-layout also supports nested splitters, enabling more complex layouts with multiple levels of resizable areas.

Accessibility

  • react-resizable:

    react-resizable provides basic accessibility features, but you may need to enhance it further depending on your implementation.

  • react-split-pane:

    react-split-pane is designed with accessibility in mind, providing keyboard navigation and ARIA attributes for the splitter and panes.

  • react-splitter-layout:

    react-splitter-layout also focuses on accessibility, offering keyboard support and ARIA roles to ensure that the splitter and its components are usable by all.

Ease of Use: Code Examples

  • react-resizable:

    Basic usage of react-resizable

    import React from 'react';
    import { Resizable } from 'react-resizable';
    import 'react-resizable/css/styles.css';
    
    const ResizableBox = () => {
      return (
        <Resizable width={200} height={200} minConstraints={[100, 100]} maxConstraints={[300, 300]}>
          <div style={{ border: '1px solid black', width: '100%', height: '100%' }}>
            Resizable Box
          </div>
        </Resizable>
      );
    };
    
    export default ResizableBox;
    
  • react-split-pane:

    Basic usage of react-split-pane

    import React from 'react';
    import SplitPane from 'react-split-pane';
    
    const SplitPaneExample = () => {
      return (
        <SplitPane split="vertical" minSize={50} defaultSize={100} maxSize={300}>
          <div style={{ background: '#f0f0f0' }}>Left Pane</div>
          <div style={{ background: '#e0e0e0' }}>Right Pane</div>
        </SplitPane>
      );
    };
    
    export default SplitPaneExample;
    
  • react-splitter-layout:

    Basic usage of react-splitter-layout

    import React from 'react';
    import { SplitterLayout } from 'react-splitter-layout';
    import 'react-splitter-layout/lib/index.css';
    
    const SplitterLayoutExample = () => {
      return (
        <SplitterLayout>
          <div style={{ background: '#f0f0f0' }}>Pane 1</div>
          <div style={{ background: '#e0e0e0' }}>Pane 2</div>
          <div style={{ background: '#d0d0d0' }}>Pane 3</div>
        </SplitterLayout>
      );
    };
    
    export default SplitterLayoutExample;
    

How to Choose: react-resizable vs react-split-pane vs react-splitter-layout

  • react-resizable:

    Choose react-resizable if you need a lightweight, flexible solution for making any element resizable. It provides a simple API and is highly customizable, allowing you to create resizable components with minimal setup.

  • react-split-pane:

    Choose react-split-pane if you need a straightforward way to create split-pane layouts with adjustable dividers. It is easy to use and integrates well with existing layouts, making it ideal for applications that require simple, two-pane or multi-pane designs.

  • react-splitter-layout:

    Choose react-splitter-layout if you need a more feature-rich splitter layout with support for horizontal and vertical splitting, as well as nested splitters. It offers better control over the layout and is suitable for more complex applications that require advanced splitting functionality.

README for react-resizable

React-Resizable

npm version npm downloads Build Status

View the Demo

A simple widget that can be resized via one or more handles.

You can either use the <Resizable> element directly, or use the much simpler <ResizableBox> element.

See the example and associated code in ExampleLayout and ResizableBox for more details.

Table of Contents

Installation

$ npm install --save react-resizable

Extracting Styles

You must include the associated styles in your application, otherwise the resize handles will not be visible and will not work properly.

// In your JS/TS entry point:
import 'react-resizable/css/styles.css';

Or import it in your CSS:

@import 'react-resizable/css/styles.css';

If you're using a bundler that doesn't support CSS imports, you can find the styles at node_modules/react-resizable/css/styles.css and include them manually.

Compatibility

VersionReact Version
3.x>= 16.3
2.xSkipped
1.x14 - 17

Usage

This package has two major exports:

  • <Resizable>: A raw component that does not have state. Use as a building block for larger components, by listening to its callbacks and setting its props.
  • <ResizableBox>: A simple <div {...props} /> element that manages basic state. Convenient for simple use-cases.

<Resizable>

import { Resizable } from 'react-resizable';
import 'react-resizable/css/styles.css';

class Example extends React.Component {
  state = {
    width: 200,
    height: 200,
  };

  onResize = (event, {node, size, handle}) => {
    this.setState({width: size.width, height: size.height});
  };

  render() {
    return (
      <Resizable
        height={this.state.height}
        width={this.state.width}
        onResize={this.onResize}
      >
        <div
          className="box"
          style={{width: this.state.width + 'px', height: this.state.height + 'px'}}
        >
          <span>Contents</span>
        </div>
      </Resizable>
    );
  }
}

<ResizableBox>

import { ResizableBox } from 'react-resizable';
import 'react-resizable/css/styles.css';

class Example extends React.Component {
  render() {
    return (
      <ResizableBox
        width={200}
        height={200}
        draggableOpts={{grid: [25, 25]}}
        minConstraints={[100, 100]}
        maxConstraints={[300, 300]}
      >
        <span>Contents</span>
      </ResizableBox>
    );
  }
}

Props

These props apply to both <Resizable> and <ResizableBox>. Unknown props that are not in the list below will be passed to the child component.

type ResizeCallbackData = {
  node: HTMLElement,
  size: {width: number, height: number},
  handle: ResizeHandleAxis
};

type ResizeHandleAxis = 's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne';

type ResizableProps = {
  children: React.Element<any>,
  width: number,
  height: number,
  // Either a ReactElement to be used as handle, or a function
  // returning an element that is fed the handle's location as its first argument.
  handle: ReactElement<any> | (resizeHandle: ResizeHandleAxis, ref: ReactRef<HTMLElement>) => ReactElement<any>,
  // If you change this, be sure to update your css
  handleSize: [number, number] = [10, 10],
  lockAspectRatio: boolean = false,
  axis: 'both' | 'x' | 'y' | 'none' = 'both',
  minConstraints: [number, number] = [10, 10],
  maxConstraints: [number, number] = [Infinity, Infinity],
  onResizeStop?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
  onResizeStart?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
  onResize?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
  draggableOpts?: ?Object,
  resizeHandles?: ?Array<ResizeHandleAxis> = ['se'],
  // If `transform: scale(n)` is set on the parent, this should be set to `n`.
  transformScale?: number = 1
};

The following props can also be used on <ResizableBox>:

{
  style?: Object // styles the returned <div />
}

If a width or height is passed to <ResizableBox>'s style prop, it will be ignored as it is required for internal function.

You can pass options directly to the underlying DraggableCore instance by using the prop draggableOpts. See the demo for more on this.

Resize Handle

If you override the resize handle, we expect that any ref passed to your new handle will represent the underlying DOM element.

This is required, as react-resizable must be able to access the underlying DOM node to attach handlers and measure position deltas.

There are a few ways to do this:

Native DOM Element

This requires no special treatment.

<Resizable handle={<div className="foo" />} />

Custom React Component

You must forward the ref and props to the underlying DOM element.

Class Components

class MyHandleComponent extends React.Component {
  render() {
    const {handleAxis, innerRef, ...props} = this.props;
    return <div ref={innerRef} className={`foo handle-${handleAxis}`} {...props} />
  }
}
const MyHandle = React.forwardRef((props, ref) => <MyHandleComponent innerRef={ref} {...props} />);

<Resizable handle={<MyHandle />} />

Functional Components

const MyHandle = React.forwardRef((props, ref) => {
  const {handleAxis, ...restProps} = props;
  return <div ref={ref} className={`foo handle-${handleAxis}`} {...restProps} />;
});

<Resizable handle={<MyHandle />} />

Custom Function

You can define a function as a handle, which will simply receive an axis (see above ResizeHandleAxis type) and ref. This may be more clear to read, depending on your coding style.

const MyHandle = (props) => {
  return <div ref={props.innerRef} className="foo" {...props} />;
};

<Resizable handle={(handleAxis, ref) => <MyHandle innerRef={ref} className={`foo handle-${handleAxis}`} />} />

License

MIT