react-draggable vs react-grid-layout vs react-split-pane vs flexlayout-react vs react-flexbox-grid vs react-mosaic-component
React Layout and UI Management Libraries Comparison
1 Year
react-draggablereact-grid-layoutreact-split-paneflexlayout-reactreact-flexbox-gridreact-mosaic-componentSimilar Packages:
What's React Layout and UI Management Libraries?

These libraries provide various solutions for managing layouts and user interactions in React applications. They cater to different needs such as drag-and-drop functionality, responsive grid systems, and flexible layout management, allowing developers to create dynamic and user-friendly interfaces. Each library has its own strengths and use cases, making it essential to choose the right one based on project requirements and design goals.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-draggable3,130,3139,194243 kB24215 days agoMIT
react-grid-layout880,10021,336508 kB23815 days agoMIT
react-split-pane356,1913,271-1665 years agoMIT
flexlayout-react27,6361,120528 kB1772 months agoISC
react-flexbox-grid22,0472,934-617 years agoMIT
react-mosaic-component21,3324,603260 kB307 months agoApache-2.0
Feature Comparison: react-draggable vs react-grid-layout vs react-split-pane vs flexlayout-react vs react-flexbox-grid vs react-mosaic-component

Layout Management

  • react-draggable:

    React-draggable offers basic drag-and-drop capabilities without a full layout management system. It allows elements to be moved around the interface easily, but does not manage layout or positioning beyond the drag-and-drop functionality.

  • react-grid-layout:

    React-grid-layout combines layout management with drag-and-drop functionality, allowing users to rearrange grid items dynamically. It supports responsive layouts and is perfect for applications that require a customizable grid interface.

  • react-split-pane:

    React-split-pane allows for the creation of resizable panes, enabling users to adjust the size of different sections of the UI. This is useful for applications that require a split view, enhancing user experience by providing customizable layouts.

  • flexlayout-react:

    Flexlayout-react provides a powerful layout management system that allows developers to create complex layouts with nested panels. It supports resizing, dragging, and dynamic updates, making it suitable for applications that require a customizable interface.

  • react-flexbox-grid:

    React-flexbox-grid simplifies the creation of responsive layouts using Flexbox. It provides a grid system that allows for easy alignment and distribution of elements, making it ideal for straightforward responsive design.

  • react-mosaic-component:

    React-mosaic-component enables the creation of a mosaic-style layout where users can rearrange and resize tiles. This is particularly useful for applications that require a flexible and interactive layout management system.

User Interaction

  • react-draggable:

    React-draggable focuses on enabling simple drag-and-drop interactions. It allows users to move elements freely, making it suitable for applications where user interaction is a key component of the interface.

  • react-grid-layout:

    React-grid-layout enhances user interaction by allowing users to drag and resize grid items. This interactivity is crucial for applications that require user customization of the layout, such as dashboards or data visualization tools.

  • react-split-pane:

    React-split-pane enhances user interaction by allowing users to resize panes according to their needs. This feature is particularly useful in applications where users need to view multiple sections of content simultaneously.

  • flexlayout-react:

    Flexlayout-react supports user interaction through draggable and resizable panels, allowing users to customize their workspace. This enhances user engagement by providing a tailored experience based on individual preferences.

  • react-flexbox-grid:

    React-flexbox-grid does not directly handle user interactions but provides a responsive layout that can enhance user experience by ensuring elements are well-aligned and accessible across different devices.

  • react-mosaic-component:

    React-mosaic-component enhances user interaction by allowing users to rearrange and resize tiles easily. This flexibility is essential for applications that require a dynamic and interactive layout management system.

Responsiveness

  • react-draggable:

    React-draggable does not inherently provide responsiveness but can be integrated into responsive designs. Developers need to manage the layout separately to ensure elements remain accessible on different screen sizes.

  • react-grid-layout:

    React-grid-layout supports responsive layouts by allowing grid items to adjust based on screen size. It provides breakpoints for different screen sizes, ensuring a consistent user experience across devices.

  • react-split-pane:

    React-split-pane does not provide built-in responsiveness, but developers can implement responsive design techniques to ensure that the split panes adjust appropriately on different screen sizes.

  • flexlayout-react:

    Flexlayout-react supports responsive design through its flexible layout management system, allowing panels to adjust based on screen size. This is essential for applications that need to work across various devices and resolutions.

  • react-flexbox-grid:

    React-flexbox-grid is built for responsiveness, leveraging Flexbox to create layouts that adapt seamlessly to various screen sizes. This makes it an excellent choice for mobile-first design approaches.

  • react-mosaic-component:

    React-mosaic-component can be made responsive by configuring the layout to adapt to different screen sizes. This is important for applications that require a flexible and interactive layout that works well on various devices.

