React-Grid-Layout
A draggable and resizable grid layout with responsive breakpoints, for Reac...
README
React-Grid-Layout
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.
GIF from production usage on BitMEX.com
Table of Contents
- Demos
- Features
- Usage
Demos
1. Showcase
1. Basic
1. Error Case
1. Toolbox
Projects Using React-Grid-Layout
- BitMEX
- Grafana
- Metabase
- HubSpot
- Reflect
- Kibana
- Graphext
- Monday
- Quadency
- Hakkiri
- Ubidots
- Statsout
_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
- Compatibility with `Version | Compatibility |
---|---|
------------ | --------------- |
>= | React |
>= | React |
>= | React |
0.8. | React |
< | React |
Installation
- ``` sh
- npm install react-grid-layout
- ```
Include the following stylesheets in your application:
- ```
- /node_modules/react-grid-layout/css/styles.css
- /node_modules/react-resizable/css/styles.css
- ```
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
- ``` js
- import GridLayout from "react-grid-layout";
- class MyFirstGrid extends React.Component {
- render() {
- // layout is an array of objects, see the demo for more complete usage
- const layout = [
- { i: "a", x: 0, y: 0, w: 1, h: 2, static: true },
- { i: "b", x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 },
- { i: "c", x: 4, y: 0, w: 1, h: 2 }
- ];
- return (
- <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>
- );
- }
- }
- ```
You may also choose to set layout properties directly on the children:
- ``` js
- import GridLayout from "react-grid-layout";
- class MyFirstGrid extends React.Component {
- render() {
- return (
- <GridLayout className="layout" cols={12} rowHeight={30} width={1200}>
- <div key="a" data-grid={{ x: 0, y: 0, w: 1, h: 2, static: true }}>
- a
- </div>
- <div key="b" data-grid={{ x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 }}>
- b
- </div>
- <div key="c" data-grid={{ x: 4, y: 0, w: 1, h: 2 }}>
- c
- </div>
- </GridLayout>
- );
- }
- }
- ```