React-Grid-Layout

A draggable and resizable grid layout with responsive breakpoints, for Reac...

README

React-Grid-Layout

travis build CDNJS npm package [npm downloads]()

React-Grid-Layout is a grid layout system much like Packery or
Gridster, for React.

Unlike those systems, it is responsive and supports breakpoints. Breakpoint layouts can be provided by the user
or autogenerated.

RGL is React-only and does not require jQuery.

BitMEX UI

GIF from production usage on BitMEX.com



Table of Contents



Demos



Projects Using React-Grid-Layout



_Know of others? Create a PR to let me know!_

Features


- 100% React - no jQuery
- Compatible with server-rendered apps
- Draggable widgets
- Resizable widgets
- Static widgets
- Configurable packing: horizontal, vertical, or off
- Bounds checking for dragging and resizing
- Widgets may be added or removed without rebuilding grid
- Layout can be serialized and restored
- Responsive breakpoints
- Separate layouts per responsive breakpoint
- Grid Items placed using CSS Transforms
  - Performance with CSS Transforms: on / off, note paint (green) as % of time
- Compatibility with ``

VersionCompatibility
---------------------------
>=React
>=React
>=React
0.8.React
<React

Installation


Install the React-Grid-Layout package package using npm:

  1. ``` sh
  2. npm install react-grid-layout
  3. ```

Include the following stylesheets in your application:

  1. ```
  2. /node_modules/react-grid-layout/css/styles.css
  3. /node_modules/react-resizable/css/styles.css
  4. ```

Usage


Use ReactGridLayout like any other component. The following example below will
produce a grid with three items where:

- users will not be able to drag or resize item a
- item b will be restricted to a minimum width of 2 grid blocks and a maximum width of 4 grid blocks
- users will be able to freely drag and resize item c

  1. ``` js
  2. import GridLayout from "react-grid-layout";

  3. class MyFirstGrid extends React.Component {
  4.   render() {
  5.     // layout is an array of objects, see the demo for more complete usage
  6.     const layout = [
  7.       { i: "a", x: 0, y: 0, w: 1, h: 2, static: true },
  8.       { i: "b", x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 },
  9.       { i: "c", x: 4, y: 0, w: 1, h: 2 }
  10.     ];
  11.     return (
  12.       <GridLayout
  13.         className="layout"
  14.         layout={layout}
  15.         cols={12}
  16.         rowHeight={30}
  17.         width={1200}
  18.       >
  19.         <div key="a">a</div>
  20.         <div key="b">b</div>
  21.         <div key="c">c</div>
  22.       </GridLayout>
  23.     );
  24.   }
  25. }
  26. ```

You may also choose to set layout properties directly on the children:

  1. ``` js
  2. import GridLayout from "react-grid-layout";

  3. class MyFirstGrid extends React.Component {
  4.   render() {
  5.     return (
  6.       <GridLayout className="layout" cols={12} rowHeight={30} width={1200}>
  7.         <div key="a" data-grid={{ x: 0, y: 0, w: 1, h: 2, static: true }}>
  8.           a
  9.         </div>
  10.         <div key="b" data-grid={{ x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 }}>
  11.           b
  12.         </div>
  13.         <div key="c" data-grid={{ x: 4, y: 0, w: 1, h: 2 }}>
  14.           c
  15.         </div>
  16.       </GridLayout>
  17.     );
  18.   }
  19. }
  20. ```

Usage without Browserify/Webpack


A module usable in a `