Customization

  • react-draggable:

    React-draggable provides limited customization options focused on drag-and-drop behavior. Developers can customize the draggable elements, but layout management is not part of this library's functionality.

  • react-grid-layout:

    React-grid-layout provides a high level of customization for grid items, including size, position, and responsive breakpoints. This is essential for applications that need to adapt to user preferences and screen sizes.

  • react-split-pane:

    React-split-pane offers customization options for the appearance and behavior of the split panes, allowing developers to define how users interact with the resizable sections of the UI.

  • flexlayout-react:

    Flexlayout-react offers extensive customization options for panel configurations, allowing developers to define how panels behave and appear. This flexibility is crucial for applications that require a tailored user interface.

  • react-flexbox-grid:

    React-flexbox-grid allows for customization of grid properties, enabling developers to define spacing, alignment, and breakpoints. This makes it easier to create unique responsive layouts based on project needs.

  • react-mosaic-component:

    React-mosaic-component allows for customization of tile behavior and appearance, enabling developers to create unique layouts that fit the application's design requirements.

Integration

  • react-draggable:

    React-draggable is lightweight and can be integrated into any React application with minimal setup, making it ideal for adding drag-and-drop functionality to existing components.

  • react-grid-layout:

    React-grid-layout can be integrated into larger applications, providing a robust grid system that enhances user interaction and layout management without disrupting existing code.

  • react-split-pane:

    React-split-pane can be easily integrated into applications needing resizable panes, providing a straightforward solution for creating split views without extensive modifications.

  • flexlayout-react:

    Flexlayout-react can be easily integrated into existing React applications, providing a seamless way to manage complex layouts without significant refactoring.

  • react-flexbox-grid:

    React-flexbox-grid integrates well with other CSS frameworks and libraries, allowing developers to create responsive layouts without conflicting styles.

  • react-mosaic-component:

    React-mosaic-component can be integrated into applications requiring a mosaic layout, providing a unique user experience while maintaining compatibility with other React components.

How to Choose: react-draggable vs react-grid-layout vs react-split-pane vs flexlayout-react vs react-flexbox-grid vs react-mosaic-component
  • react-draggable:

    Select react-draggable for simple drag-and-drop functionality. It's perfect for scenarios where you want to enable users to move elements around the interface without the overhead of a full layout system. Use it for interactive components that require basic drag-and-drop capabilities.

  • react-grid-layout:

    Use react-grid-layout for a more advanced grid system that supports drag-and-drop and resizing of grid items. It's particularly useful for applications that need a grid layout with dynamic content, such as dashboards or data visualization tools where users can customize their view.

  • react-split-pane:

    Select react-split-pane if you need to create resizable panes in your application. It's best for applications that require a split view, allowing users to adjust the size of different sections of the UI, such as code editors or file explorers.

  • flexlayout-react:

    Choose flexlayout-react if you need a highly customizable layout manager that supports complex layouts with resizable and draggable panels. It's ideal for applications requiring a flexible and dynamic user interface, such as dashboards or IDEs.

  • react-flexbox-grid:

    Opt for react-flexbox-grid if you want a responsive grid system based on Flexbox. This is suitable for projects that require a straightforward way to create responsive layouts without getting into complex configurations. It's great for developers familiar with CSS Flexbox who want to quickly implement grid layouts.

  • react-mosaic-component:

    Choose react-mosaic-component when you need a tiled layout with the ability to rearrange and resize tiles. This library is ideal for applications that require a mosaic-style layout, such as collaborative tools or design applications where users can manage multiple panels.

README for react-draggable

React-Draggable

TravisCI Build Status Appveyor Build Status npm downloads gzip size version

A simple component for making elements draggable.

<Draggable>
  <div>I can now be moved around!</div>
</Draggable>

|Version | Compatibility| |------------|--------------| |4.x | React 16.3+ | |3.x | React 15-16 | |2.x | React 0.14 - 15 | |1.x | React 0.13 - 0.14 | |0.x | React 0.10 - 0.13 |


Technical Documentation

Installing

$ npm install react-draggable

If you aren't using browserify/webpack, a UMD version of react-draggable is available. It is updated per-release only. This bundle is also what is loaded when installing from npm. It expects external React and ReactDOM.

If you want a UMD version of the latest master revision, you can generate it yourself from master by cloning this repository and running $ make. This will create umd dist files in the dist/ folder.

Exports

The default export is <Draggable>. At the .DraggableCore property is <DraggableCore>. Here's how to use it:

// ES6
import Draggable from 'react-draggable'; // The default
import {DraggableCore} from 'react-draggable'; // <DraggableCore>
import Draggable, {DraggableCore} from 'react-draggable'; // Both at the same time

// CommonJS
let Draggable = require('react-draggable');
let DraggableCore = Draggable.DraggableCore;

<Draggable>

A <Draggable> element wraps an existing element and extends it with new event handlers and styles. It does not create a wrapper element in the DOM.

Draggable items are moved using CSS Transforms. This allows items to be dragged regardless of their current positioning (relative, absolute, or static). Elements can also be moved between drags without incident.

If the item you are dragging already has a CSS Transform applied, it will be overwritten by <Draggable>. Use an intermediate wrapper (<Draggable><span>...</span></Draggable>) in this case.

Draggable Usage

View the Demo and its source for more.

import React from 'react';
import ReactDOM from 'react-dom';
import Draggable from 'react-draggable';

class App extends React.Component {

  eventLogger = (e: MouseEvent, data: Object) => {
    console.log('Event: ', e);
    console.log('Data: ', data);
  };

  render() {
    return (
      <Draggable
        axis="x"
        handle=".handle"
        defaultPosition={{x: 0, y: 0}}
        position={null}
        grid={[25, 25]}
        scale={1}
        onStart={this.handleStart}
        onDrag={this.handleDrag}
        onStop={this.handleStop}>
        <div>
          <div className="handle">Drag from here</div>
          <div>This readme is really dragging on...</div>
        </div>
      </Draggable>
    );
  }
}

ReactDOM.render(<App/>, document.body);

Draggable API

The <Draggable/> component transparently adds draggability to its children.

Note: Only a single child is allowed or an Error will be thrown.

For the <Draggable/> component to correctly attach itself to its child, the child element must provide support for the following props:

  • style is used to give the transform css to the child.
  • className is used to apply the proper classes to the object being dragged.
  • onMouseDown, onMouseUp, onTouchStart, and onTouchEnd are used to keep track of dragging state.

React.DOM elements support the above properties by default, so you may use those elements as children without any changes. If you wish to use a React component you created, you'll need to be sure to transfer prop.

<Draggable> Props:

//
// Types:
//
type DraggableEventHandler = (e: Event, data: DraggableData) => void | false;
type DraggableData = {
  node: HTMLElement,
  // lastX + deltaX === x
  x: number, y: number,
  deltaX: number, deltaY: number,
  lastX: number, lastY: number
};

//
// Props:
//
{
// If set to `true`, will allow dragging on non left-button clicks.
allowAnyClick: boolean,

// Default `false` and default behavior before 4.5.0.
// If set to `true`, the 'touchstart' event will not be prevented,
// which will allow scrolling inside containers. We recommend
// using the 'handle' / 'cancel' props when possible instead of enabling this.
// 
// See https://github.com/react-grid-layout/react-draggable/issues/728
allowMobileScroll: boolean,

// Determines which axis the draggable can move. This only affects
// flushing to the DOM. Callbacks will still include all values.
// Accepted values:
// - `both` allows movement horizontally and vertically (default).
// - `x` limits movement to horizontal axis.
// - `y` limits movement to vertical axis.
// - 'none' stops all movement.
axis: string,

// Specifies movement boundaries. Accepted values:
// - `parent` restricts movement within the node's offsetParent
//    (nearest node with position relative or absolute), or
// - a selector, restricts movement within the targeted node
// - An object with `left, top, right, and bottom` properties.
//   These indicate how far in each direction the draggable
//   can be moved.
bounds: {left?: number, top?: number, right?: number, bottom?: number} | string,

// Specifies a selector to be used to prevent drag initialization. The string is passed to
// Element.matches, so it's possible to use multiple selectors like `.first, .second`.
// Example: '.body'
cancel: string,

// Class names for draggable UI.
// Default to 'react-draggable', 'react-draggable-dragging', and 'react-draggable-dragged'
defaultClassName: string,
defaultClassNameDragging: string,
defaultClassNameDragged: string,

// Specifies the `x` and `y` that the dragged item should start at.
// This is generally not necessary to use (you can use absolute or relative
// positioning of the child directly), but can be helpful for uniformity in
// your callbacks and with css transforms.
defaultPosition: {x: number, y: number},

// If true, will not call any drag handlers.
disabled: boolean,

// Default `true`. Adds "user-select: none" while dragging to avoid selecting text.
enableUserSelectHack: boolean,

// Specifies the x and y that dragging should snap to.
grid: [number, number],

// Specifies a selector to be used as the handle that initiates drag.
// Example: '.handle'
handle: string,

// If desired, you can provide your own offsetParent for drag calculations.
// By default, we use the Draggable's offsetParent. This can be useful for elements
// with odd display types or floats.
offsetParent: HTMLElement,

// Called whenever the user mouses down. Called regardless of handle or
// disabled status.
onMouseDown: (e: MouseEvent) => void,

// Called when dragging starts. If `false` is returned any handler,
// the action will cancel.
onStart: DraggableEventHandler,

// Called while dragging.
onDrag: DraggableEventHandler,

// Called when dragging stops.
onStop: DraggableEventHandler,

// If running in React Strict mode, ReactDOM.findDOMNode() is deprecated.
// Unfortunately, in order for <Draggable> to work properly, we need raw access
// to the underlying DOM node. If you want to avoid the warning, pass a `nodeRef`
// as in this example:
//
// function MyComponent() {
//   const nodeRef = React.useRef(null);
//   return (
//     <Draggable nodeRef={nodeRef}>
//       <div ref={nodeRef}>Example Target</div>
//     </Draggable>
//   );
// }
//
// This can be used for arbitrarily nested components, so long as the ref ends up
// pointing to the actual child DOM node and not a custom component.
//
// For rich components, you need to both forward the ref *and props* to the underlying DOM
// element. Props must be forwarded so that DOM event handlers can be attached. 
// For example:
//
//   const Component1 = React.forwardRef(function (props, ref) {
//     return <div {...props} ref={ref}>Nested component</div>;
//   });
//
//   const nodeRef = React.useRef(null);
//   <DraggableCore onDrag={onDrag} nodeRef={nodeRef}>
//     <Component1 ref={nodeRef} />
//   </DraggableCore>
//
// Thanks to react-transition-group for the inspiration.
//
// `nodeRef` is also available on <DraggableCore>.
nodeRef: React.Ref<typeof React.Component>,

// Much like React form elements, if this property is present, the item
// becomes 'controlled' and is not responsive to user input. Use `position`
// if you need to have direct control of the element.
position: {x: number, y: number}

// A position offset to start with. Useful for giving an initial position
// to the element. Differs from `defaultPosition` in that it does not
// affect the position returned in draggable callbacks, and in that it
// accepts strings, like `{x: '10%', y: '10%'}`.
positionOffset: {x: number | string, y: number | string},

// Specifies the scale of the canvas your are dragging this element on. This allows
// you to, for example, get the correct drag deltas while you are zoomed in or out via
// a transform or matrix in the parent of this element.
scale: number
}

Note that sending className, style, or transform as properties will error - set them on the child element directly.

Controlled vs. Uncontrolled

<Draggable> is a 'batteries-included' component that manages its own state. If you want to completely control the lifecycle of the component, use <DraggableCore>.

For some users, they may want the nice state management that <Draggable> provides, but occasionally want to programmatically reposition their components. <Draggable> allows this customization via a system that is similar to how React handles form components.

If the prop position: {x: number, y: number} is defined, the <Draggable> will ignore its internal state and use the provided position instead. Alternatively, you can seed the position using defaultPosition. Technically, since <Draggable> works only on position deltas, you could also seed the initial position using CSS top/left.

We make one modification to the React philosophy here - we still allow dragging while a component is controlled. We then expect you to use at least an onDrag or onStop handler to synchronize state.

To disable dragging while controlled, send the prop disabled={true} - at this point the <Draggable> will operate like a completely static component.

<DraggableCore>

For users that require absolute control, a <DraggableCore> element is available. This is useful as an abstraction over touch and mouse events, but with full control. <DraggableCore> has no internal state.

See React-Resizable and React-Grid-Layout for some usage examples.

<DraggableCore> is a useful building block for other libraries that simply want to abstract browser-specific quirks and receive callbacks when a user attempts to move an element. It does not set styles or transforms on itself and thus must have callbacks attached to be useful.

DraggableCore API

<DraggableCore> takes a limited subset of options:

{
  allowAnyClick: boolean,
  allowMobileScroll: boolean,
  cancel: string,
  disabled: boolean,
  enableUserSelectHack: boolean,
  offsetParent: HTMLElement,
  grid: [number, number],
  handle: string,
  onStart: DraggableEventHandler,
  onDrag: DraggableEventHandler,
  onStop: DraggableEventHandler,
  onMouseDown: (e: MouseEvent) => void,
  scale: number
}

Note that there is no start position. <DraggableCore> simply calls drag handlers with the below parameters, indicating its position (as inferred from the underlying MouseEvent) and deltas. It is up to the parent to set actual positions on <DraggableCore>.

Drag callbacks (onStart, onDrag, onStop) are called with the same arguments as <Draggable>.


Contributing

  • Fork the project
  • Run the project in development mode: $ npm run dev
  • Make changes.
  • Add appropriate tests
  • $ npm test
  • If tests don't pass, make them pass.
  • Update README with appropriate docs.
  • Commit and PR

Release checklist

  • Update CHANGELOG
  • make release-patch, make release-minor, or make-release-major
  • make publish

License

MIT